carrier.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. //
  2. // Created by huli on 2021/3/12.
  3. //
  4. #include "carrier.h"
  5. #include "dispatch_manager.h"
  6. Carrier::Carrier()
  7. {
  8. m_request_x = 0; //搬运器坐标x轴,
  9. m_request_y = 0; //搬运器坐标y轴,
  10. m_request_z = 0; //搬运器坐标z轴,
  11. m_request_y1 = 0; //搬运器坐标y1轴, 搬运器抓车杆纵向移动(前轮抓杆)
  12. m_request_y2 = 0; //搬运器坐标y2轴, 搬运器抓车杆纵向移动(后轮抓杆)
  13. m_request_clamp_motion = E_CLAMP_NO_ACTION; //搬运器夹车杆. 0=无动作,1=夹紧,2=松开
  14. m_request_joint_motion_x = E_JOINT_NO_ACTION; //电梯与X轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
  15. m_request_joint_motion_y = E_JOINT_NO_ACTION; //小跑车与Y轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
  16. m_request_space_id = 0; //搬运器空间位置的id.
  17. m_request_floor_id = 0; //搬运器楼层位置的id.
  18. m_request_wheelbase = 0; //搬运器抓车杆前后轮距.
  19. m_respons_status = RESPONS_WORKING; //指令完成状态, 搬运器答复指令, 返回任务完成的情况
  20. m_respons_x = 0; //搬运器坐标x轴,
  21. m_respons_y = 0; //搬运器坐标y轴,
  22. m_respons_z = 0; //搬运器坐标z轴,
  23. m_respons_y1 = 0; //搬运器坐标y1轴, 搬运器抓车杆纵向移动(前轮抓杆)
  24. m_respons_y2 = 0; //搬运器坐标y2轴, 搬运器抓车杆纵向移动(后轮抓杆)
  25. m_respons_clamp_motion = E_CLAMP_NO_ACTION; //搬运器夹车杆. 0=无动作,1=夹紧,2=松开
  26. m_respons_joint_motion_x = E_JOINT_NO_ACTION; //电梯与X轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
  27. m_respons_joint_motion_y = E_JOINT_NO_ACTION; //小跑车与Y轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
  28. m_respons_space_id = 0; //搬运器空间位置的id.
  29. m_respons_floor_id = 0; //搬运器楼层位置的id.
  30. m_respons_wheelbase = 0; //搬运器抓车杆前后轮距.
  31. m_status_updata_time = std::chrono::system_clock::now();
  32. m_last_heartbeat = 0; //上一次的心跳
  33. m_actual_device_status = HARDWARE_DEVICE_UNKNOWN; //搬运器的硬件设备状态
  34. m_actual_load_status = LOAD_UNKNOWN; //搬运器的负载状态, 小跑车上面是否有车.
  35. m_actual_x = 0; //搬运器坐标x轴,
  36. m_actual_y = 0; //搬运器坐标y轴,
  37. m_actual_z = 0; //搬运器坐标z轴,
  38. m_actual_y1 = 0; //搬运器坐标y1轴, 搬运器抓车杆纵向移动(前轮抓杆)
  39. m_actual_y2 = 0; //搬运器坐标y2轴, 搬运器抓车杆纵向移动(后轮抓杆)
  40. m_actual_clamp_motion1 = E_CLAMP_NO_ACTION; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  41. m_actual_clamp_motion2 = E_CLAMP_NO_ACTION; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  42. m_actual_small_sports_car_motion = E_SMALL_SPORTS_NO_ACTION;
  43. m_actual_joint_motion_x1 = E_JOINT_NO_ACTION; //电梯与X轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
  44. m_actual_joint_motion_x2 = E_JOINT_NO_ACTION; //电梯与X轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
  45. memset(m_actual_error_code, 0, 50); //搬运器设备的报警信息位
  46. memset(m_actual_warning_code, 0, 50); //升降机设备的报警信息位
  47. m_actual_coordinates_id = 0;
  48. m_actual_coordinates_rows = 0;
  49. m_actual_coordinates_columns = 0;
  50. m_redirect_flag = false;
  51. m_catcher_run_flag = false;
  52. m_redirect_pickup_parkspace_id = 0;
  53. m_redirect_pickup_car_type = Common_data::Car_type::UNKNOW_CAR_TYPE;
  54. m_redirect_store_parkspace_id = 0;
  55. m_redirect_store_car_type = Common_data::Car_type::UNKNOW_CAR_TYPE;
  56. }
  57. Carrier::~Carrier()
  58. {
  59. }
  60. //检查任务类型, 子类必须重载, 用来检查输入的任务是否为子类所需的.
  61. Error_manager Carrier::check_task_type(std::shared_ptr<Task_Base> p_task)
  62. {
  63. //检查任务类型,
  64. if (p_task->get_task_type() != Task_Base::Task_type::CARRIER_TASK)
  65. {
  66. return Error_manager(Error_code::CARRIER_TASK_TYPE_ERROR, Error_level::MINOR_ERROR,
  67. "Carrier::check_task_type get_task_type() != CARRIER_TASK ");
  68. }
  69. return Error_code::SUCCESS;
  70. }
  71. //获取硬件设备的状态, 必须子类继承
  72. Carrier::Hardware_device_status Carrier::get_actual_device_status()
  73. {
  74. return m_actual_device_status;
  75. }
  76. std::string Carrier::get_current_command_key()
  77. {
  78. return (m_request_key + " +++ " + m_respons_key);
  79. }
  80. //把任务单写入到内存中, 子类必须重载
  81. Error_manager Carrier::write_task_to_memory(std::shared_ptr<Task_Base> p_task)
  82. {
  83. //检查任务类型,
  84. if (p_task->get_task_type() != Task_Base::Task_type::CARRIER_TASK)
  85. {
  86. return Error_manager(Error_code::CARRIER_TASK_TYPE_ERROR, Error_level::MINOR_ERROR,
  87. "Carrier::check_task_type get_task_type() != CARRIER_TASK ");
  88. }
  89. else
  90. {
  91. Carrier_task* tp_carrier_task = (Carrier_task*)p_task.get();
  92. std::unique_lock<std::mutex> t_lock1(tp_carrier_task->m_lock);
  93. m_request_key = tp_carrier_task->m_request_key;
  94. m_request_x = tp_carrier_task->m_request_x;
  95. m_request_y = tp_carrier_task->m_request_y;
  96. m_request_z = tp_carrier_task->m_request_z;
  97. m_request_y1 = tp_carrier_task->m_request_y1;
  98. m_request_y2 = tp_carrier_task->m_request_y2;
  99. m_request_clamp_motion = (Dispatch_device_base::Clamp_motion)tp_carrier_task->m_request_clamp_motion;
  100. m_request_joint_motion_x = (Dispatch_device_base::Joint_motion)tp_carrier_task->m_request_joint_motion_x;
  101. m_request_joint_motion_y = (Dispatch_device_base::Joint_motion)tp_carrier_task->m_request_joint_motion_y;
  102. m_request_space_id = tp_carrier_task->m_request_space_id;
  103. m_request_floor_id = tp_carrier_task->m_request_floor_id;
  104. m_request_wheelbase = tp_carrier_task->m_request_wheelbase;
  105. return Error_code::SUCCESS;
  106. }
  107. return Error_code::SUCCESS;
  108. }
  109. //更新设备底层通信数据, 子类必须重载
  110. Error_manager Carrier::update_device_communication()
  111. {
  112. std::unique_lock<std::mutex> t_lock1(Dispatch_communication::get_instance_references().m_data_lock);
  113. //请求消息, 调度->plc
  114. Dispatch_communication::Carrier_request_from_dispatch_to_plc_for_data * tp_carrier_request_from_dispatch_to_plc_for_data =
  115. & Dispatch_communication::get_instance_references().m_carrier_request_from_dispatch_to_plc_for_data[m_device_id];
  116. Dispatch_communication::Carrier_request_from_dispatch_to_plc_for_key * tp_carrier_request_from_dispatch_to_plc_for_key =
  117. & Dispatch_communication::get_instance_references().m_carrier_request_from_dispatch_to_plc_for_key[m_device_id];
  118. memset(tp_carrier_request_from_dispatch_to_plc_for_key->m_request_key, 0, 50);
  119. int t_size = m_request_key.size()<=50 ? m_request_key.size() : 50 ;
  120. memcpy(tp_carrier_request_from_dispatch_to_plc_for_key->m_request_key, m_request_key.c_str(), t_size);
  121. tp_carrier_request_from_dispatch_to_plc_for_data->m_request_x = m_request_x;
  122. tp_carrier_request_from_dispatch_to_plc_for_data->m_request_y = m_request_y;
  123. tp_carrier_request_from_dispatch_to_plc_for_data->m_request_z = m_request_z;
  124. tp_carrier_request_from_dispatch_to_plc_for_data->m_request_y1 = m_request_y1;
  125. tp_carrier_request_from_dispatch_to_plc_for_data->m_request_y2 = m_request_y2;
  126. tp_carrier_request_from_dispatch_to_plc_for_data->m_request_clamp_motion = m_request_clamp_motion;
  127. tp_carrier_request_from_dispatch_to_plc_for_data->m_request_joint_motion_x = m_request_joint_motion_x;
  128. tp_carrier_request_from_dispatch_to_plc_for_data->m_request_joint_motion_y = m_request_joint_motion_y;
  129. tp_carrier_request_from_dispatch_to_plc_for_data->m_request_space_id = m_request_space_id;
  130. tp_carrier_request_from_dispatch_to_plc_for_data->m_request_floor_id = m_request_floor_id;
  131. tp_carrier_request_from_dispatch_to_plc_for_data->m_request_wheelbase = m_request_wheelbase;
  132. //答复消息, plc->调度
  133. Dispatch_communication::Carrier_response_from_plc_to_dispatch * tp_carrier_response_from_plc_to_dispatch =
  134. & Dispatch_communication::get_instance_references().m_carrier_response_from_plc_to_dispatch[m_device_id];
  135. m_respons_key = (char*) tp_carrier_response_from_plc_to_dispatch->m_respons_key;
  136. m_respons_status = (Dispatch_device_base::Respons_status)tp_carrier_response_from_plc_to_dispatch->m_respons_status;
  137. m_respons_x = tp_carrier_response_from_plc_to_dispatch->m_respons_x;
  138. m_respons_y = tp_carrier_response_from_plc_to_dispatch->m_respons_y;
  139. m_respons_z = tp_carrier_response_from_plc_to_dispatch->m_respons_z;
  140. m_respons_y1 = tp_carrier_response_from_plc_to_dispatch->m_respons_y1;
  141. m_respons_y2 = tp_carrier_response_from_plc_to_dispatch->m_respons_y2;
  142. m_respons_clamp_motion = (Dispatch_device_base::Clamp_motion)tp_carrier_response_from_plc_to_dispatch->m_respons_clamp_motion;
  143. m_respons_joint_motion_x = (Dispatch_device_base::Joint_motion)tp_carrier_response_from_plc_to_dispatch->m_respons_joint_motion_x;
  144. m_respons_joint_motion_y = (Dispatch_device_base::Joint_motion)tp_carrier_response_from_plc_to_dispatch->m_respons_joint_motion_y;
  145. m_respons_space_id = tp_carrier_response_from_plc_to_dispatch->m_respons_space_id;
  146. m_respons_floor_id = tp_carrier_response_from_plc_to_dispatch->m_respons_floor_id;
  147. m_respons_wheelbase = tp_carrier_response_from_plc_to_dispatch->m_respons_wheelbase;
  148. //状态消息, plc->调度
  149. Dispatch_communication::Carrier_status_from_plc_to_dispatch *tp_carrier_status_from_plc_to_dispatch =
  150. & Dispatch_communication::get_instance_references().m_carrier_status_from_plc_to_dispatch[m_device_id];
  151. //设备异常 //注注注注注注注注意了, ==的优先级比&要高.
  152. if ( (tp_carrier_status_from_plc_to_dispatch->m_safe_status & 0x02) == 0 )
  153. {
  154. m_actual_device_status = Dispatch_device_base::HARDWARE_DEVICE_EMERGENCY_STOP;
  155. m_dispatch_device_status = Dispatch_device_base::DISPATCH_DEVICE_FAULT;
  156. }
  157. else if ( (tp_carrier_status_from_plc_to_dispatch->m_safe_status & 0x01) == 0 )
  158. {
  159. m_actual_device_status = Dispatch_device_base::HARDWARE_DEVICE_FAULT;
  160. m_dispatch_device_status = Dispatch_device_base::DISPATCH_DEVICE_FAULT;
  161. }
  162. else if ( (tp_carrier_status_from_plc_to_dispatch->m_safe_status & 0x08) == 0 )
  163. {
  164. m_actual_device_status = Dispatch_device_base::HARDWARE_DEVICE_COLLISION;
  165. m_dispatch_device_status = Dispatch_device_base::DISPATCH_DEVICE_FAULT;
  166. }
  167. //正常状态
  168. else
  169. {
  170. if (tp_carrier_status_from_plc_to_dispatch->m_work_status == 1)
  171. {
  172. m_actual_device_status = Dispatch_device_base::HARDWARE_DEVICE_WORKING;
  173. }
  174. else if(tp_carrier_status_from_plc_to_dispatch->m_work_status == 2)
  175. {
  176. m_actual_device_status = Dispatch_device_base::HARDWARE_DEVICE_READY;
  177. }
  178. else if(tp_carrier_status_from_plc_to_dispatch->m_work_status == 0)
  179. {
  180. m_actual_device_status = Dispatch_device_base::HARDWARE_DEVICE_UNKNOWN;
  181. }
  182. //故障恢复之后 E_FAULT ->> E_THREE_LEVEL_WORK
  183. if ( m_dispatch_device_status == Dispatch_device_base::DISPATCH_DEVICE_FAULT )
  184. {
  185. m_dispatch_device_status = Dispatch_device_base::DISPATCH_DEVICE_THREE_LEVEL_WORK;
  186. }
  187. //else 流程状态维持不变
  188. }
  189. m_actual_load_status = (Dispatch_device_base::Load_status)tp_carrier_status_from_plc_to_dispatch->m_actual_load_status;
  190. m_actual_x = tp_carrier_status_from_plc_to_dispatch->m_actual_x;
  191. m_actual_y = tp_carrier_status_from_plc_to_dispatch->m_actual_y;
  192. //plc没有 给3楼的中跑车写入z轴, 所以手动写入z轴, 方便后面判断坐标
  193. if ( m_device_id == 2 && m_actual_x >1)
  194. {
  195. m_actual_z = Dispatch_coordinates::get_instance_references().m_carrier_3th_floor_z;
  196. }
  197. else
  198. {
  199. m_actual_z = tp_carrier_status_from_plc_to_dispatch->m_actual_z;
  200. }
  201. m_actual_y1 = tp_carrier_status_from_plc_to_dispatch->m_actual_y1;
  202. m_actual_y2 = tp_carrier_status_from_plc_to_dispatch->m_actual_y2;
  203. m_actual_clamp_motion1 = (Dispatch_device_base::Clamp_motion)tp_carrier_status_from_plc_to_dispatch->m_actual_clamp_motion1;
  204. m_actual_clamp_motion2 = (Dispatch_device_base::Clamp_motion)tp_carrier_status_from_plc_to_dispatch->m_actual_clamp_motion2;
  205. m_actual_small_sports_car_motion = (Dispatch_device_base::Small_sports_car_motion)tp_carrier_status_from_plc_to_dispatch->m_actual_small_sports_car_motion;
  206. m_actual_joint_motion_x1 = (Dispatch_device_base::Joint_motion)tp_carrier_status_from_plc_to_dispatch->m_actual_joint_motion_x1;
  207. m_actual_joint_motion_x2 = (Dispatch_device_base::Joint_motion)tp_carrier_status_from_plc_to_dispatch->m_actual_joint_motion_x2;
  208. memcpy(m_actual_error_code, tp_carrier_status_from_plc_to_dispatch->m_actual_error_code, 50);
  209. memcpy(m_actual_warning_code, tp_carrier_status_from_plc_to_dispatch->m_actual_warning_code, 50);
  210. m_actual_error_description = (char*)(tp_carrier_status_from_plc_to_dispatch->m_actual_error_description-2);
  211. update_actual_coordinates_id();
  212. //通过心跳帧来判断通信是否正常
  213. if ( m_last_heartbeat != tp_carrier_status_from_plc_to_dispatch->m_heartbeat )
  214. {
  215. m_last_heartbeat = tp_carrier_status_from_plc_to_dispatch->m_heartbeat;
  216. m_status_updata_time = std::chrono::system_clock::now();
  217. /*
  218. if ( get_device_id() == 2)
  219. {
  220. // std::this_thread::sleep_for(std::chrono::seconds(1));
  221. // std::cout << " 111111111111111111111111111 = " << 123 << std::endl;
  222. std::cout << " huli test :::: " << " get_dispatch_device_status = " << get_dispatch_device_status() << std::endl;
  223. // std::cout << " huli test :::: " << " get_device_id() = " << get_device_id() << std::endl;
  224. std::cout << " tp_carrier_request_from_dispatch_to_plc_for_key->m_request_key = " << tp_carrier_request_from_dispatch_to_plc_for_key->m_request_key << std::endl;
  225. std::cout << " tp_carrier_response_from_plc_to_dispatch->m_respons_key = " << tp_carrier_response_from_plc_to_dispatch->m_respons_key << std::endl;
  226. // int b = tp_carrier_status_from_plc_to_dispatch->m_safe_status;
  227. // std::cout << " huli test :::: " << " tp_carrier_status_from_plc_to_dispatch->m_safe_status = " << b << std::endl;
  228. // int a = tp_carrier_status_from_plc_to_dispatch->m_work_status;
  229. // std::cout << " tp_carrier_status_from_plc_to_dispatch->m_work_status = " << a << std::endl;
  230. // std::cout << " m_request_key = " << m_request_key << std::endl;
  231. // std::cout << " m_respons_key = " << m_respons_key << std::endl;
  232. // std::cout << " huli test :::: " << " m_request_x = " << m_request_x << std::endl;
  233. // std::cout << " huli test :::: " << " m_respons_x = " << m_respons_x << std::endl;
  234. // std::cout << " huli test :::: " << " m_actual_x = " << m_actual_x << std::endl;
  235. // std::cout << " m_actual_device_status = " << m_actual_device_status << std::endl;
  236. // std::cout << " 111111111111111111111111111 = " << 456 << std::endl;
  237. }
  238. */
  239. //重连之后,搬运器状态 E_DISCONNECT ->> E_THREE_LEVEL_WORK
  240. if ( m_dispatch_device_status == Dispatch_device_base::DISPATCH_DEVICE_DISCONNECT )
  241. {
  242. m_dispatch_device_status = Dispatch_device_base::DISPATCH_DEVICE_THREE_LEVEL_WORK;
  243. }
  244. }
  245. else if(std::chrono::system_clock::now() - m_status_updata_time > std::chrono::milliseconds(COMMUNICATION_OVER_TIME_MS))
  246. {
  247. m_dispatch_device_status = Dispatch_device_base::DISPATCH_DEVICE_DISCONNECT;
  248. }
  249. //else 继续等待,直到消息刷新或者超时.
  250. return Error_code::SUCCESS;
  251. }
  252. //从内存中读数据到任务单, 子类必须重载
  253. Error_manager Carrier::check_and_read_memory_to_task(std::shared_ptr<Task_Base> p_task)
  254. {
  255. Dispatch_communication::get_instance_references().communication_start();
  256. //检查任务类型,
  257. if (p_task->get_task_type() != Task_Base::Task_type::CARRIER_TASK)
  258. {
  259. return Error_manager(Error_code::CARRIER_TASK_TYPE_ERROR, Error_level::MINOR_ERROR,
  260. "Carrier::check_task_type get_task_type() != CARRIER_TASK ");
  261. }
  262. else
  263. {
  264. if ( m_respons_key == m_request_key && m_respons_status != RESPONS_WORKING )
  265. {
  266. Carrier_task* tp_carrier_task = (Carrier_task*)p_task.get();
  267. std::unique_lock<std::mutex> t_lock1(tp_carrier_task->m_lock);
  268. tp_carrier_task->m_respons_key = m_respons_key;
  269. tp_carrier_task->m_respons_status = (Carrier_task::Respons_status)m_respons_status;
  270. tp_carrier_task->m_respons_x = m_respons_x;
  271. tp_carrier_task->m_respons_y = m_respons_y;
  272. tp_carrier_task->m_respons_z = m_respons_z;
  273. tp_carrier_task->m_respons_y1 = m_respons_y1;
  274. tp_carrier_task->m_respons_y2 = m_respons_y2;
  275. tp_carrier_task->m_respons_clamp_motion = (Carrier_task::Clamp_motion)m_respons_clamp_motion;
  276. tp_carrier_task->m_respons_joint_motion_x = (Carrier_task::Joint_motion)m_respons_joint_motion_x;
  277. tp_carrier_task->m_respons_joint_motion_y = (Carrier_task::Joint_motion)m_respons_joint_motion_y;
  278. tp_carrier_task->m_respons_space_id = m_respons_space_id;
  279. tp_carrier_task->m_respons_floor_id = m_respons_floor_id;
  280. tp_carrier_task->m_respons_wheelbase = m_respons_wheelbase;
  281. //如果故障,则添加错误码
  282. if ( m_respons_status == RESPONS_MINOR_ERROR || m_respons_status == RESPONS_CRITICAL_ERROR )
  283. {
  284. //添加错误码
  285. Error_manager t_error(CARRIER_RESPONS_ERROR, MINOR_ERROR, "m_respons_status is error");
  286. tp_carrier_task->set_task_error_manager(t_error);
  287. }
  288. // if ( get_device_id() == 0 )
  289. // {
  290. // std::cout << " huli test :::: " << " {{{{{{{{{{{{{{{{{{{{{ 33333333333333333333333333333333333333333 }}}}}}}}}}}}}}}}}}}}}}}}}}= " << 333 << std::endl;
  291. // std::cout << " huli test :::: " << " m_request_key = " << m_request_key << std::endl;
  292. // std::cout << " huli test :::: " << " m_request_x = " << m_request_x << std::endl;
  293. // std::cout << " huli test :::: " << " m_request_y = " << m_request_y << std::endl;
  294. // std::cout << " huli test :::: " << " m_request_z = " << m_request_z << std::endl;
  295. // std::cout << " huli test :::: " << " m_request_clamp_motion = " << m_request_clamp_motion << std::endl;
  296. // std::cout << " huli test :::: " << " m_request_wheelbase = " << m_request_wheelbase << std::endl;
  297. // std::cout << " huli test :::: " << " m_request_y1 = " << m_request_y1 << std::endl;
  298. // std::cout << " huli test :::: " << " m_request_y2 = " << m_request_y2 << std::endl;
  299. // std::cout << " m_request_joint_motion_x = " << m_request_joint_motion_x << std::endl;
  300. //
  301. // std::cout << " huli test :::: " << " m_respons_key = " << m_respons_key << std::endl;
  302. // std::cout << " huli test :::: " << " m_respons_status = " << m_respons_status << std::endl;
  303. // std::cout << " huli test :::: " << " m_respons_x = " << m_respons_x << std::endl;
  304. // std::cout << " huli test :::: " << " m_respons_y = " << m_respons_y << std::endl;
  305. // std::cout << " huli test :::: " << " m_respons_z = " << m_respons_z << std::endl;
  306. // std::cout << " huli test :::: " << " m_respons_clamp_motion = " << m_respons_clamp_motion << std::endl;
  307. // std::cout << " huli test :::: " << " m_respons_wheelbase = " << m_respons_wheelbase << std::endl;
  308. // std::cout << " huli test :::: " << " m_respons_y1 = " << m_respons_y1 << std::endl;
  309. // std::cout << " huli test :::: " << " m_respons_y2 = " << m_respons_y2 << std::endl;
  310. // std::cout << " m_respons_joint_motion_x = " << m_respons_joint_motion_x << std::endl;
  311. //
  312. // std::cout << " m_actual_device_status = " << m_actual_device_status << std::endl;
  313. // std::cout << " huli test :::: " << " m_actual_load_status = " << m_actual_load_status << std::endl;
  314. // std::cout << " huli test :::: " << " m_actual_x = " << m_actual_x << std::endl;
  315. // std::cout << " huli test :::: " << " m_actual_y = " << m_actual_y << std::endl;
  316. // std::cout << " huli test :::: " << " m_actual_z = " << m_actual_z << std::endl;
  317. // std::cout << " huli test :::: " << " m_actual_y1 = " << m_actual_y1 << std::endl;
  318. // std::cout << " huli test :::: " << " m_actual_y2 = " << m_actual_y2 << std::endl;
  319. // std::cout << " huli test :::: " << " m_actual_clamp_motion1 = " << m_actual_clamp_motion1 << std::endl;
  320. // std::cout << " huli test :::: " << " {{{{{{{{{{{{{{{{{{{{{{{{{{{{ 44444444444444444444444444444444444444444 }}}}}}}}}}}}}}}}}}}}}}}}= " << 444 << std::endl;
  321. //
  322. // }
  323. return Error_code::SUCCESS;
  324. }
  325. //返回没有收到数据
  326. else
  327. {
  328. return Error_code::NODATA;
  329. }
  330. }
  331. return Error_code::SUCCESS;
  332. }
  333. //取消下发的指令
  334. Error_manager Carrier::cancel_command()
  335. {
  336. //以后再写 need programe
  337. //目前调度和plc的通信指令做的很简单,没有暂停和急停 复位等操作.
  338. //这里先空着,以后再写.
  339. //调度模块单方面销毁任务, 不管底层plc的执行情况, 也不去告知plc任务取消.
  340. return Error_code::SUCCESS;
  341. }
  342. //更新真实 空间位置的id.
  343. Error_manager Carrier::update_actual_coordinates_id()
  344. {
  345. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  346. float t_distance_min = 99999999999999999;
  347. float t_distance_current = 0;
  348. int t_index_min = 0;
  349. //找出最近的坐标点
  350. for (auto iter = tp_dispatch_coordinates->m_packspace_coordinates_map.begin(); iter != tp_dispatch_coordinates->m_packspace_coordinates_map.end(); ++iter)
  351. {
  352. //只算x轴和z轴
  353. t_distance_current = (m_actual_x - iter->second.x)*(m_actual_x - iter->second.x) + (m_actual_z - iter->second.z)*(m_actual_z - iter->second.z);
  354. if ( t_distance_current < t_distance_min )
  355. {
  356. t_distance_min = t_distance_current;
  357. t_index_min = iter->first;
  358. }
  359. }
  360. m_actual_coordinates_id = t_index_min;
  361. //更新空间锁, 只是 覆盖写入加锁.
  362. if ( m_actual_coordinates_id != 0 )
  363. {
  364. m_actual_coordinates_rows = (m_actual_coordinates_id-1) / Dispatch_coordinates::get_instance_references().m_space_lock_columns;
  365. m_actual_coordinates_columns = (m_actual_coordinates_id-1) % Dispatch_coordinates::get_instance_references().m_space_lock_columns;
  366. //3楼的搬运器不用加空间锁
  367. if ( get_device_id() != 2 )
  368. {
  369. Dispatch_coordinates::get_instance_references().set_space_lock_for_carrier(m_actual_coordinates_rows, m_actual_coordinates_columns, m_device_id);
  370. }
  371. }
  372. return Error_code::SUCCESS;
  373. }