|
@@ -21,11 +21,11 @@ class TimeStatu:
|
|
|
def __init__(self, statu=None, timeout=3):
|
|
|
self.statu = statu
|
|
|
self.time = time.time()
|
|
|
- self.timeout_ms = timeout
|
|
|
+ self.timeout_s = timeout
|
|
|
|
|
|
def timeout(self):
|
|
|
tm = time.time()
|
|
|
- return tm - self.time > self.timeout_ms or self.statu == None
|
|
|
+ return tm - self.time > self.timeout_s or self.statu == None
|
|
|
|
|
|
|
|
|
class Robot(MqttAsync):
|
|
@@ -40,7 +40,7 @@ class Robot(MqttAsync):
|
|
|
self.messageArrivedSignal = None
|
|
|
self.currentNavData_ = None
|
|
|
self.navCmdTopic_ = None
|
|
|
- if(name == RobotName.strAGVMain):
|
|
|
+ if (name == RobotName.strAGVMain):
|
|
|
self.speedCmdTopic = "monitor_child/speedcmd"
|
|
|
else:
|
|
|
self.speedCmdTopic = "monitor_child/speedcmd"
|
|
@@ -61,6 +61,8 @@ class Robot(MqttAsync):
|
|
|
self.W_ = 2.5 # 宽
|
|
|
self.heat_ = 0 # 心跳
|
|
|
|
|
|
+ self.manual_status = ManualOperationType.eReady # 正在进行的手动操作
|
|
|
+
|
|
|
def Color(self):
|
|
|
if self.IsMainModeStatu():
|
|
|
return [0, 0, 0]
|
|
@@ -231,9 +233,13 @@ class Robot(MqttAsync):
|
|
|
if runningStatu.statu == 4:
|
|
|
return ActType.eMPC
|
|
|
if runningStatu.statu == 5:
|
|
|
- return ActType.eClampOpen
|
|
|
- if runningStatu.statu == 6:
|
|
|
return ActType.eClampClose
|
|
|
+ if runningStatu.statu == 6:
|
|
|
+ return ActType.eClampOpen
|
|
|
+ if runningStatu.statu == 7:
|
|
|
+ return ActType.eLifterRise
|
|
|
+ if runningStatu.statu == 8:
|
|
|
+ return ActType.eLifterDown
|
|
|
else:
|
|
|
return ActType.eReady
|
|
|
|
|
@@ -443,6 +449,7 @@ class Robot(MqttAsync):
|
|
|
if mode == 1:
|
|
|
action.wheelbase = wheelbase
|
|
|
cmd.newActions.add().CopyFrom(action)
|
|
|
+ print(cmd)
|
|
|
channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
|
stub = msg_rpc.NavExcutorStub(channel)
|
|
|
response = stub.Start(cmd)
|
|
@@ -459,18 +466,6 @@ class Robot(MqttAsync):
|
|
|
|
|
|
return False
|
|
|
|
|
|
- def IsLiferDowned(self):
|
|
|
- if self.timedRobotStatu_.timeout() == False:
|
|
|
- if self.IsMainModeStatu():
|
|
|
- clamp = self.timedRobotStatu_.statu.agvStatu.clamp
|
|
|
- clamp_other = self.timedRobotStatu_.statu.agvStatu.clamp_other
|
|
|
- return (clamp == 1 and clamp_other == 1)
|
|
|
- else:
|
|
|
- return self.timedRobotStatu_.statu.agvStatu.clamp == 1
|
|
|
-
|
|
|
- return False
|
|
|
-
|
|
|
-
|
|
|
def IsClampRunning(self):
|
|
|
if self.timedRobotStatu_.timeout() == False:
|
|
|
if self.IsMainModeStatu():
|
|
@@ -525,6 +520,68 @@ class Robot(MqttAsync):
|
|
|
response = stub.Start(cmd)
|
|
|
return True
|
|
|
|
|
|
+ def IsLiferDowned(self):
|
|
|
+ if self.timedRobotStatu_.timeout() == False:
|
|
|
+ if self.IsMainModeStatu():
|
|
|
+ lifter = self.timedRobotStatu_.statu.agvStatu.lifter
|
|
|
+ lifter_other = self.timedRobotStatu_.statu.agvStatu.lifter_other
|
|
|
+ return (lifter == 2 and lifter_other == 2)
|
|
|
+ else:
|
|
|
+ return self.timedRobotStatu_.statu.agvStatu.lifter == 2
|
|
|
+ return False
|
|
|
+
|
|
|
+ def IsLiferRunning(self):
|
|
|
+ if self.timedRobotStatu_.timeout() == False:
|
|
|
+ if self.IsMainModeStatu():
|
|
|
+ lifter = self.timedRobotStatu_.statu.agvStatu.lifter
|
|
|
+ lifter_other = self.timedRobotStatu_.statu.agvStatu.lifter_other
|
|
|
+ return (lifter == 0 and lifter_other == 0)
|
|
|
+ else:
|
|
|
+ return self.timedRobotStatu_.statu.agvStatu.lifter == 0
|
|
|
+ return False
|
|
|
+
|
|
|
+ def IsLiferRose(self):
|
|
|
+ if self.timedRobotStatu_.timeout() == False:
|
|
|
+ if self.IsMainModeStatu():
|
|
|
+ lifter = self.timedRobotStatu_.statu.agvStatu.lifter
|
|
|
+ lifter_other = self.timedRobotStatu_.statu.agvStatu.lifter_other
|
|
|
+ return (lifter == 1 and lifter_other == 1)
|
|
|
+ else:
|
|
|
+ return self.timedRobotStatu_.statu.agvStatu.lifter == 1
|
|
|
+ return False
|
|
|
+
|
|
|
+ def LiferRise(self):
|
|
|
+ if self.IsLiferRose() == True:
|
|
|
+ print("lifter has rose")
|
|
|
+ return True
|
|
|
+ cmd = message.NavCmd()
|
|
|
+ cmd.action = 0
|
|
|
+ key = str(uuid.uuid4())
|
|
|
+ cmd.key = (key)
|
|
|
+ act = message.NewAction()
|
|
|
+ act.type = 9
|
|
|
+ cmd.newActions.add().CopyFrom(act)
|
|
|
+ channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
|
+ stub = msg_rpc.NavExcutorStub(channel)
|
|
|
+ response = stub.Start(cmd)
|
|
|
+ return True
|
|
|
+
|
|
|
+ def LiferDown(self):
|
|
|
+ if self.IsLiferDowned() == True:
|
|
|
+ print("lifter has downed")
|
|
|
+ return True
|
|
|
+ cmd = message.NavCmd()
|
|
|
+ cmd.action = 0
|
|
|
+ key = str(uuid.uuid4())
|
|
|
+ cmd.key = (key)
|
|
|
+ act = message.NewAction()
|
|
|
+ act.type = 10
|
|
|
+ cmd.newActions.add().CopyFrom(act)
|
|
|
+ channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
|
+ stub = msg_rpc.NavExcutorStub(channel)
|
|
|
+ response = stub.Start(cmd)
|
|
|
+ return True
|
|
|
+
|
|
|
def CancelNavTask(self):
|
|
|
cmd = message.NavCmd()
|
|
|
cmd.action = 3
|
|
@@ -537,11 +594,85 @@ class Robot(MqttAsync):
|
|
|
print(" Cancel task completed!!!")
|
|
|
return True
|
|
|
|
|
|
- def ManualTask(self, current_operation, step_acc):
|
|
|
+ def IsManualTaskRunning(self):
|
|
|
+ return self.manual_status != ManualOperationType.eReady
|
|
|
+
|
|
|
+ def ManualTask(self, current_operation, step_acc=0, speed=0):
|
|
|
+ print("speed: ", speed)
|
|
|
if self.IsNavigating():
|
|
|
print("AGV is navigating!!!")
|
|
|
return
|
|
|
+ if self.IsManualTaskRunning():
|
|
|
+ return print("ManualTask | ManualTask is running...")
|
|
|
+ self.manual_status = current_operation
|
|
|
+
|
|
|
+ if ManualOperationType.eReady < current_operation <= ManualOperationType.eRightMove:
|
|
|
+ cmd = message.ToAgvCmd()
|
|
|
+ self.heat_ += 1
|
|
|
+ self.heat_ %= 255
|
|
|
+ cmd.H = self.heat_
|
|
|
+ if self.IsMainModeStatu():
|
|
|
+ cmd.M = 1
|
|
|
+ else:
|
|
|
+ cmd.M = 0
|
|
|
+
|
|
|
+ if current_operation == ManualOperationType.eCounterclockwiseRotate:
|
|
|
+ cmd.T = 1
|
|
|
+ cmd.V = 0
|
|
|
+ cmd.W = speed / 180 * math.pi * sigmoid(step_acc, 0, 1)
|
|
|
+ if current_operation == ManualOperationType.eClockwiseRotate:
|
|
|
+ cmd.T = 1
|
|
|
+ cmd.V = 0
|
|
|
+ cmd.W = -speed / 180 * math.pi * sigmoid(step_acc, 0, 1)
|
|
|
+ if current_operation == ManualOperationType.eForwardMove:
|
|
|
+ cmd.T = 3
|
|
|
+ cmd.V = speed * sigmoid(step_acc, 0, 1)
|
|
|
+ cmd.W = 0
|
|
|
+ if current_operation == ManualOperationType.eBackwardMove:
|
|
|
+ cmd.T = 3
|
|
|
+ cmd.V = -speed * sigmoid(step_acc, 0, 1)
|
|
|
+ cmd.W = 0
|
|
|
+ if current_operation == ManualOperationType.eLeftMove:
|
|
|
+ cmd.T = 2
|
|
|
+ cmd.V = speed * sigmoid(step_acc, 0, 1)
|
|
|
+ cmd.W = 0
|
|
|
+ if current_operation == ManualOperationType.eRightMove:
|
|
|
+ cmd.T = 2
|
|
|
+ cmd.V = -speed * sigmoid(step_acc, 0, 1)
|
|
|
+ cmd.W = 0
|
|
|
+ cmd.L = self.L_
|
|
|
+ cmd.end = 1
|
|
|
+
|
|
|
+ # 处理为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)
|
|
|
+
|
|
|
+ # channel = grpc.insecure_channel(self.rpc_ipport_)
|
|
|
+ # stub = msg_rpc.NavExcutorStub(channel)
|
|
|
+ # response = stub.ManualOperation(cmd_0)
|
|
|
+ # print("client received: ", response)
|
|
|
+ self.manual_status = ManualOperationType.eReady
|
|
|
+ # print("ManualOperation {op_type} task completed!!!".format(op_type=hex(current_operation)))
|
|
|
+ return True
|
|
|
+
|
|
|
+ elif ManualOperationType.eClampClose <= current_operation <= ManualOperationType.eClampOpen:
|
|
|
+ self.Manual_Unit_Clamp(current_operation)
|
|
|
+ return True
|
|
|
|
|
|
+ elif ManualOperationType.eLifterRise <= current_operation <= ManualOperationType.eLifterDown:
|
|
|
+ self.Manual_Unit_Lifter(current_operation)
|
|
|
+ return True
|
|
|
+ return False
|
|
|
+
|
|
|
+ def Manual_Unit_Lifter(self, current_operation: ManualOperationType):
|
|
|
+ print(current_operation)
|
|
|
cmd = message.ToAgvCmd()
|
|
|
self.heat_ += 1
|
|
|
self.heat_ %= 255
|
|
@@ -550,35 +681,9 @@ class Robot(MqttAsync):
|
|
|
cmd.M = 1
|
|
|
else:
|
|
|
cmd.M = 0
|
|
|
+ cmd.T = self.ManualOperationType2AgvCmdType(current_operation)
|
|
|
|
|
|
- if current_operation == ManualOperationType.eCounterclockwiseRotate:
|
|
|
- cmd.T = 1
|
|
|
- cmd.V = 0
|
|
|
- cmd.W = 4.0 / 180 * math.pi * sigmoid(step_acc, 0, 1)
|
|
|
- if current_operation == ManualOperationType.eClockwiseRotate:
|
|
|
- cmd.T = 1
|
|
|
- cmd.V = 0
|
|
|
- cmd.W = -4.0 / 180 * math.pi * sigmoid(step_acc, 0, 1)
|
|
|
- if current_operation == ManualOperationType.eForwardMove:
|
|
|
- cmd.T = 3
|
|
|
- cmd.V = 0.6 * sigmoid(step_acc, 0, 1)
|
|
|
- cmd.W = 0
|
|
|
- if current_operation == ManualOperationType.eBackwardMove:
|
|
|
- cmd.T = 3
|
|
|
- cmd.V = -0.6 * sigmoid(step_acc, 0, 1)
|
|
|
- cmd.W = 0
|
|
|
- if current_operation == ManualOperationType.eLeftMove:
|
|
|
- cmd.T = 2
|
|
|
- cmd.V = 0.6 * sigmoid(step_acc, 0, 1)
|
|
|
- cmd.W = 0
|
|
|
- if current_operation == ManualOperationType.eRightMove:
|
|
|
- cmd.T = 2
|
|
|
- cmd.V = -0.6 * sigmoid(step_acc, 0, 1)
|
|
|
- cmd.W = 0
|
|
|
- cmd.L = self.L_
|
|
|
- cmd.end = 1
|
|
|
-
|
|
|
- # 处理为json格式
|
|
|
+ # 处理为json格式 # jtf.MessageToJson(cmd)
|
|
|
cmd_dict = {}
|
|
|
for field in cmd.DESCRIPTOR.fields:
|
|
|
cmd_dict[field.name] = field.default_value
|
|
@@ -586,34 +691,40 @@ class Robot(MqttAsync):
|
|
|
cmd_dict[field.name] = value
|
|
|
cmd_json = json.dumps(cmd_dict, indent=None, separators=(',', ':'))
|
|
|
self.publish(self.speedCmdTopic, cmd_json)
|
|
|
-
|
|
|
print(cmd_json)
|
|
|
+ self.manual_status = ManualOperationType.eReady
|
|
|
+ return True
|
|
|
|
|
|
- # 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("ManualOperation {op_type} task completed!!!".format(op_type=current_operation))
|
|
|
+ def Manual_Unit_Clamp(self, current_operation: ManualOperationType):
|
|
|
+ print(current_operation)
|
|
|
+ cmd = message.ToAgvCmd()
|
|
|
+ self.heat_ += 1
|
|
|
+ self.heat_ %= 255
|
|
|
+ cmd.H = self.heat_
|
|
|
+ if self.IsMainModeStatu():
|
|
|
+ cmd.M = 1
|
|
|
+ else:
|
|
|
+ cmd.M = 0
|
|
|
+ cmd.T = self.ManualOperationType2AgvCmdType(current_operation)
|
|
|
+
|
|
|
+ # 处理为json格式 # jtf.MessageToJson(cmd)
|
|
|
+ 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)
|
|
|
+ self.manual_status = ManualOperationType.eReady
|
|
|
return True
|
|
|
+
|
|
|
+ def ManualOperationType2AgvCmdType(self, mo_type: ManualOperationType):
|
|
|
+ if mo_type == ManualOperationType.eLifterRise:
|
|
|
+ return ActType.eLifterRise
|
|
|
+ if mo_type == ManualOperationType.eLifterDown:
|
|
|
+ return ActType.eLifterDown
|
|
|
+ if mo_type == ManualOperationType.eClampClose:
|
|
|
+ return ActType.eClampClose
|
|
|
+ if mo_type == ManualOperationType.eClampOpen:
|
|
|
+ return ActType.eClampOpen
|