test.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # ===============================================================================
  4. #
  5. # test.py
  6. #
  7. # Test program for the simple GL Viewer.
  8. #
  9. # Copyright (c) 2011, Arne Schmitz <arne.schmitz@gmx.net>
  10. # All rights reserved.
  11. #
  12. # Redistribution and use in source and binary forms, with or without
  13. # modification, are permitted provided that the following conditions are met:
  14. # * Redistributions of source code must retain the above copyright
  15. # notice, this list of conditions and the following disclaimer.
  16. # * Redistributions in binary form must reproduce the above copyright
  17. # notice, this list of conditions and the following disclaimer in the
  18. # documentation and/or other materials provided with the distribution.
  19. # * Neither the name of the <organization> nor the
  20. # names of its contributors may be used to endorse or promote products
  21. # derived from this software without specific prior written permission.
  22. #
  23. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  27. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  30. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. #
  34. # ===============================================================================
  35. import asyncio
  36. import math
  37. import threading
  38. import time
  39. import sys
  40. from PyQt5.QtGui import *
  41. from PyQt5.QtWidgets import *
  42. from PyQt5.QtCore import *
  43. from MapGLWidget import MapGLWidget
  44. import json
  45. import dijkstra.Map as mp
  46. import ControllWidget
  47. import JointContrallerWidget
  48. import ManualOperationWidget
  49. import RobotData as RD
  50. import message_pb2 as message
  51. import google.protobuf.json_format as jtf
  52. import google.protobuf.text_format as tf
  53. from concurrent.futures import ThreadPoolExecutor
  54. import uuid
  55. from mytool.txt_helper.txt_operation import TXTOperation
  56. from custom_define import RobotName
  57. from mytool.RabbitMq_helper import async_communication as rabitmq
  58. import concurrent.futures
  59. import TaskTable
  60. from queue import Queue
  61. # ===============================================================================
  62. class MainWindow(QMainWindow):
  63. """docstring for Mainwindow"""
  64. mapManager = mp.MapManager()
  65. ui_nodes = {}
  66. ui_nodes["street_nodes"] = []
  67. ui_nodes["space_nodes"] = []
  68. taskTable = TaskTable.TaskTable()
  69. def __init__(self, parent=None):
  70. super(MainWindow, self).__init__(parent)
  71. self.basic()
  72. self.showMaximized()
  73. self.count_frame_ = ControllWidget.CountFrame()
  74. self.isLocalTest = True
  75. self.isAutoDispatchOnline = False
  76. self.Cancel_ = False
  77. task_thread = threading.Thread(target=self.execTask)
  78. task_thread.start()
  79. self.mapManager.LoadJson("./map.json")
  80. for node_id in self.mapManager.VertexDict("Base"):
  81. if node_id.find("S_") >= 0:
  82. self.ui_nodes["space_nodes"].append(node_id)
  83. if node_id.find("R_") >= 0:
  84. self.ui_nodes["street_nodes"].append(node_id)
  85. rpc_1 = "192.168.0.70:9090"
  86. mqtt_1 = ["pyui1", "192.168.0.70", 1883, "admin", "zx123456"]
  87. rpc_2 = "192.168.0.71:9090"
  88. mqtt_2 = ["pyui2", "192.168.0.71", 1883, "admin", "zx123456"]
  89. if self.isLocalTest:
  90. rpc_1 = "127.0.0.1:9090"
  91. mqtt_1 = ["pyui-main", "127.0.0.1", 1883, "admin", "zx123456"]
  92. rpc_2 = "127.0.0.1:9091"
  93. mqtt_2 = ["pyui-child", "127.0.0.1", 1883, "admin", "zx123456"]
  94. config1 = {"label": RobotName.strAGVMain,
  95. "rpc": rpc_1,
  96. "street_nodes": self.ui_nodes["street_nodes"],
  97. "space_nodes": self.ui_nodes["space_nodes"],
  98. "mqtt": mqtt_1,
  99. "subTopics": {"agv_main/agv_statu": message.RobotStatu.__name__,
  100. "agv_main/nav_statu": message.NavStatu.__name__},
  101. "cmdTopic": "agv_main/nav_cmd",
  102. "robotColor": [0.7, 0.2, 0.3]}
  103. config2 = {"label": RobotName.strAGV2,
  104. "rpc": rpc_2,
  105. # "rpc": "127.0.0.1:9091",
  106. "street_nodes": self.ui_nodes["street_nodes"],
  107. "space_nodes": self.ui_nodes["space_nodes"],
  108. "mqtt": mqtt_2,
  109. "subTopics": {"agv_child/agv_statu": message.RobotStatu.__name__,
  110. "agv_child/nav_statu": message.NavStatu.__name__},
  111. "cmdTopic": "agv_child/nav_cmd",
  112. "robotColor": [0.4, 0.2, 0.8]}
  113. self.gl = MapGLWidget() # 将opengl例子嵌入GUI
  114. self.Controller1 = ControllWidget.ControlFrame(config1)
  115. self.Controller2 = ControllWidget.ControlFrame(config2)
  116. robot_dict = {self.Controller1.robot_.name_: self.Controller1.robot_,
  117. self.Controller2.robot_.name_: self.Controller2.robot_}
  118. self.ManualOperationWidget = ManualOperationWidget.ManualOperationWidget(robot_dict)
  119. splitter_main = self.split_()
  120. self.setCentralWidget(splitter_main)
  121. self.gl.SetRobot1Instance(self.Controller1.robot_)
  122. self.gl.SetRobot2Instance(self.Controller2.robot_)
  123. self.gl.SetMaps(self.mapManager.maps)
  124. self.timer_ = QTimer()
  125. self.timer_.timeout.connect(self.Update)
  126. self.timer_.start(100)
  127. # 启动RabbitMQ
  128. self.g_rabbitmq = None
  129. if self.isAutoDispatchOnline:
  130. self.g_rabbitmq = rabitmq.RabbitAsyncCommunicator("192.168.0.201", 5672, "zx", "123456")
  131. calbbacks = [["agv_park_command_request_queue", self.recv_park_request],
  132. ["agv_pick_command_request_queue", self.recv_pick_request]]
  133. self.g_rabbitmq.Init(calbbacks, None)
  134. self.g_rabbitmq.setDaemon(True) # 守护线程随主线程结束
  135. self.g_rabbitmq.start()
  136. def execTask(self):
  137. while self.Cancel_ == False:
  138. task = self.taskTable.GetTask()
  139. if task != None:
  140. if isinstance(task, (message.park_table)):
  141. print(" exec park task :%s" % (task.primary_key))
  142. ret = self.AutoParkTask(task)
  143. self.taskTable.UpdateResult(task.primary_key, ret)
  144. if isinstance(task, (message.pick_table)):
  145. print(" exec pick task :%s" % (task.primary_key))
  146. ret = self.AutoPickTask(task)
  147. self.taskTable.UpdateResult(task.primary_key, ret)
  148. time.sleep(0.5)
  149. async def recv_park_request(self, msg):
  150. print("Recv_park_request------------------\n", msg)
  151. park_table = message.park_table()
  152. try:
  153. tf.Parse(msg, park_table)
  154. except Exception as e:
  155. print("Parse error\n")
  156. return False
  157. if self.isAutoDispatchOnline:
  158. return await self.PushParkTask(park_table)
  159. return False
  160. async def recv_pick_request(self, msg):
  161. print("Recv_pick_request------------------\n", msg)
  162. pick_table = message.pick_table()
  163. try:
  164. tf.Parse(msg, pick_table)
  165. except Exception as e:
  166. print("Parse error\n")
  167. return False
  168. if self.isAutoDispatchOnline:
  169. return await self.PushPickTask(pick_table)
  170. return False
  171. def updateMap_park(self, entrance_id, pose, wheelbase): # 0:前车轨迹,1:后车轨迹,2:添加整车轨迹
  172. self.mapManager.ResetMap("Front", 0, wheelbase / 2)
  173. [trans_x, trans_y, trans_a] = pose
  174. self.mapManager.maps["Front"].ResetVertexValue(mp.SpaceNode(entrance_id, trans_x, trans_y, trans_a))
  175. [id, x, y] = self.ComputeStreetNode("Front", entrance_id, trans_x, trans_y, trans_a)
  176. self.mapManager.maps["Front"].ResetVertexValue(mp.StreetNode(id, x, y))
  177. self.mapManager.ResetMap("Back", 0, -wheelbase / 2)
  178. [trans_x, trans_y, trans_a] = pose
  179. self.mapManager.maps["Back"].ResetVertexValue(mp.SpaceNode(entrance_id, trans_x, trans_y, trans_a))
  180. [id, x, y] = self.ComputeStreetNode("Back", entrance_id, trans_x, trans_y, trans_a)
  181. self.mapManager.maps["Back"].ResetVertexValue(mp.StreetNode(id, x, y))
  182. def asyncExecute(self, tasks):
  183. results = [feature.result() for feature in concurrent.futures.as_completed(tasks)]
  184. print("==========================\n")
  185. print(results)
  186. print("==========================\n")
  187. ret = True
  188. for result in results:
  189. ret = ret and result
  190. return ret
  191. def GetMainFrontBackAGV(self):
  192. controlMain = self.Controller1
  193. nagtive = False
  194. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  195. nagtive = True
  196. control1 = None
  197. control2 = None
  198. if nagtive == False:
  199. control1 = self.Controller1
  200. control2 = self.Controller2
  201. else:
  202. control2 = self.Controller1
  203. control1 = self.Controller2
  204. return [controlMain, control1, control2]
  205. async def PushParkTask(self, park_table: message.park_table = None):
  206. pushed = False
  207. while pushed == False and self.Cancel_ == False:
  208. pushed = self.taskTable.PushTask(park_table.primary_key, park_table)
  209. await asyncio.sleep(0.3)
  210. if pushed != True or self.Cancel_ != False:
  211. return False
  212. ret = None
  213. while pushed and self.Cancel_ == False:
  214. ret = self.taskTable.GetResult(park_table.primary_key)
  215. if ret == None:
  216. await asyncio.sleep(1)
  217. else:
  218. break
  219. return (ret != None)
  220. async def PushPickTask(self, pick_table: message.pick_table = None):
  221. pushed = False
  222. while pushed == False and self.Cancel_ == False:
  223. pushed = self.taskTable.PushTask(pick_table.primary_key, pick_table)
  224. await asyncio.sleep(0.3)
  225. if pushed != True or self.Cancel_ != False:
  226. return False
  227. ret = None
  228. while pushed and self.Cancel_ == False:
  229. ret = self.taskTable.GetResult(pick_table.primary_key)
  230. if ret == None:
  231. await asyncio.sleep(1)
  232. else:
  233. break
  234. return (ret != None)
  235. def AutoParkTask(self, park_table: message.park_table = None):
  236. print("AutoParkTask:---------------------\n")
  237. task_flag = 1 # 存车
  238. [controlMain, control1, control2] = self.GetMainFrontBackAGV()
  239. mainMap, frontMap, backMap = ["Base", "Front", "Back"]
  240. entrance_id = "S_" + str(park_table.terminal_id) # "S1101"
  241. entrance_x, entrance_y, entrance_theta = [park_table.entrance_measure_info.measure_info_to_plc_forward.cx,
  242. park_table.entrance_measure_info.measure_info_to_plc_forward.cy,
  243. (
  244. 90 + park_table.entrance_measure_info.measure_info_to_plc_forward.theta) / 180 * math.pi]
  245. # 变换到地图坐标系
  246. [dx, dy, da] = [-0.184040126204, -0.647539079189, 178.9302736990612 / 180 * math.pi]
  247. trans_x = -0.999825716019 * entrance_x - 0.018668506294 * entrance_y + dx
  248. trans_y = 0.018668506294 * entrance_x - 0.999825716019 * entrance_y + dy
  249. trans_a = entrance_theta + da - math.pi
  250. while trans_a < 0:
  251. trans_a += math.pi
  252. print("entrance:", entrance_id, trans_x, trans_y, trans_a / math.pi * 180)
  253. target_id = "S_" + str(park_table.allocated_space_info.table_id) # "S147"
  254. print("target:", target_id)
  255. # 轴距
  256. wheel_base = park_table.entrance_measure_info.measure_info_to_plc_forward.wheelbase
  257. control1.WheelBaseEdit.setText(str(wheel_base))
  258. control2.WheelBaseEdit.setText(str(wheel_base))
  259. trans_x += wheel_base / 2 * math.cos(trans_a)
  260. trans_y += wheel_base / 2 * math.sin(trans_a)
  261. # # # 双单车入库-----------------------------------------------------
  262. # if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
  263. # return False
  264. # autoDirect = True
  265. # self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], wheel_base)
  266. #
  267. # cur_pose1 = control1.robot_.timedRobotStatu_.statu
  268. # [label, pt] = self.mapManager.findNeastNode(frontMap, [cur_pose1.x, cur_pose1.y])
  269. # control1.robot_.GeneratePath(label, entrance_id, frontMap)
  270. # print("Front: begin:%s target:%s wheelBase:%f" % (label, entrance_id, wheel_base))
  271. #
  272. # cur_pose2 = control2.robot_.timedRobotStatu_.statu
  273. # [label, pt] = self.mapManager.findNeastNode(backMap, [cur_pose2.x, cur_pose2.y])
  274. # control2.robot_.GeneratePath(label, entrance_id, backMap)
  275. # print("Back: begin:%s target:%s wheelBase:%f" % (label, entrance_id, wheel_base))
  276. #
  277. # threadPool = ThreadPoolExecutor(2)
  278. # features = [
  279. # threadPool.submit(control1.robot_.Navigatting, label, entrance_id, autoDirect, wheel_base, task_flag),
  280. # threadPool.submit(control2.robot_.Navigatting, label, entrance_id, autoDirect, wheel_base, task_flag)
  281. # ]
  282. #
  283. # if self.asyncExecute(features) == False:
  284. # print(" Park Failed ")
  285. # return False
  286. # # ------------------------------------------
  287. # # 双单车驶至入口前巷道点
  288. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], wheel_base)
  289. entrance_streetNode = entrance_id.replace("S_", "R_")
  290. if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
  291. return False
  292. cur_pose1 = control1.robot_.timedRobotStatu_.statu
  293. [label, pt] = self.mapManager.findNeastNode(frontMap, [cur_pose1.x, cur_pose1.y])
  294. control1.robot_.GeneratePath(label, entrance_streetNode, frontMap)
  295. print("Front: begin:%s target:%s wheelBase:%f" % (label, entrance_streetNode, wheel_base))
  296. cur_pose2 = control2.robot_.timedRobotStatu_.statu
  297. [label, pt] = self.mapManager.findNeastNode(backMap, [cur_pose2.x, cur_pose2.y])
  298. control2.robot_.GeneratePath(label, entrance_streetNode, backMap)
  299. print("Back: begin:%s target:%s wheelBase:%f" % (label, entrance_streetNode, wheel_base))
  300. autoDirect = True
  301. threadPool = ThreadPoolExecutor(2)
  302. features = [
  303. threadPool.submit(control1.robot_.Navigatting, label, entrance_id, autoDirect, wheel_base, task_flag),
  304. threadPool.submit(control2.robot_.Navigatting, label, entrance_id, autoDirect, wheel_base, task_flag)
  305. ]
  306. if self.asyncExecute(features) == False:
  307. print(" Park Failed ")
  308. return False
  309. # 整车驶进入口---------------------------------
  310. if (controlMain.robot_.SwitchMoveMode(1, wheel_base) == False):
  311. return False
  312. map_name = "Front"
  313. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  314. map_name = "Back"
  315. controlMain.robot_.GeneratePath(entrance_streetNode, entrance_id, map_name)
  316. if controlMain.robot_.Navigatting(entrance_streetNode, entrance_id, True, wheel_base, task_flag) == False:
  317. return False
  318. # # ---------------------------------
  319. print(" input entrance completed!!!!")
  320. if (controlMain.robot_.SwitchMoveMode(1, wheel_base) == False):
  321. return False
  322. controlMain.robot_.ClampClose()
  323. # 整车去车位---------------------------------
  324. # map_name = "Front"
  325. # if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  326. # map_name = "Back"
  327. # controlMain.robot_.GeneratePath(entrance_id, target_id, map_name)
  328. # print("begin:%s target:%s wheelBase:%f" % (entrance_id, target_id, wheel_base))
  329. # controlMain.robot_.Navigatting(entrance_id, target_id, autoDirect, wheel_base, task_flag)
  330. # 整车驶离入口到入口航道点
  331. map_name = "Front"
  332. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  333. map_name = "Back"
  334. controlMain.robot_.GeneratePath(entrance_id, entrance_streetNode, map_name)
  335. print("begin:%s target:%s wheelBase:%f" % (entrance_id, entrance_streetNode, wheel_base))
  336. controlMain.robot_.Navigatting(entrance_id, entrance_streetNode, autoDirect, wheel_base, task_flag)
  337. # 整车从入口航道点到车位
  338. map_name = "Front"
  339. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  340. map_name = "Back"
  341. controlMain.robot_.GeneratePath(entrance_streetNode, target_id, map_name)
  342. print("begin:%s target:%s wheelBase:%f" % (entrance_streetNode, target_id, wheel_base))
  343. controlMain.robot_.Navigatting(entrance_streetNode, target_id, autoDirect, wheel_base, task_flag)
  344. print("-------------------------")
  345. # 整车松夹池------------------------------------
  346. if controlMain.robot_.ClampOpen() == False:
  347. return False
  348. map_name = "Front"
  349. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  350. map_name = "Back"
  351. # 整车出库---------------------------------
  352. # 限定轴距2.6m
  353. temp_wheel_base = self.mapManager.default_wheel_base
  354. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], temp_wheel_base)
  355. if (controlMain.robot_.SwitchMoveMode(1, temp_wheel_base) == False):
  356. return False
  357. entrance_streetNode = target_id.replace("S_", "R_")
  358. controlMain.robot_.GeneratePath(target_id, entrance_streetNode, map_name)
  359. if controlMain.robot_.Navigatting(target_id, entrance_streetNode, True, temp_wheel_base, task_flag) == False:
  360. return False
  361. #
  362. # if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
  363. # return False
  364. #
  365. # # 双单车出库
  366. # controlMain, control1, control2 = self.GetMainFrontBackAGV()
  367. # end_street = target_id.replace("S_", "R_")
  368. # control1.robot_.GeneratePath(target_id, end_street, frontMap)
  369. # control2.robot_.GeneratePath(target_id, end_street, backMap)
  370. #
  371. # threadPool = ThreadPoolExecutor(2)
  372. # threadPool.submit(control1.robot_.Navigatting,
  373. # target_id, end_street, autoDirect, wheel_base, task_flag)
  374. # threadPool.submit(control2.robot_.Navigatting,
  375. # target_id, end_street, autoDirect, wheel_base, task_flag)
  376. # threadPool.shutdown(wait=True)
  377. # 反馈
  378. self.g_rabbitmq.publish("command_ex", "agv_park_command_response_port",
  379. tf.MessageToString(park_table, as_utf8=True))
  380. print("Publish_park_response------------------\n", park_table)
  381. return True
  382. def updateMap_pick(self, wheelBase): # 轴距
  383. self.mapManager.ResetMap("Front", 0, wheelBase / 2)
  384. self.mapManager.ResetMap("Back", 0, -wheelBase / 2)
  385. def AutoPickTask(self, pick_table: message.pick_table = None):
  386. print("AutoPickTask:---------------------\n")
  387. task_flag = 2 # 取车
  388. controlMain, control1, control2 = self.GetMainFrontBackAGV()
  389. mainMap, frontMap, backMap = ["Main", "Front", "Back"]
  390. space_id = "S_" + str(pick_table.actually_space_info.table_id) # "S147"
  391. export_id = "S_" + str(pick_table.terminal_id) # "S1101"
  392. print(space_id, export_id)
  393. # 轴距
  394. wheel_base = pick_table.actually_measure_info.measure_info_to_plc_forward.wheelbase
  395. control1.WheelBaseEdit.setText(str(wheel_base))
  396. control2.WheelBaseEdit.setText(str(wheel_base))
  397. # # 双单车入库 -------------------------
  398. # self.updateMap_pick(wheel_base)
  399. # if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
  400. # return False
  401. # cur_pose1 = control1.robot_.timedRobotStatu_.statu
  402. # [label, pt] = self.mapManager.findNeastNode(frontMap, [cur_pose1.x, cur_pose1.y])
  403. # control1.robot_.GeneratePath(label, space_id, frontMap)
  404. # print("Front: begin:%s target:%s wheelBase:%f" % (label, space_id, wheel_base))
  405. #
  406. # cur_pose2 = control2.robot_.timedRobotStatu_.statu
  407. # [label, pt] = self.mapManager.findNeastNode(backMap, [cur_pose2.x, cur_pose2.y])
  408. # control2.robot_.GeneratePath(label, space_id, backMap)
  409. # print("Back: begin:%s target:%s wheelBase:%f" % (label, space_id, wheel_base))
  410. #
  411. # autoDirect = True
  412. # threadPool = ThreadPoolExecutor(2)
  413. # features = [threadPool.submit(control1.robot_.Navigatting, label, space_id, autoDirect, wheel_base, task_flag),
  414. # threadPool.submit(control2.robot_.Navigatting, label, space_id, autoDirect, wheel_base, task_flag)]
  415. # if self.asyncExecute(features) == False:
  416. # print(" Pick Failed ")
  417. # return False
  418. # # ------------------------------------------
  419. # # 双单车驶至车位前巷道点
  420. self.updateMap_pick(wheel_base)
  421. space_streetNode = space_id.replace("S_", "R_")
  422. if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
  423. return False
  424. cur_pose1 = control1.robot_.timedRobotStatu_.statu
  425. [label, pt] = self.mapManager.findNeastNode(frontMap, [cur_pose1.x, cur_pose1.y])
  426. control1.robot_.GeneratePath(label, space_streetNode, frontMap)
  427. print("Front: begin:%s target:%s wheelBase:%f" % (label, space_streetNode, wheel_base))
  428. cur_pose2 = control2.robot_.timedRobotStatu_.statu
  429. [label, pt] = self.mapManager.findNeastNode(backMap, [cur_pose2.x, cur_pose2.y])
  430. control2.robot_.GeneratePath(label, space_streetNode, backMap)
  431. print("Back: begin:%s target:%s wheelBase:%f" % (label, space_streetNode, wheel_base))
  432. autoDirect = True
  433. threadPool = ThreadPoolExecutor(2)
  434. features = [
  435. threadPool.submit(control1.robot_.Navigatting, label, space_streetNode, autoDirect, wheel_base, task_flag),
  436. threadPool.submit(control2.robot_.Navigatting, label, space_streetNode, autoDirect, wheel_base, task_flag)
  437. ]
  438. if self.asyncExecute(features) == False:
  439. print(" Pick Failed ")
  440. return False
  441. # 整车驶进车位---------------------------------
  442. if (controlMain.robot_.SwitchMoveMode(1, wheel_base) == False):
  443. return False
  444. map_name = "Front"
  445. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  446. map_name = "Back"
  447. controlMain.robot_.GeneratePath(space_streetNode, space_id, map_name)
  448. if controlMain.robot_.Navigatting(space_streetNode, space_id, True, wheel_base, task_flag) == False:
  449. return False
  450. # # ---------------------------------
  451. # 整车夹持------------------------------------
  452. print(" input space completed!!!!")
  453. if (controlMain.robot_.SwitchMoveMode(1, wheel_base) == False):
  454. return False
  455. if controlMain.robot_.ClampClose() == False:
  456. return False
  457. # 整车到出口---------------------------------
  458. map_name = "Front"
  459. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  460. map_name = "Back"
  461. controlMain.robot_.GeneratePath(space_id, export_id, map_name)
  462. print("Total: begin:%s target:%s wheelBase:%f" % (space_id, export_id, wheel_base))
  463. if controlMain.robot_.Navigatting(space_id, export_id, True, wheel_base, task_flag) == False:
  464. return False
  465. # 整车松夹池------------------------------------
  466. if controlMain.robot_.ClampOpen() == False:
  467. return False
  468. # 整车回巷道------------------------------------
  469. temp_wheel_base = self.mapManager.default_wheel_base
  470. self.updateMap_pick(temp_wheel_base)
  471. if (controlMain.robot_.SwitchMoveMode(1, temp_wheel_base) == False):
  472. return False
  473. map_name = "Front"
  474. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  475. map_name = "Back"
  476. space_streetNode = export_id.replace("S_", "R_")
  477. controlMain.robot_.GeneratePath(export_id, space_streetNode, map_name)
  478. if controlMain.robot_.Navigatting(export_id, space_streetNode, True, temp_wheel_base, task_flag) == False:
  479. return False
  480. # 双单车出库
  481. # controlMain, control1, control2 = self.GetMainFrontBackAGV()
  482. # self.ReLoadMap(frontMap, "./map.json")
  483. # self.updateMap_pick(export_id, frontMap)
  484. # control1.robot_.GeneratePath(export_id, "F_exportLink", frontMap)
  485. #
  486. # self.ReLoadMap(backMap, "./map.json")
  487. # self.updateMap_pick(export_id, backMap)
  488. # control2.robot_.GeneratePath(export_id, "B_exportLink", backMap)
  489. #
  490. # threadPool = ThreadPoolExecutor(2)
  491. # features=[
  492. # threadPool.submit(control1.robot_.Navigatting,export_id, "F_exportLink", True, wheel_base, task_flag),
  493. # threadPool.submit(control2.robot_.Navigatting,export_id, "B_exportLink", True, wheel_base, task_flag)
  494. # ]
  495. # if self.asyncExecute(features) == False:
  496. # print(" Pick Failed ")
  497. # return False
  498. print(" over publish...")
  499. # 反馈
  500. self.g_rabbitmq.publish("command_ex", "agv_pick_command_response_port",
  501. tf.MessageToString(pick_table, as_utf8=True))
  502. print("Publish_park_response------------------\n", pick_table)
  503. return True
  504. def ComputeStreetNode(self, mapName, s_id, s_x, s_y, s_theta):
  505. """
  506. """
  507. id, n_x, n_y = "", 0, 0
  508. if s_id == "S_1101":
  509. id = "R_1101"
  510. n_y = self.mapManager.maps[mapName].graph_.points[id][1]
  511. k = math.tan(s_theta)
  512. n_x = (n_y - s_y) / k + s_x # 弧度
  513. print(id, n_x, n_y)
  514. return [id, n_x, n_y]
  515. def readJson(self, file):
  516. with open(file, 'r', encoding='utf-8') as fp:
  517. map = json.load(fp)
  518. return map
  519. def Update(self):
  520. self.gl.update()
  521. if self.isAutoDispatchOnline:
  522. # self.Controller1.setEnabled(False)
  523. # self.Controller2.setEnabled(False)
  524. pass
  525. else:
  526. self.Controller1.setVisible(True)
  527. self.Controller2.setVisible(True)
  528. # 窗口基础属性
  529. def basic(self):
  530. # 设置标题,大小,图标
  531. self.setWindowTitle("GT")
  532. self.resize(1100, 650)
  533. self.setWindowIcon(QIcon("./image/Gt.png"))
  534. # 居中显示
  535. screen = QDesktopWidget().geometry()
  536. self_size = self.geometry()
  537. self.move(int((screen.width() - self_size.width()) / 2), int((screen.height() - self_size.height()) / 2))
  538. def closeEvent(self, QCloseEvent):
  539. self.Cancel_ = True
  540. self.gl.close()
  541. print("close...")
  542. # 分割窗口
  543. def split_(self):
  544. splitter_main = QSplitter(Qt.Horizontal)
  545. splitter = QSplitter(Qt.Vertical)
  546. splitter.addWidget(self.count_frame_)
  547. splitter.addWidget(self.Controller1)
  548. splitter.addWidget(self.Controller2)
  549. splitter.addWidget(self.ManualOperationWidget)
  550. splitter.setStretchFactor(0, 1)
  551. splitter.setStretchFactor(1, 3)
  552. splitter.setStretchFactor(2, 3)
  553. splitter.setStretchFactor(3, 1)
  554. splitter_main.addWidget(splitter)
  555. splitter_main.addWidget(self.gl)
  556. splitter_main.setStretchFactor(0, 1)
  557. splitter_main.setStretchFactor(1, 10)
  558. return splitter_main
  559. if __name__ == "__main__":
  560. app = QApplication(sys.argv)
  561. win = MainWindow()
  562. win.show()
  563. sys.exit(app.exec_())
  564. # ===============================================================================
  565. #
  566. # Local Variables:
  567. # mode: Python
  568. # indent-tabs-mode: nil
  569. # End:
  570. #
  571. # ===============================================================================