|
@@ -1,22 +1,25 @@
|
|
|
+import copy
|
|
|
import enum
|
|
|
import time
|
|
|
import message_pb2 as message
|
|
|
from mqtt_async import MqttAsync
|
|
|
import google.protobuf.json_format as jtf
|
|
|
-from dijkstra.Map import DijikstraMap,SpaceNode,StreetNode
|
|
|
+from dijkstra.Map import DijikstraMap, SpaceNode, StreetNode
|
|
|
import uuid
|
|
|
import random
|
|
|
import math
|
|
|
import Count
|
|
|
+from sigmoid import sigmoid
|
|
|
+
|
|
|
|
|
|
class ActType(enum.Enum):
|
|
|
- eReady=0
|
|
|
- eRotation=1
|
|
|
- eHorizon=2
|
|
|
- eVertical=3
|
|
|
- eMPC=4
|
|
|
- eClampOpen=5
|
|
|
- eClampClose=6
|
|
|
+ eReady = 0
|
|
|
+ eRotation = 1
|
|
|
+ eHorizon = 2
|
|
|
+ eVertical = 3
|
|
|
+ eMPC = 4
|
|
|
+ eClampOpen = 5
|
|
|
+ eClampClose = 6
|
|
|
|
|
|
|
|
|
class TimeStatu:
|
|
@@ -29,6 +32,7 @@ class TimeStatu:
|
|
|
tm = time.time()
|
|
|
return tm - self.time > self.timeout_ms or self.statu == None
|
|
|
|
|
|
+
|
|
|
class Robot(MqttAsync):
|
|
|
|
|
|
def __init__(self, name=""):
|
|
@@ -46,10 +50,10 @@ class Robot(MqttAsync):
|
|
|
self.robotColor_ = [0.7, 0.2, 0.3] # agv当前颜色
|
|
|
self.name_ = name
|
|
|
|
|
|
- self.begId_="------"
|
|
|
- self.targetId_="------"
|
|
|
+ self.begId_ = "------"
|
|
|
+ self.targetId_ = "------"
|
|
|
|
|
|
- self.autoTest_=False
|
|
|
+ self.autoTest_ = False
|
|
|
|
|
|
self.l_ = 0.8 # 轮长
|
|
|
self.L_ = 1.3 # 轴距
|
|
@@ -132,38 +136,51 @@ class Robot(MqttAsync):
|
|
|
return self.timedNavStatu_.timeout() == False and self.timedRobotStatu_.timeout() == False
|
|
|
|
|
|
def IsNavigating(self):
|
|
|
- return not self.ActionType()==ActType.eReady
|
|
|
+ return not self.ActionType() == ActType.eReady
|
|
|
'''if self.timedNavStatu_.timeout() == False:
|
|
|
key = self.timedNavStatu_.statu.key
|
|
|
if key == "" or key == None:
|
|
|
return False
|
|
|
return True'''
|
|
|
|
|
|
- def GeneratePath(self, begID, endID):
|
|
|
+ def GeneratePath(self, begID, endID, task_type="None"):
|
|
|
self.currentNavPathNodes_ = DijikstraMap().GetShortestPath(begID, endID)
|
|
|
+
|
|
|
+ if task_type == "DoubleAGV":
|
|
|
+ print("AdjustPath------------------")
|
|
|
+ if self.IsMainModeStatu() is False:
|
|
|
+ print("原始路径:")
|
|
|
+ for node in self.currentNavPathNodes_:
|
|
|
+ print(node.id_, node.y_)
|
|
|
+ self.currentNavPathNodes_ = self.AdjustPath(self.currentNavPathNodes_)
|
|
|
+ print("修改路径:")
|
|
|
+ for node in self.currentNavPathNodes_:
|
|
|
+ print(node.id_, node.y_)
|
|
|
+
|
|
|
self.currentNavPath_ = DijikstraMap().CreatePath(self.currentNavPathNodes_, 0.5)
|
|
|
if self.currentNavPathNodes_ is not None and self.currentNavPath_ is not None:
|
|
|
- self.begId_=begID
|
|
|
- self.targetId_=endID
|
|
|
+ self.begId_ = begID
|
|
|
+ self.targetId_ = endID
|
|
|
return True
|
|
|
return False
|
|
|
|
|
|
-
|
|
|
def PositionId(self):
|
|
|
if self.timedRobotStatu_.timeout():
|
|
|
return None
|
|
|
- x=self.timedRobotStatu_.statu.x
|
|
|
- y=self.timedRobotStatu_.statu.y
|
|
|
+ x = self.timedRobotStatu_.statu.x
|
|
|
+ y = self.timedRobotStatu_.statu.y
|
|
|
djks_map = DijikstraMap()
|
|
|
[label, pt] = djks_map.findNeastNode([x, y])
|
|
|
- return [label,pt]
|
|
|
+ return [label, pt]
|
|
|
+
|
|
|
'''
|
|
|
阻塞直到导航完成
|
|
|
'''
|
|
|
- def Navigatting(self, begId, targetId,autoDirect):
|
|
|
+
|
|
|
+ def Navigatting(self, begId, targetId, autoDirect, task_type="None"):
|
|
|
print("nav")
|
|
|
- self.GeneratePath(begId, targetId)
|
|
|
- #self.ExecPathNodes(autoDirect)
|
|
|
+ self.GeneratePath(begId, targetId, task_type=task_type)
|
|
|
+ # self.ExecPathNodes(autoDirect)
|
|
|
self.ExecNavtask(autoDirect)
|
|
|
while self.IsNavigating() == True:
|
|
|
'''if self.Connected() == False:
|
|
@@ -180,92 +197,104 @@ class Robot(MqttAsync):
|
|
|
|
|
|
return True
|
|
|
|
|
|
- def AutoTestNavClamp(self,begId,targetId):
|
|
|
- beg=begId
|
|
|
- target=targetId
|
|
|
+ def AutoTestNavClamp(self, begId, targetId):
|
|
|
+ beg = begId
|
|
|
+ target = targetId
|
|
|
while self.autoTest_:
|
|
|
- if self.TestNavClampOnce(beg,target)==False:
|
|
|
+ if self.TestNavClampOnce(beg, target) == False:
|
|
|
print(" quit auto Test")
|
|
|
break
|
|
|
print("1111")
|
|
|
- posInfo=self.PositionId()
|
|
|
+ posInfo = self.PositionId()
|
|
|
if posInfo is not None:
|
|
|
- [label,pt]=posInfo
|
|
|
- beg=label
|
|
|
- print("beg",beg)
|
|
|
- node=DijikstraMap().GetVertex(beg)
|
|
|
+ [label, pt] = posInfo
|
|
|
+ beg = label
|
|
|
+ print("beg", beg)
|
|
|
+ node = DijikstraMap().GetVertex(beg)
|
|
|
|
|
|
if node is not None:
|
|
|
- if isinstance(node,(SpaceNode)):
|
|
|
- target="O"
|
|
|
- if isinstance(node,(StreetNode)):
|
|
|
- end_nodes=["E","B","C","D"]
|
|
|
- id=random.randint(0,1000)%4
|
|
|
- target=end_nodes[id]
|
|
|
- print("3333",target)
|
|
|
- print(" Next nav clamp cmd,%s to %s"%(beg,target))
|
|
|
+ if isinstance(node, (SpaceNode)):
|
|
|
+ target = "O"
|
|
|
+ if isinstance(node, (StreetNode)):
|
|
|
+ end_nodes = ["E", "B", "C", "D"]
|
|
|
+ id = random.randint(0, 1000) % 4
|
|
|
+ target = end_nodes[id]
|
|
|
+ print("3333", target)
|
|
|
+ print(" Next nav clamp cmd,%s to %s" % (beg, target))
|
|
|
|
|
|
def ActionType(self):
|
|
|
if self.timedNavStatu_.timeout() == False:
|
|
|
- runningStatu=self.timedNavStatu_.statu
|
|
|
- if runningStatu.statu==0:
|
|
|
+ runningStatu = self.timedNavStatu_.statu
|
|
|
+ if runningStatu.statu == 0:
|
|
|
return ActType.eReady
|
|
|
- if runningStatu.statu==1:
|
|
|
+ if runningStatu.statu == 1:
|
|
|
return ActType.eRotation
|
|
|
- if runningStatu.statu==2:
|
|
|
+ if runningStatu.statu == 2:
|
|
|
return ActType.eHorizon
|
|
|
- if runningStatu.statu==3:
|
|
|
+ if runningStatu.statu == 3:
|
|
|
return ActType.eVertical
|
|
|
- if runningStatu.statu==4:
|
|
|
+ if runningStatu.statu == 4:
|
|
|
return ActType.eMPC
|
|
|
- if runningStatu.statu==5:
|
|
|
+ if runningStatu.statu == 5:
|
|
|
return ActType.eClampOpen
|
|
|
- if runningStatu.statu==6:
|
|
|
+ if runningStatu.statu == 6:
|
|
|
return ActType.eClampClose
|
|
|
else:
|
|
|
return ActType.eReady
|
|
|
|
|
|
@staticmethod
|
|
|
- def generateProtoNode(node,accuracy):
|
|
|
- [dx,dy,dyaw]=accuracy
|
|
|
- protoNode=message.PathNode()
|
|
|
- protoNode.pose.x=node.x_
|
|
|
- protoNode.pose.y=node.y_
|
|
|
- protoNode.accuracy.x=dx
|
|
|
- protoNode.accuracy.y=dx
|
|
|
- protoNode.accuracy.theta=dyaw
|
|
|
+ def generateProtoNode(node, accuracy):
|
|
|
+ [dx, dy, dyaw] = accuracy
|
|
|
+ protoNode = message.PathNode()
|
|
|
+ protoNode.x = node.x_
|
|
|
+ protoNode.y = node.y_
|
|
|
+ protoNode.l = dx
|
|
|
+ protoNode.w = dy
|
|
|
+ protoNode.theta = dyaw
|
|
|
return protoNode
|
|
|
- def ExecNavtask(self,autoDirect):
|
|
|
- cmd=message.NavCmd()
|
|
|
+
|
|
|
+ def ExecNavtask(self, autoDirect):
|
|
|
+ cmd = message.NavCmd()
|
|
|
key = str(uuid.uuid4())
|
|
|
cmd.key = key
|
|
|
- cmd.action=0
|
|
|
-
|
|
|
- limitMPC_v=message.SpeedLimit()
|
|
|
- limitRotate=message.SpeedLimit()
|
|
|
- limAdjustV=message.SpeedLimit()
|
|
|
- limitAdjustH=message.SpeedLimit()
|
|
|
- limitInOutV=message.SpeedLimit()
|
|
|
- limitMPC_v.min=0.03
|
|
|
- limitMPC_v.max=1.2
|
|
|
- limitRotate.min=3*math.pi/180.0
|
|
|
- limitRotate.max=25*math.pi/180.0
|
|
|
- limAdjustV.min=0.03
|
|
|
- limAdjustV.max=0.5
|
|
|
- limitAdjustH.min=0.03
|
|
|
- limitAdjustH.max=0.3
|
|
|
- limitInOutV.min=0.03
|
|
|
- limitInOutV.max=0.8
|
|
|
-
|
|
|
- actions=self.SplitPath(self.currentNavPathNodes_)
|
|
|
+ cmd.action = 0
|
|
|
+
|
|
|
+ limitMPC_v = message.SpeedLimit()
|
|
|
+ limitRotate = message.SpeedLimit()
|
|
|
+ limAdjustV = message.SpeedLimit()
|
|
|
+ limitAdjustH = message.SpeedLimit()
|
|
|
+ limitInOutV = message.SpeedLimit()
|
|
|
+ limitMPC_v.min = 0.03
|
|
|
+ limitMPC_v.max = 1.2
|
|
|
+ limitRotate.min = 3 * math.pi / 180.0
|
|
|
+ limitRotate.max = 25 * math.pi / 180.0
|
|
|
+ limAdjustV.min = 0.03
|
|
|
+ limAdjustV.max = 0.5
|
|
|
+ limitAdjustH.min = 0.03
|
|
|
+ limitAdjustH.max = 0.3
|
|
|
+ limitInOutV.min = 0.03
|
|
|
+ limitInOutV.max = 0.8
|
|
|
+
|
|
|
+ # if task_type == "DoubleAGV":
|
|
|
+ # print("AdjustPath------------------")
|
|
|
+ # if self.IsMainModeStatu() is False:
|
|
|
+ # print("原始路径:")
|
|
|
+ # for node in self.currentNavPathNodes_:
|
|
|
+ # print(node.id_, node.y_)
|
|
|
+ # self.currentNavPathNodes_ = self.AdjustPath(self.currentNavPathNodes_)
|
|
|
+ # print("修改路径:")
|
|
|
+ # for node in self.currentNavPathNodes_:
|
|
|
+ # print(node.id_, node.y_)
|
|
|
+
|
|
|
+ actions = self.SplitPath(self.currentNavPathNodes_)
|
|
|
for action in actions:
|
|
|
- [type,nodes]=action
|
|
|
- if type=="input":
|
|
|
- [street,space]=nodes
|
|
|
- protoSpace=self.generateProtoNode(space,[0.05,0.05,0.7*math.pi/180.0])
|
|
|
- protoStreet=self.generateProtoNode(street,[0.05,0.05,1*math.pi/180.0])
|
|
|
- act=message.NewAction()
|
|
|
- act.type=1
|
|
|
+ [type, nodes] = action
|
|
|
+ if type == "input":
|
|
|
+ [street, space] = nodes
|
|
|
+ protoSpace = self.generateProtoNode(space, [0.05, 0.05, 0.7 * math.pi / 180.0])
|
|
|
+ protoStreet = self.generateProtoNode(street, [0.05, 0.05, 1 * math.pi / 180.0])
|
|
|
+ act = message.NewAction()
|
|
|
+ act.type = 1
|
|
|
act.spaceNode.CopyFrom(protoSpace)
|
|
|
act.streetNode.CopyFrom(protoStreet)
|
|
|
act.NodeAngularLimit.CopyFrom(limitRotate)
|
|
@@ -273,12 +302,12 @@ class Robot(MqttAsync):
|
|
|
act.adjustVelocitylimit.CopyFrom(limAdjustV)
|
|
|
act.adjustHorizonLimit.CopyFrom(limitAdjustH)
|
|
|
cmd.newActions.add().CopyFrom(act)
|
|
|
- if type=="output":
|
|
|
- [space,street]=nodes
|
|
|
- protoSpace=self.generateProtoNode(space,[0.05,0.05,0.7*math.pi/180.0])
|
|
|
- protoStreet=self.generateProtoNode(street,[0.05,0.05,1*math.pi/180.0])
|
|
|
- act=message.NewAction()
|
|
|
- act.type=2
|
|
|
+ if type == "output":
|
|
|
+ [space, street] = nodes
|
|
|
+ protoSpace = self.generateProtoNode(space, [0.05, 0.05, 0.7 * math.pi / 180.0])
|
|
|
+ protoStreet = self.generateProtoNode(street, [0.05, 0.05, 1 * math.pi / 180.0])
|
|
|
+ act = message.NewAction()
|
|
|
+ act.type = 2
|
|
|
act.spaceNode.CopyFrom(protoSpace)
|
|
|
act.streetNode.CopyFrom(protoStreet)
|
|
|
act.InOutVLimit.CopyFrom(limitInOutV)
|
|
@@ -286,8 +315,8 @@ class Robot(MqttAsync):
|
|
|
act.adjustVelocitylimit.CopyFrom(limAdjustV)
|
|
|
act.adjustHorizonLimit.CopyFrom(limitAdjustH)
|
|
|
cmd.newActions.add().CopyFrom(act)
|
|
|
- if type=="nav":
|
|
|
- action =self.CreateNavPathNodesAction(nodes,autoDirect)
|
|
|
+ if type == "nav":
|
|
|
+ action = self.CreateNavPathNodesAction(nodes, autoDirect)
|
|
|
if action is None:
|
|
|
print("Nav cmd is None")
|
|
|
return False
|
|
@@ -298,48 +327,50 @@ class Robot(MqttAsync):
|
|
|
print("Nav cmd is None")
|
|
|
return False
|
|
|
|
|
|
- count=3
|
|
|
- while self.ActionType() == ActType.eReady and count>0:
|
|
|
+ count = 3
|
|
|
+ while self.ActionType() == ActType.eReady and count > 0:
|
|
|
self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
- count-=1
|
|
|
+ count -= 1
|
|
|
time.sleep(1)
|
|
|
print("send nav cmd completed!!!")
|
|
|
return True
|
|
|
- def CreateNavPathNodesAction(self,path,autoDirect):
|
|
|
+
|
|
|
+ def CreateNavPathNodesAction(self, path, autoDirect):
|
|
|
if path is not None and self.timedRobotStatu_.timeout() == False:
|
|
|
for node in path:
|
|
|
- if isinstance(node,(SpaceNode)):
|
|
|
+ if isinstance(node, (SpaceNode)):
|
|
|
print(" nodes must all street node")
|
|
|
return None
|
|
|
statu = self.timedRobotStatu_.statu
|
|
|
if statu is not None:
|
|
|
- newAction=message.NewAction()
|
|
|
- limitMPC_v=message.SpeedLimit()
|
|
|
- limitRotate=message.SpeedLimit()
|
|
|
- limAdjustV=message.SpeedLimit()
|
|
|
- limitAdjustH=message.SpeedLimit()
|
|
|
- limitMPC_v.min=0.03
|
|
|
- limitMPC_v.max=1.5
|
|
|
- limitRotate.min=3*math.pi/180.0
|
|
|
- limitRotate.max=25*math.pi/180.0
|
|
|
- limAdjustV.min=0.03
|
|
|
- limAdjustV.max=0.3
|
|
|
- limitAdjustH.min=0.03
|
|
|
- limitAdjustH.max=0.3
|
|
|
-
|
|
|
- count=0
|
|
|
- size=len(path)
|
|
|
+ newAction = message.NewAction()
|
|
|
+ limitMPC_v = message.SpeedLimit()
|
|
|
+ limitRotate = message.SpeedLimit()
|
|
|
+ limAdjustV = message.SpeedLimit()
|
|
|
+ limitAdjustH = message.SpeedLimit()
|
|
|
+ limitMPC_v.min = 0.03
|
|
|
+ limitMPC_v.max = 1.5
|
|
|
+ limitRotate.min = 3 * math.pi / 180.0
|
|
|
+ limitRotate.max = 25 * math.pi / 180.0
|
|
|
+ limAdjustV.min = 0.03
|
|
|
+ limAdjustV.max = 0.3
|
|
|
+ limitAdjustH.min = 0.03
|
|
|
+ limitAdjustH.max = 0.3
|
|
|
+
|
|
|
+ count = 0
|
|
|
+ size = len(path)
|
|
|
for i in range(size):
|
|
|
- node=path[i]
|
|
|
- pose=message.Pose2d()
|
|
|
- accuracy=message.Pose2d()
|
|
|
- pose.x=node.x_
|
|
|
- pose.y=node.y_
|
|
|
- if i+1<size:
|
|
|
- next=path[i+1]
|
|
|
+ node = path[i]
|
|
|
+ pathNode = message.PathNode()
|
|
|
+ pathNode.x = node.x_
|
|
|
+ pathNode.y = node.y_
|
|
|
+ distance = 0
|
|
|
+ if i + 1 < size:
|
|
|
+ next = path[i + 1]
|
|
|
vector = [next.x_ - node.x_, next.y_ - node.y_]
|
|
|
dx = vector[0]
|
|
|
dy = vector[1]
|
|
|
+ distance = math.sqrt(dx * dx + dy * dy)
|
|
|
yaw = math.asin(dy / math.sqrt(dx * dx + dy * dy))
|
|
|
if yaw >= 0:
|
|
|
if dx < 0:
|
|
@@ -347,31 +378,23 @@ class Robot(MqttAsync):
|
|
|
if yaw < 0:
|
|
|
if dx < 0:
|
|
|
yaw = -math.pi - yaw
|
|
|
- pose.theta=yaw
|
|
|
+ pathNode.theta = -yaw
|
|
|
else:
|
|
|
- pose.theta=0
|
|
|
+ pathNode.theta = 0
|
|
|
|
|
|
- if self.IsMainModeStatu() and count==0:
|
|
|
- accuracy.x=0.05
|
|
|
- accuracy.y=0.1
|
|
|
- accuracy.theta=0.5*math.pi/(180.0)
|
|
|
|
|
|
- if count==size-1:
|
|
|
- accuracy.x=0.02
|
|
|
- accuracy.y=0.02
|
|
|
- accuracy.theta=1*math.pi/(180.0)
|
|
|
+ if self.IsMainModeStatu():
|
|
|
+ pathNode.l = 0.15
|
|
|
+ pathNode.w = 0.05
|
|
|
else:
|
|
|
- accuracy.x=0.05
|
|
|
- accuracy.y=0.1
|
|
|
- accuracy.theta=2*math.pi/180.0
|
|
|
- count+=1
|
|
|
-
|
|
|
- pathNode=message.PathNode()
|
|
|
- pathNode.pose.CopyFrom(pose)
|
|
|
- pathNode.accuracy.CopyFrom(accuracy)
|
|
|
- newAction.type=4
|
|
|
+ pathNode.l = 0.3
|
|
|
+ pathNode.w = 0.1
|
|
|
+
|
|
|
+ count += 1
|
|
|
+
|
|
|
+ newAction.type = 4
|
|
|
if autoDirect:
|
|
|
- newAction.type=3
|
|
|
+ newAction.type = 3
|
|
|
newAction.pathNodes.add().CopyFrom(pathNode)
|
|
|
newAction.NodeVelocityLimit.CopyFrom(limitMPC_v)
|
|
|
newAction.NodeAngularLimit.CopyFrom(limitRotate)
|
|
@@ -383,80 +406,108 @@ class Robot(MqttAsync):
|
|
|
else:
|
|
|
print("current path is none")
|
|
|
return None
|
|
|
- def ExecPathNodes(self,autoDirect):
|
|
|
+
|
|
|
+ def ExecPathNodes(self, autoDirect):
|
|
|
if self.navCmdTopic_ == None:
|
|
|
print("Robot has not set nav cmd topic")
|
|
|
return False
|
|
|
- if not self.ActionType()==ActType.eReady:
|
|
|
+ if not self.ActionType() == ActType.eReady:
|
|
|
print(" robot is navigating ,key:%s" % (self.timedNavStatu_.statu.key))
|
|
|
return False
|
|
|
|
|
|
cmd = message.NavCmd()
|
|
|
key = str(uuid.uuid4())
|
|
|
cmd.key = key
|
|
|
- cmd.action=0
|
|
|
+ cmd.action = 0
|
|
|
|
|
|
- action =self.CreateNavPathNodesAction(self.currentNavPathNodes_,autoDirect)
|
|
|
+ action = self.CreateNavPathNodesAction(self.currentNavPathNodes_, autoDirect)
|
|
|
if action is None:
|
|
|
print("Nav cmd is None")
|
|
|
return False
|
|
|
cmd.newActions.add().CopyFrom(action)
|
|
|
|
|
|
print(cmd)
|
|
|
- published=False
|
|
|
+ published = False
|
|
|
while self.IsNavigating() == False:
|
|
|
if not self.ActionType() == ActType.eReady:
|
|
|
- published=True
|
|
|
- if published==False:
|
|
|
+ published = True
|
|
|
+ if published == False:
|
|
|
self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
time.sleep(1)
|
|
|
print("send nav cmd completed!!!")
|
|
|
return True
|
|
|
|
|
|
+ '''
|
|
|
+ 根据AGV单车的起始位置调整路径
|
|
|
+ '''
|
|
|
+
|
|
|
+ def AdjustPath(self, path):
|
|
|
+ adjusted_path = copy.deepcopy(path)
|
|
|
+ y_offset = 1.2
|
|
|
+ dy = 0
|
|
|
+ # if self.IsMainAgv() or self.name_ == "AgvMain":
|
|
|
+ if self.name_ == "AgvMain":
|
|
|
+ dy = 1
|
|
|
+ # if not self.IsMainAgv() or self == "AGV2":
|
|
|
+ if self.name_ == "AGV2":
|
|
|
+ dy = -1
|
|
|
+ print("dy:", dy)
|
|
|
+ for node in adjusted_path:
|
|
|
+ if isinstance(node, StreetNode):
|
|
|
+ if dy > 0:
|
|
|
+ node.y_ += y_offset
|
|
|
+ elif dy < 0:
|
|
|
+ node.y_ -= y_offset
|
|
|
+ else:
|
|
|
+ pass
|
|
|
+
|
|
|
+ return adjusted_path
|
|
|
+
|
|
|
'''
|
|
|
拆分路径,生成动作集,input:入库动作,nav:导航动作,output:出库动作
|
|
|
'''
|
|
|
- def SplitPath(self,path):
|
|
|
|
|
|
- space_count=0
|
|
|
+ def SplitPath(self, path):
|
|
|
+
|
|
|
+ space_count = 0
|
|
|
for i in range(len(path)):
|
|
|
- if isinstance(path[i],(SpaceNode)):
|
|
|
- space_count+=1
|
|
|
- if i==0 or i==len(path)-1:
|
|
|
+ if isinstance(path[i], (SpaceNode)):
|
|
|
+ space_count += 1
|
|
|
+ if i == 0 or i == len(path) - 1:
|
|
|
pass
|
|
|
else:
|
|
|
print("Error: space node is not first/last of path")
|
|
|
return None
|
|
|
|
|
|
- actions=[]
|
|
|
- lastNode=None
|
|
|
+ actions = []
|
|
|
+ lastNode = None
|
|
|
|
|
|
- navIndex=-1
|
|
|
+ navIndex = -1
|
|
|
for node in path:
|
|
|
- if lastNode==None:
|
|
|
- lastNode=node
|
|
|
+ if lastNode == None:
|
|
|
+ lastNode = node
|
|
|
continue
|
|
|
|
|
|
- if isinstance(node,(SpaceNode)): #当前点是车位点
|
|
|
- if isinstance(lastNode,(SpaceNode)): #上一点为车位点
|
|
|
+ if isinstance(node, (SpaceNode)): # 当前点是车位点
|
|
|
+ if isinstance(lastNode, (SpaceNode)): # 上一点为车位点
|
|
|
print("Error: last node and current node is space node ")
|
|
|
- lastNode=None
|
|
|
+ lastNode = None
|
|
|
continue
|
|
|
- elif isinstance(lastNode,(StreetNode)): #上一点为马路点,则动作为入库
|
|
|
- actions.append(["input",[lastNode,node]])
|
|
|
- lastNode=None
|
|
|
+ elif isinstance(lastNode, (StreetNode)): # 上一点为马路点,则动作为入库
|
|
|
+ actions.append(["input", [lastNode, node]])
|
|
|
+ lastNode = None
|
|
|
continue
|
|
|
|
|
|
- if isinstance(node,(StreetNode)):
|
|
|
- if isinstance(lastNode,(SpaceNode)): #上一点为车位点, 出库
|
|
|
- actions.append(["output",[lastNode,node]])
|
|
|
+ if isinstance(node, (StreetNode)):
|
|
|
+ if isinstance(lastNode, (SpaceNode)): # 上一点为车位点, 出库
|
|
|
+ actions.append(["output", [lastNode, node]])
|
|
|
|
|
|
- elif isinstance(lastNode,(StreetNode)):
|
|
|
- if navIndex<0:
|
|
|
- actions.append(["nav",[lastNode]])
|
|
|
- navIndex=len(actions)-1
|
|
|
+ elif isinstance(lastNode, (StreetNode)):
|
|
|
+ if navIndex < 0:
|
|
|
+ actions.append(["nav", [lastNode]])
|
|
|
+ navIndex = len(actions) - 1
|
|
|
actions[navIndex][1].append(node)
|
|
|
- lastNode=node
|
|
|
+ lastNode = node
|
|
|
|
|
|
return actions
|
|
|
|
|
@@ -467,16 +518,16 @@ class Robot(MqttAsync):
|
|
|
cmd = message.NavCmd()
|
|
|
key = str(uuid.uuid4())
|
|
|
cmd.key = key
|
|
|
- cmd.action=0
|
|
|
+ cmd.action = 0
|
|
|
|
|
|
- action=message.NewAction()
|
|
|
- action.type=8
|
|
|
+ action = message.NewAction()
|
|
|
+ action.type = 8
|
|
|
action.changedMode = mode
|
|
|
if mode == 2:
|
|
|
action.wheelbase = wheelbase
|
|
|
cmd.newActions.add().CopyFrom(action)
|
|
|
- loop=3
|
|
|
- while loop>0:
|
|
|
+ loop = 3
|
|
|
+ while loop > 0:
|
|
|
if mode == 2:
|
|
|
if self.IsMainModeStatu():
|
|
|
return True
|
|
@@ -484,7 +535,7 @@ class Robot(MqttAsync):
|
|
|
if self.IsMainModeStatu() == False:
|
|
|
return True
|
|
|
self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
- loop-=1
|
|
|
+ loop -= 1
|
|
|
time.sleep(0.5)
|
|
|
return False
|
|
|
|
|
@@ -498,6 +549,7 @@ class Robot(MqttAsync):
|
|
|
return self.timedRobotStatu_.statu.agvStatu.clamp == 1
|
|
|
|
|
|
return False
|
|
|
+
|
|
|
def IsClampRunning(self):
|
|
|
if self.timedRobotStatu_.timeout() == False:
|
|
|
if self.IsMainModeStatu():
|
|
@@ -525,17 +577,17 @@ class Robot(MqttAsync):
|
|
|
print("clamp closed")
|
|
|
return True
|
|
|
cmd = message.NavCmd()
|
|
|
- cmd.action=0
|
|
|
+ cmd.action = 0
|
|
|
key = str(uuid.uuid4())
|
|
|
cmd.key = (key)
|
|
|
act = message.NewAction()
|
|
|
act.type = 6
|
|
|
cmd.newActions.add().CopyFrom(act)
|
|
|
- published=False
|
|
|
- while self.IsClampClosed()==False:
|
|
|
- if self.ActionType()==ActType.eClampClose:
|
|
|
- published=True
|
|
|
- if published==False:
|
|
|
+ published = False
|
|
|
+ while self.IsClampClosed() == False:
|
|
|
+ if self.ActionType() == ActType.eClampClose:
|
|
|
+ published = True
|
|
|
+ if published == False:
|
|
|
self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
time.sleep(0.5)
|
|
|
return True
|
|
@@ -545,24 +597,24 @@ class Robot(MqttAsync):
|
|
|
print("clamp opended")
|
|
|
return True
|
|
|
cmd = message.NavCmd()
|
|
|
- cmd.action=0
|
|
|
+ cmd.action = 0
|
|
|
key = str(uuid.uuid4())
|
|
|
cmd.key = (key)
|
|
|
act = message.NewAction()
|
|
|
act.type = 7
|
|
|
cmd.newActions.add().CopyFrom(act)
|
|
|
- published=False
|
|
|
- while self.IsClampOpened()==False:
|
|
|
- if self.ActionType()==ActType.eClampOpen:
|
|
|
- published=True
|
|
|
- if published==False:
|
|
|
+ published = False
|
|
|
+ while self.IsClampOpened() == False:
|
|
|
+ if self.ActionType() == ActType.eClampOpen:
|
|
|
+ published = True
|
|
|
+ if published == False:
|
|
|
self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
time.sleep(0.5)
|
|
|
return True
|
|
|
|
|
|
def CancelNavTask(self):
|
|
|
cmd = message.NavCmd()
|
|
|
- cmd.action=3
|
|
|
+ cmd.action = 3
|
|
|
|
|
|
while self.IsNavigating() == True:
|
|
|
self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|