|
@@ -4,6 +4,7 @@ import time
|
|
|
import message_pb2 as message
|
|
|
import grpc
|
|
|
import message_pb2_grpc as msg_rpc
|
|
|
+from ManualOperationWidget import ManualOperationType
|
|
|
from mqtt_async import MqttAsync
|
|
|
import google.protobuf.json_format as jtf
|
|
|
from dijkstra.Map import DijikstraMap, SpaceNode, StreetNode
|
|
@@ -37,15 +38,16 @@ class TimeStatu:
|
|
|
|
|
|
class Robot(MqttAsync):
|
|
|
|
|
|
- def __init__(self,rpc_ipport,name=""):
|
|
|
+ def __init__(self, rpc_ipport, name=""):
|
|
|
MqttAsync.__init__(self)
|
|
|
self.timedRobotStatu_ = TimeStatu(message.RobotStatu, 0)
|
|
|
self.timedNavStatu_ = TimeStatu(message.NavStatu, 0)
|
|
|
self.dataTopic_ = {}
|
|
|
- self.rpc_ipport_=rpc_ipport
|
|
|
+ self.rpc_ipport_ = rpc_ipport
|
|
|
self.messageArrivedSignal = None
|
|
|
self.currentNavData_ = None
|
|
|
self.navCmdTopic_ = None
|
|
|
+ self.speedCmdTopic = "monitor_child/speedcmd"
|
|
|
self.currentNavPathNodes_ = None
|
|
|
self.currentNavPath_ = None
|
|
|
|
|
@@ -61,6 +63,7 @@ class Robot(MqttAsync):
|
|
|
self.l_ = 0.8 # 轮长
|
|
|
self.L_ = 1.3 # 轴距
|
|
|
self.W_ = 2.5 # 宽
|
|
|
+ self.heat_ = 0 # 心跳
|
|
|
|
|
|
def Color(self):
|
|
|
if self.IsMainModeStatu():
|
|
@@ -243,7 +246,7 @@ class Robot(MqttAsync):
|
|
|
protoNode = message.PathNode()
|
|
|
protoNode.x = node.x_
|
|
|
protoNode.y = node.y_
|
|
|
- protoNode.id=node.id_
|
|
|
+ protoNode.id = node.id_
|
|
|
return protoNode
|
|
|
|
|
|
def ExecNavtask(self, autoDirect):
|
|
@@ -261,7 +264,7 @@ class Robot(MqttAsync):
|
|
|
protoStreet = self.generateProtoNode(street)
|
|
|
act = message.NewAction()
|
|
|
act.type = 1
|
|
|
- act.wheelbase=2.78
|
|
|
+ act.wheelbase = 2.78
|
|
|
act.spaceNode.CopyFrom(protoSpace)
|
|
|
act.streetNode.CopyFrom(protoStreet)
|
|
|
|
|
@@ -272,7 +275,7 @@ class Robot(MqttAsync):
|
|
|
protoStreet = self.generateProtoNode(street)
|
|
|
act = message.NewAction()
|
|
|
act.type = 2
|
|
|
- act.wheelbase=2.78
|
|
|
+ act.wheelbase = 2.78
|
|
|
act.spaceNode.CopyFrom(protoSpace)
|
|
|
act.streetNode.CopyFrom(protoStreet)
|
|
|
|
|
@@ -284,31 +287,33 @@ class Robot(MqttAsync):
|
|
|
return False
|
|
|
else:
|
|
|
cmd.newActions.add().CopyFrom(action)
|
|
|
-
|
|
|
+ print(cmd)
|
|
|
if cmd is None:
|
|
|
print("Nav cmd is None")
|
|
|
return False
|
|
|
|
|
|
- channel=grpc.insecure_channel(self.rpc_ipport_)
|
|
|
+ channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
|
stub = msg_rpc.NavExcutorStub(channel)
|
|
|
|
|
|
response = stub.Start(cmd)
|
|
|
print("client received: ", response)
|
|
|
- if not response.ret==0:
|
|
|
- print("nav failed :%s"%(response.info))
|
|
|
+ if not response.ret == 0:
|
|
|
+ print("nav failed :%s" % (response.info))
|
|
|
else:
|
|
|
print("nav completed !!!")
|
|
|
|
|
|
return True
|
|
|
|
|
|
def CreateNavPathNodesAction(self, path, autoDirect):
|
|
|
- if path is not None and self.timedRobotStatu_.timeout() == False:
|
|
|
+ # if path is not None and self.timedRobotStatu_.timeout() == False:
|
|
|
+ if 1:
|
|
|
for node in path:
|
|
|
if isinstance(node, (SpaceNode)):
|
|
|
print(" nodes must all street node")
|
|
|
return None
|
|
|
statu = self.timedRobotStatu_.statu
|
|
|
- if statu is not None:
|
|
|
+ # if statu is not None:
|
|
|
+ if 1:
|
|
|
newAction = message.NewAction()
|
|
|
size = len(path)
|
|
|
for i in range(size):
|
|
@@ -349,7 +354,7 @@ class Robot(MqttAsync):
|
|
|
cmd.newActions.add().CopyFrom(action)
|
|
|
|
|
|
print(cmd)
|
|
|
- channel=grpc.insecure_channel(self.rpc_ipport_)
|
|
|
+ channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
|
stub = msg_rpc.NavExcutorStub(channel)
|
|
|
response = stub.Start(cmd)
|
|
|
return True
|
|
@@ -443,7 +448,7 @@ class Robot(MqttAsync):
|
|
|
if mode == 2:
|
|
|
action.wheelbase = wheelbase
|
|
|
cmd.newActions.add().CopyFrom(action)
|
|
|
- channel=grpc.insecure_channel(self.rpc_ipport_)
|
|
|
+ channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
|
stub = msg_rpc.NavExcutorStub(channel)
|
|
|
response = stub.Start(cmd)
|
|
|
return False
|
|
@@ -492,7 +497,7 @@ class Robot(MqttAsync):
|
|
|
act = message.NewAction()
|
|
|
act.type = 6
|
|
|
cmd.newActions.add().CopyFrom(act)
|
|
|
- channel=grpc.insecure_channel(self.rpc_ipport_)
|
|
|
+ channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
|
stub = msg_rpc.NavExcutorStub(channel)
|
|
|
response = stub.Start(cmd)
|
|
|
return True
|
|
@@ -508,7 +513,7 @@ class Robot(MqttAsync):
|
|
|
act = message.NewAction()
|
|
|
act.type = 7
|
|
|
cmd.newActions.add().CopyFrom(act)
|
|
|
- channel=grpc.insecure_channel(self.rpc_ipport_)
|
|
|
+ channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
|
stub = msg_rpc.NavExcutorStub(channel)
|
|
|
response = stub.Start(cmd)
|
|
|
return True
|
|
@@ -517,10 +522,77 @@ class Robot(MqttAsync):
|
|
|
cmd = message.NavCmd()
|
|
|
cmd.action = 3
|
|
|
|
|
|
- channel=grpc.insecure_channel(self.rpc_ipport_)
|
|
|
+ channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
|
stub = msg_rpc.NavExcutorStub(channel)
|
|
|
|
|
|
response = stub.Cancel(cmd)
|
|
|
print("client received: ", response)
|
|
|
print(" Cancel task completed!!!")
|
|
|
return True
|
|
|
+
|
|
|
+ def ManualTask(self, current_operation):
|
|
|
+ cmd = message.ToAgvCmd()
|
|
|
+ self.heat_ += 1
|
|
|
+ self.heat_ %= 255
|
|
|
+ cmd.H = self.heat_
|
|
|
+ if self.IsMainModeStatu():
|
|
|
+ cmd.M = 2
|
|
|
+ else:
|
|
|
+ cmd.M = 1
|
|
|
+
|
|
|
+ if current_operation == ManualOperationType.eCounterclockwiseRotate:
|
|
|
+ cmd.T = 1
|
|
|
+ cmd.V = 0
|
|
|
+ cmd.W = 2.0/180*math.pi
|
|
|
+ if current_operation == ManualOperationType.eClockwiseRotate:
|
|
|
+ cmd.T = 1
|
|
|
+ cmd.V = 0
|
|
|
+ cmd.W = -2.0 / 180 * math.pi
|
|
|
+ if current_operation == ManualOperationType.eForwardMove:
|
|
|
+ cmd.T = 3
|
|
|
+ cmd.V = 0.5
|
|
|
+ cmd.W = 0
|
|
|
+ if current_operation == ManualOperationType.eBackwardMove:
|
|
|
+ cmd.T = 3
|
|
|
+ cmd.V = -0.5
|
|
|
+ cmd.W = 0
|
|
|
+ if current_operation == ManualOperationType.eLeftMove:
|
|
|
+ cmd.T = 2
|
|
|
+ cmd.V = 0.5
|
|
|
+ cmd.W = 0
|
|
|
+ if current_operation == ManualOperationType.eRightMove:
|
|
|
+ cmd.T = 2
|
|
|
+ cmd.V = -0.5
|
|
|
+ cmd.W = 0
|
|
|
+ cmd.L = self.L_
|
|
|
+ cmd.end = 1
|
|
|
+ self.publish(self.speedCmdTopic, jtf.MessageToJson(cmd))
|
|
|
+
|
|
|
+ # cmd_0 = message.ManualCmd()
|
|
|
+ # cmd_0.key = str(uuid.uuid4())
|
|
|
+ # if current_operation == ManualOperationType.eCounterclockwiseRotate:
|
|
|
+ # cmd_0.operation_type = 1
|
|
|
+ # cmd_0.velocity = 1
|
|
|
+ # if current_operation == ManualOperationType.eClockwiseRotate:
|
|
|
+ # cmd_0.operation_type = 1
|
|
|
+ # cmd_0.velocity = -1
|
|
|
+ # if current_operation == ManualOperationType.eForwardMove:
|
|
|
+ # cmd_0.operation_type = 2
|
|
|
+ # cmd_0.velocity = 1
|
|
|
+ # if current_operation == ManualOperationType.eBackwardMove:
|
|
|
+ # cmd_0.operation_type = 2
|
|
|
+ # cmd_0.velocity = -1
|
|
|
+ # if current_operation == ManualOperationType.eLeftMove:
|
|
|
+ # cmd_0.operation_type = 3
|
|
|
+ # cmd_0.velocity = 1
|
|
|
+ # if current_operation == ManualOperationType.eRightMove:
|
|
|
+ # cmd_0.operation_type = 3
|
|
|
+ # cmd_0.velocity = -1
|
|
|
+ #
|
|
|
+ # channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
|
+ # stub = msg_rpc.NavExcutorStub(channel)
|
|
|
+ # response = stub.ManualOperation(cmd_0)
|
|
|
+ # print("client received: ", response)
|
|
|
+ print(cmd)
|
|
|
+ print("ManualOperation {op_type} task completed!!!".format(op_type=current_operation))
|
|
|
+ return True
|