Scheduler_d1.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. """
  2. tips:
  3. 推算半径:13.7
  4. 倒车与正开的偏移量是5米;倒车中心点=正开中心点+5
  5. """
  6. # 坐标数据文件
  7. data_file_dir = '../data'
  8. data_file_path = '../data/渣罐坐标数据.json'
  9. # data_file_path = '/home/ubuntu/repositories/repositories/casperz.py-project/project-fastapi-hs/data/渣罐坐标数据.json'
  10. # data_file_path = r"E:\casper\repositories\repositories\casperz.py-project\project-fastapi-hs\data\渣罐坐标数据.json"
  11. # 道路名称列表
  12. path_name_list = [
  13. 'MN',
  14. 'KL',
  15. 'IJ',
  16. 'GH',
  17. 'EF',
  18. 'CD',
  19. 'AB',
  20. ]
  21. # 圆心点坐标字典
  22. d1 = {
  23. 'LM.head': {'center_x': 11, 'center_y': 22},
  24. 'JK.head': {'center_x': 11, 'center_y': 22},
  25. 'HI.head': {'center_x': 11, 'center_y': 22},
  26. 'FG.head': {'center_x': 11, 'center_y': 22},
  27. 'DE.head': {'center_x': 11, 'center_y': 22},
  28. 'BC.head': {'center_x': 11, 'center_y': 22},
  29. 'A.head': {'center_x': 11, 'center_y': 22},
  30. 'LM.tail': {'center_x': 11, 'center_y': 22},
  31. 'JK.tail': {'center_x': 11, 'center_y': 22},
  32. 'HI.tail': {'center_x': 11, 'center_y': 22},
  33. 'FG.tail': {'center_x': 11, 'center_y': 22},
  34. 'DE.tail': {'center_x': 11, 'center_y': 22},
  35. 'BC.tail': {'center_x': 11, 'center_y': 22},
  36. 'A.tail': {'center_x': 11, 'center_y': 22},
  37. }
  38. # 渣罐坐标字典
  39. d4 = {
  40. # 停车区坐标
  41. 'pack.1': {'point': (11, 22)},
  42. 'pack.2': {'point': (11, 22)},
  43. # 接渣口坐标
  44. 'load.1': {'point': (11, 22)},
  45. 'load.2': {'point': (11, 22)},
  46. 'load.3': {'point': (11, 22)},
  47. # 倒渣口坐标
  48. 'dump.MN': {'point': (11, 205.75)}, # 1号倒渣口
  49. 'dump.KL': {'point': (11, 177.75)}, # 2号倒渣口
  50. 'dump.IJ': {'point': (11, 149.75)}, # 3号倒渣口
  51. 'dump.GH': {'point': (11, 121.75)}, # 4号倒渣口
  52. 'dump.EF': {'point': (11, 93.75)}, # 5号倒渣口
  53. 'dump.CD': {'point': (11, 65.75)}, # 6号倒渣口
  54. 'dump.AB': {'point': (11, 37.75)}, # 7号倒渣口
  55. # 渣罐位坐标
  56. 'M.31': {'pot': (22, 33), 'road_center': (44, 55)},
  57. 'M.30': {'pot': (22, 33), 'road_center': (44, 55)},
  58. 'M.29': {'pot': (22, 33), 'road_center': (44, 55)},
  59. 'M.28': {'pot': (22, 33), 'road_center': (44, 55)},
  60. 'M.27': {'pot': (22, 33), 'road_center': (44, 55)},
  61. 'M.26': {'pot': (22, 33), 'road_center': (44, 55)},
  62. 'M.25': {'pot': (22, 33), 'road_center': (44, 55)},
  63. 'M.24': {'pot': (22, 33), 'road_center': (44, 55)},
  64. 'M.23': {'pot': (22, 33), 'road_center': (44, 55)},
  65. 'M.22': {'pot': (22, 33), 'road_center': (44, 55)},
  66. 'M.21': {'pot': (22, 33), 'road_center': (44, 55)},
  67. 'M.20': {'pot': (22, 33), 'road_center': (44, 55)},
  68. 'M.19': {'pot': (22, 33), 'road_center': (44, 55)},
  69. 'M.18': {'pot': (22, 33), 'road_center': (44, 55)},
  70. 'M.17': {'pot': (22, 33), 'road_center': (44, 55)},
  71. 'M.16': {'pot': (22, 33), 'road_center': (44, 55)},
  72. 'M.15': {'pot': (22, 33), 'road_center': (44, 55)},
  73. 'M.14': {'pot': (22, 33), 'road_center': (44, 55)},
  74. 'M.13': {'pot': (22, 33), 'road_center': (44, 55)},
  75. 'M.12': {'pot': (22, 33), 'road_center': (44, 55)},
  76. 'M.11': {'pot': (22, 33), 'road_center': (44, 55)},
  77. 'M.10': {'pot': (22, 33), 'road_center': (44, 55)},
  78. 'M.9': {'pot': (22, 33), 'road_center': (44, 55)},
  79. 'M.8': {'pot': (22, 33), 'road_center': (44, 55)},
  80. 'M.7': {'pot': (22, 33), 'road_center': (44, 55)},
  81. 'M.6': {'pot': (22, 33), 'road_center': (44, 55)},
  82. 'M.5': {'pot': (22, 33), 'road_center': (44, 55)},
  83. 'M.4': {'pot': (22, 33), 'road_center': (44, 55)},
  84. 'M.3': {'pot': (22, 33), 'road_center': (44, 55)},
  85. 'M.2': {'pot': (22, 33), 'road_center': (44, 55)},
  86. 'M.1': {'pot': (22, 33), 'road_center': (44, 55)},
  87. 'F.31': {'pot': (22, 33), 'road_center': (44, 55)},
  88. 'F.30': {'pot': (22, 33), 'road_center': (44, 55)},
  89. 'F.29': {'pot': (22, 33), 'road_center': (44, 55)},
  90. 'F.28': {'pot': (22, 33), 'road_center': (44, 55)},
  91. 'F.27': {'pot': (22, 33), 'road_center': (44, 55)},
  92. 'F.26': {'pot': (22, 33), 'road_center': (44, 55)},
  93. 'F.25': {'pot': (22, 33), 'road_center': (44, 55)},
  94. 'F.24': {'pot': (22, 33), 'road_center': (44, 55)},
  95. 'F.23': {'pot': (22, 33), 'road_center': (44, 55)},
  96. 'F.22': {'pot': (22, 33), 'road_center': (44, 55)},
  97. 'F.21': {'pot': (22, 33), 'road_center': (44, 55)},
  98. 'F.20': {'pot': (22, 33), 'road_center': (44, 55)},
  99. 'F.19': {'pot': (22, 33), 'road_center': (44, 55)},
  100. 'F.18': {'pot': (22, 33), 'road_center': (44, 55)},
  101. 'F.17': {'pot': (22, 33), 'road_center': (44, 55)},
  102. 'F.16': {'pot': (22, 33), 'road_center': (44, 55)},
  103. 'F.15': {'pot': (22, 33), 'road_center': (44, 55)},
  104. 'F.14': {'pot': (22, 33), 'road_center': (44, 55)},
  105. 'F.13': {'pot': (22, 33), 'road_center': (44, 55)},
  106. 'F.12': {'pot': (22, 33), 'road_center': (44, 55)},
  107. 'F.11': {'pot': (22, 33), 'road_center': (44, 55)},
  108. 'F.10': {'pot': (22, 33), 'road_center': (44, 55)},
  109. 'F.9': {'pot': (22, 33), 'road_center': (44, 55)},
  110. 'F.8': {'pot': (22, 33), 'road_center': (44, 55)},
  111. 'F.7': {'pot': (22, 33), 'road_center': (44, 55)},
  112. 'F.6': {'pot': (22, 33), 'road_center': (44, 55)},
  113. 'F.5': {'pot': (22, 33), 'road_center': (44, 55)},
  114. 'F.4': {'pot': (22, 33), 'road_center': (44, 55)},
  115. 'F.3': {'pot': (22, 33), 'road_center': (44, 55)},
  116. 'F.2': {'pot': (22, 33), 'road_center': (44, 55)},
  117. 'F.1': {'pot': (22, 33), 'road_center': (44, 55)},
  118. }
  119. def get_nearest_point_name_from_pot_point(current_x, current_y):
  120. """
  121. 获取当前位置距离最忌的罐体位置名称
  122. """
  123. current_x = float(current_x)
  124. current_y = float(current_y)
  125. min_distance = float('inf') # 初始值无穷大
  126. nearest_point_name = str() # 最近点名称
  127. # --- check road center ---
  128. for k, v in d4.items():
  129. if 'pack' in k or 'load' in k or 'dump' in k:
  130. continue
  131. point_x = float(v.get('road_center')[0])
  132. point_y = float(v.get('road_center')[1])
  133. distance = ((point_x - current_x) ** 2 + (point_y - current_y) ** 2) ** (1 / 2)
  134. if distance < min_distance:
  135. min_distance = distance
  136. nearest_point_name = k
  137. # --- check dump port ---
  138. for k, v in d4.items():
  139. if 'dump' not in k:
  140. continue
  141. point_x = float(v.get('point')[0])
  142. point_y = float(v.get('point')[1])
  143. distance = ((point_x - current_x) ** 2 + (point_y - current_y) ** 2) ** (1 / 2)
  144. if distance < min_distance:
  145. min_distance = distance
  146. nearest_point_name = k
  147. return nearest_point_name
  148. def get_nearest_point_from_road_center_point(x, y):
  149. """
  150. 获取当前所在位置最接近的坐标位置
  151. """
  152. x = float(x)
  153. y = float(y)
  154. min_distance = float('inf') # 初始值无穷大
  155. for k, v in d4.items():
  156. center_x = float(v.get('road_center')[0])
  157. center_y = float(v.get('road_center')[1])
  158. distance = ((center_x - x) ** 2 + (center_y - y) ** 2) ** (1 / 2)
  159. if distance < min_distance:
  160. min_distance = distance
  161. nearest_point = center_x, center_y
  162. return nearest_point
  163. def get_path_name_by_pot_name(pot_name='M.25'):
  164. """根据渣罐名获取道路名"""
  165. s1, s2 = pot_name.split('.')
  166. for s in path_name_list:
  167. if s1 in s:
  168. return s
  169. def get_path_name_by_dump_name(dump_name='dump.MN'):
  170. """根据渣罐名获取道路名"""
  171. _, s2 = dump_name.split('.')
  172. return s2
  173. def get_center_point(w1='N', w2='head'):
  174. """
  175. 获取圆心点坐标
  176. w1: 关键字
  177. w2: 关键字
  178. """
  179. for k, v in d1.items():
  180. k_s1, k_s2 = k.split('.')
  181. if w1 not in k_s1:
  182. continue
  183. if w2 not in k_s2:
  184. continue
  185. return dict(**v, **{'name': k})
  186. import json
  187. import numpy
  188. def test(current_direction_type=3, start_x=11, start_y=22, target_point_name='M.1'):
  189. """
  190. current_direction_type: 起始方向 3 围栏方向 9 渣场方向 12 维修间方向 6 维修间正对方向 0 未知(默认值)
  191. start_x: 起始位置
  192. start_y: 起始位置
  193. target_point_name: 目标名称
  194. """
  195. # --- update d1 ---
  196. data = json.load(open(f"{data_file_dir}/圆心坐标数据.json", 'rb'))
  197. for item in data.get(
  198. 'name|center_x|center_y|center_3_x|center_3_y|center_9_x|center_9_y|center_12_x|center_12_y|center_6_x|center_6_y'):
  199. name, center_x, center_y, center_3_x, center_3_y, center_9_x, center_9_y, center_12_x, center_12_y, center_6_x, center_6_y = item.split(
  200. '|')
  201. d1[name] = {
  202. 'center_x': float(center_x),
  203. 'center_y': float(center_y),
  204. 'center_3_x': float(center_3_x),
  205. 'center_3_y': float(center_3_y),
  206. 'center_9_x': float(center_9_x),
  207. 'center_9_y': float(center_9_y),
  208. 'center_12_x': float(center_12_x),
  209. 'center_12_y': float(center_12_y),
  210. 'center_6_x': float(center_6_x),
  211. 'center_6_y': float(center_6_y),
  212. }
  213. # --- update d4 ---
  214. data = json.load(open(data_file_path, 'rb'))
  215. for item in data.get('pot_name|pot_x|pot_y|road_center_x|road_center_y'):
  216. pot_name, pot_x, pot_y, road_center_x, road_center_y = item.split('|')
  217. d4[pot_name] = {
  218. 'pot': (float(pot_x), float(pot_y)),
  219. 'road_center': (float(road_center_x), float(road_center_y)),
  220. }
  221. # --- update d4 ---
  222. data = json.load(open(f"{data_file_dir}/倒渣口坐标数据.json", 'rb'))
  223. for item in data.get('name|x|y'):
  224. name, x, y = item.split('|')
  225. d4[name] = {
  226. 'point': (float(x), float(y)),
  227. }
  228. # --- check ---
  229. if not start_x and not start_y:
  230. return "Reason: 参数缺失"
  231. # --- check ---
  232. if current_direction_type not in [3, 9]:
  233. return "Reason: 暂不支持"
  234. # --- define ---
  235. current_point_name = get_nearest_point_name_from_pot_point(start_x, start_y)
  236. s_point_item = dict(**d4.get(current_point_name), **{'name': current_point_name})
  237. e_point_item = dict(**d4.get(target_point_name), **{'name': target_point_name})
  238. # --- define ---
  239. radius = 14 # 转弯半径
  240. s_s1, s_s2 = current_point_name.split('.')
  241. e_s1, e_s2 = target_point_name.split('.')
  242. print(f"current_point_name: {current_point_name}")
  243. print(f"target_point_name: {target_point_name}")
  244. # --- check ---
  245. if 'dump' not in current_point_name and 'dump' not in target_point_name:
  246. if current_direction_type == 9 and s_s1 == e_s1 and int(s_s2) > int(e_s2):
  247. """
  248. 情况1:判断是否是在正前方的情况1
  249. """
  250. return [
  251. {
  252. 'type': 'forward',
  253. 'nav_coordinates': [
  254. {
  255. # 直行轨迹坐标参数
  256. 'start_point_x': s_point_item.get('road_center')[0],
  257. 'start_point_y': s_point_item.get('road_center')[1],
  258. 'end_point_x': e_point_item.get('road_center')[0],
  259. 'end_point_y': e_point_item.get('road_center')[1],
  260. },
  261. ],
  262. }
  263. ]
  264. elif current_direction_type == 3 and s_s1 == e_s1 and int(s_s2) < int(e_s2):
  265. """
  266. 情况2:判断是否是在正前方的情况2
  267. """
  268. return [
  269. {
  270. 'type': 'forward',
  271. 'nav_coordinates': [
  272. # 直线行驶
  273. {
  274. 'start_point_x': s_point_item.get('road_center')[0],
  275. 'start_point_y': s_point_item.get('road_center')[1],
  276. 'end_point_x': e_point_item.get('road_center')[0],
  277. 'end_point_y': e_point_item.get('road_center')[1],
  278. },
  279. ],
  280. }
  281. ]
  282. elif current_direction_type == 9 and s_s1 > e_s1:
  283. """
  284. 情况3:从起始渣罐位向9点6点3点方向行驶到目标渣罐位
  285. """
  286. path_name = get_path_name_by_pot_name(current_point_name)
  287. corner_name = path_name[:1] # 拐弯点 9点向6点 取首位
  288. center_point_1 = get_center_point(w1=corner_name, w2='head')
  289. path_name = get_path_name_by_pot_name(target_point_name)
  290. corner_name = path_name[-1:] # 拐弯点 6点向3点 取末位
  291. center_point_2 = get_center_point(w1=corner_name, w2='head')
  292. # print(f"debug.294: center_point_1: {center_point_1}")
  293. # print(f"debug.294: center_point_2: {center_point_2}")
  294. return [
  295. {
  296. 'type': 'forward',
  297. 'nav_coordinates': [
  298. # 直线行驶
  299. {
  300. 'start_point_x': s_point_item.get('road_center')[0], # 起始点坐标
  301. 'start_point_y': s_point_item.get('road_center')[1], # 起始点坐标
  302. 'end_point_x': center_point_1.get('center_12_x'), # 入弯坐标
  303. 'end_point_y': center_point_1.get('center_12_y'), # 入弯坐标
  304. },
  305. # 转弯行驶
  306. {
  307. "start_point_x": center_point_1.get('center_12_x'), # 入弯坐标
  308. "start_point_y": center_point_1.get('center_12_y'), # 入弯坐标
  309. "center_point_x": center_point_1.get('center_x'), # 圆心坐标
  310. "center_point_y": center_point_1.get('center_y'), # 圆心坐标
  311. "end_point_x": center_point_1.get('center_9_x'), # 出弯坐标
  312. "end_point_y": center_point_1.get('center_9_y'), # 出弯坐标
  313. },
  314. # 直线行驶
  315. {
  316. 'start_point_x': center_point_1.get('center_9_x'), # 出弯坐标
  317. 'start_point_y': center_point_1.get('center_9_y'), # 出弯坐标
  318. 'end_point_x': center_point_2.get('center_9_x'), # 入弯坐标
  319. 'end_point_y': center_point_2.get('center_9_y'), # 入弯坐标
  320. },
  321. # 转弯行驶
  322. {
  323. "start_point_x": center_point_2.get('center_9_x'), # 入弯坐标
  324. "start_point_y": center_point_2.get('center_9_y'), # 入弯坐标
  325. "center_point_x": center_point_2.get('center_x'), # 圆心坐标
  326. "center_point_y": center_point_2.get('center_y'), # 圆心坐标
  327. "end_point_x": center_point_2.get('center_6_x'), # 出弯坐标
  328. "end_point_y": center_point_2.get('center_6_y'), # 出弯坐标
  329. },
  330. # 直线行驶
  331. {
  332. 'start_point_x': center_point_2.get('center_6_x'), # 出弯坐标
  333. 'start_point_y': center_point_2.get('center_6_y'), # 出弯坐标
  334. 'end_point_x': e_point_item.get('road_center')[0], # 目标点坐标
  335. 'end_point_y': e_point_item.get('road_center')[1], # 目标点坐标
  336. },
  337. ],
  338. }
  339. ]
  340. elif current_direction_type == 9 and s_s1 == e_s1 and int(s_s2) < int(e_s2):
  341. """
  342. 情况5:判断是否是在正后方的情况
  343. """
  344. path_name = get_path_name_by_pot_name(current_point_name)
  345. corner_name = path_name[:1] # 拐弯点 9点6点3点 取首位
  346. center_point_1 = get_center_point(w1=corner_name, w2='head')
  347. center_point_2 = get_center_point(w1=corner_name, w2='tail')
  348. print(f"debug.403: center_point_1: {center_point_1}")
  349. print(f"debug.403: center_point_2: {center_point_2}")
  350. return [
  351. {
  352. 'type': 'forward',
  353. 'nav_coordinates': [
  354. # 直线行驶
  355. {
  356. 'start_point_x': s_point_item.get('road_center')[0], # 起始点坐标
  357. 'start_point_y': s_point_item.get('road_center')[1], # 起始点坐标
  358. 'end_point_x': center_point_1.get('center_12_x'), # 入弯坐标
  359. 'end_point_y': center_point_1.get('center_12_y'), # 入弯坐标
  360. },
  361. # 转弯行驶
  362. {
  363. "start_point_x": center_point_1.get('center_12_x'), # 入弯坐标
  364. "start_point_y": center_point_1.get('center_12_y'), # 入弯坐标
  365. "center_point_x": center_point_1.get('center_x'), # 圆心坐标
  366. "center_point_y": center_point_1.get('center_y'), # 圆心坐标
  367. "end_point_x": center_point_1.get('center_6_x'), # 出弯坐标
  368. "end_point_y": center_point_1.get('center_6_y'), # 出弯坐标
  369. },
  370. # 直线行驶
  371. {
  372. 'start_point_x': center_point_1.get('center_6_x'), # 出弯坐标
  373. 'start_point_y': center_point_1.get('center_6_x'), # 出弯坐标
  374. 'end_point_x': center_point_2.get('center_6_x'), # 入弯坐标
  375. 'end_point_y': center_point_2.get('center_6_y'), # 入弯坐标
  376. },
  377. # 转弯行驶
  378. {
  379. "start_point_x": center_point_2.get('center_6_x'), # 入弯坐标
  380. "start_point_y": center_point_2.get('center_6_y'), # 入弯坐标
  381. "center_point_x": center_point_2.get('center_x'), # 圆心坐标
  382. "center_point_y": center_point_2.get('center_y'), # 圆心坐标
  383. "end_point_x": center_point_2.get('center_12_x'), # 出弯坐标
  384. "end_point_y": center_point_2.get('center_12_y'), # 出弯坐标
  385. },
  386. # 直线行驶
  387. {
  388. 'start_point_x': center_point_2.get('center_12_x'), # 出弯坐标
  389. 'start_point_y': center_point_2.get('center_12_y'), # 出弯坐标
  390. 'end_point_x': e_point_item.get('road_center')[0], # 目标点坐标
  391. 'end_point_y': e_point_item.get('road_center')[1], # 目标点坐标
  392. },
  393. ]
  394. }
  395. ]
  396. else:
  397. return "Result: 暂不支持"
  398. elif 'dump' not in current_point_name and 'dump' in target_point_name:
  399. if current_direction_type == 9:
  400. """
  401. 情况4:渣罐位,车头9点方向,6点拐弯,3点拐弯,倒车倒入指定倒渣口
  402. """
  403. # --- get ---
  404. path_name = get_path_name_by_pot_name(current_point_name)
  405. corner_name = path_name[:1] # 拐弯点 9点向6点 取首位
  406. center_point_1 = get_center_point(w1=corner_name, w2='head')
  407. path_name = get_path_name_by_dump_name(target_point_name)
  408. corner_name = path_name[-1:] # 拐弯点 6点向3点 取末位
  409. center_point_2 = get_center_point(w1=corner_name, w2='head')
  410. print(f"debug.465: center_point_1: {center_point_1}")
  411. print(f"debug.465: center_point_2: {center_point_2}")
  412. # --- set ---
  413. degrees = 1.3
  414. short = 30 * numpy.sin(numpy.radians(degrees))
  415. long = 30 * numpy.cos(numpy.radians(degrees))
  416. return [
  417. {
  418. 'type': 'forward',
  419. 'nav_coordinates': [
  420. # 直线行驶
  421. {
  422. 'start_point_x': s_point_item.get('road_center')[0], # 起始点坐标
  423. 'start_point_y': s_point_item.get('road_center')[1], # 起始点坐标
  424. 'end_point_x': center_point_1.get('center_12_x'), # 入弯坐标
  425. 'end_point_y': center_point_1.get('center_12_y'), # 入弯坐标
  426. },
  427. # 转弯行驶
  428. {
  429. "start_point_x": center_point_1.get('center_12_x'), # 入弯坐标
  430. "start_point_y": center_point_1.get('center_12_y'), # 入弯坐标
  431. "center_point_x": center_point_1.get('center_x'), # 圆心坐标
  432. "center_point_y": center_point_1.get('center_y'), # 圆心坐标
  433. "end_point_x": center_point_1.get('center_9_x'), # 出弯坐标
  434. "end_point_y": center_point_1.get('center_9_x'), # 出弯坐标
  435. },
  436. # 直线行驶
  437. {
  438. 'start_point_x': center_point_1.get('center_9_x'), # 出弯坐标
  439. 'start_point_y': center_point_1.get('center_9_x'), # 出弯坐标
  440. 'end_point_x': center_point_2.get('center_9_x'), # 入弯坐标
  441. 'end_point_y': center_point_2.get('center_9_y'), # 入弯坐标
  442. },
  443. # 转弯行驶
  444. {
  445. "start_point_x": center_point_2.get('center_9_x'), # 入弯坐标
  446. "start_point_y": center_point_2.get('center_9_y'), # 入弯坐标
  447. "center_point_x": center_point_2.get('center_x'), # 圆心坐标
  448. "center_point_y": center_point_2.get('center_x'), # 圆心坐标
  449. "end_point_x": center_point_2.get('center_6_x'), # 出弯坐标
  450. "end_point_y": center_point_2.get('center_6_y'), # 出弯坐标
  451. },
  452. # 直线行驶
  453. {
  454. 'start_point_x': center_point_2.get('center_6_x'), # 出弯坐标
  455. 'start_point_y': center_point_2.get('center_6_y'), # 出弯坐标
  456. 'end_point_x': center_point_2.get('center_6_x') + long, # 前进30米,摆正车身,为倒车准备
  457. 'end_point_y': center_point_2.get('center_6_y') - short, # 前进30米,摆正车身,为倒车准备
  458. },
  459. ]
  460. },
  461. {
  462. 'type': 'backward',
  463. 'nav_coordinates': [
  464. # 直线行驶
  465. {
  466. 'start_point_x': center_point_2.get('center_6_x') + long, # 前进30米,摆正车身,为倒车准备
  467. 'start_point_y': center_point_2.get('center_6_y') - short, # 前进30米,摆正车身,为倒车准备
  468. 'end_point_x': e_point_item.get('point')[0], # 倒渣口坐标
  469. 'end_point_y': e_point_item.get('point')[1], # 倒渣口坐标
  470. },
  471. ]
  472. }
  473. ]
  474. else:
  475. return "Result: 暂不支持"
  476. elif 'dump' in current_point_name and 'dump' not in target_point_name and current_direction_type == 3:
  477. if e_s1 in s_s2:
  478. """
  479. 情况6:倒渣位,车头3点方向,目标点正对目标巷道情况
  480. """
  481. return [
  482. {
  483. 'type': 'forward',
  484. 'nav_coordinates': [
  485. # 直线行驶
  486. {
  487. 'start_point_x': s_point_item.get('point')[0], # 起始点坐标
  488. 'start_point_y': s_point_item.get('point')[1], # 起始点坐标
  489. 'end_point_x': e_point_item.get('road_center')[0], # 目标点坐标
  490. 'end_point_y': e_point_item.get('road_center')[1], # 目标点坐标
  491. },
  492. ]
  493. }
  494. ]
  495. elif e_s1 > s_s2[1]:
  496. """
  497. 情况7:倒渣位,车头3点方向,目标点位于巷道上侧
  498. """
  499. path_name = get_path_name_by_dump_name(current_point_name)
  500. corner_name = path_name[-1:] # 拐弯点 3点12点 取末位
  501. center_point_1 = get_center_point(w1=corner_name, w2='tail')
  502. path_name = get_path_name_by_pot_name(target_point_name)
  503. corner_name = path_name[:1] # 拐弯点 12点9点 取首位
  504. center_point_2 = get_center_point(w1=corner_name, w2='tail')
  505. nav_coordinates_1 = [
  506. # 直线行驶
  507. {
  508. 'start_point_x': s_point_item.get('point')[0], # 起始点坐标
  509. 'start_point_y': s_point_item.get('point')[1], # 起始点坐标
  510. 'end_point_x': center_point_1.get('center_6_x'), # 入弯坐标
  511. 'end_point_y': center_point_1.get('center_6_y'), # 入弯坐标
  512. },
  513. # 转弯行驶
  514. {
  515. "start_point_x": center_point_1.get('center_6_x'), # 入弯坐标
  516. "start_point_y": center_point_1.get('center_6_y'), # 入弯坐标
  517. "center_point_x": center_point_1.get('center_x'), # 圆心坐标
  518. "center_point_y": center_point_1.get('center_y'), # 圆心坐标
  519. "end_point_x": center_point_1.get('center_3_x'), # 出弯坐标
  520. "end_point_y": center_point_1.get('center_3_y'), # 出弯坐标
  521. },
  522. ]
  523. nav_coordinates_2 = [
  524. # 直线行驶
  525. {
  526. 'start_point_x': center_point_1.get('center_3_x'), # 出弯坐标
  527. 'start_point_y': center_point_1.get('center_3_y'), # 出弯坐标
  528. 'end_point_x': center_point_2.get('center_3_x'), # 入弯坐标
  529. 'end_point_y': center_point_2.get('center_3_x'), # 入弯坐标
  530. }
  531. ]
  532. # --- check ---
  533. if nav_coordinates_2[0].get('start_point_x') == nav_coordinates_2[0].get('end_point_x'):
  534. nav_coordinates_2 = []
  535. if nav_coordinates_2[0].get('start_point_y') == nav_coordinates_2[0].get('end_point_y'):
  536. nav_coordinates_2 = []
  537. nav_coordinates_3 = [
  538. # 转弯行驶
  539. {
  540. "start_point_x": center_point_2.get('center_3_x'), # 入弯坐标
  541. "start_point_y": center_point_2.get('center_3_x'), # 入弯坐标
  542. "center_point_x": center_point_2.get('center_x'), # 圆心坐标
  543. "center_point_y": center_point_2.get('center_y'), # 圆心坐标
  544. "end_point_x": center_point_2.get('center_12_x'), # 出弯坐标
  545. "end_point_y": center_point_2.get('center_12_y'), # 出弯坐标
  546. },
  547. # 直线行驶
  548. {
  549. 'start_point_x': center_point_2.get('center_12_x'), # 出弯坐标
  550. 'start_point_y': center_point_2.get('center_12_y'), # 出弯坐标
  551. 'end_point_x': e_point_item.get('road_center')[0], # 目标点坐标
  552. 'end_point_y': e_point_item.get('road_center')[1], # 目标点坐标
  553. }
  554. ]
  555. return [
  556. {
  557. 'type': 'forward',
  558. 'nav_coordinates': nav_coordinates_1 + nav_coordinates_2 + nav_coordinates_3
  559. }
  560. ]
  561. elif e_s1 < s_s2[0]:
  562. """
  563. 情况8:倒渣位,车头3点方向,目标点位于巷道下侧
  564. """
  565. return "Result: 暂不支持 222"
  566. else:
  567. return "Result: 暂不支持"
  568. return "Result: 暂不支持"
  569. else:
  570. return "Result: 暂不支持"
  571. if __name__ == '__main__':
  572. # --- 现场实际测试数据 ---
  573. offset = 6.4
  574. M01 = 14.450 + (offset * 0), 199.64
  575. M31 = 184.93 - (offset * 6), 195.7
  576. M03 = 35.5, 205.75
  577. M12 = 85, 205.75
  578. dumpCD = 15.49 - 10, 63.06
  579. # 情况1:判断是否是在正前方的情况1 M.10 -> M.2
  580. # out = test(current_direction_type=9, start_x=M31[0], start_y=M31[1], target_point_name='M.1')
  581. # 情况2:判断是否是在正前方的情况2 M.12 -> M.20
  582. # out = test(current_direction_type=3, start_x=M12[0], start_y=M12[1], target_point_name='M.20')
  583. # 情况3:从起始渣罐位向9点6点3点方向行驶到目标渣罐位 | M.12 -> F.20
  584. # out = test(current_direction_type=9, start_x=M12[0], start_y=M12[1], target_point_name='F.20')
  585. # 情况4:渣罐位,车头9点方向,6点拐弯,3点拐弯,倒车倒入指定倒渣口
  586. # out = test(current_direction_type=9, start_x=M31[0], start_y=M31[1], target_point_name='dump.CD')
  587. # out = test(current_direction_type=9, start_x=M03[0], start_y=M03[1], target_point_name='dump.CD')
  588. # 情况5:判断是否是在正后方的情况 M.3 -> M.10(共2个弯)
  589. # out = test(current_direction_type=9, start_x=M01[0], start_y=M01[1], target_point_name='M.10')
  590. # out = test(current_direction_type=9, start_x=M03[0], start_y=M03[1], target_point_name='M.10')
  591. # 情况6:倒渣位,车头3点方向,目标点正对目标巷道情况
  592. # out = test(current_direction_type=3, start_x=dumpCD[0], start_y=dumpCD[1], target_point_name='D.20')
  593. # 情况7:倒渣位,车头3点方向,目标点位于巷道上侧
  594. out = test(current_direction_type=3, start_x=dumpCD[0], start_y=dumpCD[1], target_point_name='M.1')
  595. # 情况8:倒渣位,车头3点方向,目标点位于巷道下侧 todo 存在一上来就转弯,有个圆心怎么算呢
  596. # out = test(current_direction_type=3, start_x=dumpCD[0], start_y=dumpCD[1], target_point_name='A.30')
  597. print(out)
  598. # --- test ---
  599. # out = get_nearest_point_name_from_pot_point(dumpCD[0], dumpCD[1])
  600. # print(out)