test.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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 = False
  75. self.isAutoDispatchOnline = True
  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. [controlMain, control1, control2] = self.GetMainFrontBackAGV()
  238. mainMap, frontMap, backMap = ["Base", "Front", "Back"]
  239. entrance_id = "S_" + str(park_table.terminal_id) # "S1101"
  240. entrance_x, entrance_y, entrance_theta = [park_table.entrance_measure_info.measure_info_to_plc_forward.cx,
  241. park_table.entrance_measure_info.measure_info_to_plc_forward.cy,
  242. (
  243. 90 + park_table.entrance_measure_info.measure_info_to_plc_forward.theta) / 180 * math.pi]
  244. # 变换到地图坐标系
  245. [dx, dy, da] = [-0.184040126204, -0.647539079189, 178.9302736990612 / 180 * math.pi]
  246. trans_x = -0.999825716019 * entrance_x - 0.018668506294 * entrance_y + dx
  247. trans_y = 0.018668506294 * entrance_x - 0.999825716019 * entrance_y + dy
  248. trans_a = entrance_theta + da - math.pi
  249. while trans_a < 0:
  250. trans_a += math.pi
  251. print("entrance:", entrance_id, trans_x, trans_y, trans_a / math.pi * 180)
  252. target_id = "S_" + str(park_table.allocated_space_info.table_id) # "S147"
  253. print("target:", target_id)
  254. # 轴距
  255. wheel_base = park_table.entrance_measure_info.measure_info_to_plc_forward.wheelbase
  256. control1.WheelBaseEdit.setText(str(wheel_base))
  257. control2.WheelBaseEdit.setText(str(wheel_base))
  258. trans_x += wheel_base / 2 * math.cos(trans_a)
  259. trans_y += wheel_base / 2 * math.sin(trans_a)
  260. if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
  261. return False
  262. autoDirect = True
  263. # # 双单车入库-----------------------------------------------------
  264. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], wheel_base)
  265. cur_pose1 = control1.robot_.timedRobotStatu_.statu
  266. [label, pt] = self.mapManager.findNeastNode(frontMap, [cur_pose1.x, cur_pose1.y])
  267. control1.robot_.GeneratePath(label, entrance_id, frontMap)
  268. print("Front: begin:%s target:%s wheelBase:%f" % (label, entrance_id, wheel_base))
  269. cur_pose2 = control2.robot_.timedRobotStatu_.statu
  270. [label, pt] = self.mapManager.findNeastNode(backMap, [cur_pose2.x, cur_pose2.y])
  271. control2.robot_.GeneratePath(label, entrance_id, backMap)
  272. print("Back: begin:%s target:%s wheelBase:%f" % (label, entrance_id, wheel_base))
  273. threadPool = ThreadPoolExecutor(2)
  274. features = [threadPool.submit(control1.robot_.Navigatting, label, entrance_id, autoDirect, wheel_base),
  275. threadPool.submit(control2.robot_.Navigatting, label, entrance_id, autoDirect, wheel_base)]
  276. if self.asyncExecute(features) == False:
  277. print(" Park Failed ")
  278. return False
  279. # # ------------------------------------------
  280. # # 双单车驶至入口前巷道点
  281. # streetNode = entrance_id.replace("S_", "R_")
  282. # if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
  283. # return False
  284. # cur_pose1 = control1.robot_.timedRobotStatu_.statu
  285. # [label, pt] = self.mapManager.findNeastNode(frontMap, [cur_pose1.x, cur_pose1.y])
  286. # control1.robot_.GeneratePath(label, streetNode, frontMap)
  287. # print("Front: begin:%s target:%s wheelBase:%f" % (label, streetNode, wheel_base))
  288. #
  289. # cur_pose2 = control2.robot_.timedRobotStatu_.statu
  290. # [label, pt] = self.mapManager.findNeastNode(backMap, [cur_pose2.x, cur_pose2.y])
  291. # control2.robot_.GeneratePath(label, streetNode, backMap)
  292. # print("Back: begin:%s target:%s wheelBase:%f" % (label, streetNode, wheel_base))
  293. #
  294. # autoDirect = True
  295. # threadPool = ThreadPoolExecutor(2)
  296. # features = [threadPool.submit(control1.robot_.Navigatting, label, entrance_id, autoDirect, wheel_base),
  297. # threadPool.submit(control2.robot_.Navigatting, label, entrance_id, autoDirect, wheel_base)]
  298. # if self.asyncExecute(features) == False:
  299. # print(" Pick Failed ")
  300. # return False
  301. #
  302. # # 整车驶进入口---------------------------------
  303. # if (controlMain.robot_.SwitchMoveMode(1, wheel_base) == False):
  304. # return False
  305. #
  306. # map_name = "Front"
  307. # if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  308. # map_name = "Back"
  309. # controlMain.robot_.GeneratePath(streetNode, entrance_id, map_name)
  310. # if controlMain.robot_.Navigatting(streetNode, entrance_id, True, wheel_base) == False:
  311. # return False
  312. # # ---------------------------------
  313. print(" input entrance completed!!!!")
  314. if (controlMain.robot_.SwitchMoveMode(1, wheel_base) == False):
  315. return False
  316. controlMain.robot_.ClampClose()
  317. # 整车去车位---------------------------------
  318. map_name = "Front"
  319. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  320. map_name = "Back"
  321. controlMain.robot_.GeneratePath(entrance_id, target_id, map_name)
  322. print("begin:%s target:%s wheelBase:%f" % (entrance_id, target_id, wheel_base))
  323. controlMain.robot_.Navigatting(entrance_id, target_id, autoDirect, wheel_base)
  324. print("-------------------------")
  325. # 整车松夹池------------------------------------
  326. if controlMain.robot_.ClampOpen()==False:
  327. return False
  328. map_name = "Front"
  329. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  330. map_name = "Back"
  331. # 整车出库---------------------------------
  332. # 限定轴距2.6m
  333. temp_wheel_base = self.mapManager.default_wheel_base
  334. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], temp_wheel_base)
  335. if (controlMain.robot_.SwitchMoveMode(1, temp_wheel_base) == False):
  336. return False
  337. streetNode = target_id.replace("S_", "R_")
  338. controlMain.robot_.GeneratePath(target_id, streetNode, map_name)
  339. if controlMain.robot_.Navigatting(target_id, streetNode, True, temp_wheel_base) == False:
  340. return False
  341. #
  342. # if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
  343. # return False
  344. #
  345. # # 双单车出库
  346. # controlMain, control1, control2 = self.GetMainFrontBackAGV()
  347. # end_street = target_id.replace("S_", "R_")
  348. # control1.robot_.GeneratePath(target_id, end_street, frontMap)
  349. # control2.robot_.GeneratePath(target_id, end_street, backMap)
  350. #
  351. # threadPool = ThreadPoolExecutor(2)
  352. # threadPool.submit(control1.robot_.Navigatting,
  353. # target_id, end_street, autoDirect, wheel_base)
  354. # threadPool.submit(control2.robot_.Navigatting,
  355. # target_id, end_street, autoDirect, wheel_base)
  356. # threadPool.shutdown(wait=True)
  357. # 反馈
  358. self.g_rabbitmq.publish("command_ex", "agv_park_command_response_port",
  359. tf.MessageToString(park_table, as_utf8=True))
  360. print("Publish_park_response------------------\n", park_table)
  361. return True
  362. def updateMap_pick(self, wheelBase): # 轴距
  363. self.mapManager.ResetMap("Front", 0, wheelBase / 2)
  364. self.mapManager.ResetMap("Back", 0, -wheelBase / 2)
  365. def AutoPickTask(self, pick_table: message.pick_table = None):
  366. print("AutoPickTask:---------------------\n")
  367. controlMain, control1, control2 = self.GetMainFrontBackAGV()
  368. mainMap, frontMap, backMap = ["Main", "Front", "Back"]
  369. space_id = "S_" + str(pick_table.actually_space_info.table_id) # "S147"
  370. export_id = "S_" + str(pick_table.terminal_id) # "S1101"
  371. print(space_id, export_id)
  372. # 轴距
  373. wheel_base = pick_table.actually_measure_info.measure_info_to_plc_forward.wheelbase
  374. control1.WheelBaseEdit.setText(str(wheel_base))
  375. control2.WheelBaseEdit.setText(str(wheel_base))
  376. self.updateMap_pick(wheel_base)
  377. # 双单车入库
  378. if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
  379. return False
  380. cur_pose1 = control1.robot_.timedRobotStatu_.statu
  381. [label, pt] = self.mapManager.findNeastNode(frontMap, [cur_pose1.x, cur_pose1.y])
  382. control1.robot_.GeneratePath(label, space_id, frontMap)
  383. print("Front: begin:%s target:%s wheelBase:%f" % (label, space_id, wheel_base))
  384. cur_pose2 = control2.robot_.timedRobotStatu_.statu
  385. [label, pt] = self.mapManager.findNeastNode(backMap, [cur_pose2.x, cur_pose2.y])
  386. control2.robot_.GeneratePath(label, space_id, backMap)
  387. print("Back: begin:%s target:%s wheelBase:%f" % (label, space_id, wheel_base))
  388. autoDirect = True
  389. threadPool = ThreadPoolExecutor(2)
  390. features = [threadPool.submit(control1.robot_.Navigatting, label, space_id, autoDirect, wheel_base),
  391. threadPool.submit(control2.robot_.Navigatting, label, space_id, autoDirect, wheel_base)]
  392. if self.asyncExecute(features) == False:
  393. print(" Pick Failed ")
  394. return False
  395. # # ------------------------------------------
  396. # # 双单车驶至车位前巷道点
  397. # streetNode = space_id.replace("S_", "R_")
  398. # if (controlMain.robot_.SwitchMoveMode(0, wheel_base) == False):
  399. # return False
  400. # cur_pose1 = control1.robot_.timedRobotStatu_.statu
  401. # [label, pt] = self.mapManager.findNeastNode(frontMap, [cur_pose1.x, cur_pose1.y])
  402. # control1.robot_.GeneratePath(label, streetNode, frontMap)
  403. # print("Front: begin:%s target:%s wheelBase:%f" % (label, streetNode, wheel_base))
  404. #
  405. # cur_pose2 = control2.robot_.timedRobotStatu_.statu
  406. # [label, pt] = self.mapManager.findNeastNode(backMap, [cur_pose2.x, cur_pose2.y])
  407. # control2.robot_.GeneratePath(label, streetNode, backMap)
  408. # print("Back: begin:%s target:%s wheelBase:%f" % (label, streetNode, wheel_base))
  409. #
  410. # autoDirect = True
  411. # threadPool = ThreadPoolExecutor(2)
  412. # features = [threadPool.submit(control1.robot_.Navigatting, label, streetNode, autoDirect, wheel_base),
  413. # threadPool.submit(control2.robot_.Navigatting, label, streetNode, autoDirect, wheel_base)]
  414. # if self.asyncExecute(features) == False:
  415. # print(" Pick Failed ")
  416. # return False
  417. #
  418. # # 整车驶进车位---------------------------------
  419. # if (controlMain.robot_.SwitchMoveMode(1, wheel_base) == False):
  420. # return False
  421. #
  422. # map_name = "Front"
  423. # if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  424. # map_name = "Back"
  425. # controlMain.robot_.GeneratePath(streetNode, space_id, map_name)
  426. # if controlMain.robot_.Navigatting(streetNode, space_id, True, wheel_base) == False:
  427. # return False
  428. # # ---------------------------------
  429. # 整车夹持------------------------------------
  430. print(" input space completed!!!!")
  431. if (controlMain.robot_.SwitchMoveMode(1, wheel_base) == False):
  432. return False
  433. if controlMain.robot_.ClampClose() == False:
  434. return False
  435. # 整车到出口---------------------------------
  436. map_name = "Front"
  437. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  438. map_name = "Back"
  439. controlMain.robot_.GeneratePath(space_id, export_id, map_name)
  440. print("Total: begin:%s target:%s wheelBase:%f" % (space_id, export_id, wheel_base))
  441. if controlMain.robot_.Navigatting(space_id, export_id, True, wheel_base) == False:
  442. return False
  443. # 整车松夹池------------------------------------
  444. if controlMain.robot_.ClampOpen() == False:
  445. return False
  446. # 整车回巷道------------------------------------
  447. temp_wheel_base = self.mapManager.default_wheel_base
  448. self.updateMap_pick(temp_wheel_base)
  449. if (controlMain.robot_.SwitchMoveMode(1, temp_wheel_base) == False):
  450. return False
  451. map_name = "Front"
  452. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  453. map_name = "Back"
  454. streetNode = export_id.replace("S_", "R_")
  455. controlMain.robot_.GeneratePath(export_id, streetNode, map_name)
  456. if controlMain.robot_.Navigatting(export_id, streetNode, True, temp_wheel_base) == False:
  457. return False
  458. # 双单车出库
  459. # controlMain, control1, control2 = self.GetMainFrontBackAGV()
  460. # self.ReLoadMap(frontMap, "./map.json")
  461. # self.updateMap_pick(export_id, frontMap)
  462. # control1.robot_.GeneratePath(export_id, "F_exportLink", frontMap)
  463. #
  464. # self.ReLoadMap(backMap, "./map.json")
  465. # self.updateMap_pick(export_id, backMap)
  466. # control2.robot_.GeneratePath(export_id, "B_exportLink", backMap)
  467. #
  468. # threadPool = ThreadPoolExecutor(2)
  469. # features=[threadPool.submit(control1.robot_.Navigatting,export_id, "F_exportLink", True, wheel_base),
  470. # threadPool.submit(control2.robot_.Navigatting,export_id, "B_exportLink", True, wheel_base)]
  471. # if self.asyncExecute(features) == False:
  472. # print(" Pick Failed ")
  473. # return False
  474. print(" over publish...")
  475. # 反馈
  476. self.g_rabbitmq.publish("command_ex", "agv_pick_command_response_port",
  477. tf.MessageToString(pick_table, as_utf8=True))
  478. print("Publish_park_response------------------\n", pick_table)
  479. return True
  480. def ComputeStreetNode(self, mapName, s_id, s_x, s_y, s_theta):
  481. """
  482. """
  483. id, n_x, n_y = "", 0, 0
  484. if s_id == "S_1101":
  485. id = "R_1101"
  486. n_y = self.mapManager.maps[mapName].graph_.points[id][1]
  487. k = math.tan(s_theta)
  488. n_x = (n_y - s_y) / k + s_x # 弧度
  489. print(id, n_x, n_y)
  490. return [id, n_x, n_y]
  491. def readJson(self, file):
  492. with open(file, 'r', encoding='utf-8') as fp:
  493. map = json.load(fp)
  494. return map
  495. def Update(self):
  496. self.gl.update()
  497. if self.isAutoDispatchOnline:
  498. # self.Controller1.setEnabled(False)
  499. # self.Controller2.setEnabled(False)
  500. pass
  501. else:
  502. self.Controller1.setVisible(True)
  503. self.Controller2.setVisible(True)
  504. # 窗口基础属性
  505. def basic(self):
  506. # 设置标题,大小,图标
  507. self.setWindowTitle("GT")
  508. self.resize(1100, 650)
  509. self.setWindowIcon(QIcon("./image/Gt.png"))
  510. # 居中显示
  511. screen = QDesktopWidget().geometry()
  512. self_size = self.geometry()
  513. self.move(int((screen.width() - self_size.width()) / 2), int((screen.height() - self_size.height()) / 2))
  514. def closeEvent(self, QCloseEvent):
  515. self.Cancel_ = True
  516. self.gl.close()
  517. print("close...")
  518. # 分割窗口
  519. def split_(self):
  520. splitter_main = QSplitter(Qt.Horizontal)
  521. splitter = QSplitter(Qt.Vertical)
  522. splitter.addWidget(self.count_frame_)
  523. splitter.addWidget(self.Controller1)
  524. splitter.addWidget(self.Controller2)
  525. splitter.addWidget(self.ManualOperationWidget)
  526. splitter.setStretchFactor(0, 1)
  527. splitter.setStretchFactor(1, 3)
  528. splitter.setStretchFactor(2, 3)
  529. splitter.setStretchFactor(3, 1)
  530. splitter_main.addWidget(splitter)
  531. splitter_main.addWidget(self.gl)
  532. splitter_main.setStretchFactor(0, 1)
  533. splitter_main.setStretchFactor(1, 10)
  534. return splitter_main
  535. if __name__ == "__main__":
  536. app = QApplication(sys.argv)
  537. win = MainWindow()
  538. win.show()
  539. sys.exit(app.exec_())
  540. # ===============================================================================
  541. #
  542. # Local Variables:
  543. # mode: Python
  544. # indent-tabs-mode: nil
  545. # End:
  546. #
  547. # ===============================================================================