Scheduler_a1.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. """
  2. """
  3. # 圆心点坐标字典 todo 关于入弯和出弯 是否是固定的
  4. d1 = {
  5. 'LM.head': {'center': (11, 22), 'center_12': (11, 21), 'center_9': (11, 21), 'center_6': (11, 21)},
  6. 'JK.head': {'center': (11, 22), 'center_12': (11, 21), 'center_9': (11, 21), 'center_6': (11, 21)},
  7. 'HI.head': {'center': (11, 22), 'center_12': (11, 21), 'center_9': (11, 21), 'center_6': (11, 21)},
  8. 'FG.head': {'center': (11, 22), 'center_12': (11, 21), 'center_9': (11, 21), 'center_6': (11, 21)},
  9. 'DE.head': {'center': (11, 22), 'center_12': (11, 21), 'center_9': (11, 21), 'center_6': (11, 21)},
  10. 'BC.head': {'center': (11, 22), 'center_12': (11, 21), 'center_9': (11, 21), 'center_6': (11, 21)},
  11. 'A.head': {'center': (11, 22), 'center_12': (11, 21), 'center_9': (11, 21), 'center_6': (11, 21)},
  12. 'LM.tail': {'center': (11, 22), 'center_12': (11, 21), 'center_3': (11, 21), 'center_6': (11, 21)},
  13. 'JK.tail': {'center': (11, 22), 'center_12': (11, 21), 'center_3': (11, 21), 'center_6': (11, 21)},
  14. 'HI.tail': {'center': (11, 22), 'center_12': (11, 21), 'center_3': (11, 21), 'center_6': (11, 21)},
  15. 'FG.tail': {'center': (11, 22), 'center_12': (11, 21), 'center_3': (11, 21), 'center_6': (11, 21)},
  16. 'DE.tail': {'center': (11, 22), 'center_12': (11, 21), 'center_3': (11, 21), 'center_6': (11, 21)},
  17. 'BC.tail': {'center': (11, 22), 'center_12': (11, 21), 'center_3': (11, 21), 'center_6': (11, 21)},
  18. 'A.tail': {'center': (11, 22), 'center_12': (11, 21), 'center_3': (11, 21), 'center_6': (11, 21)},
  19. }
  20. # 倒渣口坐标字典
  21. d2 = {
  22. 'dump.MN': {'dump': (11, 205.75)}, # 1号倒渣口
  23. 'dump.KL': {'dump': (11, 177.75)}, # 2号倒渣口
  24. 'dump.IJ': {'dump': (11, 149.75)}, # 3号倒渣口
  25. 'dump.GH': {'dump': (11, 121.75)}, # 4号倒渣口
  26. 'dump.EF': {'dump': (11, 93.75)}, # 5号倒渣口
  27. 'dump.CD': {'dump': (11, 65.75)}, # 6号倒渣口
  28. 'dump.AB': {'dump': (11, 37.75)}, # 7号倒渣口
  29. }
  30. # 接渣口坐标字典
  31. d3 = {
  32. 'load.1': {'load': (11, 22)},
  33. 'load.2': {'load': (11, 22)},
  34. 'load.3': {'load': (11, 22)},
  35. }
  36. # 停车区坐标字典
  37. d5 = {
  38. 'pack.1': {'x': 77, 'y': 44},
  39. 'pack.2': {'x': 77, 'y': 44},
  40. }
  41. # 渣罐坐标字典
  42. d4 = {
  43. 'M.31': {'pot': (22, 33), 'road_center': (44, 55)},
  44. 'M.30': {'pot': (22, 33), 'road_center': (44, 55)},
  45. 'M.29': {'pot': (22, 33), 'road_center': (44, 55)},
  46. 'M.28': {'pot': (22, 33), 'road_center': (44, 55)},
  47. 'M.27': {'pot': (22, 33), 'road_center': (44, 55)},
  48. 'M.26': {'pot': (22, 33), 'road_center': (44, 55)},
  49. 'M.25': {'pot': (22, 33), 'road_center': (44, 55)},
  50. 'M.24': {'pot': (22, 33), 'road_center': (44, 55)},
  51. 'M.23': {'pot': (22, 33), 'road_center': (44, 55)},
  52. 'M.22': {'pot': (22, 33), 'road_center': (44, 55)},
  53. 'M.21': {'pot': (22, 33), 'road_center': (44, 55)},
  54. 'M.20': {'pot': (22, 33), 'road_center': (44, 55)},
  55. 'M.19': {'pot': (22, 33), 'road_center': (44, 55)},
  56. 'M.18': {'pot': (22, 33), 'road_center': (44, 55)},
  57. 'M.17': {'pot': (22, 33), 'road_center': (44, 55)},
  58. 'M.16': {'pot': (22, 33), 'road_center': (44, 55)},
  59. 'M.15': {'pot': (22, 33), 'road_center': (44, 55)},
  60. 'M.14': {'pot': (22, 33), 'road_center': (44, 55)},
  61. 'M.13': {'pot': (22, 33), 'road_center': (44, 55)},
  62. 'M.12': {'pot': (22, 33), 'road_center': (44, 55)},
  63. 'M.11': {'pot': (22, 33), 'road_center': (44, 55)},
  64. 'M.10': {'pot': (22, 33), 'road_center': (44, 55)},
  65. 'M.9': {'pot': (22, 33), 'road_center': (44, 55)},
  66. 'M.8': {'pot': (22, 33), 'road_center': (44, 55)},
  67. 'M.7': {'pot': (22, 33), 'road_center': (44, 55)},
  68. 'M.6': {'pot': (22, 33), 'road_center': (44, 55)},
  69. 'M.5': {'pot': (22, 33), 'road_center': (44, 55)},
  70. 'M.4': {'pot': (22, 33), 'road_center': (44, 55)},
  71. 'M.3': {'pot': (22, 33), 'road_center': (44, 55)},
  72. 'M.2': {'pot': (22, 33), 'road_center': (44, 55)},
  73. 'M.1': {'pot': (22, 33), 'road_center': (44, 55)},
  74. 'F.31': {'pot': (22, 33), 'road_center': (44, 55)},
  75. 'F.30': {'pot': (22, 33), 'road_center': (44, 55)},
  76. 'F.29': {'pot': (22, 33), 'road_center': (44, 55)},
  77. 'F.28': {'pot': (22, 33), 'road_center': (44, 55)},
  78. 'F.27': {'pot': (22, 33), 'road_center': (44, 55)},
  79. 'F.26': {'pot': (22, 33), 'road_center': (44, 55)},
  80. 'F.25': {'pot': (22, 33), 'road_center': (44, 55)},
  81. 'F.24': {'pot': (22, 33), 'road_center': (44, 55)},
  82. 'F.23': {'pot': (22, 33), 'road_center': (44, 55)},
  83. 'F.22': {'pot': (22, 33), 'road_center': (44, 55)},
  84. 'F.21': {'pot': (22, 33), 'road_center': (44, 55)},
  85. 'F.20': {'pot': (22, 33), 'road_center': (44, 55)},
  86. 'F.19': {'pot': (22, 33), 'road_center': (44, 55)},
  87. 'F.18': {'pot': (22, 33), 'road_center': (44, 55)},
  88. 'F.17': {'pot': (22, 33), 'road_center': (44, 55)},
  89. 'F.16': {'pot': (22, 33), 'road_center': (44, 55)},
  90. 'F.15': {'pot': (22, 33), 'road_center': (44, 55)},
  91. 'F.14': {'pot': (22, 33), 'road_center': (44, 55)},
  92. 'F.13': {'pot': (22, 33), 'road_center': (44, 55)},
  93. 'F.12': {'pot': (22, 33), 'road_center': (44, 55)},
  94. 'F.11': {'pot': (22, 33), 'road_center': (44, 55)},
  95. 'F.10': {'pot': (22, 33), 'road_center': (44, 55)},
  96. 'F.9': {'pot': (22, 33), 'road_center': (44, 55)},
  97. 'F.8': {'pot': (22, 33), 'road_center': (44, 55)},
  98. 'F.7': {'pot': (22, 33), 'road_center': (44, 55)},
  99. 'F.6': {'pot': (22, 33), 'road_center': (44, 55)},
  100. 'F.5': {'pot': (22, 33), 'road_center': (44, 55)},
  101. 'F.4': {'pot': (22, 33), 'road_center': (44, 55)},
  102. 'F.3': {'pot': (22, 33), 'road_center': (44, 55)},
  103. 'F.2': {'pot': (22, 33), 'road_center': (44, 55)},
  104. 'F.1': {'pot': (22, 33), 'road_center': (44, 55)},
  105. }
  106. def get_nearest_point_from_road_center_point(x, y):
  107. """
  108. 获取当前所在位置最接近的坐标位置
  109. todo 判断是否是合理的范围,逻辑上移 offset = 11 # 允许范围(单位:米)
  110. """
  111. x = float(x)
  112. y = float(y)
  113. min_distance = float('inf') # 初始值无穷大
  114. for k, v in d4.items():
  115. center_x = float(v.get('road_center')[0])
  116. center_y = float(v.get('road_center')[1])
  117. distance = ((center_x - x) ** 2 + (center_y - y) ** 2) ** (1 / 2)
  118. if distance < min_distance:
  119. min_distance = distance
  120. nearest_point = center_x, center_y
  121. return nearest_point
  122. def get_center_point_by_keyword(w1='N', w2='head'):
  123. """
  124. 获取圆心点坐标
  125. w1: 关键字
  126. w2: 关键字
  127. """
  128. # d1 = todo 从json文件中获取
  129. for k, v in d1.items():
  130. k_s1, k_s2 = k.split('.')
  131. if w1 not in k_s1:
  132. continue
  133. if w2 not in k_s2:
  134. continue
  135. return dict(**v, **{'name': k})
  136. def get_path_name_by_pot_name(pot_name='M.25'):
  137. """根据渣罐名获取道路名"""
  138. s1, s2 = pot_name.split('.')
  139. path_name_list = [
  140. 'MN',
  141. 'KL',
  142. 'IJ',
  143. 'GH',
  144. 'EF',
  145. 'CD',
  146. 'AB',
  147. ]
  148. for s in path_name_list:
  149. if s1 in s:
  150. return s
  151. import json
  152. def test(s_direction='head', s_name='M.10', e_name='M.1'):
  153. """
  154. s_direction: 起始方向 head 渣场方向 tail 围栏方向
  155. s_name: 起始位置
  156. e_name: 目标位置
  157. """
  158. # --- update d4 ---
  159. data = json.load(open('../data/渣罐坐标数据.json', 'r'))
  160. for item in data.get('pot_name|pot_x|pot_y|road_center_x|road_center_y'):
  161. pot_name, pot_x, pot_y, road_center_x, road_center_y = item.split('|')
  162. d4[pot_name] = {
  163. 'pot': (pot_x, pot_y),
  164. 'road_center': (road_center_x, road_center_y),
  165. }
  166. # --- test
  167. # x, y = get_nearest_point_from_road_center_point(x=112.5, y=27.25)
  168. # return x, y
  169. # --- check ---
  170. if s_direction not in ['head', 'tail']:
  171. return {'code': 1, 'data': []}
  172. # --- check ---
  173. if not s_name or not e_name:
  174. return {'code': 2, 'data': []}
  175. # --- prepare ---
  176. if 'dump' in s_name:
  177. s_point_item = dict(**d2.get(s_name), **{'name': s_name})
  178. else:
  179. s_point_item = dict(**d4.get(s_name), **{'name': s_name})
  180. # --- prepare ---
  181. if 'dump' in e_name:
  182. e_point_item = dict(**d2.get(e_name), **{'name': e_name})
  183. else:
  184. e_point_item = dict(**d4.get(e_name), **{'name': e_name})
  185. # --- check --- 判断是否是在正前方的情况1
  186. if s_direction == 'head' and 'dump' not in s_name and 'dump' not in e_name:
  187. s_s1, s_s2 = s_name.split('.')
  188. e_s1, e_s2 = e_name.split('.')
  189. if s_s1 == e_s1 and int(e_s2) < int(s_s2):
  190. return {'code': 0, 'data': [s_point_item, e_point_item]}
  191. # --- check --- 判断是否是在正前方的情况2
  192. if s_direction == 'tail' and 'dump' not in s_name and 'dump' not in e_name:
  193. s_s1, s_s2 = s_name.split('.')
  194. e_s1, e_s2 = e_name.split('.')
  195. if s_s1 == e_s1 and int(s_s2) < int(e_s2):
  196. return {'code': 0, 'data': [s_point_item, e_point_item]}
  197. # --- check --- head方向,向下行驶,并拐弯情况(共2个弯,1个出弯,1个入弯)
  198. if s_direction == 'head' and 'dump' not in s_name and 'dump' not in e_name:
  199. s_s1, s_s2 = s_name.split('.')
  200. e_s1, e_s2 = e_name.split('.')
  201. if s_s1 != e_s1:
  202. w1 = get_path_name_by_pot_name(s_name)[:1] # 第一位
  203. center_point_item_1 = get_center_point_by_keyword(w1=w1, w2='head')
  204. w1 = get_path_name_by_pot_name(e_name)[-1:] # 最后位
  205. center_point_item_2 = get_center_point_by_keyword(w1=w1, w2='head')
  206. return {'code': 0, 'data': [s_point_item, center_point_item_1, center_point_item_2, e_point_item]}
  207. # --- check --- head方向,向下行驶,从包位到倒渣口(共1个弯,1个出弯)
  208. if s_direction == 'head' and 'dump' not in s_name and 'dump' in e_name:
  209. pass
  210. # --- check --- head方向,向下行驶,从倒渣口到包位(共1个弯,1个入弯)
  211. if s_direction == 'head' and 'dump' in s_name and 'dump' not in e_name:
  212. pass
  213. # --- check --- tail方向,向上行驶,从倒渣口到包位(共1个弯,1个入弯)
  214. if s_direction == 'tail' and 'dump' in s_name and 'dump' not in e_name:
  215. pass
  216. # --- check --- tail方向,向上行驶,从倒渣口到包位(共1个弯,1个入弯)
  217. if s_direction == 'tail' and 'dump' in s_name and 'dump' not in e_name:
  218. pass
  219. if __name__ == '__main__':
  220. # --- test ---
  221. # 判断是否是在正前方的情况1
  222. # out = test(s_direction='head', s_name='M.10', e_name='M.1')
  223. # 判断是否是在正前方的情况2
  224. # out = test(s_direction='tail', s_name='M.12', e_name='M.20')
  225. # head方向,向下行驶,并拐弯情况(共2个弯,1个是出弯,1个是入弯)
  226. out = test(s_direction='head', s_name='M.12', e_name='F.20')
  227. print(out)