test.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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 math
  36. import threading
  37. import time
  38. import sys
  39. from PyQt5.QtGui import *
  40. from PyQt5.QtWidgets import *
  41. from PyQt5.QtCore import *
  42. from MapGLWidget import MapGLWidget
  43. import json
  44. import dijkstra.Map as mp
  45. import ControllWidget
  46. import JointContrallerWidget
  47. import ManualOperationWidget
  48. import RobotData as RD
  49. import message_pb2 as message
  50. import google.protobuf.json_format as jtf
  51. import google.protobuf.text_format as tf
  52. from concurrent.futures import ThreadPoolExecutor
  53. import uuid
  54. from mytool.txt_helper.txt_operation import TXTOperation
  55. from custom_define import RobotName
  56. from mytool.RabbitMq_helper import async_communication as rabitmq
  57. # ===============================================================================
  58. class MainWindow(QMainWindow):
  59. """docstring for Mainwindow"""
  60. mapManager = mp.MapManager()
  61. ui_nodes = {}
  62. ui_nodes["street_nodes"] = []
  63. ui_nodes["space_nodes"] = []
  64. def __init__(self, parent=None):
  65. super(MainWindow, self).__init__(parent)
  66. self.basic()
  67. self.count_frame_ = ControllWidget.CountFrame()
  68. self.loadJsonMap("./map.json")
  69. self.isLocalTest = False
  70. self.isAutoDispatchOnline = True
  71. rpc_1 = "192.168.0.70:9090"
  72. mqtt_1 = ["pyui1", "192.168.0.70", 1883, "admin", "zx123456"]
  73. rpc_2 = "192.168.0.71:9090"
  74. mqtt_2 = ["pyui2", "192.168.0.71", 1883, "admin", "zx123456"]
  75. if self.isLocalTest:
  76. rpc_1 = "127.0.0.1:9090"
  77. mqtt_1 = ["pyui-main", "127.0.0.1", 1883, "admin", "zx123456"]
  78. rpc_2 = "127.0.0.1:9091"
  79. mqtt_2 = ["pyui-child", "127.0.0.1", 1883, "admin", "zx123456"]
  80. config1 = {"label": RobotName.strAGVMain,
  81. "rpc": rpc_1,
  82. "street_nodes": self.ui_nodes["street_nodes"],
  83. "space_nodes": self.ui_nodes["space_nodes"],
  84. "mqtt": mqtt_1,
  85. "subTopics": {"agv_main/agv_statu": message.RobotStatu.__name__,
  86. "agv_main/nav_statu": message.NavStatu.__name__},
  87. "cmdTopic": "agv_main/nav_cmd",
  88. "robotColor": [0.7, 0.2, 0.3]}
  89. config2 = {"label": RobotName.strAGV2,
  90. "rpc": rpc_2,
  91. # "rpc": "127.0.0.1:9091",
  92. "street_nodes": self.ui_nodes["street_nodes"],
  93. "space_nodes": self.ui_nodes["space_nodes"],
  94. "mqtt": mqtt_2,
  95. "subTopics": {"agv_child/agv_statu": message.RobotStatu.__name__,
  96. "agv_child/nav_statu": message.NavStatu.__name__},
  97. "cmdTopic": "agv_child/nav_cmd",
  98. "robotColor": [0.4, 0.2, 0.8]}
  99. self.Controller1 = ControllWidget.ControlFrame(config1)
  100. self.Controller2 = ControllWidget.ControlFrame(config2)
  101. robot_dict = {self.Controller1.robot_.name_: self.Controller1.robot_,
  102. self.Controller2.robot_.name_: self.Controller2.robot_}
  103. self.ManualOperationWidget = ManualOperationWidget.ManualOperationWidget(robot_dict)
  104. splitter_main = self.split_()
  105. self.setCentralWidget(splitter_main)
  106. self.gl.SetRobot1Instance(self.Controller1.robot_)
  107. self.gl.SetRobot2Instance(self.Controller2.robot_)
  108. self.timer_ = QTimer()
  109. self.timer_.timeout.connect(self.Update)
  110. self.timer_.start(100)
  111. # 启动RabbitMQ
  112. self.g_rabbitmq = None
  113. if self.isAutoDispatchOnline:
  114. self.g_rabbitmq = rabitmq.RabbitAsyncCommunicator("192.168.0.201", 5672, "zx", "123456")
  115. calbbacks = [["agv_park_command_request_queue", self.recv_park_request],
  116. ["agv_pick_command_request_queue", self.recv_pick_request]]
  117. self.g_rabbitmq.Init(calbbacks, None)
  118. self.g_rabbitmq.setDaemon(True) # 守护线程随主线程结束
  119. self.g_rabbitmq.start()
  120. def recv_park_request(self, msg):
  121. print("Recv_park_request------------------\n", msg)
  122. park_table = message.park_table()
  123. try:
  124. tf.Parse(msg, park_table)
  125. except Exception as e:
  126. print("Parse error\n")
  127. if self.isAutoDispatchOnline:
  128. self.AutoParkTask(park_table)
  129. def recv_pick_request(self, msg):
  130. print("Recv_pick_request------------------\n", msg)
  131. pick_table = message.pick_table()
  132. try:
  133. tf.Parse(msg, pick_table)
  134. except Exception as e:
  135. print("Parse error\n")
  136. if self.isAutoDispatchOnline:
  137. self.AutoPickTask(pick_table)
  138. def ReLoadMap(self, mapName, file):
  139. self.mapManager.Reset(mapName)
  140. map = self.readJson(file)
  141. flag = "C_"
  142. if mapName == "Front":
  143. flag = "F_"
  144. elif mapName == "Back":
  145. flag = "B_"
  146. elif mapName == "Main":
  147. flag = "C_"
  148. else:
  149. print(" map name is error:%s" % (mapName))
  150. return
  151. for node in map['street_nodes'].items():
  152. [id, point] = node
  153. street_node = mp.StreetNode(id, point[0], point[1])
  154. if street_node.id_.find(flag) >= 0:
  155. if street_node.id_.find("OutLink")>=0:
  156. continue
  157. self.mapManager.AddVertex(mapName, street_node)
  158. for node in map['space_nodes'].items():
  159. [id, point] = node
  160. [x, y, yaw] = point
  161. space_node = mp.SpaceNode(id, point[0], point[1], yaw)
  162. self.mapManager.AddVertex(mapName, space_node)
  163. for road in map['roads'].items():
  164. [roadName, points] = road
  165. for pt1 in points:
  166. for pt2 in points:
  167. if not pt1 == pt2:
  168. if roadName.find(flag) >= 0:
  169. self.mapManager.AddEdge(mapName, pt1, pt2)
  170. def loadJsonMap(self, file):
  171. self.gl = MapGLWidget() # 将opengl例子嵌入GUI
  172. map = self.readJson(file)
  173. for node in map['street_nodes'].items():
  174. [id, point] = node
  175. street_node = mp.StreetNode(id, point[0], point[1])
  176. self.mapManager.AddVertex("Base", street_node)
  177. if street_node.id_.find("F_") >= 0:
  178. self.mapManager.AddVertex("Front", street_node)
  179. if street_node.id_.find("B_") >= 0:
  180. self.mapManager.AddVertex("Back", street_node)
  181. if street_node.id_.find("C_") >= 0:
  182. self.mapManager.AddVertex("Main", street_node)
  183. self.ui_nodes["street_nodes"].append(id)
  184. for node in map['space_nodes'].items():
  185. [id, point] = node
  186. [x, y, yaw] = point
  187. space_node = mp.SpaceNode(id, point[0], point[1], yaw)
  188. self.mapManager.AddVertex("Base", space_node)
  189. self.mapManager.AddVertex("Front", space_node)
  190. self.mapManager.AddVertex("Back", space_node)
  191. self.mapManager.AddVertex("Main", space_node)
  192. self.ui_nodes["space_nodes"].append(id)
  193. for road in map['roads'].items():
  194. [roadName, points] = road
  195. for pt1 in points:
  196. for pt2 in points:
  197. if not pt1 == pt2:
  198. self.mapManager.AddEdge("Base", pt1, pt2)
  199. if pt1.find("OutLink")>=0 or pt2.find("OutLink")>=0:
  200. continue
  201. if roadName.find("F_") >= 0:
  202. self.mapManager.AddEdge("Front", pt1, pt2)
  203. if roadName.find("B_") >= 0:
  204. self.mapManager.AddEdge("Back", pt1, pt2)
  205. if roadName.find("C_") >= 0:
  206. self.mapManager.AddEdge("Main", pt1, pt2)
  207. self.gl.SetMaps(self.mapManager.maps)
  208. def updateMap_park(self, entrance_id, pose, mapName): # 0:前车轨迹,1:后车轨迹,2:添加整车轨迹
  209. self.ReLoadMap(mapName, "./map.json")
  210. trans_x, trans_y, trans_a = pose
  211. # 加车位点
  212. self.mapManager.maps[mapName].AddVertex(mp.SpaceNode("S1101", trans_x, trans_y,trans_a))
  213. entrance_street_nodes = self.ComputeStreetNode(entrance_id, trans_x, trans_y, trans_a)
  214. print("entrance_space pose: ", self.mapManager.maps[mapName].graph_.points[entrance_id])
  215. street_name = "F_InputLink"
  216. if mapName == "Front":
  217. street_name = "F_InputLink"
  218. self.mapManager.maps[mapName].AddVertex(mp.StreetNode(street_name, entrance_street_nodes[0][0],
  219. entrance_street_nodes[0][1])) # 更新库位点对应马路点
  220. if mapName == "Main":
  221. street_name = "C_InputLink"
  222. self.mapManager.maps[mapName].AddVertex(mp.StreetNode(street_name, entrance_street_nodes[1][0],
  223. entrance_street_nodes[1][1])) # 更新库位点对应马路点
  224. if mapName == "Back":
  225. street_name = "B_InputLink"
  226. self.mapManager.maps[mapName].AddVertex(mp.StreetNode(street_name, entrance_street_nodes[2][0],
  227. entrance_street_nodes[2][1])) # 更新库位点对应马路点
  228. # 加临时边
  229. for node_id, value in self.mapManager.VertexDict(mapName).items():
  230. if node_id.find("Input") >= 0:
  231. self.mapManager.maps[mapName].AddEdge(street_name, node_id)
  232. self.mapManager.AddVertex(mapName, mp.SpaceNode(entrance_id, trans_x, trans_y, trans_a)) # 更新库位点
  233. self.mapManager.maps[mapName].AddEdge(entrance_id, street_name)
  234. print(mapName + " Map entrance_street pose ", self.mapManager.maps[mapName].graph_.points[street_name])
  235. self.gl.SetMap(mapName, self.mapManager.maps[mapName])
  236. def GenerateSpecifiedMap(self, map_type): # 0:前车地图,1:后车地图,2:整车地图
  237. pass
  238. '''map = self.load_map("./map.json")
  239. {
  240. for node in map['street_nodes'].items():
  241. [id, point] = node
  242. street_node = mp.StreetNode(id, point[0], point[1])
  243. self.mapManager.AddVertex(street_node)
  244. self.gl.AddNode([id, "street_node", point])
  245. self.ui_nodes["street_nodes"].append(id)
  246. for node in map['space_nodes'].items():
  247. [id, point] = node
  248. [x, y, yaw] = point
  249. space_node = mp.SpaceNode(id, point[0], point[1], yaw)
  250. self.mapManager.AddVertex(space_node)
  251. glNode = [id, "space_node", [x, y]]
  252. self.gl.AddNode(glNode)
  253. self.ui_nodes["space_nodes"].append(id)
  254. for road in map['roads'].items():
  255. self.gl.AddRoad(road)
  256. [_, points] = road
  257. for pt1 in points:
  258. for pt2 in points:
  259. if not pt1 == pt2:
  260. self.mapManager.AddEdge(pt1, pt2)
  261. }
  262. if type == 0:
  263. pass
  264. elif type == 1:
  265. pass
  266. elif type == 2:
  267. pass
  268. else:
  269. print("type of specified map is wrong!\n")'''
  270. def GetMainFrontBackAGV(self):
  271. controlMain = self.Controller1
  272. nagtive = False
  273. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  274. nagtive = True
  275. control1 = None
  276. control2 = None
  277. if nagtive == False:
  278. control1 = self.Controller1
  279. control2 = self.Controller2
  280. else:
  281. control2 = self.Controller1
  282. control1 = self.Controller2
  283. return [controlMain, control1, control2]
  284. def AutoParkTask(self, park_table: message.park_table = None):
  285. print("AutoParkTask:---------------------\n")
  286. [controlMain, control1, control2] = self.GetMainFrontBackAGV()
  287. mainMap, frontMap, backMap = ["Main", "Front", "Back"]
  288. entrance_id = "S" + str(park_table.terminal_id) # "S1101"
  289. entrance_x, entrance_y, entrance_theta = [park_table.entrance_measure_info.measure_info_to_plc_forward.cx,
  290. park_table.entrance_measure_info.measure_info_to_plc_forward.cy,
  291. (
  292. 90 + park_table.entrance_measure_info.measure_info_to_plc_forward.theta) / 180 * math.pi]
  293. # 变换到地图坐标系
  294. # [dx, dy, da] = [-0.223411843181, -0.643030941486, 178.9478 / 180 * math.pi]
  295. # trans_x = -0.99983137 * entrance_x - 0.01836309 * entrance_y + dx
  296. # trans_y = 0.01836309 * entrance_x - 0.99983137 * entrance_y + dy
  297. [dx, dy, da] = [-0.234040126204, -0.647539079189, 178.9302736990612 / 180 * math.pi]
  298. trans_x = -0.999825716019 * entrance_x - 0.018668506294 * entrance_y + dx
  299. trans_y = 0.018668506294 * entrance_x - 0.999825716019 * entrance_y + dy
  300. trans_a = entrance_theta + da - math.pi
  301. while trans_a < 0:
  302. trans_a += math.pi
  303. print("entrance:", entrance_id, trans_x, trans_y, trans_a / math.pi * 180)
  304. target_id = "S" + str(park_table.allocated_space_info.table_id) # "S147"
  305. print("target:", target_id)
  306. # 轴距
  307. wheel_base = park_table.entrance_measure_info.measure_info_to_plc_forward.wheelbase
  308. control1.WheelBaseEdit.setText(str(wheel_base))
  309. control2.WheelBaseEdit.setText(str(wheel_base))
  310. trans_x += wheel_base / 2 * math.cos(trans_a)
  311. trans_y += wheel_base / 2 * math.sin(trans_a)
  312. threadPool = ThreadPoolExecutor(2)
  313. threadPool.submit(control1.robot_.SwitchMoveMode, 0, wheel_base)
  314. threadPool.submit(control2.robot_.SwitchMoveMode, 0, wheel_base)
  315. threadPool.shutdown(wait=True)
  316. # # 双单车入库-----------------------------------------------------
  317. self.ReLoadMap(frontMap, "./map.json")
  318. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], frontMap)
  319. cur_pose1 = control1.robot_.timedRobotStatu_.statu
  320. [label, pt] = self.mapManager.findNeastNode(frontMap, [cur_pose1.x, cur_pose1.y])
  321. control1.robot_.GeneratePath(label, entrance_id, frontMap)
  322. print("Main: begin:%s target:%s wheelBase:%f" % (label, entrance_id, wheel_base))
  323. # 后车 ------------------------------------------------------
  324. self.ReLoadMap(backMap, "./map.json")
  325. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], backMap)
  326. cur_pose2 = control2.robot_.timedRobotStatu_.statu
  327. [label, pt] = self.mapManager.findNeastNode(backMap, [cur_pose2.x, cur_pose2.y])
  328. control2.robot_.GeneratePath(label, entrance_id, backMap)
  329. # print("Child: begin:%s target:%s wheelBase:%f" % (label, entrance_id, wheel_base))
  330. autoDirect = True
  331. threadPool = ThreadPoolExecutor(2)
  332. threadPool.submit(control1.robot_.Navigatting,
  333. label, entrance_id, autoDirect, wheel_base)
  334. threadPool.submit(control2.robot_.Navigatting,
  335. label, entrance_id, autoDirect, wheel_base)
  336. threadPool.shutdown(wait=True)
  337. print(" input entrance completed!!!!")
  338. threadPool = ThreadPoolExecutor(1)
  339. threadPool.submit(controlMain.robot_.SwitchMoveMode, 1, wheel_base)
  340. threadPool.shutdown(wait=True)
  341. threadPool = ThreadPoolExecutor(1)
  342. threadPool.submit(controlMain.robot_.ClampClose)
  343. threadPool.shutdown(wait=True)
  344. # 整车入库---------------------------------
  345. map_name="Front"
  346. if controlMain.robot_.timedRobotStatu_.statu.theta<0:
  347. map_name="Back"
  348. self.ReLoadMap(map_name, "./map.json")
  349. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], map_name)
  350. controlMain.robot_.GeneratePath(entrance_id, target_id, map_name)
  351. print("begin:%s target:%s wheelBase:%f" % (entrance_id, target_id, wheel_base))
  352. threadPool = ThreadPoolExecutor(1)
  353. threadPool.submit(controlMain.robot_.Navigatting,
  354. entrance_id, target_id, autoDirect, wheel_base)
  355. threadPool.shutdown(wait=True)
  356. # 整车松夹池------------------------------------
  357. threadPool = ThreadPoolExecutor(1)
  358. threadPool.submit(controlMain.robot_.ClampOpen)
  359. threadPool.shutdown(wait=True)
  360. threadPool = ThreadPoolExecutor(1)
  361. threadPool.submit(controlMain.robot_.SwitchMoveMode, 0, wheel_base)
  362. threadPool.shutdown(wait=True)
  363. # 双单车出库
  364. self.ReLoadMap(frontMap, "./map.json")
  365. controlMain, control1, control2 = self.GetMainFrontBackAGV()
  366. control1.robot_.GeneratePath(target_id, "F_Input_R147", frontMap)
  367. self.ReLoadMap(backMap, "./map.json")
  368. control2.robot_.GeneratePath(target_id, "B_Input_R147", backMap)
  369. threadPool = ThreadPoolExecutor(2)
  370. threadPool.submit(control1.robot_.Navigatting,
  371. target_id, "F_Input_R147", autoDirect, wheel_base)
  372. threadPool.submit(control2.robot_.Navigatting,
  373. target_id, "B_Input_R147", autoDirect, wheel_base)
  374. threadPool.shutdown(wait=True)
  375. # 反馈
  376. self.g_rabbitmq.publish("command_ex", "agv_park_command_response_port",
  377. tf.MessageToString(park_table, as_utf8=True))
  378. print("Publish_park_response------------------\n", park_table)
  379. return True
  380. def updateMap_pick(self, export_id, mapName): # 0:前车轨迹,1:后车轨迹,2:添加整车轨迹
  381. self.ReLoadMap(mapName, "./map.json")
  382. # export_id = "S1101"
  383. # 添加出口车位点
  384. export_x = self.mapManager.maps["Base"].graph_.points["S1100"][0]
  385. export_y = self.mapManager.maps["Base"].graph_.points["S1100"][1]
  386. self.mapManager.AddVertex(mapName, mp.SpaceNode(export_id, export_x, export_y, 90))
  387. # 更新库位点对应马路点
  388. flag = "F_"
  389. if mapName == "Front":
  390. export_y = self.mapManager.maps["Base"].graph_.points["F_OutLink"][1]
  391. node = mp.StreetNode("F_exportLink", export_x, export_y)
  392. elif mapName == "Back":
  393. flag = "B_"
  394. export_y = self.mapManager.maps["Base"].graph_.points["B_OutLink"][1]
  395. node = mp.StreetNode("B_exportLink", export_x, export_y)
  396. elif mapName == "Main":
  397. flag = "C_"
  398. export_y = self.mapManager.maps["Base"].graph_.points["C_OutLink"][1]
  399. node = mp.StreetNode("C_exportLink", export_x, export_y)
  400. self.mapManager.AddVertex(mapName, node) # 更新库位点对应马路点
  401. self.mapManager.AddEdge(mapName, export_id, node.id_)
  402. for streetID, value in self.mapManager.VertexDict(mapName).items():
  403. if streetID.find(flag) >= 0:
  404. self.mapManager.AddEdge(mapName, node.id_, streetID)
  405. print("Add edge :%s-%s ", node.id_, streetID)
  406. def AutoPickTask(self, pick_table: message.pick_table = None):
  407. print("AutoPickTask:---------------------\n")
  408. controlMain, control1, control2 = self.GetMainFrontBackAGV()
  409. mainMap, frontMap, backMap = ["Main", "Front", "Back"]
  410. space_id = "S" + str(pick_table.actually_space_info.table_id) # "S147"
  411. export_id = "S" + str(pick_table.terminal_id) # "S1101"
  412. print(space_id, export_id)
  413. # 轴距
  414. wheel_base = pick_table.actually_measure_info.measure_info_to_plc_forward.wheelbase
  415. control1.WheelBaseEdit.setText(str(wheel_base))
  416. control2.WheelBaseEdit.setText(str(wheel_base))
  417. # 双单车入库
  418. threadPool = ThreadPoolExecutor(2)
  419. threadPool.submit(control1.robot_.SwitchMoveMode, 0, wheel_base)
  420. threadPool.submit(control2.robot_.SwitchMoveMode, 0, wheel_base)
  421. threadPool.shutdown(wait=True)
  422. self.ReLoadMap(frontMap, "./map.json")
  423. self.updateMap_pick(export_id, frontMap)
  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_id, frontMap)
  427. print("Main: begin:%s target:%s wheelBase:%f" % (label, space_id, wheel_base))
  428. self.ReLoadMap(backMap, "./map.json")
  429. self.updateMap_pick(export_id, backMap)
  430. cur_pose2 = control2.robot_.timedRobotStatu_.statu
  431. [label, pt] = self.mapManager.findNeastNode(backMap, [cur_pose2.x, cur_pose2.y])
  432. control2.robot_.GeneratePath(label, space_id, backMap)
  433. print("Child: begin:%s target:%s wheelBase:%f" % (label, space_id, wheel_base))
  434. autoDirect = True
  435. threadPool = ThreadPoolExecutor(2)
  436. threadPool.submit(control1.robot_.Navigatting,
  437. label, space_id, autoDirect, wheel_base)
  438. threadPool.submit(control2.robot_.Navigatting,
  439. label, space_id, autoDirect, wheel_base)
  440. threadPool.shutdown(wait=True)
  441. # 整车夹持------------------------------------
  442. print(" input space completed!!!!")
  443. threadPool = ThreadPoolExecutor(1)
  444. threadPool.submit(controlMain.robot_.SwitchMoveMode, 1, wheel_base)
  445. threadPool.shutdown(wait=True)
  446. threadPool = ThreadPoolExecutor(1)
  447. threadPool.submit(controlMain.robot_.ClampClose)
  448. threadPool.shutdown(wait=True)
  449. # 整车到出口---------------------------------
  450. map_name = "Front"
  451. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  452. map_name = "Back"
  453. self.ReLoadMap(map_name, "./map.json")
  454. self.updateMap_pick(export_id, map_name)
  455. controlMain.robot_.GeneratePath(space_id, export_id, map_name)
  456. print("Total: begin:%s target:%s wheelBase:%f" % (space_id, export_id, wheel_base))
  457. threadPool = ThreadPoolExecutor(1)
  458. threadPool.submit(controlMain.robot_.Navigatting,
  459. space_id, export_id, True, wheel_base)
  460. threadPool.shutdown(wait=True)
  461. # 整车松夹池------------------------------------
  462. threadPool = ThreadPoolExecutor(1)
  463. threadPool.submit(controlMain.robot_.ClampOpen)
  464. threadPool.shutdown(wait=True)
  465. threadPool = ThreadPoolExecutor(1)
  466. threadPool.submit(controlMain.robot_.SwitchMoveMode, 0, wheel_base)
  467. threadPool.shutdown(wait=True)
  468. # 双单车出库
  469. controlMain, control1, control2 = self.GetMainFrontBackAGV()
  470. self.ReLoadMap(frontMap, "./map.json")
  471. self.updateMap_pick(export_id, frontMap)
  472. control1.robot_.GeneratePath(export_id, "F_exportLink", frontMap)
  473. self.ReLoadMap(backMap, "./map.json")
  474. self.updateMap_pick(export_id, backMap)
  475. control2.robot_.GeneratePath(export_id, "B_exportLink", backMap)
  476. threadPool = ThreadPoolExecutor(2)
  477. threadPool.submit(control1.robot_.Navigatting,
  478. export_id, "F_exportLink", True, wheel_base)
  479. threadPool.submit(control2.robot_.Navigatting,
  480. export_id, "B_exportLink", True, wheel_base)
  481. threadPool.shutdown(wait=True)
  482. # 反馈
  483. self.g_rabbitmq.publish("command_ex", "agv_pick_command_response_port",
  484. tf.MessageToString(pick_table, as_utf8=True))
  485. print("Publish_park_response------------------\n", pick_table)
  486. return True
  487. def ComputeStreetNode(self, s_id, s_x, s_y, s_theta):
  488. """
  489. """
  490. n_x, n_y = 0, 0
  491. if s_id == "S1101":
  492. n_y = self.mapManager.maps["Base"].graph_.points["C_OutLink"][1]
  493. k = math.tan(s_theta)
  494. n_x = (n_y - s_y) / k + s_x # 弧度
  495. n_yF = self.mapManager.maps["Base"].graph_.points["F_OutLink"][1]
  496. n_xF = (n_yF - s_y) / k + s_x # 弧度
  497. n_yB = self.mapManager.maps["Base"].graph_.points["B_OutLink"][1]
  498. n_xB = (n_yB - s_y) / k + s_x # 弧度
  499. # print(n_x, n_y)
  500. return [[n_xF, n_yF], [n_x, n_y], [n_xB, n_yB]]
  501. def readJson(self, file):
  502. with open(file, 'r', encoding='utf-8') as fp:
  503. map = json.load(fp)
  504. return map
  505. def Update(self):
  506. self.gl.update()
  507. if self.isAutoDispatchOnline:
  508. # self.Controller1.setEnabled(False)
  509. # self.Controller2.setEnabled(False)
  510. pass
  511. else:
  512. self.Controller1.setVisible(True)
  513. self.Controller2.setVisible(True)
  514. # 窗口基础属性
  515. def basic(self):
  516. # 设置标题,大小,图标
  517. self.setWindowTitle("GT")
  518. self.resize(1100, 650)
  519. self.setWindowIcon(QIcon("./image/Gt.png"))
  520. # 居中显示
  521. screen = QDesktopWidget().geometry()
  522. self_size = self.geometry()
  523. self.move(int((screen.width() - self_size.width()) / 2), int((screen.height() - self_size.height()) / 2))
  524. def closeEvent(self, QCloseEvent):
  525. self.gl.close()
  526. print("close...")
  527. # 分割窗口
  528. def split_(self):
  529. splitter_main = QSplitter(Qt.Horizontal)
  530. splitter = QSplitter(Qt.Vertical)
  531. splitter.addWidget(self.count_frame_)
  532. splitter.addWidget(self.Controller1)
  533. splitter.addWidget(self.Controller2)
  534. splitter.addWidget(self.ManualOperationWidget)
  535. splitter.setStretchFactor(0, 1)
  536. splitter.setStretchFactor(1, 3)
  537. splitter.setStretchFactor(2, 3)
  538. splitter.setStretchFactor(3, 1)
  539. splitter_main.addWidget(splitter)
  540. splitter_main.addWidget(self.gl)
  541. splitter_main.setStretchFactor(0, 1)
  542. splitter_main.setStretchFactor(2, 4)
  543. return splitter_main
  544. if __name__ == "__main__":
  545. app = QApplication(sys.argv)
  546. win = MainWindow()
  547. win.show()
  548. sys.exit(app.exec_())
  549. # ===============================================================================
  550. # Main
  551. # ===============================================================================
  552. '''app = QApplication(sys.argv)
  553. mainWindow = MapGLWidget()
  554. mainWindow.show()
  555. mainWindow.raise_() # Need this at least on OS X, otherwise the window ends up in background
  556. sys.exit(app.exec_())'''
  557. # ===============================================================================
  558. #
  559. # Local Variables:
  560. # mode: Python
  561. # indent-tabs-mode: nil
  562. # End:
  563. #
  564. # ===============================================================================