Scheduler_c1.py 28 KB

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