dispatch_process.cpp 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. //
  2. // Created by huli on 2021/3/22.
  3. //
  4. #include "dispatch_process.h"
  5. #include "../system/system_communication.h"
  6. #include "../dispatch/dispatch_manager.h"
  7. Dispatch_process::Dispatch_process()
  8. {
  9. m_dispatch_process_status = DISPATCH_PROCESS_STATUS_UNKNOW;
  10. m_dispatch_process_type = DISPATCH_PROCESS_TYPE_UNKNOW;
  11. m_dispatch_source = 0;
  12. m_dispatch_destination = 0;
  13. m_dispatch_process_catcher_motion = CATCHER_MOTION_UNKNOW;
  14. m_dispatch_process_carrier_motion = CARRIER_MOTION_UNKNOW;
  15. }
  16. Dispatch_process::~Dispatch_process()
  17. {
  18. Dispatch_process_uninit();
  19. }
  20. //初始化, 就把主控发送的请求传入即可.
  21. Error_manager Dispatch_process::Dispatch_process_init(message::Dispatch_request_msg dispatch_request_msg)
  22. {
  23. if ( dispatch_request_msg.base_info().has_timeout_ms() )
  24. {
  25. m_timeout_ms = dispatch_request_msg.base_info().timeout_ms() - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
  26. }
  27. else
  28. {
  29. m_timeout_ms = DISPATCH_PROCESS_TIMEOUT_MS - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
  30. }
  31. m_command_key = dispatch_request_msg.command_key();
  32. m_start_time = std::chrono::system_clock::now();
  33. if ( dispatch_request_msg.dispatch_motion_direction() == message::E_STORE_CAR )
  34. {
  35. m_dispatch_process_type = DISPATCH_PROCESS_STORE;
  36. m_dispatch_source = dispatch_request_msg.terminal_id() + PASSAGEWAY_ID_BASE ;
  37. m_dispatch_destination = dispatch_request_msg.parkspace_info().parkspace_id() + PARKSPACE_ID_BASE;
  38. Common_data::copy_data(m_parkspace_information, dispatch_request_msg.parkspace_info());
  39. Common_data::copy_data(m_car_measure_information, dispatch_request_msg.locate_information());
  40. }
  41. else if( dispatch_request_msg.dispatch_motion_direction() == message::E_PICKUP_CAR )
  42. {
  43. m_dispatch_process_type = DISPATCH_PROCESS_PICKUP;
  44. m_dispatch_source = dispatch_request_msg.parkspace_info().parkspace_id() + PARKSPACE_ID_BASE;
  45. m_dispatch_destination = dispatch_request_msg.terminal_id() + PASSAGEWAY_ID_BASE ;
  46. Common_data::copy_data(m_parkspace_information, dispatch_request_msg.parkspace_info());
  47. }
  48. else
  49. {
  50. m_dispatch_process_type = DISPATCH_PROCESS_TYPE_UNKNOW;
  51. return Error_manager(Error_code::PARAMETER_ERROR, Error_level::MINOR_ERROR,
  52. " Dispatch_process::Dispatch_process_init ERROR ");
  53. }
  54. m_dispatch_request_msg = dispatch_request_msg;
  55. m_dispatch_process_status = DISPATCH_PROCESS_CREATED;
  56. return Error_code::SUCCESS;
  57. }
  58. //反初始化
  59. Error_manager Dispatch_process::Dispatch_process_uninit()
  60. {
  61. return Error_code::SUCCESS;
  62. }
  63. void Dispatch_process::Main()
  64. {
  65. Error_manager t_error;
  66. //主流程, 循环执行
  67. while ( std::chrono::system_clock::now() - m_start_time < std::chrono::milliseconds(m_timeout_ms) )
  68. {
  69. std::this_thread::sleep_for(std::chrono::microseconds(1));
  70. switch ( m_dispatch_process_status )
  71. {
  72. case DISPATCH_PROCESS_CREATED:
  73. {
  74. //检查调度请求
  75. m_result = check_dispatch_request_msg();
  76. if ( m_result !=Error_code::SUCCESS)
  77. {
  78. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  79. break;
  80. }
  81. //发送调度总计划
  82. m_result = send_dispatch_plan_request_msg();
  83. if ( m_result !=Error_code::SUCCESS)
  84. {
  85. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  86. break;
  87. }
  88. //流程正常, 就进入等待状态, 等待调度控制发送动作指令
  89. m_dispatch_process_status = DISPATCH_PROCESS_READY;
  90. break;
  91. }
  92. case DISPATCH_PROCESS_READY:
  93. {
  94. //等待控制指令
  95. m_result = wait_dispatch_control_request_msg();
  96. if ( m_result !=Error_code::SUCCESS)
  97. {
  98. //不成功, 就表示没有新的指令, 那么什么都不做, 原地待命
  99. }
  100. else
  101. {
  102. //流程正常, 就去连接设备
  103. m_dispatch_process_status = DISPATCH_PROCESS_CONNECT_DEVICE;
  104. break;
  105. }
  106. //等待调度总计划答复
  107. m_result = wait_dispatch_plan_response_msg();
  108. if ( m_result !=Error_code::SUCCESS)
  109. {
  110. //不成功, 就表示没有总计划答复, 那么什么都不做, 原地待命
  111. }
  112. else
  113. {
  114. //流程正常, 就进入完成状态,
  115. m_dispatch_process_status = DISPATCH_PROCESS_OVER;
  116. break;
  117. }
  118. break;
  119. }
  120. case DISPATCH_PROCESS_CONNECT_DEVICE:
  121. {
  122. //连接调度设备
  123. m_result = connect_dispatch_device();
  124. if ( m_result !=Error_code::SUCCESS)
  125. {
  126. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  127. break;
  128. }
  129. //流程正常, 就进入工作状态,
  130. m_dispatch_process_status = DISPATCH_PROCESS_WORKING;
  131. break;
  132. break;
  133. }
  134. case DISPATCH_PROCESS_WORKING:
  135. {
  136. break;
  137. }
  138. case DISPATCH_PROCESS_RESPONSE:
  139. {
  140. break;
  141. }
  142. case DISPATCH_PROCESS_OVER:
  143. {
  144. //发送调度答复, 发给主控的
  145. m_result = send_dispatch_response_msg();
  146. if ( m_result !=Error_code::SUCCESS)
  147. {
  148. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  149. break;
  150. }
  151. //流程正常, 就进入等待状态, 等待调度控制发送动作指令
  152. m_dispatch_process_status = DISPATCH_PROCESS_RELEASE;
  153. break;
  154. }
  155. case DISPATCH_PROCESS_RELEASE:
  156. {
  157. //通知调度管理, 释放资源,
  158. m_result = release_resource();
  159. if ( m_result !=Error_code::SUCCESS)
  160. {
  161. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  162. break;
  163. }
  164. //在这里, 整个流程彻底结束, 之后线程池会自动回收 这个流程对象的资源
  165. return;
  166. break;
  167. }
  168. case DISPATCH_PROCESS_FAULT:
  169. {
  170. break;
  171. }
  172. default:
  173. {
  174. break;
  175. }
  176. }
  177. }
  178. //任务超时
  179. return;
  180. }
  181. //检查调度请求
  182. Error_manager Dispatch_process::check_dispatch_request_msg()
  183. {
  184. std::unique_lock<std::mutex> t_lock(m_lock);
  185. return Error_code::SUCCESS;
  186. }
  187. //发送调度总计划
  188. Error_manager Dispatch_process::send_dispatch_plan_request_msg()
  189. {
  190. std::unique_lock<std::mutex> t_lock(m_lock);
  191. m_dispatch_plan_request_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_plan_request_msg);
  192. m_dispatch_plan_request_msg.mutable_base_info()->set_timeout_ms(m_timeout_ms);
  193. m_dispatch_plan_request_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_mamager);
  194. m_dispatch_plan_request_msg.mutable_base_info()->set_receiver(message::Communicator::eDispatch_control);
  195. m_dispatch_plan_request_msg.set_command_key(m_command_key);
  196. m_dispatch_plan_request_msg.set_dispatch_task_type((message::Dispatch_task_type)m_dispatch_process_type);
  197. m_dispatch_plan_request_msg.set_dispatch_source(m_dispatch_source);
  198. m_dispatch_plan_request_msg.set_dispatch_destination(m_dispatch_destination);
  199. //这里不写错误码
  200. std::string t_msg = m_dispatch_plan_request_msg.SerializeAsString();
  201. System_communication::get_instance_references().encapsulate_msg(t_msg);
  202. return Error_code::SUCCESS;
  203. }
  204. //等待控制指令
  205. Error_manager Dispatch_process::wait_dispatch_control_request_msg()
  206. {
  207. std::unique_lock<std::mutex> t_lock(m_lock);
  208. //key不相等 就表示 收到了新的控制指令
  209. if ( m_dispatch_control_request_msg.command_key() == m_dispatch_control_response_msg.command_key() )
  210. {
  211. return Error_code::NODATA;
  212. }
  213. else
  214. {
  215. return Error_code::SUCCESS;
  216. }
  217. }
  218. //连接调度设备
  219. Error_manager Dispatch_process::connect_dispatch_device()
  220. {
  221. std::unique_lock<std::mutex> t_lock(m_lock);
  222. Error_manager t_error;
  223. //机器手的配置 准备工作
  224. if ( m_dispatch_control_request_msg.dispatch_device_type() >= message::Dispatch_device_type::ROBOT_1 &&
  225. m_dispatch_control_request_msg.dispatch_device_type() <= message::Dispatch_device_type::ROBOT_2 )
  226. {
  227. //找到对应的设备
  228. if ( m_dispatch_control_request_msg.dispatch_device_type() == message::Dispatch_device_type::ROBOT_1 )
  229. {
  230. mp_catcher = Dispatch_manager::get_instance_references().m_catcher_map[0];
  231. }
  232. if ( m_dispatch_control_request_msg.dispatch_device_type() == message::Dispatch_device_type::ROBOT_2 )
  233. {
  234. mp_catcher = Dispatch_manager::get_instance_references().m_catcher_map[1];
  235. }
  236. Catcher* tp_catcher = (Catcher*)mp_catcher.get();
  237. //检查设备状态
  238. if ( tp_catcher->check_status() == Error_code::SUCCESS &&
  239. tp_catcher->m_actual_device_status == Dispatch_device_base::DEVICE_READY )
  240. {
  241. //创建任务单
  242. mp_catcher_task = std::shared_ptr<Task_Base>(new Catcher_task);
  243. mp_catcher_task->task_init(NULL,std::chrono::milliseconds(15000));
  244. Catcher_task * tp_catcher_task = (Catcher_task *)mp_catcher_task.get();
  245. //第一次发送 空的唯一码, 可以和设备建立联系
  246. tp_catcher_task->m_request_key = "";
  247. tp_catcher_task->m_request_x = tp_catcher->m_actual_x;
  248. tp_catcher_task->m_request_y = tp_catcher->m_actual_y;
  249. tp_catcher_task->m_request_b = tp_catcher->m_actual_b;
  250. tp_catcher_task->m_request_z = tp_catcher->m_actual_z;
  251. tp_catcher_task->m_request_d1 = tp_catcher->m_actual_d1;
  252. tp_catcher_task->m_request_d2 = tp_catcher->m_actual_d2;
  253. tp_catcher_task->m_request_wheelbase = Dispatch_coordinates::get_instance_references().m_default_wheelbase;
  254. tp_catcher_task->m_request_clamp_motion = (Catcher_task::Clamp_motion)tp_catcher->m_actual_clamp_motion1;
  255. t_error = tp_catcher->execute_task(mp_catcher_task, Dispatch_device_base::E_ONE_LEVEL);
  256. if ( t_error != Error_code::SUCCESS )
  257. {
  258. return t_error;
  259. }
  260. }
  261. else
  262. {
  263. return Error_manager(Error_code::DISPATCH_PROCESS_DEVICE_STATUS_ERROR, Error_level::MINOR_ERROR,
  264. " Dispatch_process::excute_robot_catch_car_from_inlet device_status error ");
  265. }
  266. //设置起点
  267. m_source_coordinates = Dispatch_coordinates::get_instance_references().m_catcher_coordinates[m_dispatch_control_request_msg.dispatch_source()];
  268. //设置终点
  269. m_destination_coordinates = Dispatch_coordinates::get_instance_references().m_catcher_coordinates[m_dispatch_control_request_msg.dispatch_destination()];
  270. }
  271. //搬运器的配置 准备工作
  272. else if ( m_dispatch_control_request_msg.dispatch_device_type() >= message::Dispatch_device_type::CARRIER_1 &&
  273. m_dispatch_control_request_msg.dispatch_device_type() <= message::Dispatch_device_type::CARRIER_3 )
  274. {
  275. //找到对应的设备
  276. if ( m_dispatch_control_request_msg.dispatch_device_type() == message::Dispatch_device_type::CARRIER_1 )
  277. {
  278. mp_carrier = Dispatch_manager::get_instance_references().m_carrier_map[0];
  279. }
  280. if ( m_dispatch_control_request_msg.dispatch_device_type() == message::Dispatch_device_type::CARRIER_2 )
  281. {
  282. mp_carrier = Dispatch_manager::get_instance_references().m_carrier_map[1];
  283. }
  284. if ( m_dispatch_control_request_msg.dispatch_device_type() == message::Dispatch_device_type::CARRIER_3 )
  285. {
  286. mp_carrier = Dispatch_manager::get_instance_references().m_carrier_map[1];
  287. }
  288. Carrier* tp_carrier = (Carrier*)mp_carrier.get();
  289. //检查设备状态
  290. if ( tp_carrier->check_status() == Error_code::SUCCESS &&
  291. tp_carrier->m_actual_device_status == Dispatch_device_base::DEVICE_READY )
  292. {
  293. //创建任务单
  294. mp_carrier_task = std::shared_ptr<Task_Base>(new Carrier_task);
  295. mp_carrier_task->task_init(NULL,std::chrono::milliseconds(15000));
  296. Carrier_task * tp_carrier_task = (Carrier_task *)mp_carrier_task.get();
  297. //第一次发送 空的唯一码, 可以和设备建立联系
  298. tp_carrier_task->m_request_key = "";
  299. tp_carrier_task->m_request_x = tp_carrier->m_actual_x;
  300. tp_carrier_task->m_request_y = tp_carrier->m_actual_y;
  301. tp_carrier_task->m_request_z = tp_carrier->m_actual_z;
  302. tp_carrier_task->m_request_y1 = tp_carrier->m_actual_y1;
  303. tp_carrier_task->m_request_y2 = tp_carrier->m_actual_y2;
  304. tp_carrier_task->m_request_clamp_motion = (Carrier_task::Clamp_motion)tp_carrier->m_actual_clamp_motion1;
  305. tp_carrier_task->m_request_joint_motion_x = (Carrier_task::Joint_motion)tp_carrier->m_actual_joint_motion_x1;
  306. tp_carrier_task->m_request_joint_motion_y = Carrier_task::Joint_motion::E_JOINT_NO_ACTION;
  307. tp_carrier_task->m_request_space_id = 0;
  308. tp_carrier_task->m_request_floor_id = 0;
  309. tp_carrier_task->m_request_wheelbase = Dispatch_coordinates::get_instance_references().m_default_wheelbase;
  310. t_error = tp_carrier->execute_task(mp_catcher_task, Dispatch_device_base::E_ONE_LEVEL);
  311. if ( t_error != Error_code::SUCCESS )
  312. {
  313. return t_error;
  314. }
  315. }
  316. else
  317. {
  318. return Error_manager(Error_code::DISPATCH_PROCESS_DEVICE_STATUS_ERROR, Error_level::MINOR_ERROR,
  319. " Dispatch_process::excute_robot_catch_car_from_inlet device_status error ");
  320. }
  321. //设置起点
  322. m_source_coordinates = Dispatch_coordinates::get_instance_references().m_carrier_coordinates[m_dispatch_control_request_msg.dispatch_source()];
  323. //设置终点
  324. m_destination_coordinates = Dispatch_coordinates::get_instance_references().m_carrier_coordinates[m_dispatch_control_request_msg.dispatch_destination()];
  325. }
  326. return Error_code::SUCCESS;
  327. }
  328. //检查机器手任务单
  329. Error_manager Dispatch_process::check_catcher_task()
  330. {
  331. if ( mp_catcher_task.get() == NULL )
  332. {
  333. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  334. "Dispatch_process::check_catcher_task POINTER IS NULL ");
  335. }
  336. else
  337. {
  338. Catcher_task * tp_catcher_task = (Catcher_task *)mp_catcher_task.get();
  339. if ( tp_catcher_task->get_task_statu() == Task_Base::Task_statu::TASK_OVER )
  340. {
  341. return Error_code::SUCCESS;
  342. }
  343. else if ( tp_catcher_task->get_task_statu() == Task_Base::Task_statu::TASK_ERROR )
  344. {
  345. return tp_catcher_task->get_task_error_manager();
  346. }
  347. else if ( tp_catcher_task->get_task_statu() == Task_Base::Task_statu::TASK_WORKING &&
  348. tp_catcher_task->get_task_statu() == Task_Base::Task_statu::TASK_SIGNED &&
  349. tp_catcher_task->get_task_statu() == Task_Base::Task_statu::TASK_CREATED)
  350. {
  351. return Error_code::NODATA;
  352. }
  353. }
  354. }
  355. //检查搬运器任务单
  356. Error_manager Dispatch_process::check_carrier_task()
  357. {
  358. if ( mp_carrier_task.get() == NULL )
  359. {
  360. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  361. "Dispatch_process::check_carrier_task POINTER IS NULL ");
  362. }
  363. else
  364. {
  365. Catcher_task * tp_carrier_task = (Catcher_task *)mp_carrier_task.get();
  366. if ( tp_carrier_task->get_task_statu() == Task_Base::Task_statu::TASK_OVER )
  367. {
  368. return Error_code::SUCCESS;
  369. }
  370. else if ( tp_carrier_task->get_task_statu() == Task_Base::Task_statu::TASK_ERROR )
  371. {
  372. return tp_carrier_task->get_task_error_manager();
  373. }
  374. else if ( tp_carrier_task->get_task_statu() == Task_Base::Task_statu::TASK_WORKING &&
  375. tp_carrier_task->get_task_statu() == Task_Base::Task_statu::TASK_SIGNED &&
  376. tp_carrier_task->get_task_statu() == Task_Base::Task_statu::TASK_CREATED)
  377. {
  378. return Error_code::NODATA;
  379. }
  380. }
  381. }
  382. //检查通道口任务单
  383. Error_manager Dispatch_process::check_passageway_task()
  384. {
  385. if ( mp_passageway_task.get() == NULL )
  386. {
  387. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  388. "Dispatch_process::check_passageway_task POINTER IS NULL ");
  389. }
  390. else
  391. {
  392. Catcher_task * tp_passageway_task = (Catcher_task *)mp_passageway_task.get();
  393. if ( tp_passageway_task->get_task_statu() == Task_Base::Task_statu::TASK_OVER )
  394. {
  395. return Error_code::SUCCESS;
  396. }
  397. else if ( tp_passageway_task->get_task_statu() == Task_Base::Task_statu::TASK_ERROR )
  398. {
  399. return tp_passageway_task->get_task_error_manager();
  400. }
  401. else if ( tp_passageway_task->get_task_statu() == Task_Base::Task_statu::TASK_WORKING &&
  402. tp_passageway_task->get_task_statu() == Task_Base::Task_statu::TASK_SIGNED &&
  403. tp_passageway_task->get_task_statu() == Task_Base::Task_statu::TASK_CREATED)
  404. {
  405. return Error_code::NODATA;
  406. }
  407. }
  408. }
  409. //检查 任务单 是否完成任务, 里面会调整短步骤
  410. Error_manager Dispatch_process::check_task_ex(std::shared_ptr<Task_Base> p_catcher_task, int& step)
  411. {
  412. if ( p_catcher_task.get() == NULL )
  413. {
  414. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  415. "Dispatch_process::check_passageway_task POINTER IS NULL ");
  416. }
  417. else
  418. {
  419. if ( p_catcher_task->get_task_statu() == Task_Base::Task_statu::TASK_OVER )
  420. {
  421. step++;
  422. return Error_code::NODATA; //这里返回nodata 表示任务继续下一步
  423. }
  424. else if ( p_catcher_task->get_task_statu() == Task_Base::Task_statu::TASK_ERROR )
  425. {
  426. step = 0;
  427. return p_catcher_task->get_task_error_manager();
  428. }
  429. else if ( p_catcher_task->get_task_statu() == Task_Base::Task_statu::TASK_WORKING &&
  430. p_catcher_task->get_task_statu() == Task_Base::Task_statu::TASK_SIGNED &&
  431. p_catcher_task->get_task_statu() == Task_Base::Task_statu::TASK_CREATED)
  432. {
  433. //继续等待任务, 直到状态改变
  434. return Error_code::NODATA;
  435. }
  436. }
  437. }
  438. //执行调度控制指令, 并根据完成情况给答复
  439. Error_manager Dispatch_process::excute_dispatch_control()
  440. {
  441. //设备的动作也使用外部的Main()的线程来循环
  442. return Error_code::SUCCESS;
  443. }
  444. //机器手去入口抓车(例如:机器手移动到2号入口上方,然后下降到一楼抓车,最后上升到最上方)
  445. Error_manager Dispatch_process::excute_robot_catch_car_from_inlet()
  446. {
  447. Error_manager t_error;
  448. Catcher * tp_catcher = NULL;
  449. Catcher_task * tp_catcher_task = NULL;
  450. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  451. if ( mp_catcher.get() == NULL || mp_catcher_task.get() == NULL )
  452. {
  453. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  454. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  455. }
  456. else
  457. {
  458. tp_catcher = (Catcher *)mp_catcher.get();
  459. tp_catcher_task = (Catcher_task *)mp_catcher_task.get();
  460. }
  461. if ( tp_catcher_task->m_step == 0 )
  462. {
  463. return check_task_ex(mp_catcher_task, tp_catcher_task->m_step);
  464. }
  465. if ( tp_catcher_task->m_step == 1 )//检查姿态
  466. {
  467. //检查姿态
  468. if ( tp_catcher->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  469. {
  470. if ( tp_catcher->m_actual_clamp_motion1 != Dispatch_device_base::Clamp_motion::E_CLAMP_LOOSE ||
  471. tp_catcher->m_actual_d1 + tp_catcher->m_actual_d2 + tp_dispatch_coordinates->m_catcher_d1_d2_distance >
  472. tp_dispatch_coordinates->m_catcher_wheel_base_limit ||
  473. tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_UNKNOW )
  474. {
  475. std::unique_lock<std::mutex> t_lock1(m_lock);
  476. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  477. char t_key[50] = {0};
  478. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  479. tp_catcher_task->m_respons_key = t_key;
  480. //调整姿态
  481. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  482. tp_catcher_task->m_request_d1 = tp_dispatch_coordinates->m_catcher_d1_min;
  483. tp_catcher_task->m_request_d2 = tp_dispatch_coordinates->m_catcher_d2_min;
  484. tp_catcher_task->m_request_b = 90;
  485. tp_catcher_task->m_step++;
  486. }
  487. else
  488. {
  489. tp_catcher_task->m_step +=2;
  490. }
  491. }
  492. else
  493. {
  494. return Error_manager(Error_code::CATCHER_POSE_ERROR, Error_level::MINOR_ERROR,
  495. "tp_catcher->m_actual_load_status != Dispatch_device_base::Load_status::NO_CAR fun error ");
  496. }
  497. }
  498. if ( tp_catcher_task->m_step == 2 )
  499. {
  500. return check_task_ex(mp_catcher_task, tp_catcher_task->m_step);
  501. }
  502. if ( tp_catcher_task->m_step == 3 )//机器手z轴移到最高点.
  503. {
  504. std::unique_lock<std::mutex> t_lock1(m_lock);
  505. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  506. char t_key[50] = {0};
  507. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  508. tp_catcher_task->m_respons_key = t_key;
  509. //机器手z轴移到最高点.
  510. tp_catcher_task->m_request_z = tp_dispatch_coordinates->m_catcher_4th_floor_z;
  511. tp_catcher_task->m_step++;
  512. }
  513. if ( tp_catcher_task->m_step == 4 )
  514. {
  515. return check_task_ex(mp_catcher_task, tp_catcher_task->m_step);
  516. }
  517. if ( tp_catcher_task->m_step == 5 )//机器手 调整x y b d1 d2, 根据感测模块的定位信息, 调整机器手的姿态, 准备抓车.
  518. {
  519. std::unique_lock<std::mutex> t_lock1(m_lock);
  520. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  521. char t_key[50] = {0};
  522. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  523. tp_catcher_task->m_respons_key = t_key;
  524. //机器手 调整x y b d1 d2, 根据感测模块的定位信息, 调整机器手的姿态, 准备抓车.
  525. tp_catcher_task->m_request_x = m_car_measure_information.center_x;
  526. tp_catcher_task->m_request_y = m_car_measure_information.center_y;
  527. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  528. {
  529. //机器手如果旋转反向, 那就+180即可, 没有必要旋转归位.
  530. tp_catcher_task->m_request_b = 180 + m_car_measure_information.car_angle;
  531. }
  532. else
  533. {
  534. tp_catcher_task->m_request_b = m_car_measure_information.car_angle;
  535. }
  536. //限制轮距, 在夹车杆松开时, 机器人下降时, 轴距不能超过3000mm, 必须下降到最下面才能调整轴距, 夹车后可以上升.
  537. if ( m_car_measure_information.car_wheel_base > tp_dispatch_coordinates->m_catcher_wheel_base_limit )
  538. {
  539. tp_catcher_task->m_request_d1 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  540. tp_catcher_task->m_request_d2 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  541. tp_catcher_task->m_request_wheelbase = tp_dispatch_coordinates->m_catcher_wheel_base_limit;
  542. }
  543. else
  544. {
  545. tp_catcher_task->m_request_d1 = (m_car_measure_information.car_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  546. tp_catcher_task->m_request_d2 = (m_car_measure_information.car_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  547. tp_catcher_task->m_request_wheelbase = m_car_measure_information.car_wheel_base;
  548. }
  549. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  550. tp_catcher_task->m_step++;
  551. }
  552. if ( tp_catcher_task->m_step == 6 )
  553. {
  554. return check_task_ex(mp_catcher_task, tp_catcher_task->m_step);
  555. }
  556. if ( tp_catcher_task->m_step == 7 )//机器手z轴移到最低点.
  557. {
  558. std::unique_lock<std::mutex> t_lock1(m_lock);
  559. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  560. char t_key[50] = {0};
  561. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  562. tp_catcher_task->m_respons_key = t_key;
  563. //机器手z轴移到最低点.
  564. tp_catcher_task->m_request_z = tp_dispatch_coordinates->m_catcher_1th_floor_z;
  565. tp_catcher_task->m_step++;
  566. }
  567. if ( tp_catcher_task->m_step == 8 )
  568. {
  569. return check_task_ex(mp_catcher_task, tp_catcher_task->m_step);
  570. }
  571. if ( tp_catcher_task->m_step == 9 )//修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  572. {
  573. std::unique_lock<std::mutex> t_lock1(m_lock);
  574. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  575. //修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  576. if ( m_car_measure_information.car_wheel_base > tp_dispatch_coordinates->m_catcher_wheel_base_limit )
  577. {
  578. std::unique_lock<std::mutex> t_lock1(m_lock);
  579. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  580. char t_key[50] = {0};
  581. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  582. tp_catcher_task->m_respons_key = t_key;
  583. //修正轴距
  584. tp_catcher_task->m_request_d1 = (m_car_measure_information.car_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  585. tp_catcher_task->m_request_d2 = (m_car_measure_information.car_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  586. tp_catcher_task->m_request_wheelbase = m_car_measure_information.car_wheel_base;
  587. tp_catcher_task->m_step++;
  588. }
  589. else
  590. {
  591. tp_catcher_task->m_step = tp_catcher_task->m_step +2;
  592. }
  593. }
  594. if ( tp_catcher_task->m_step == 10 )
  595. {
  596. return check_task_ex(mp_catcher_task, tp_catcher_task->m_step);
  597. }
  598. if ( tp_catcher_task->m_step == 11 )//机器手 夹车
  599. {
  600. std::unique_lock<std::mutex> t_lock1(m_lock);
  601. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  602. char t_key[50] = {0};
  603. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  604. tp_catcher_task->m_respons_key = t_key;
  605. //机器手 夹车
  606. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_TIGHT;
  607. tp_catcher_task->m_step++;
  608. }
  609. if ( tp_catcher_task->m_step == 12 )
  610. {
  611. return check_task_ex(mp_catcher_task, tp_catcher_task->m_step);
  612. }
  613. if ( tp_catcher_task->m_step == 13 )//机器手 z轴上升到最高处
  614. {
  615. std::unique_lock<std::mutex> t_lock1(m_lock);
  616. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  617. char t_key[50] = {0};
  618. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  619. tp_catcher_task->m_respons_key = t_key;
  620. //机器手 z轴上升到最高处
  621. tp_catcher_task->m_request_z = tp_dispatch_coordinates->m_catcher_4th_floor_z;
  622. tp_catcher_task->m_step++;
  623. }
  624. if ( tp_catcher_task->m_step == 14 )
  625. {
  626. return check_task_ex(mp_catcher_task, tp_catcher_task->m_step);
  627. }
  628. if ( tp_catcher_task->m_step == 15 )
  629. {
  630. std::unique_lock<std::mutex> t_lock1(m_lock);
  631. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  632. char t_key[50] = {0};
  633. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  634. tp_catcher_task->m_respons_key = t_key;
  635. //机器手 调整x y b d1 d2, 调整机器手的姿态, 准备把车放置到中跑车上.
  636. tp_catcher_task->m_request_x = m_destination_coordinates.x;
  637. tp_catcher_task->m_request_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (tp_catcher_task->m_request_wheelbase /2);
  638. //存车需要反向, 取车不需要
  639. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  640. {
  641. tp_catcher_task->m_request_b = 90;
  642. }
  643. else
  644. {
  645. tp_catcher_task->m_request_b = 270;
  646. }
  647. tp_catcher_task->m_step++;
  648. }
  649. if ( tp_catcher_task->m_step == 16 )
  650. {
  651. return check_task_ex(mp_catcher_task, tp_catcher_task->m_step);
  652. }
  653. if ( tp_catcher_task->m_step == 17 )
  654. {
  655. return Error_code::SUCCESS;
  656. }
  657. }
  658. //机器手把车放到中跑车上面(例如:机器手下降到中跑车上放车,最后上升到最上方)(通过目标点 指定放到哪一个中跑车上)
  659. Error_manager Dispatch_process::excute_robot_put_car_to_carrier()
  660. {
  661. }
  662. //机器手去中跑车上抓车(例如:机器手移动到1号中跑车上方,然后下降到中跑车抓车,最后上升到最上方)
  663. Error_manager Dispatch_process::excute_robot_catch_car_from_carrier()
  664. {
  665. }
  666. //机器手去出口放车(例如:机器手移动到3号出口上方,然后下降到一楼放车,最后上升到最上方)
  667. Error_manager Dispatch_process::excute_robot_put_car_to_outlet()
  668. {
  669. }
  670. //机器手的自由移动(例如:机器手移动到6号出入口的上方4楼处,给其他设备避让)(不进行抓车和放车的操作)
  671. Error_manager Dispatch_process::excute_robot_move()
  672. {
  673. }
  674. //搬运器从机器手上接车(例如:搬运器移动到2号入口的上方,然后等待机器手把车放到中跑车上,小跑车保持松夹杆状态)
  675. Error_manager Dispatch_process::excute_carrier_receive_car_from_robot()
  676. {
  677. Error_manager t_error;
  678. Carrier * tp_carrier = NULL;
  679. Carrier_task * tp_carrier_task = NULL;
  680. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  681. if ( mp_carrier.get() == NULL || mp_carrier_task.get() == NULL )
  682. {
  683. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  684. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  685. }
  686. else
  687. {
  688. tp_carrier = (Carrier *)mp_carrier.get();
  689. tp_carrier_task = (Carrier_task *)mp_carrier_task.get();
  690. }
  691. if ( tp_carrier_task->m_step == 0 )
  692. {
  693. return check_task_ex(mp_carrier_task, tp_carrier_task->m_step);
  694. }
  695. if ( tp_carrier_task->m_step == 1 )//检查姿态
  696. {
  697. //检查姿态
  698. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  699. {
  700. if ( tp_carrier_task->m_request_clamp_motion != Carrier_task::Clamp_motion::E_CLAMP_LOOSE )
  701. {
  702. std::unique_lock<std::mutex> t_lock1(m_lock);
  703. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  704. char t_key[50] = {0};
  705. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  706. tp_carrier_task->m_respons_key = t_key;
  707. //调整姿态
  708. tp_carrier_task->m_request_clamp_motion = Carrier_task::Clamp_motion::E_CLAMP_LOOSE;
  709. tp_carrier_task->m_step++;
  710. }
  711. else
  712. {
  713. tp_carrier_task->m_step +=2;
  714. }
  715. }
  716. else
  717. {
  718. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  719. "tp_carrier->m_actual_load_status != Dispatch_device_base::Load_status::NO_CAR fun error ");
  720. }
  721. }
  722. if ( tp_carrier_task->m_step == 2 )
  723. {
  724. return check_task_ex(mp_catcher_task, tp_carrier_task->m_step);
  725. }
  726. if ( tp_carrier_task->m_step == 3 )//让小跑车回到中跑车上
  727. {
  728. if ( Common_data::approximate(tp_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, 0.01) )
  729. {
  730. tp_carrier_task->m_step +=2;
  731. }
  732. else
  733. {
  734. std::unique_lock<std::mutex> t_lock1(m_lock);
  735. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  736. char t_key[50] = {0};
  737. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  738. tp_carrier_task->m_respons_key = t_key;
  739. //让小跑车回到中跑车上
  740. tp_carrier_task->m_request_y = tp_dispatch_coordinates->m_carrier_default_y_back;
  741. tp_carrier_task->m_request_wheelbase = m_car_measure_information.car_wheel_base;
  742. tp_carrier_task->m_request_y1 = tp_dispatch_coordinates->m_carrier_default_y1_back;
  743. tp_carrier_task->m_request_y2 = tp_carrier_task->m_request_y1 - tp_carrier_task->m_request_wheelbase;
  744. tp_carrier_task->m_step++;
  745. }
  746. }
  747. if ( tp_carrier_task->m_step == 4 )
  748. {
  749. return check_task_ex(mp_catcher_task, tp_carrier_task->m_step);
  750. }
  751. if ( tp_carrier_task->m_step == 5 )//让中跑车回到电梯井
  752. {
  753. if ( Common_data::approximate(tp_carrier->m_actual_z, m_destination_coordinates.z, 0.01) )
  754. {
  755. tp_carrier_task->m_step +=2;
  756. }
  757. else
  758. {
  759. std::unique_lock<std::mutex> t_lock1(m_lock);
  760. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  761. char t_key[50] = {0};
  762. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  763. tp_carrier_task->m_respons_key = t_key;
  764. if ( mp_carrier->get_device_id() == 0 )
  765. {
  766. //让中跑车回到电梯井
  767. tp_carrier_task->m_request_x = tp_dispatch_coordinates->m_carrier_default_x_left;
  768. tp_carrier_task->m_step++;
  769. }
  770. else if ( mp_carrier->get_device_id() == 1 )
  771. {
  772. //让中跑车回到电梯井
  773. tp_carrier_task->m_request_x = tp_dispatch_coordinates->m_carrier_default_x_right;
  774. tp_carrier_task->m_step++;
  775. }
  776. else
  777. {
  778. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  779. " m_destination_coordinates.z PARAMRTER ERROR ");
  780. }
  781. }
  782. }
  783. if ( tp_carrier_task->m_step == 6 )
  784. {
  785. return check_task_ex(mp_catcher_task, tp_carrier_task->m_step);
  786. }
  787. if ( tp_carrier_task->m_step == 7 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  788. {
  789. if ( Common_data::approximate(tp_carrier->m_actual_z, m_destination_coordinates.z, 0.01) )
  790. {
  791. tp_carrier_task->m_step +=2;
  792. }
  793. else
  794. {
  795. std::unique_lock<std::mutex> t_lock1(m_lock);
  796. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  797. char t_key[50] = {0};
  798. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  799. tp_carrier_task->m_respons_key = t_key;
  800. //收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  801. tp_carrier_task->m_request_joint_motion_x = Carrier_task::Joint_motion::E_JOINT_TAKE_BACK;
  802. tp_carrier_task->m_step++;
  803. }
  804. }
  805. if ( tp_carrier_task->m_step == 8 )
  806. {
  807. return check_task_ex(mp_catcher_task, tp_carrier_task->m_step);
  808. }
  809. if ( tp_carrier_task->m_step == 9 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  810. {
  811. if ( Common_data::approximate(tp_carrier->m_actual_z, m_destination_coordinates.z, 0.01) )
  812. {
  813. tp_carrier_task->m_step +=2;
  814. }
  815. else
  816. {
  817. std::unique_lock<std::mutex> t_lock1(m_lock);
  818. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  819. char t_key[50] = {0};
  820. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  821. tp_carrier_task->m_respons_key = t_key;
  822. //电梯移动到对应的楼层
  823. tp_carrier_task->m_request_z = m_destination_coordinates.z;
  824. tp_carrier_task->m_step++;
  825. }
  826. }
  827. if ( tp_carrier_task->m_step == 10 )
  828. {
  829. return check_task_ex(mp_catcher_task, tp_carrier_task->m_step);
  830. }
  831. }
  832. //搬运器把车存到停车位上(例如:小跑车夹车后,搬运器移动到56号停车位,然后小跑车将车存入车位,之后搬运器退回至电梯井)
  833. Error_manager Dispatch_process::excute_carrier_store_car_to_parkingspace()
  834. {
  835. }
  836. //搬运器把车存到停车位上(例如:小跑车夹车后,搬运器移动到56号停车位,然后小跑车将车存入车位,之后搬运器退回至56车位外面即可)
  837. Error_manager Dispatch_process::excute_carrier_store_car_to_parkingspace_ex()
  838. {
  839. }
  840. //搬运器从停车位上取车(例如:搬运器移动到56号停车位,然后小跑车将车从车位取出,之后搬运器退回至电梯井)
  841. Error_manager Dispatch_process::excute_carrier_pickup_car_from_parkingspace()
  842. {
  843. }
  844. //搬运器从停车位上取车(例如:搬运器移动到56号停车位,然后小跑车将车从车位取出,之后搬运器退回至56车位外面即可)
  845. Error_manager Dispatch_process::excute_carrier_pickup_car_from_parkingspace_ex()
  846. {
  847. }
  848. //搬运器把车交付给机器手(例如:搬运器移动到3号入口的上方,小跑车松夹杆,然后等待机器手把车从中跑车上取走)
  849. Error_manager Dispatch_process::excute_carrier_deliver_car_to_robot()
  850. {
  851. }
  852. //搬运器的自由移动(可以提前到2楼来准备接车,或者为了避让就退回至电梯井)(小跑车不进行取车和存车)
  853. Error_manager Dispatch_process::excute_carrier_move()
  854. {
  855. }
  856. //执行通道口动作
  857. Error_manager Dispatch_process::excute_passageway_motion()
  858. {
  859. return Error_code::SUCCESS;
  860. }
  861. //等待调度总计划答复
  862. Error_manager Dispatch_process::wait_dispatch_plan_response_msg()
  863. {
  864. std::unique_lock<std::mutex> t_lock(m_lock);
  865. //key 相等 就表示 收到了总计划答复
  866. if ( m_dispatch_plan_request_msg.command_key() == m_dispatch_plan_response_msg.command_key() )
  867. {
  868. return Error_code::SUCCESS;
  869. }
  870. else
  871. {
  872. return Error_code::NODATA;
  873. }
  874. }
  875. //发送调度答复, 发给主控的
  876. Error_manager Dispatch_process::send_dispatch_response_msg()
  877. {
  878. std::unique_lock<std::mutex> t_lock(m_lock);
  879. m_dispatch_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_response_msg);
  880. m_dispatch_response_msg.mutable_base_info()->set_timeout_ms(m_timeout_ms);
  881. m_dispatch_response_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_mamager);
  882. m_dispatch_response_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
  883. m_dispatch_response_msg.set_command_key(m_command_key);
  884. m_dispatch_response_msg.mutable_error_manager()->CopyFrom(m_dispatch_plan_response_msg.error_manager());
  885. std::string t_msg = m_dispatch_response_msg.SerializeAsString();
  886. System_communication::get_instance_references().encapsulate_msg(t_msg);
  887. return Error_code::SUCCESS;
  888. }
  889. //通知调度管理, 释放资源,
  890. Error_manager Dispatch_process::release_resource()
  891. {
  892. return Dispatch_manager::get_instance_references().release_dispatch_process(m_command_key);
  893. }
  894. //异常处理
  895. Error_manager Dispatch_process::Exception_handling()
  896. {
  897. return Error_code::SUCCESS;
  898. }
  899. //机器手调整到正常待机的姿态
  900. Error_manager Dispatch_process::cartcher_adjust_to_ready(Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  901. {
  902. std::unique_lock<std::mutex> t_lock1(m_lock);
  903. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  904. char t_key[50] = {0};
  905. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  906. tp_catcher_task->m_respons_key = t_key;
  907. //调整姿态
  908. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  909. tp_catcher_task->m_request_d1 = tp_dispatch_coordinates->m_catcher_d1_min;
  910. tp_catcher_task->m_request_d2 = tp_dispatch_coordinates->m_catcher_d2_min;
  911. tp_catcher_task->m_request_b = 90;
  912. return Error_code::SUCCESS;
  913. }
  914. //机器手 移动z
  915. Error_manager Dispatch_process::cartcher_move_z(Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, float target)
  916. {
  917. std::unique_lock<std::mutex> t_lock1(m_lock);
  918. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  919. char t_key[50] = {0};
  920. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  921. tp_catcher_task->m_respons_key = t_key;
  922. //机器手 移动z
  923. tp_catcher_task->m_request_z = target;
  924. return Error_code::SUCCESS;
  925. }
  926. //机器手调整到 准备从地面抓车前的姿态
  927. Error_manager Dispatch_process::cartcher_adjust_from_ground(Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  928. {
  929. std::unique_lock<std::mutex> t_lock1(m_lock);
  930. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  931. char t_key[50] = {0};
  932. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  933. tp_catcher_task->m_respons_key = t_key;
  934. //机器手 调整x y b d1 d2, 根据感测模块的定位信息, 调整机器手的姿态, 准备抓车.
  935. tp_catcher_task->m_request_x = m_car_measure_information.center_x;
  936. tp_catcher_task->m_request_y = m_car_measure_information.center_y;
  937. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  938. {
  939. //机器手如果旋转反向, 那就+180即可, 没有必要旋转归位.
  940. tp_catcher_task->m_request_b = 180 + m_car_measure_information.car_angle;
  941. }
  942. else
  943. {
  944. tp_catcher_task->m_request_b = m_car_measure_information.car_angle;
  945. }
  946. //限制轮距, 在夹车杆松开时, 机器人下降时, 轴距不能超过3000mm, 必须下降到最下面才能调整轴距, 夹车后可以上升.
  947. if ( m_car_measure_information.car_wheel_base > tp_dispatch_coordinates->m_catcher_wheel_base_limit )
  948. {
  949. tp_catcher_task->m_request_d1 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  950. tp_catcher_task->m_request_d2 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  951. tp_catcher_task->m_request_wheelbase = tp_dispatch_coordinates->m_catcher_wheel_base_limit;
  952. }
  953. else
  954. {
  955. tp_catcher_task->m_request_d1 = (m_car_measure_information.car_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  956. tp_catcher_task->m_request_d2 = (m_car_measure_information.car_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  957. tp_catcher_task->m_request_wheelbase = m_car_measure_information.car_wheel_base;
  958. }
  959. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  960. return Error_code::SUCCESS;
  961. }
  962. //机器手 修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  963. Error_manager Dispatch_process::cartcher_adjust_wheel_base(Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  964. {
  965. std::unique_lock<std::mutex> t_lock1(m_lock);
  966. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  967. char t_key[50] = {0};
  968. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  969. tp_catcher_task->m_respons_key = t_key;
  970. //修正轴距
  971. tp_catcher_task->m_request_d1 = (m_car_measure_information.car_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  972. tp_catcher_task->m_request_d2 = (m_car_measure_information.car_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  973. tp_catcher_task->m_request_wheelbase = m_car_measure_information.car_wheel_base;
  974. return Error_code::SUCCESS;
  975. }
  976. //机器手 移动c轴 夹杆
  977. Error_manager Dispatch_process::cartcher_move_c(Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, Catcher_task::Clamp_motion target)
  978. {
  979. std::unique_lock<std::mutex> t_lock1(m_lock);
  980. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  981. char t_key[50] = {0};
  982. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  983. tp_catcher_task->m_respons_key = t_key;
  984. //机器手 夹车
  985. tp_catcher_task->m_request_clamp_motion = target;
  986. }
  987. //机器手调整到 准备把车放到搬运器的姿态
  988. Error_manager Dispatch_process::cartcher_adjust_to_carrier(Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  989. {
  990. std::unique_lock<std::mutex> t_lock1(m_lock);
  991. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  992. char t_key[50] = {0};
  993. sprintf(t_key, "%s+%d+%d", m_dispatch_control_request_msg.command_key().c_str(), m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  994. tp_catcher_task->m_respons_key = t_key;
  995. //机器手 调整x y b d1 d2, 调整机器手的姿态, 准备把车放置到中跑车上.
  996. tp_catcher_task->m_request_x = m_destination_coordinates.x;
  997. tp_catcher_task->m_request_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (tp_catcher_task->m_request_wheelbase /2);
  998. //存车需要反向, 取车不需要
  999. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  1000. {
  1001. tp_catcher_task->m_request_b = 90;
  1002. }
  1003. else
  1004. {
  1005. tp_catcher_task->m_request_b = 270;
  1006. }
  1007. }