|
@@ -7,6 +7,7 @@ from dijkstra.Map import DijikstraMap,SpaceNode,StreetNode
|
|
import uuid
|
|
import uuid
|
|
from auto_test import TestCount
|
|
from auto_test import TestCount
|
|
import random
|
|
import random
|
|
|
|
+import math
|
|
|
|
|
|
class ActType(enum.Enum):
|
|
class ActType(enum.Enum):
|
|
eReady=0
|
|
eReady=0
|
|
@@ -162,7 +163,8 @@ class Robot(MqttAsync):
|
|
def Navigatting(self, begId, targetId):
|
|
def Navigatting(self, begId, targetId):
|
|
print("nav")
|
|
print("nav")
|
|
self.GeneratePath(begId, targetId)
|
|
self.GeneratePath(begId, targetId)
|
|
- self.ExecNavtask()
|
|
|
|
|
|
+ self.ExecPathNodes()
|
|
|
|
+ #self.ExecNavtask()
|
|
while self.IsNavigating() == True:
|
|
while self.IsNavigating() == True:
|
|
'''if self.Connected() == False:
|
|
'''if self.Connected() == False:
|
|
print("robot disconnected cancel task")
|
|
print("robot disconnected cancel task")
|
|
@@ -256,6 +258,101 @@ class Robot(MqttAsync):
|
|
time.sleep(1)
|
|
time.sleep(1)
|
|
print("send nav cmd completed!!!")
|
|
print("send nav cmd completed!!!")
|
|
return True
|
|
return True
|
|
|
|
+ def ExecPathNodes(self,autoDirect=False):
|
|
|
|
+ if self.navCmdTopic_ == None:
|
|
|
|
+ print("Robot has not set nav cmd topic")
|
|
|
|
+ return False
|
|
|
|
+ if not self.ActionType()==ActType.eReady:
|
|
|
|
+ print(" robot is navigating ,key:%s" % (self.timedNavStatu_.statu.key))
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
+ cmd = message.NavCmd()
|
|
|
|
+ cmd.action=6
|
|
|
|
+ if self.currentNavPathNodes_ is not None and self.timedRobotStatu_.timeout() == False:
|
|
|
|
+ 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.05
|
|
|
|
+ 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.3
|
|
|
|
+ limitAdjustH.min=0.03
|
|
|
|
+ limitAdjustH.max=0.3
|
|
|
|
+
|
|
|
|
+ count=0
|
|
|
|
+ size=len(self.currentNavPathNodes_)
|
|
|
|
+ for i in range(size):
|
|
|
|
+ node=self.currentNavPathNodes_[i]
|
|
|
|
+ pose=message.Pose2d()
|
|
|
|
+ accuracy=message.Pose2d()
|
|
|
|
+ pose.x=node.x_
|
|
|
|
+ pose.y=node.y_
|
|
|
|
+ if i+1<size:
|
|
|
|
+ next=self.currentNavPathNodes_[i+1]
|
|
|
|
+ vector = [next.x_ - node.x_, next.y_ - node.y_]
|
|
|
|
+ dx = vector[0]
|
|
|
|
+ dy = vector[1]
|
|
|
|
+ yaw = math.asin(dy / math.sqrt(dx * dx + dy * dy))
|
|
|
|
+ if yaw >= 0:
|
|
|
|
+ if dx < 0:
|
|
|
|
+ yaw = math.pi - yaw
|
|
|
|
+ if yaw < 0:
|
|
|
|
+ if dx < 0:
|
|
|
|
+ yaw = -math.pi - yaw
|
|
|
|
+ pose.theta=yaw
|
|
|
|
+ else:
|
|
|
|
+ pose.theta=0
|
|
|
|
+
|
|
|
|
+ if count==size-1:
|
|
|
|
+ accuracy.x=0.02
|
|
|
|
+ accuracy.y=0.02
|
|
|
|
+ accuracy.theta=0.5*math.pi/(180.0)
|
|
|
|
+ else:
|
|
|
|
+ accuracy.x=0.05
|
|
|
|
+ accuracy.y=0.1
|
|
|
|
+ accuracy.theta=3*math.pi/180.0
|
|
|
|
+
|
|
|
|
+ pathNode=message.PathNode()
|
|
|
|
+ pathNode.pose.CopyFrom(pose)
|
|
|
|
+ pathNode.accuracy.CopyFrom(accuracy)
|
|
|
|
+ newAction.type=4
|
|
|
|
+ if autoDirect:
|
|
|
|
+ newAction.type=3
|
|
|
|
+ newAction.pathNodes.add().CopyFrom(pathNode)
|
|
|
|
+ newAction.NodeVelocityLimit.CopyFrom(limitMPC_v)
|
|
|
|
+ newAction.NodeAngularLimit.CopyFrom(limitRotate)
|
|
|
|
+ newAction.adjustVelocitylimit.CopyFrom(limAdjustV)
|
|
|
|
+ newAction.adjustHorizonLimit.CopyFrom(limitAdjustH)
|
|
|
|
+ cmd.newActions.add().CopyFrom(newAction)
|
|
|
|
+
|
|
|
|
+ count+=1
|
|
|
|
+
|
|
|
|
+ else:
|
|
|
|
+ print("statu is None")
|
|
|
|
+ return False
|
|
|
|
+ else:
|
|
|
|
+ print("current path is none")
|
|
|
|
+ return False
|
|
|
|
+ if cmd is None:
|
|
|
|
+ print("Nav cmd is None")
|
|
|
|
+ return False
|
|
|
|
+ print(cmd)
|
|
|
|
+ published=False
|
|
|
|
+ while self.IsNavigating() == False:
|
|
|
|
+ if not self.ActionType() == ActType.eReady:
|
|
|
|
+ published=True
|
|
|
|
+ if published==False:
|
|
|
|
+ self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
|
+ time.sleep(1)
|
|
|
|
+ print("send nav cmd completed!!!")
|
|
|
|
+ return True
|
|
|
|
+
|
|
|
|
|
|
def SwitchMoveMode(self, mode, wheelbase):
|
|
def SwitchMoveMode(self, mode, wheelbase):
|
|
if self.IsMainAgv() == False:
|
|
if self.IsMainAgv() == False:
|