|
@@ -5,8 +5,10 @@ import message_pb2 as message
|
|
import grpc
|
|
import grpc
|
|
import message_pb2_grpc as msg_rpc
|
|
import message_pb2_grpc as msg_rpc
|
|
from ManualOperationWidget import ManualOperationType
|
|
from ManualOperationWidget import ManualOperationType
|
|
|
|
+from custom_define import RobotName, ActType
|
|
from mqtt_async import MqttAsync
|
|
from mqtt_async import MqttAsync
|
|
import google.protobuf.json_format as jtf
|
|
import google.protobuf.json_format as jtf
|
|
|
|
+import json
|
|
from dijkstra.Map import DijikstraMap, SpaceNode, StreetNode
|
|
from dijkstra.Map import DijikstraMap, SpaceNode, StreetNode
|
|
import uuid
|
|
import uuid
|
|
import random
|
|
import random
|
|
@@ -15,16 +17,6 @@ import Count
|
|
from sigmoid import sigmoid
|
|
from sigmoid import sigmoid
|
|
|
|
|
|
|
|
|
|
-class ActType(enum.Enum):
|
|
|
|
- eReady = 0
|
|
|
|
- eRotation = 1
|
|
|
|
- eHorizon = 2
|
|
|
|
- eVertical = 3
|
|
|
|
- eMPC = 4
|
|
|
|
- eClampOpen = 5
|
|
|
|
- eClampClose = 6
|
|
|
|
-
|
|
|
|
-
|
|
|
|
class TimeStatu:
|
|
class TimeStatu:
|
|
def __init__(self, statu=None, timeout=3):
|
|
def __init__(self, statu=None, timeout=3):
|
|
self.statu = statu
|
|
self.statu = statu
|
|
@@ -40,6 +32,7 @@ class Robot(MqttAsync):
|
|
|
|
|
|
def __init__(self, rpc_ipport, name=""):
|
|
def __init__(self, rpc_ipport, name=""):
|
|
MqttAsync.__init__(self)
|
|
MqttAsync.__init__(self)
|
|
|
|
+ self.test_speed = 0
|
|
self.timedRobotStatu_ = TimeStatu(message.RobotStatu, 0)
|
|
self.timedRobotStatu_ = TimeStatu(message.RobotStatu, 0)
|
|
self.timedNavStatu_ = TimeStatu(message.NavStatu, 0)
|
|
self.timedNavStatu_ = TimeStatu(message.NavStatu, 0)
|
|
self.dataTopic_ = {}
|
|
self.dataTopic_ = {}
|
|
@@ -47,7 +40,10 @@ class Robot(MqttAsync):
|
|
self.messageArrivedSignal = None
|
|
self.messageArrivedSignal = None
|
|
self.currentNavData_ = None
|
|
self.currentNavData_ = None
|
|
self.navCmdTopic_ = None
|
|
self.navCmdTopic_ = None
|
|
- self.speedCmdTopic = "monitor_child/speedcmd"
|
|
|
|
|
|
+ if(name == RobotName.strAGVMain):
|
|
|
|
+ self.speedCmdTopic = "monitor_child/speedcmd"
|
|
|
|
+ else:
|
|
|
|
+ self.speedCmdTopic = "monitor_child/speedcmd"
|
|
self.currentNavPathNodes_ = None
|
|
self.currentNavPathNodes_ = None
|
|
self.currentNavPath_ = None
|
|
self.currentNavPath_ = None
|
|
|
|
|
|
@@ -79,7 +75,7 @@ class Robot(MqttAsync):
|
|
def IsMainModeStatu(self):
|
|
def IsMainModeStatu(self):
|
|
if self.IsMainAgv():
|
|
if self.IsMainAgv():
|
|
if self.timedNavStatu_.timeout() == False:
|
|
if self.timedNavStatu_.timeout() == False:
|
|
- if self.timedNavStatu_.statu.move_mode == 2:
|
|
|
|
|
|
+ if self.timedNavStatu_.statu.move_mode == 1:
|
|
return True
|
|
return True
|
|
return False
|
|
return False
|
|
|
|
|
|
@@ -183,11 +179,11 @@ class Robot(MqttAsync):
|
|
阻塞直到导航完成
|
|
阻塞直到导航完成
|
|
'''
|
|
'''
|
|
|
|
|
|
- def Navigatting(self, begId, targetId, autoDirect, task_type="None"):
|
|
|
|
|
|
+ def Navigatting(self, begId, targetId, autoDirect, wheelbase=0, task_type="None"):
|
|
print("nav")
|
|
print("nav")
|
|
self.GeneratePath(begId, targetId, task_type=task_type)
|
|
self.GeneratePath(begId, targetId, task_type=task_type)
|
|
# self.ExecPathNodes(autoDirect)
|
|
# self.ExecPathNodes(autoDirect)
|
|
- self.ExecNavtask(autoDirect)
|
|
|
|
|
|
+ self.ExecNavtask(autoDirect, wheelbase)
|
|
|
|
|
|
if self.IsMainModeStatu():
|
|
if self.IsMainModeStatu():
|
|
Count.TestCount().loadCountAdd()
|
|
Count.TestCount().loadCountAdd()
|
|
@@ -249,7 +245,7 @@ class Robot(MqttAsync):
|
|
protoNode.id = node.id_
|
|
protoNode.id = node.id_
|
|
return protoNode
|
|
return protoNode
|
|
|
|
|
|
- def ExecNavtask(self, autoDirect):
|
|
|
|
|
|
+ def ExecNavtask(self, autoDirect, wheelbase=0):
|
|
cmd = message.NavCmd()
|
|
cmd = message.NavCmd()
|
|
key = str(uuid.uuid4())
|
|
key = str(uuid.uuid4())
|
|
cmd.key = key
|
|
cmd.key = key
|
|
@@ -264,7 +260,7 @@ class Robot(MqttAsync):
|
|
protoStreet = self.generateProtoNode(street)
|
|
protoStreet = self.generateProtoNode(street)
|
|
act = message.NewAction()
|
|
act = message.NewAction()
|
|
act.type = 1
|
|
act.type = 1
|
|
- act.wheelbase = 2.78
|
|
|
|
|
|
+ act.wheelbase = wheelbase
|
|
act.spaceNode.CopyFrom(protoSpace)
|
|
act.spaceNode.CopyFrom(protoSpace)
|
|
act.streetNode.CopyFrom(protoStreet)
|
|
act.streetNode.CopyFrom(protoStreet)
|
|
|
|
|
|
@@ -275,7 +271,7 @@ class Robot(MqttAsync):
|
|
protoStreet = self.generateProtoNode(street)
|
|
protoStreet = self.generateProtoNode(street)
|
|
act = message.NewAction()
|
|
act = message.NewAction()
|
|
act.type = 2
|
|
act.type = 2
|
|
- act.wheelbase = 2.78
|
|
|
|
|
|
+ act.wheelbase = wheelbase
|
|
act.spaceNode.CopyFrom(protoSpace)
|
|
act.spaceNode.CopyFrom(protoSpace)
|
|
act.streetNode.CopyFrom(protoStreet)
|
|
act.streetNode.CopyFrom(protoStreet)
|
|
|
|
|
|
@@ -294,7 +290,6 @@ class Robot(MqttAsync):
|
|
|
|
|
|
channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
stub = msg_rpc.NavExcutorStub(channel)
|
|
stub = msg_rpc.NavExcutorStub(channel)
|
|
-
|
|
|
|
response = stub.Start(cmd)
|
|
response = stub.Start(cmd)
|
|
print("client received: ", response)
|
|
print("client received: ", response)
|
|
if not response.ret == 0:
|
|
if not response.ret == 0:
|
|
@@ -368,10 +363,10 @@ class Robot(MqttAsync):
|
|
y_offset = 1.2
|
|
y_offset = 1.2
|
|
dy = 0
|
|
dy = 0
|
|
# if self.IsMainAgv() or self.name_ == "AgvMain":
|
|
# if self.IsMainAgv() or self.name_ == "AgvMain":
|
|
- if self.name_ == "AgvMain":
|
|
|
|
|
|
+ if self.name_ == RobotName.strAGVMain:
|
|
dy = 1
|
|
dy = 1
|
|
# if not self.IsMainAgv() or self == "AGV2":
|
|
# if not self.IsMainAgv() or self == "AGV2":
|
|
- if self.name_ == "AGV2":
|
|
|
|
|
|
+ if self.name_ == RobotName.strAGV2:
|
|
dy = -1
|
|
dy = -1
|
|
print("dy:", dy)
|
|
print("dy:", dy)
|
|
for node in adjusted_path:
|
|
for node in adjusted_path:
|
|
@@ -445,7 +440,7 @@ class Robot(MqttAsync):
|
|
action = message.NewAction()
|
|
action = message.NewAction()
|
|
action.type = 8
|
|
action.type = 8
|
|
action.changedMode = mode
|
|
action.changedMode = mode
|
|
- if mode == 2:
|
|
|
|
|
|
+ if mode == 1:
|
|
action.wheelbase = wheelbase
|
|
action.wheelbase = wheelbase
|
|
cmd.newActions.add().CopyFrom(action)
|
|
cmd.newActions.add().CopyFrom(action)
|
|
channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
@@ -530,43 +525,57 @@ class Robot(MqttAsync):
|
|
print(" Cancel task completed!!!")
|
|
print(" Cancel task completed!!!")
|
|
return True
|
|
return True
|
|
|
|
|
|
- def ManualTask(self, current_operation):
|
|
|
|
|
|
+ def ManualTask(self, current_operation, step_acc):
|
|
|
|
+ if self.IsNavigating():
|
|
|
|
+ print("AGV is navigating!!!")
|
|
|
|
+ return
|
|
|
|
+
|
|
cmd = message.ToAgvCmd()
|
|
cmd = message.ToAgvCmd()
|
|
self.heat_ += 1
|
|
self.heat_ += 1
|
|
self.heat_ %= 255
|
|
self.heat_ %= 255
|
|
cmd.H = self.heat_
|
|
cmd.H = self.heat_
|
|
if self.IsMainModeStatu():
|
|
if self.IsMainModeStatu():
|
|
- cmd.M = 2
|
|
|
|
- else:
|
|
|
|
cmd.M = 1
|
|
cmd.M = 1
|
|
|
|
+ else:
|
|
|
|
+ cmd.M = 0
|
|
|
|
|
|
if current_operation == ManualOperationType.eCounterclockwiseRotate:
|
|
if current_operation == ManualOperationType.eCounterclockwiseRotate:
|
|
cmd.T = 1
|
|
cmd.T = 1
|
|
cmd.V = 0
|
|
cmd.V = 0
|
|
- cmd.W = 2.0/180*math.pi
|
|
|
|
|
|
+ cmd.W = 4.0 / 180 * math.pi * sigmoid(step_acc, 0, 1)
|
|
if current_operation == ManualOperationType.eClockwiseRotate:
|
|
if current_operation == ManualOperationType.eClockwiseRotate:
|
|
cmd.T = 1
|
|
cmd.T = 1
|
|
cmd.V = 0
|
|
cmd.V = 0
|
|
- cmd.W = -2.0 / 180 * math.pi
|
|
|
|
|
|
+ cmd.W = -4.0 / 180 * math.pi * sigmoid(step_acc, 0, 1)
|
|
if current_operation == ManualOperationType.eForwardMove:
|
|
if current_operation == ManualOperationType.eForwardMove:
|
|
cmd.T = 3
|
|
cmd.T = 3
|
|
- cmd.V = 0.5
|
|
|
|
|
|
+ cmd.V = 0.6 * sigmoid(step_acc, 0, 1)
|
|
cmd.W = 0
|
|
cmd.W = 0
|
|
if current_operation == ManualOperationType.eBackwardMove:
|
|
if current_operation == ManualOperationType.eBackwardMove:
|
|
cmd.T = 3
|
|
cmd.T = 3
|
|
- cmd.V = -0.5
|
|
|
|
|
|
+ cmd.V = -0.6 * sigmoid(step_acc, 0, 1)
|
|
cmd.W = 0
|
|
cmd.W = 0
|
|
if current_operation == ManualOperationType.eLeftMove:
|
|
if current_operation == ManualOperationType.eLeftMove:
|
|
cmd.T = 2
|
|
cmd.T = 2
|
|
- cmd.V = 0.5
|
|
|
|
|
|
+ cmd.V = 0.6 * sigmoid(step_acc, 0, 1)
|
|
cmd.W = 0
|
|
cmd.W = 0
|
|
if current_operation == ManualOperationType.eRightMove:
|
|
if current_operation == ManualOperationType.eRightMove:
|
|
cmd.T = 2
|
|
cmd.T = 2
|
|
- cmd.V = -0.5
|
|
|
|
|
|
+ cmd.V = -0.6 * sigmoid(step_acc, 0, 1)
|
|
cmd.W = 0
|
|
cmd.W = 0
|
|
cmd.L = self.L_
|
|
cmd.L = self.L_
|
|
cmd.end = 1
|
|
cmd.end = 1
|
|
- self.publish(self.speedCmdTopic, jtf.MessageToJson(cmd))
|
|
|
|
|
|
+
|
|
|
|
+ # 处理为json格式
|
|
|
|
+ cmd_dict = {}
|
|
|
|
+ for field in cmd.DESCRIPTOR.fields:
|
|
|
|
+ cmd_dict[field.name] = field.default_value
|
|
|
|
+ for field, value in cmd.ListFields():
|
|
|
|
+ cmd_dict[field.name] = value
|
|
|
|
+ cmd_json = json.dumps(cmd_dict, indent=None, separators=(',', ':'))
|
|
|
|
+ self.publish(self.speedCmdTopic, cmd_json)
|
|
|
|
+
|
|
|
|
+ print(cmd_json)
|
|
|
|
|
|
# cmd_0 = message.ManualCmd()
|
|
# cmd_0 = message.ManualCmd()
|
|
# cmd_0.key = str(uuid.uuid4())
|
|
# cmd_0.key = str(uuid.uuid4())
|
|
@@ -593,6 +602,6 @@ class Robot(MqttAsync):
|
|
# stub = msg_rpc.NavExcutorStub(channel)
|
|
# stub = msg_rpc.NavExcutorStub(channel)
|
|
# response = stub.ManualOperation(cmd_0)
|
|
# response = stub.ManualOperation(cmd_0)
|
|
# print("client received: ", response)
|
|
# print("client received: ", response)
|
|
- print(cmd)
|
|
|
|
|
|
+
|
|
print("ManualOperation {op_type} task completed!!!".format(op_type=current_operation))
|
|
print("ManualOperation {op_type} task completed!!!".format(op_type=current_operation))
|
|
return True
|
|
return True
|