|
@@ -57,7 +57,7 @@ from custom_define import RobotName
|
|
|
from mytool.RabbitMq_helper import async_communication as rabitmq
|
|
|
|
|
|
import concurrent.futures
|
|
|
-
|
|
|
+import TaskTable
|
|
|
from queue import Queue
|
|
|
|
|
|
|
|
@@ -70,6 +70,7 @@ class MainWindow(QMainWindow):
|
|
|
ui_nodes = {}
|
|
|
ui_nodes["street_nodes"] = []
|
|
|
ui_nodes["space_nodes"] = []
|
|
|
+ taskTable = TaskTable.TaskTable()
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
super(MainWindow, self).__init__(parent)
|
|
@@ -79,6 +80,11 @@ class MainWindow(QMainWindow):
|
|
|
self.isLocalTest = False
|
|
|
self.isAutoDispatchOnline = True
|
|
|
|
|
|
+ self.Cancel_ = False
|
|
|
+
|
|
|
+ task_thread = threading.Thread(target=self.execTask)
|
|
|
+ task_thread.start()
|
|
|
+
|
|
|
self.mapManager.LoadJson("./map.json")
|
|
|
|
|
|
for node_id in self.mapManager.VertexDict("Base"):
|
|
@@ -146,7 +152,21 @@ class MainWindow(QMainWindow):
|
|
|
self.g_rabbitmq.setDaemon(True) # 守护线程随主线程结束
|
|
|
self.g_rabbitmq.start()
|
|
|
|
|
|
- def recv_park_request(self, msg):
|
|
|
+ def execTask(self):
|
|
|
+ while self.Cancel_ == False:
|
|
|
+ task = self.taskTable.GetTask()
|
|
|
+ if task != None:
|
|
|
+ if isinstance(task, (message.park_table)):
|
|
|
+ print(" exec park task :%s" % (task.primary_key))
|
|
|
+ ret = self.AutoParkTask(task)
|
|
|
+ self.taskTable.UpdateResult(task.primary_key, ret)
|
|
|
+ if isinstance(task, (message.pick_table)):
|
|
|
+ print(" exec pick task :%s" % (task.primary_key))
|
|
|
+ ret = self.AutoPickTask(task)
|
|
|
+ self.taskTable.UpdateResult(task.primary_key, ret)
|
|
|
+ time.sleep(0.5)
|
|
|
+
|
|
|
+ async def recv_park_request(self, msg):
|
|
|
print("Recv_park_request------------------\n", msg)
|
|
|
|
|
|
park_table = message.park_table()
|
|
@@ -157,10 +177,10 @@ class MainWindow(QMainWindow):
|
|
|
return False
|
|
|
|
|
|
if self.isAutoDispatchOnline:
|
|
|
- return self.AutoParkTask(park_table)
|
|
|
+ return await self.PushParkTask(park_table)
|
|
|
return False
|
|
|
|
|
|
- def recv_pick_request(self, msg):
|
|
|
+ async def recv_pick_request(self, msg):
|
|
|
print("Recv_pick_request------------------\n", msg)
|
|
|
pick_table = message.pick_table()
|
|
|
|
|
@@ -170,13 +190,8 @@ class MainWindow(QMainWindow):
|
|
|
print("Parse error\n")
|
|
|
return False
|
|
|
|
|
|
- # 加入自动任务列表
|
|
|
- '''if self.isAutoDispatchOnline:
|
|
|
- temp = time.time()
|
|
|
- self.auto_task_queue.put((2, pick_table, temp))'''
|
|
|
-
|
|
|
if self.isAutoDispatchOnline:
|
|
|
- return self.AutoPickTask(pick_table)
|
|
|
+ return await self.PushPickTask(pick_table)
|
|
|
return False
|
|
|
|
|
|
def updateMap_park(self, entrance_id, pose, wheelbase): # 0:前车轨迹,1:后车轨迹,2:添加整车轨迹
|
|
@@ -219,6 +234,40 @@ class MainWindow(QMainWindow):
|
|
|
control1 = self.Controller2
|
|
|
return [controlMain, control1, control2]
|
|
|
|
|
|
+ async def PushParkTask(self, park_table: message.park_table = None):
|
|
|
+ pushed = False
|
|
|
+ while pushed == False and self.Cancel_ == False:
|
|
|
+ pushed = self.taskTable.PushTask(park_table.primary_key, park_table)
|
|
|
+ await asyncio.sleep(0.3)
|
|
|
+ if pushed != True or self.Cancel_ != False:
|
|
|
+ return False
|
|
|
+ ret = None
|
|
|
+ while pushed and self.Cancel_ == False:
|
|
|
+ ret = self.taskTable.GetResult(park_table.primary_key)
|
|
|
+ if ret == None:
|
|
|
+ await asyncio.sleep(1)
|
|
|
+ else:
|
|
|
+ break
|
|
|
+
|
|
|
+ return (ret != None)
|
|
|
+
|
|
|
+ async def PushPickTask(self, pick_table: message.pick_table = None):
|
|
|
+ pushed = False
|
|
|
+ while pushed == False and self.Cancel_ == False:
|
|
|
+ pushed = self.taskTable.PushTask(pick_table.primary_key, pick_table)
|
|
|
+ await asyncio.sleep(0.3)
|
|
|
+ if pushed != True or self.Cancel_ != False:
|
|
|
+ return False
|
|
|
+ ret = None
|
|
|
+ while pushed and self.Cancel_ == False:
|
|
|
+ ret = self.taskTable.GetResult(pick_table.primary_key)
|
|
|
+ if ret == None:
|
|
|
+ await asyncio.sleep(1)
|
|
|
+ else:
|
|
|
+ break
|
|
|
+
|
|
|
+ return (ret != None)
|
|
|
+
|
|
|
def AutoParkTask(self, park_table: message.park_table = None):
|
|
|
print("AutoParkTask:---------------------\n")
|
|
|
|
|
@@ -288,24 +337,35 @@ class MainWindow(QMainWindow):
|
|
|
|
|
|
print("-------------------------")
|
|
|
# 整车松夹池------------------------------------
|
|
|
- threadPool = ThreadPoolExecutor(1)
|
|
|
- threadPool.submit(controlMain.robot_.ClampOpen)
|
|
|
- threadPool.shutdown(wait=True)
|
|
|
- if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
|
|
|
+ if controlMain.robot_.ClampOpen()==False:
|
|
|
return False
|
|
|
|
|
|
- # 双单车出库
|
|
|
- controlMain, control1, control2 = self.GetMainFrontBackAGV()
|
|
|
- end_street = target_id.replace("S_", "R_")
|
|
|
- control1.robot_.GeneratePath(target_id, end_street, frontMap)
|
|
|
- control2.robot_.GeneratePath(target_id, end_street, backMap)
|
|
|
+ map_name = "Front"
|
|
|
+ if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
|
|
|
+ map_name = "Back"
|
|
|
|
|
|
- threadPool = ThreadPoolExecutor(2)
|
|
|
- threadPool.submit(control1.robot_.Navigatting,
|
|
|
- target_id, end_street, autoDirect, wheel_base)
|
|
|
- threadPool.submit(control2.robot_.Navigatting,
|
|
|
- target_id, end_street, autoDirect, wheel_base)
|
|
|
- threadPool.shutdown(wait=True)
|
|
|
+ streetNode = target_id.replace("S_", "R_")
|
|
|
+ controlMain.robot_.GeneratePath(target_id, streetNode, map_name)
|
|
|
+ if controlMain.robot_.Navigatting(target_id, streetNode, True, wheel_base) == False:
|
|
|
+ return False
|
|
|
+
|
|
|
+
|
|
|
+ #
|
|
|
+ # if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
|
|
|
+ # return False
|
|
|
+ #
|
|
|
+ # # 双单车出库
|
|
|
+ # controlMain, control1, control2 = self.GetMainFrontBackAGV()
|
|
|
+ # end_street = target_id.replace("S_", "R_")
|
|
|
+ # control1.robot_.GeneratePath(target_id, end_street, frontMap)
|
|
|
+ # control2.robot_.GeneratePath(target_id, end_street, backMap)
|
|
|
+ #
|
|
|
+ # threadPool = ThreadPoolExecutor(2)
|
|
|
+ # threadPool.submit(control1.robot_.Navigatting,
|
|
|
+ # target_id, end_street, autoDirect, wheel_base)
|
|
|
+ # threadPool.submit(control2.robot_.Navigatting,
|
|
|
+ # target_id, end_street, autoDirect, wheel_base)
|
|
|
+ # threadPool.shutdown(wait=True)
|
|
|
|
|
|
# 反馈
|
|
|
self.g_rabbitmq.publish("command_ex", "agv_park_command_response_port",
|
|
@@ -320,8 +380,6 @@ class MainWindow(QMainWindow):
|
|
|
def AutoPickTask(self, pick_table: message.pick_table = None):
|
|
|
print("AutoPickTask:---------------------\n")
|
|
|
|
|
|
-
|
|
|
-
|
|
|
controlMain, control1, control2 = self.GetMainFrontBackAGV()
|
|
|
mainMap, frontMap, backMap = ["Main", "Front", "Back"]
|
|
|
|
|
@@ -404,7 +462,6 @@ class MainWindow(QMainWindow):
|
|
|
# print(" Pick Failed ")
|
|
|
# return False
|
|
|
|
|
|
-
|
|
|
print(" over publish...")
|
|
|
# 反馈
|
|
|
self.g_rabbitmq.publish("command_ex", "agv_pick_command_response_port",
|
|
@@ -452,6 +509,7 @@ class MainWindow(QMainWindow):
|
|
|
self.move(int((screen.width() - self_size.width()) / 2), int((screen.height() - self_size.height()) / 2))
|
|
|
|
|
|
def closeEvent(self, QCloseEvent):
|
|
|
+ self.Cancel_ = True
|
|
|
self.gl.close()
|
|
|
print("close...")
|
|
|
|