|
@@ -1,3 +1,4 @@
|
|
|
+import enum
|
|
|
import time
|
|
|
import message_pb2 as message
|
|
|
from mqtt_async import MqttAsync
|
|
@@ -7,6 +8,15 @@ import uuid
|
|
|
from auto_test import TestCount
|
|
|
import random
|
|
|
|
|
|
+class ActType(enum.Enum):
|
|
|
+ eReady=0
|
|
|
+ eRotation=1
|
|
|
+ eHorizon=2
|
|
|
+ eVertical=3
|
|
|
+ eMPC=4
|
|
|
+ eClampOpen=5
|
|
|
+ eClampClose=6
|
|
|
+
|
|
|
|
|
|
class TimeStatu:
|
|
|
def __init__(self, statu=None, timeout=3):
|
|
@@ -18,8 +28,8 @@ class TimeStatu:
|
|
|
tm = time.time()
|
|
|
return tm - self.time > self.timeout_ms or self.statu == None
|
|
|
|
|
|
-
|
|
|
class Robot(MqttAsync):
|
|
|
+
|
|
|
def __init__(self, name=""):
|
|
|
MqttAsync.__init__(self)
|
|
|
self.timedRobotStatu_ = TimeStatu(message.RobotStatu, 0)
|
|
@@ -121,11 +131,12 @@ class Robot(MqttAsync):
|
|
|
return self.timedNavStatu_.timeout() == False and self.timedRobotStatu_.timeout() == False
|
|
|
|
|
|
def IsNavigating(self):
|
|
|
- if self.timedNavStatu_.timeout() == False:
|
|
|
+ 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
|
|
|
+ return True'''
|
|
|
|
|
|
def GeneratePath(self, begID, endID):
|
|
|
self.currentNavPathNodes_ = DijikstraMap().GetShortestPath(begID, endID)
|
|
@@ -196,13 +207,31 @@ class Robot(MqttAsync):
|
|
|
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:
|
|
|
+ return ActType.eReady
|
|
|
+ if runningStatu.statu==1:
|
|
|
+ return ActType.eRotation
|
|
|
+ if runningStatu.statu==2:
|
|
|
+ return ActType.eHorizon
|
|
|
+ if runningStatu.statu==3:
|
|
|
+ return ActType.eVertical
|
|
|
+ if runningStatu.statu==4:
|
|
|
+ return ActType.eMPC
|
|
|
+ if runningStatu.statu==5:
|
|
|
+ return ActType.eClampOpen
|
|
|
+ if runningStatu.statu==6:
|
|
|
+ return ActType.eClampClose
|
|
|
+ else:
|
|
|
+ return ActType.eReady
|
|
|
|
|
|
def ExecNavtask(self):
|
|
|
if self.navCmdTopic_ == None:
|
|
|
print("Robot has not set nav cmd topic")
|
|
|
return False
|
|
|
- if self.IsNavigating():
|
|
|
+ if not self.ActionType()==ActType.eReady:
|
|
|
print(" robot is navigating ,key:%s" % (self.timedNavStatu_.statu.key))
|
|
|
return False
|
|
|
|
|
@@ -218,11 +247,12 @@ class Robot(MqttAsync):
|
|
|
if cmd is None:
|
|
|
print("Nav cmd is None")
|
|
|
return False
|
|
|
-
|
|
|
- self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
- time.sleep(1)
|
|
|
+ published=False
|
|
|
while self.IsNavigating() == False:
|
|
|
- self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
+ 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
|
|
@@ -237,17 +267,17 @@ class Robot(MqttAsync):
|
|
|
cmd.action = 4
|
|
|
if mode == 1:
|
|
|
cmd.action = 5
|
|
|
-
|
|
|
- self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
- while True:
|
|
|
+ loop=3
|
|
|
+ while loop>0:
|
|
|
if mode == 2:
|
|
|
if self.IsMainModeStatu():
|
|
|
return True
|
|
|
if mode == 1:
|
|
|
if self.IsMainModeStatu() == False:
|
|
|
return True
|
|
|
- time.sleep(0.1)
|
|
|
self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
+ loop-=1
|
|
|
+ time.sleep(0.5)
|
|
|
return False
|
|
|
|
|
|
def IsClampClosed(self):
|
|
@@ -293,15 +323,14 @@ class Robot(MqttAsync):
|
|
|
act = message.Action()
|
|
|
act.type = 3
|
|
|
cmd.actions.add().CopyFrom(act)
|
|
|
- self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
- time.sleep(1)
|
|
|
- while True:
|
|
|
- if self.IsClampClosed() == True:
|
|
|
- return True
|
|
|
- if self.IsClampRunning()==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(1)
|
|
|
- return False
|
|
|
+ time.sleep(0.5)
|
|
|
+ return True
|
|
|
|
|
|
def ClampOpen(self):
|
|
|
if self.IsClampOpened() == True:
|
|
@@ -313,20 +342,18 @@ class Robot(MqttAsync):
|
|
|
act = message.Action()
|
|
|
act.type = 4
|
|
|
cmd.actions.add().CopyFrom(act)
|
|
|
- self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
- time.sleep(1)
|
|
|
- while True:
|
|
|
- if self.IsClampOpened() == True:
|
|
|
- return True
|
|
|
- if self.IsClampRunning() == 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(1)
|
|
|
- return False
|
|
|
+ time.sleep(0.5)
|
|
|
+ return True
|
|
|
|
|
|
def CancelNavTask(self):
|
|
|
cmd = message.NavCmd()
|
|
|
cmd.action = 3
|
|
|
- self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
while self.IsNavigating() == True:
|
|
|
self.publish(self.navCmdTopic_, jtf.MessageToJson(cmd))
|
|
|
time.sleep(1)
|