test.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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. "road_1100F": [
  59. "S1100",
  60. "FInput_R1100"
  61. ],
  62. "road_1100": [
  63. "S1100",
  64. "CInput_R1100"
  65. ],
  66. "road_1100B": [
  67. "S1100",
  68. "BInput_R1100"
  69. ]
  70. '''
  71. # ===============================================================================
  72. class MainWindow(QMainWindow):
  73. """docstring for Mainwindow"""
  74. djks_map_ = mp.MapManager()
  75. ui_nodes = {}
  76. ui_nodes["street_nodes"] = []
  77. ui_nodes["space_nodes"] = []
  78. def __init__(self, parent=None):
  79. super(MainWindow, self).__init__(parent)
  80. self.basic()
  81. self.count_frame_ = ControllWidget.CountFrame()
  82. self.LoadMap()
  83. self.isLocalTest = False
  84. self.isAutoDispatchOnline = True
  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.Controller1 = ControllWidget.ControlFrame(config1)
  114. self.Controller2 = ControllWidget.ControlFrame(config2)
  115. robot_dict = {self.Controller1.robot_.name_: self.Controller1.robot_,
  116. self.Controller2.robot_.name_: self.Controller2.robot_}
  117. self.ManualOperationWidget = ManualOperationWidget.ManualOperationWidget(robot_dict)
  118. splitter_main = self.split_()
  119. self.setCentralWidget(splitter_main)
  120. self.gl.SetRobot1Instance(self.Controller1.robot_)
  121. self.gl.SetRobot2Instance(self.Controller2.robot_)
  122. self.timer_ = QTimer()
  123. self.timer_.timeout.connect(self.Update)
  124. self.timer_.start(100)
  125. # 启动RabbitMQ
  126. self.g_rabbitmq = None
  127. if self.isAutoDispatchOnline:
  128. self.g_rabbitmq = rabitmq.RabbitAsyncCommunicator("192.168.0.201", 5672, "zx", "123456")
  129. calbbacks = [["agv_park_command_request_queue", self.recv_park_request],
  130. ["agv_pick_command_request_queue", self.recv_pick_request]]
  131. self.g_rabbitmq.Init(calbbacks, None)
  132. self.g_rabbitmq.setDaemon(True) # 守护线程随主线程结束
  133. self.g_rabbitmq.start()
  134. def recv_park_request(self, msg):
  135. print("Recv_park_request------------------\n", msg)
  136. park_table = message.park_table()
  137. try:
  138. tf.Parse(msg, park_table)
  139. except Exception as e:
  140. print("Parse error\n")
  141. # split_msg = msg.split(' ')
  142. # result = [float(split_msg[0]), float(split_msg[1]), float(split_msg[2])]
  143. if self.isAutoDispatchOnline:
  144. self.AutoParkTask(park_table)
  145. def recv_pick_request(self, msg):
  146. print("Recv_pick_request------------------\n", msg)
  147. pick_table = message.pick_table()
  148. try:
  149. tf.Parse(msg, pick_table)
  150. except Exception as e:
  151. print("Parse error\n")
  152. # split_msg = msg.split(' ')
  153. # result = [float(split_msg[0]), float(split_msg[1]), float(split_msg[2])]
  154. if self.isAutoDispatchOnline:
  155. self.AutoPickTask(pick_table)
  156. def updateMap_park(self, entrance_id, pose, type): # 0:前车轨迹,1:后车轨迹,2:添加整车轨迹
  157. self.djks_map_.Reset() # 重置地图
  158. trans_x, trans_y, trans_a = pose
  159. self.djks_map_.AddVertex_t(mp.SpaceNode(entrance_id, trans_x, trans_y, trans_a)) # 更新库位点
  160. entrance_street_nodes = self.ComputeStreetNode(entrance_id, trans_x, trans_y, trans_a)
  161. print("entrance_space pose: ", self.djks_map_.map_t.graph_.points[entrance_id])
  162. if type == 0:
  163. self.djks_map_.AddVertex_t(mp.StreetNode("FInput_R1101", entrance_street_nodes[0][0],
  164. entrance_street_nodes[0][1])) # 更新库位点对应马路点
  165. self.djks_map_.AddEdge_t(entrance_id, "FInput_R1101")
  166. # 加临时边
  167. for node_id, value in self.djks_map_.VertexDict().items():
  168. if node_id.find("FInput") >= 0:
  169. self.djks_map_.AddEdge_t("FInput_R1101", node_id)
  170. print("F entrance_street pose ", self.djks_map_.map_t.graph_.points["FInput_R1101"])
  171. elif type == 1:
  172. self.djks_map_.AddVertex_t(mp.StreetNode("BInput_R1101", entrance_street_nodes[2][0],
  173. entrance_street_nodes[2][1])) # 更新库位点对应马路点
  174. self.djks_map_.AddEdge_t(entrance_id, "BInput_R1101")
  175. # 加临时边
  176. for node_id, value in self.djks_map_.VertexDict().items():
  177. if node_id.find("BInput") >= 0:
  178. self.djks_map_.AddEdge_t("BInput_R1101", node_id)
  179. else:
  180. self.djks_map_.AddVertex_t(mp.StreetNode("CInput_R1101", entrance_street_nodes[1][0],
  181. entrance_street_nodes[1][1])) # 更新库位点对应马路点
  182. self.djks_map_.AddEdge_t(entrance_id, "CInput_R1101")
  183. for node_id, value in self.djks_map_.VertexDict().items():
  184. if node_id.find("CInput") >= 0:
  185. self.djks_map_.AddEdge_t("CInput_R1101", node_id)
  186. print("C entrance_street pose ", self.djks_map_.map_t.graph_.points["CInput_R1101"])
  187. def AutoParkTask(self, park_table: message.park_table = None):
  188. print("AutoParkTask:---------------------\n")
  189. controlMain=self.Controller1
  190. control1=self.Controller1
  191. control2=self.Controller2
  192. if control1.robot_.timedRobotStatu_.statu.theta<0 :
  193. control1 = self.Controller2
  194. control2 = self.Controller1
  195. entrance_id = "S" + str(park_table.terminal_id) # "S1101"
  196. entrance_x, entrance_y, entrance_theta = [park_table.entrance_measure_info.measure_info_to_plc_forward.cx,
  197. park_table.entrance_measure_info.measure_info_to_plc_forward.cy,
  198. (
  199. 90 + park_table.entrance_measure_info.measure_info_to_plc_forward.theta) / 180 * math.pi]
  200. # 变换到地图坐标系
  201. [dx, dy, da] = [-0.223411843181, -0.643030941486, 178.9478 / 180 * math.pi]
  202. trans_x = -0.99983137 * entrance_x - 0.01836309 * entrance_y + dx
  203. trans_y = 0.01836309 * entrance_x - 0.99983137 * entrance_y + dy
  204. trans_a = entrance_theta + da - math.pi
  205. while trans_a < 0:
  206. trans_a += math.pi
  207. print("entrance:", entrance_id, trans_x, trans_y, trans_a / math.pi * 180)
  208. target_id = "S" + str(park_table.allocated_space_info.table_id) # "S147"
  209. print("target:", target_id)
  210. # 轴距
  211. wheel_base = park_table.entrance_measure_info.measure_info_to_plc_forward.wheelbase
  212. control1.WheelBaseEdit.setText(str(wheel_base))
  213. control2.WheelBaseEdit.setText(str(wheel_base))
  214. trans_x += wheel_base / 2 * math.cos(trans_a)
  215. trans_y += wheel_base / 2 * math.sin(trans_a)
  216. # # 开始系列子流程-----------------------------------------------------
  217. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], 0)
  218. cur_pose1 = control1.robot_.timedRobotStatu_.statu
  219. [label, pt] = mp.MapManager().findNeastNode([cur_pose1.x, cur_pose1.y])
  220. control1.robot_.GeneratePath(label, entrance_id)
  221. print("Main: begin:%s target:%s wheelBase:%f" % (label, entrance_id, wheel_base))
  222. # 后车 ------------------------------------------------------
  223. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], 1)
  224. cur_pose2 = control2.robot_.timedRobotStatu_.statu
  225. [label, pt] = mp.MapManager().findNeastNode([cur_pose2.x, cur_pose2.y])
  226. self.Controller2.robot_.GeneratePath(label, entrance_id)
  227. print("Child: begin:%s target:%s wheelBase:%f" % (label, entrance_id, wheel_base))
  228. autoDirect = True
  229. threadPool = ThreadPoolExecutor(2)
  230. threadPool.submit(control1.robot_.Navigatting,
  231. label, entrance_id, autoDirect, wheel_base)
  232. threadPool.submit(control2.robot_.Navigatting,
  233. label, entrance_id, autoDirect, wheel_base)
  234. threadPool.shutdown(wait=True)
  235. print(" input entrance completed!!!!")
  236. threadPool = ThreadPoolExecutor(1)
  237. threadPool.submit(controlMain.robot_.SwitchMoveMode, 1, wheel_base)
  238. threadPool.shutdown(wait=True)
  239. threadPool = ThreadPoolExecutor(1)
  240. threadPool.submit(controlMain.robot_.ClampClose)
  241. threadPool.shutdown(wait=True)
  242. # 整车入库---------------------------------
  243. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], 2)
  244. controlMain.robot_.GeneratePath(entrance_id, target_id)
  245. print("begin:%s target:%s wheelBase:%f" % (entrance_id, target_id, wheel_base))
  246. threadPool = ThreadPoolExecutor(1)
  247. threadPool.submit(controlMain.robot_.Navigatting,
  248. entrance_id, target_id, autoDirect, wheel_base)
  249. threadPool.shutdown(wait=True)
  250. # 整车松夹池------------------------------------
  251. threadPool = ThreadPoolExecutor(1)
  252. threadPool.submit(controlMain.robot_.ClampOpen)
  253. threadPool.shutdown(wait=True)
  254. threadPool = ThreadPoolExecutor(1)
  255. threadPool.submit(controlMain.robot_.SwitchMoveMode, 0, wheel_base)
  256. threadPool.shutdown(wait=True)
  257. # 双单车出库
  258. self.djks_map_.Reset() # 重置地图
  259. control1.robot_.GeneratePath(target_id, "FInput_R147")
  260. control2.robot_.GeneratePath(target_id, "BInput_R147")
  261. threadPool = ThreadPoolExecutor(2)
  262. threadPool.submit(control1.robot_.Navigatting,
  263. target_id, "FInput_R147", autoDirect, wheel_base)
  264. threadPool.submit(control2.robot_.Navigatting,
  265. target_id, "BInput_R147", autoDirect, wheel_base)
  266. threadPool.shutdown(wait=True)
  267. # # 主车进入口
  268. #
  269. #
  270. # node = mp.MapManager().GetVertex(label)# StreetNode
  271. # self.Controller1.robot_.Navigatting(label, entrance_id, True, wheel_base)
  272. # # 副车进入口
  273. # cur_child_pose = self.Controller2.robot_.timedRobotStatu_.statu
  274. # [label, pt] = mp.MapManager().findNeastNode([cur_child_pose.x, cur_child_pose.y])
  275. # node = mp.MapManager().GetVertex(label)# StreetNode
  276. # self.Controller2.robot_.Navigatting(label, entrance_id, True, wheel_base)
  277. # # 切换整车模式
  278. # self.Controller1.robot_.MainAgvchangecb()
  279. # # 整车夹持
  280. # self.Controller1.robot_.ClampClose()
  281. # # 整车进目标车位
  282. # self.Controller1.robot_.Navigatting(entrance_id, target_id, True, wheel_base)
  283. # #
  284. # # ---------------------------------------------------------------
  285. # 恢复
  286. # self.djks_map_.Reset()
  287. def updateMap_pick(self, export_id, type):# 0:前车轨迹,1:后车轨迹,2:添加整车轨迹
  288. print("5555555")
  289. self.djks_map_.Reset() # 重置地图
  290. # export_id = "S1103"
  291. # 添加出口车位点
  292. self.djks_map_.AddVertex_t(mp.SpaceNode(export_id, self.djks_map_.map_t.graph_.points["S1100"][0],
  293. self.djks_map_.map_t.graph_.points["S1100"][1], 90)) # 更新库位点对应马路点
  294. if type==0:
  295. self.djks_map_.AddEdge_t(export_id, "FInput_R1100")
  296. elif type==1:
  297. self.djks_map_.AddEdge_t(export_id, "BInput_R1100")
  298. elif type == 2:
  299. export_street_node_x = self.djks_map_.map_t.graph_.points["CInput_R1100"][0]
  300. export_street_node_y = self.djks_map_.map_t.graph_.points["CInput_R1100"][1]
  301. self.djks_map_.AddVertex_t(mp.StreetNode("CInput_R1103", export_street_node_x,
  302. export_street_node_y)) # 更新库位点对应马路点
  303. self.djks_map_.AddEdge_t(export_id, "CInput_R1103")
  304. for node_id, value in self.djks_map_.VertexDict().items():
  305. if node_id.find("CInput") >= 0:
  306. self.djks_map_.AddEdge_t("CInput_R1103", node_id)
  307. print("C entrance_street pose ", self.djks_map_.map_t.graph_.points["CInput_R1103"])
  308. def AutoPickTask(self, pick_table: message.pick_table = None):
  309. print("AutoPickTask:---------------------\n")
  310. controlMain = self.Controller1
  311. control1 = self.Controller1
  312. control2 = self.Controller2
  313. if control1.robot_.timedRobotStatu_.statu.theta < 0:
  314. control1 = self.Controller2
  315. control2 = self.Controller1
  316. self.djks_map_.Reset() # 重置地图
  317. space_id = "S" + str(pick_table.actually_space_info.table_id) # "S147"
  318. export_id = "S" + str(pick_table.terminal_id) # "S1103"
  319. print(space_id, export_id)
  320. # 轴距
  321. wheel_base = pick_table.actually_measure_info.measure_info_to_plc_forward.wheelbase
  322. control1.WheelBaseEdit.setText(str(wheel_base))
  323. control2.WheelBaseEdit.setText(str(wheel_base))
  324. # self.updateMap_pick(export_id, 2)
  325. # 双单车入库
  326. cur_pose1 = control1.robot_.timedRobotStatu_.statu
  327. [label, pt] = mp.MapManager().findNeastNode([cur_pose1.x, cur_pose1.y])
  328. control1.robot_.GeneratePath(label, space_id)
  329. print("Main: begin:%s target:%s wheelBase:%f" % (label, space_id, wheel_base))
  330. cur_pose2 = control2.robot_.timedRobotStatu_.statu
  331. [label, pt] = mp.MapManager().findNeastNode([cur_pose2.x, cur_pose2.y])
  332. control2.robot_.GeneratePath(label, space_id)
  333. print("Child: begin:%s target:%s wheelBase:%f" % (label, space_id, wheel_base))
  334. autoDirect = True
  335. threadPool = ThreadPoolExecutor(2)
  336. threadPool.submit(control1.robot_.Navigatting,
  337. label, space_id, autoDirect, wheel_base)
  338. threadPool.submit(control2.robot_.Navigatting,
  339. label, space_id, autoDirect, wheel_base)
  340. threadPool.shutdown(wait=True)
  341. # 整车夹持------------------------------------
  342. print(" input space completed!!!!")
  343. threadPool = ThreadPoolExecutor(1)
  344. threadPool.submit(controlMain.robot_.SwitchMoveMode, 1, wheel_base)
  345. threadPool.shutdown(wait=True)
  346. threadPool = ThreadPoolExecutor(1)
  347. threadPool.submit(controlMain.robot_.ClampClose)
  348. threadPool.shutdown(wait=True)
  349. # 整车到出口---------------------------------
  350. self.updateMap_pick(export_id,2)
  351. controlMain.robot_.GeneratePath(space_id, export_id)
  352. print("Total: begin:%s target:%s wheelBase:%f" % (space_id, export_id, wheel_base))
  353. threadPool = ThreadPoolExecutor(1)
  354. threadPool.submit(controlMain.robot_.Navigatting,
  355. space_id, export_id, True, wheel_base)
  356. threadPool.shutdown(wait=True)
  357. # 整车松夹池------------------------------------
  358. threadPool = ThreadPoolExecutor(1)
  359. threadPool.submit(controlMain.robot_.ClampOpen)
  360. threadPool.shutdown(wait=True)
  361. threadPool = ThreadPoolExecutor(1)
  362. threadPool.submit(controlMain.robot_.SwitchMoveMode, 0, wheel_base)
  363. threadPool.shutdown(wait=True)
  364. # 双单车出库
  365. self.updateMap_pick(export_id, 0)
  366. control1.robot_.GeneratePath(export_id, "FInput_R1100")
  367. self.updateMap_pick(export_id, 1)
  368. control2.robot_.GeneratePath(export_id, "BInput_R1100")
  369. threadPool = ThreadPoolExecutor(2)
  370. threadPool.submit(control1.robot_.Navigatting,
  371. export_id, "FInput_R1100", True, wheel_base)
  372. threadPool.submit(control2.robot_.Navigatting,
  373. export_id, "BInput_R1100", True, wheel_base)
  374. threadPool.shutdown(wait=True)
  375. def ComputeStreetNode(self, s_id, s_x, s_y, s_theta):
  376. """
  377. """
  378. n_x, n_y = 0, 0
  379. if s_id == "S1101":
  380. n_y = self.djks_map_.map_t.graph_.points["CInput_R1100"][1]
  381. k = math.tan(s_theta)
  382. n_x = (n_y - s_y) / k + s_x # 弧度
  383. n_yF = self.djks_map_.map_t.graph_.points["FInput_R1100"][1]
  384. n_xF = (n_yF - s_y) / k + s_x # 弧度
  385. n_yB = self.djks_map_.map_t.graph_.points["BInput_R1100"][1]
  386. n_xB = (n_yB - s_y) / k + s_x # 弧度
  387. # print(n_x, n_y)
  388. return [[n_xF, n_yF], [n_x, n_y], [n_xB, n_yB]]
  389. def LoadMap(self):
  390. self.gl = MapGLWidget() # 将opengl例子嵌入GUI
  391. map = self.load_map("./map.json")
  392. for node in map['street_nodes'].items():
  393. [id, point] = node
  394. street_node = mp.StreetNode(id, point[0], point[1])
  395. self.djks_map_.AddVertex(street_node)
  396. self.gl.AddNode([id, "street_node", point])
  397. self.ui_nodes["street_nodes"].append(id)
  398. for node in map['space_nodes'].items():
  399. [id, point] = node
  400. [x, y, yaw] = point
  401. space_node = mp.SpaceNode(id, point[0], point[1], yaw)
  402. self.djks_map_.AddVertex(space_node)
  403. glNode = [id, "space_node", [x, y]]
  404. self.gl.AddNode(glNode)
  405. self.ui_nodes["space_nodes"].append(id)
  406. for road in map['roads'].items():
  407. self.gl.AddRoad(road)
  408. [_, points] = road
  409. for pt1 in points:
  410. for pt2 in points:
  411. if not pt1 == pt2:
  412. self.djks_map_.AddEdge(pt1, pt2)
  413. def load_map(self, file):
  414. with open(file, 'r', encoding='utf-8') as fp:
  415. map = json.load(fp)
  416. return map
  417. def Update(self):
  418. self.gl.update()
  419. if self.isAutoDispatchOnline:
  420. # self.Controller1.setEnabled(False)
  421. # self.Controller2.setEnabled(False)
  422. pass
  423. else:
  424. self.Controller1.setVisible(True)
  425. self.Controller2.setVisible(True)
  426. # 窗口基础属性
  427. def basic(self):
  428. # 设置标题,大小,图标
  429. self.setWindowTitle("GT")
  430. self.resize(1100, 650)
  431. self.setWindowIcon(QIcon("./image/Gt.png"))
  432. # 居中显示
  433. screen = QDesktopWidget().geometry()
  434. self_size = self.geometry()
  435. self.move(int((screen.width() - self_size.width()) / 2), int((screen.height() - self_size.height()) / 2))
  436. def closeEvent(self, QCloseEvent):
  437. self.gl.close()
  438. print("close...")
  439. # 分割窗口
  440. def split_(self):
  441. splitter_main = QSplitter(Qt.Horizontal)
  442. splitter = QSplitter(Qt.Vertical)
  443. splitter.addWidget(self.count_frame_)
  444. splitter.addWidget(self.Controller1)
  445. splitter.addWidget(self.Controller2)
  446. splitter.addWidget(self.ManualOperationWidget)
  447. splitter.setStretchFactor(0, 1)
  448. splitter.setStretchFactor(1, 3)
  449. splitter.setStretchFactor(2, 3)
  450. splitter.setStretchFactor(3, 1)
  451. splitter_main.addWidget(splitter)
  452. splitter_main.addWidget(self.gl)
  453. splitter_main.setStretchFactor(0, 1)
  454. splitter_main.setStretchFactor(2, 4)
  455. return splitter_main
  456. if __name__ == "__main__":
  457. app = QApplication(sys.argv)
  458. win = MainWindow()
  459. win.show()
  460. sys.exit(app.exec_())
  461. # ===============================================================================
  462. # Main
  463. # ===============================================================================
  464. '''app = QApplication(sys.argv)
  465. mainWindow = MapGLWidget()
  466. mainWindow.show()
  467. mainWindow.raise_() # Need this at least on OS X, otherwise the window ends up in background
  468. sys.exit(app.exec_())'''
  469. # ===============================================================================
  470. #
  471. # Local Variables:
  472. # mode: Python
  473. # indent-tabs-mode: nil
  474. # End:
  475. #
  476. # ===============================================================================