dispatch_process.cpp 130 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097
  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_wheel_base = 0;
  14. }
  15. Dispatch_process::~Dispatch_process()
  16. {
  17. Dispatch_process_uninit();
  18. }
  19. //初始化, 就把主控发送的请求传入即可.
  20. Error_manager Dispatch_process::Dispatch_process_init(message::Dispatch_request_msg &dispatch_request_msg)
  21. {
  22. if ( dispatch_request_msg.base_info().has_timeout_ms() )
  23. {
  24. m_timeout_ms = dispatch_request_msg.base_info().timeout_ms() - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
  25. }
  26. else
  27. {
  28. m_timeout_ms = DISPATCH_PROCESS_TIMEOUT_MS - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
  29. }
  30. m_command_key = dispatch_request_msg.command_key();
  31. m_start_time = std::chrono::system_clock::now();
  32. if ( dispatch_request_msg.dispatch_motion_direction() == message::E_STORE_CAR )
  33. {
  34. m_dispatch_process_type = DISPATCH_PROCESS_STORE;
  35. m_dispatch_source = dispatch_request_msg.terminal_id() + PASSAGEWAY_ID_BASE ;
  36. m_dispatch_destination = dispatch_request_msg.parkspace_info().parkingspace_index_id() + PARKSPACE_ID_BASE;
  37. Common_data::copy_data(m_parkspace_information, dispatch_request_msg.parkspace_info());
  38. Common_data::scaling(m_parkspace_information, 1000);
  39. Common_data::copy_data(m_car_measure_information, dispatch_request_msg.locate_information());
  40. Common_data::scaling(m_car_measure_information, 1000);
  41. m_wheel_base = m_car_measure_information.car_wheel_base;
  42. }
  43. else if( dispatch_request_msg.dispatch_motion_direction() == message::E_PICKUP_CAR )
  44. {
  45. m_dispatch_process_type = DISPATCH_PROCESS_PICKUP;
  46. m_dispatch_source = dispatch_request_msg.parkspace_info().parkingspace_index_id() + PARKSPACE_ID_BASE;
  47. m_dispatch_destination = dispatch_request_msg.terminal_id() + PASSAGEWAY_ID_BASE ;
  48. Common_data::copy_data(m_parkspace_information, dispatch_request_msg.parkspace_info());
  49. Common_data::scaling(m_parkspace_information, 1000);
  50. m_wheel_base = m_parkspace_information.car_information.car_wheel_base;
  51. }
  52. else
  53. {
  54. m_dispatch_process_type = DISPATCH_PROCESS_TYPE_UNKNOW;
  55. return Error_manager(Error_code::PARAMETER_ERROR, Error_level::MINOR_ERROR,
  56. " Dispatch_process::Dispatch_process_init ERROR ");
  57. }
  58. if ( m_wheel_base < 1000 )
  59. {
  60. return Error_manager(Error_code::PARAMETER_ERROR, Error_level::MINOR_ERROR,
  61. " m_wheel_base < 1000 ERROR ");
  62. }
  63. m_dispatch_request_msg = dispatch_request_msg;
  64. m_dispatch_process_status = DISPATCH_PROCESS_CREATED;
  65. return Error_code::SUCCESS;
  66. }
  67. //反初始化
  68. Error_manager Dispatch_process::Dispatch_process_uninit()
  69. {
  70. std::unique_lock<std::mutex> t_lock(m_lock);
  71. for (auto iter = m_dispatch_control_node_map.begin(); iter != m_dispatch_control_node_map.end(); ++iter)
  72. {
  73. if ( iter->second.mp_dispatch_task.get() != NULL )
  74. {
  75. iter->second.mp_dispatch_task->set_task_statu(Task_Base::Task_statu::TASK_WITHDRAW);
  76. iter->second.mp_dispatch_task.reset();
  77. iter->second.mp_dispatch_device.reset();
  78. }
  79. }
  80. return Error_code::SUCCESS;
  81. }
  82. //检查流程是否空闲待机
  83. Error_manager Dispatch_process::check_process_ready()
  84. {
  85. return Error_code::SUCCESS;
  86. if ( m_dispatch_process_status == DISPATCH_PROCESS_READY )
  87. {
  88. return Error_code::SUCCESS;
  89. }
  90. else
  91. {
  92. return Error_manager(Error_code::DISPATCH_PROCESS_IS_NOT_READY, Error_level::MINOR_ERROR,
  93. " Dispatch_process::check_process_ready() fun error ");
  94. }
  95. }
  96. void Dispatch_process::Main()
  97. {
  98. Error_manager t_error;
  99. //主流程, 循环执行
  100. while ( std::chrono::system_clock::now() - m_start_time < std::chrono::milliseconds(m_timeout_ms) )
  101. {
  102. std::this_thread::sleep_for(std::chrono::microseconds(1));
  103. std::this_thread::sleep_for(std::chrono::milliseconds(1));
  104. // std::this_thread::sleep_for(std::chrono::seconds(1));
  105. // std::cout << " huli test :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: " << " m_dispatch_process_status = " << m_dispatch_process_status << std::endl;
  106. switch ( m_dispatch_process_status )
  107. {
  108. case DISPATCH_PROCESS_CREATED://流程创建,
  109. {
  110. //检查调度请求
  111. m_result = check_dispatch_request_msg();
  112. if ( m_result !=Error_code::SUCCESS)
  113. {
  114. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  115. break;
  116. }
  117. //发送调度总计划
  118. m_result = send_dispatch_plan_request_msg();
  119. if ( m_result !=Error_code::SUCCESS)
  120. {
  121. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  122. break;
  123. }
  124. //流程正常, 就进入等待状态, 等待调度控制发送动作指令
  125. m_dispatch_process_status = DISPATCH_PROCESS_READY;
  126. break;
  127. }
  128. case DISPATCH_PROCESS_READY://流程准备,待机
  129. {
  130. //调度控制, 并根据完成情况给答复
  131. dispatch_control_motion();
  132. //等待调度总计划答复
  133. m_result = wait_dispatch_plan_response_msg();
  134. if ( m_result ==Error_code::SUCCESS)
  135. {
  136. //流程正常, 就进入完成状态,
  137. m_dispatch_process_status = DISPATCH_PROCESS_OVER;
  138. break;
  139. }
  140. else if ( m_result !=Error_code::NODATA )
  141. {
  142. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  143. break;
  144. }
  145. //else nodata, 就表示没有新的指令, 那么什么都不做, 原地待命
  146. break;
  147. }
  148. case DISPATCH_PROCESS_OVER://流程完成
  149. {
  150. //发送调度答复, 发给主控的
  151. m_result = send_dispatch_response_msg();
  152. if ( m_result !=Error_code::SUCCESS)
  153. {
  154. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  155. break;
  156. }
  157. //流程正常, 就进入等待状态, 等待调度控制发送动作指令
  158. m_dispatch_process_status = DISPATCH_PROCESS_RELEASE;
  159. break;
  160. }
  161. case DISPATCH_PROCESS_RELEASE://流程释放
  162. {
  163. //通知调度管理, 释放资源,
  164. m_result = release_resource();
  165. if ( m_result !=Error_code::SUCCESS)
  166. {
  167. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  168. break;
  169. }
  170. //在这里, 整个流程彻底结束, 之后线程池会自动回收 这个流程对象的资源
  171. return;
  172. break;
  173. }
  174. case DISPATCH_PROCESS_FAULT://故障
  175. {
  176. release_resource();
  177. Exception_handling();
  178. //在这里, 整个流程彻底结束, 之后线程池会自动回收 这个流程对象的资源
  179. return;
  180. break;
  181. }
  182. default:
  183. {
  184. break;
  185. }
  186. }
  187. }
  188. //任务超时
  189. LOG(INFO) << " Dispatch_process::Main() time out "<< this;
  190. return;
  191. }
  192. //检查调度请求
  193. Error_manager Dispatch_process::check_dispatch_request_msg()
  194. {
  195. std::unique_lock<std::mutex> t_lock(m_lock);
  196. return Error_code::SUCCESS;
  197. }
  198. //发送调度总计划
  199. Error_manager Dispatch_process::send_dispatch_plan_request_msg()
  200. {
  201. std::unique_lock<std::mutex> t_lock(m_lock);
  202. m_dispatch_plan_request_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_plan_request_msg);
  203. m_dispatch_plan_request_msg.mutable_base_info()->set_timeout_ms(m_timeout_ms);
  204. m_dispatch_plan_request_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
  205. m_dispatch_plan_request_msg.mutable_base_info()->set_receiver(message::Communicator::eDispatch_control);
  206. m_dispatch_plan_request_msg.set_command_key(m_dispatch_request_msg.command_key());
  207. m_dispatch_plan_request_msg.set_dispatch_task_type((message::Dispatch_task_type)m_dispatch_process_type);
  208. m_dispatch_plan_request_msg.set_dispatch_source(m_dispatch_source);
  209. m_dispatch_plan_request_msg.set_dispatch_destination(m_dispatch_destination);
  210. //这里不写错误码
  211. std::string t_msg = m_dispatch_plan_request_msg.SerializeAsString();
  212. System_communication::get_instance_references().encapsulate_msg(t_msg);
  213. return Error_code::SUCCESS;
  214. }
  215. //执行调度控制指令, 并根据完成情况给答复
  216. Error_manager Dispatch_process::dispatch_control_motion()
  217. {
  218. Error_manager t_error;
  219. std::unique_lock<std::mutex> t_lock(m_lock);
  220. m_result.error_manager_clear_all();
  221. for (auto iter = m_dispatch_control_node_map.begin(); iter != m_dispatch_control_node_map.end(); ++iter)
  222. {
  223. switch ( iter->second.m_dispatch_control_status )
  224. {
  225. case DISPATCH_CONTROL_STATUS_UNKNOW:
  226. case DISPATCH_CONTROL_CREATED:
  227. case DISPATCH_CONTROL_READY:
  228. {
  229. t_error = wait_dispatch_control_request_msg(iter->first, iter->second);
  230. if ( t_error == Error_code::SUCCESS)
  231. {
  232. //流程正常, 就进入完成状态,
  233. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_CONNECT_DEVICE;
  234. }
  235. //else 原地待命
  236. break;
  237. }
  238. case DISPATCH_CONTROL_CONNECT_DEVICE:
  239. {
  240. //连接调度设备
  241. t_error = connect_dispatch_device(iter->first, iter->second);
  242. if ( t_error !=Error_code::SUCCESS)
  243. {
  244. iter->second.m_error = t_error;
  245. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_RESPONSE;
  246. }
  247. else
  248. {
  249. //流程正常, 就进入工作状态,
  250. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_WORKING;
  251. iter->second.m_time_to_send_control_response = std::chrono::system_clock::now();
  252. }
  253. break;
  254. }
  255. case DISPATCH_CONTROL_WORKING:
  256. {
  257. //执行调度控制指令, 并根据完成情况给答复
  258. t_error = excute_dispatch_control(iter->first, iter->second);
  259. if ( t_error == Error_code::NODATA )
  260. {
  261. //继续 长流程, 什么也不做
  262. if ( std::chrono::system_clock::now() - iter->second.m_time_to_send_control_response >= std::chrono::seconds(1) )
  263. {
  264. //发送调度控制答复, 发给调度控制的
  265. t_error = send_dispatch_control_response_msg(iter->first, iter->second, message::E_TASK_WORKING);
  266. iter->second.m_time_to_send_control_response = std::chrono::system_clock::now();
  267. }
  268. }
  269. else
  270. {
  271. //长流程结束, 就答复 control_response_msg
  272. // 注:这里执行调度控制, 即使报错了 也要答复给调度控制, 交给调度控制来进行决策.
  273. iter->second.m_error = t_error;
  274. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_TASK_WITHDRAW;
  275. }
  276. break;
  277. }
  278. case DISPATCH_CONTROL_TASK_WITHDRAW://流程 收回任务单
  279. {
  280. //发送调度控制答复, 发给调度控制的
  281. t_error = dispatch_control_withdraw_task(iter->first, iter->second);
  282. //流程正常, 就进入等待状态, 等待调度控制发送动作指令
  283. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_RESPONSE;
  284. break;
  285. }
  286. case DISPATCH_CONTROL_RESPONSE://流程 给调度控制答复
  287. {
  288. //发送调度控制答复, 发给调度控制的
  289. t_error = send_dispatch_control_response_msg(iter->first, iter->second, message::E_TASK_OVER);
  290. //流程正常, 就进入等待状态, 等待调度控制发送动作指令
  291. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_DISCONNECT_DEVICE;
  292. break;
  293. }
  294. case DISPATCH_CONTROL_DISCONNECT_DEVICE://流程 解除设备
  295. {
  296. //断开调度设备, 释放任务单 与设备解除连接
  297. t_error = disconnect_dispatch_device(iter->first, iter->second);
  298. if ( t_error == Error_code::SUCCESS )
  299. {
  300. //流程正常, 就回到 等待状态, 等待调度控制发送动作指令
  301. iter->second.m_error.error_manager_clear_all();
  302. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_READY;
  303. }
  304. //else 保持不变继续等待
  305. break;
  306. }
  307. default:
  308. {
  309. break;
  310. }
  311. }
  312. }
  313. return Error_code::SUCCESS;
  314. }
  315. //等待控制指令
  316. Error_manager Dispatch_process::wait_dispatch_control_request_msg(int dispatch_device_type, Dispatch_control_node & dispatch_control_node)
  317. {
  318. //key不相等 就表示 收到了新的控制指令
  319. if ( dispatch_control_node.m_dispatch_control_request_msg.command_key() != dispatch_control_node.m_dispatch_control_response_msg.command_key() )
  320. {
  321. return Error_code::SUCCESS;
  322. }
  323. else
  324. {
  325. return Error_code::NODATA;
  326. }
  327. return Error_code::SUCCESS;
  328. }
  329. //连接调度设备, 创建新的任务单 与设备建立连接
  330. Error_manager Dispatch_process::connect_dispatch_device(int dispatch_device_type, Dispatch_control_node & dispatch_control_node)
  331. {
  332. Error_manager t_error;
  333. if ( dispatch_device_type == message::Dispatch_device_type::ROBOT_1 ||
  334. dispatch_device_type == message::Dispatch_device_type::ROBOT_2 )
  335. {
  336. //找到对应的设备
  337. if ( dispatch_device_type == message::Dispatch_device_type::ROBOT_1 )
  338. {
  339. dispatch_control_node.mp_dispatch_device = Dispatch_manager::get_instance_references().m_catcher_map[0];
  340. }
  341. if ( dispatch_device_type == message::Dispatch_device_type::ROBOT_2 )
  342. {
  343. dispatch_control_node.mp_dispatch_device = Dispatch_manager::get_instance_references().m_catcher_map[1];
  344. }
  345. Catcher* tp_catcher = (Catcher*)dispatch_control_node.mp_dispatch_device.get();
  346. //检查设备状态
  347. if ( tp_catcher->check_status() == Error_code::SUCCESS &&
  348. tp_catcher->m_actual_device_status == Dispatch_device_base::HARDWARE_DEVICE_READY )
  349. {
  350. //创建任务单
  351. dispatch_control_node.mp_dispatch_task = std::shared_ptr<Task_Base>(new Catcher_task);
  352. dispatch_control_node.mp_dispatch_task->task_init(NULL,std::chrono::milliseconds(15000));
  353. Catcher_task * tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  354. //第一次发送 空的唯一码, 可以和设备建立联系
  355. tp_catcher_task->m_request_key = "";
  356. tp_catcher_task->m_request_x = tp_catcher->m_actual_x;
  357. tp_catcher_task->m_request_y = tp_catcher->m_actual_y;
  358. tp_catcher_task->m_request_b = tp_catcher->m_actual_b;
  359. tp_catcher_task->m_request_z = tp_catcher->m_actual_z;
  360. tp_catcher_task->m_request_d1 = tp_catcher->m_actual_d1;
  361. tp_catcher_task->m_request_d2 = tp_catcher->m_actual_d2;
  362. tp_catcher_task->m_request_wheelbase = Dispatch_coordinates::get_instance_references().m_default_wheelbase;
  363. tp_catcher_task->m_request_clamp_motion = (Catcher_task::Clamp_motion)tp_catcher->m_actual_clamp_motion1;
  364. t_error = tp_catcher->execute_task(dispatch_control_node.mp_dispatch_task, Dispatch_device_base::DISPATCH_TASK_ONE_LEVEL);
  365. if ( t_error != Error_code::SUCCESS )
  366. {
  367. dispatch_control_node.m_error = t_error;
  368. return t_error;
  369. }
  370. }
  371. else
  372. {
  373. std::cout << " huli test :::: " << " 123123123123123123123 = " << 1233 << std::endl;
  374. std::cout << " huli test :::: " << " tp_catcher->check_status() = " << tp_catcher->check_status().to_string() << std::endl;
  375. std::cout << " huli test :::: " << " tp_catcher->m_actual_device_status = " << tp_catcher->m_actual_device_status << std::endl;
  376. t_error = Error_manager(Error_code::DISPATCH_PROCESS_DEVICE_STATUS_ERROR, Error_level::MINOR_ERROR,
  377. " tp_catcher->m_actual_device_status device_status error ");
  378. dispatch_control_node.m_error = t_error;
  379. return t_error;
  380. }
  381. //设置起点
  382. dispatch_control_node.m_source_coordinates = Dispatch_coordinates::get_instance_references().m_catcher_coordinates[dispatch_control_node.m_dispatch_control_request_msg.dispatch_source()];
  383. //设置终点
  384. dispatch_control_node.m_destination_coordinates = Dispatch_coordinates::get_instance_references().m_catcher_coordinates[dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination()];
  385. std::cout << " huli test :::: " << " ---------------------------------------- = " << 123 << std::endl;
  386. std::cout << " huli test :::: " << " dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination() = " << dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination() << std::endl;
  387. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.x = " << dispatch_control_node.m_destination_coordinates.x << std::endl;
  388. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.y = " << dispatch_control_node.m_destination_coordinates.y << std::endl;
  389. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.z = " << dispatch_control_node.m_destination_coordinates.z << std::endl;
  390. std::cout << " huli test :::: " << "*******************************************" << 123 << std::endl;
  391. }
  392. //搬运器的配置 准备工作
  393. else if ( dispatch_device_type == message::Dispatch_device_type::CARRIER_1 ||
  394. dispatch_device_type == message::Dispatch_device_type::CARRIER_2 ||
  395. dispatch_device_type == message::Dispatch_device_type::CARRIER_3 )
  396. {
  397. //找到对应的设备
  398. if ( dispatch_device_type == message::Dispatch_device_type::CARRIER_1 )
  399. {
  400. dispatch_control_node.mp_dispatch_device = Dispatch_manager::get_instance_references().m_carrier_map[0];
  401. }
  402. if ( dispatch_device_type == message::Dispatch_device_type::CARRIER_2 )
  403. {
  404. dispatch_control_node.mp_dispatch_device = Dispatch_manager::get_instance_references().m_carrier_map[1];
  405. }
  406. if ( dispatch_device_type == message::Dispatch_device_type::CARRIER_3 )
  407. {
  408. dispatch_control_node.mp_dispatch_device = Dispatch_manager::get_instance_references().m_carrier_map[2];
  409. }
  410. Carrier* tp_carrier = (Carrier*)dispatch_control_node.mp_dispatch_device.get();
  411. //检查设备状态
  412. if ( tp_carrier->check_status() == Error_code::SUCCESS &&
  413. tp_carrier->m_actual_device_status == Dispatch_device_base::HARDWARE_DEVICE_READY )
  414. {
  415. //创建任务单
  416. dispatch_control_node.mp_dispatch_task = std::shared_ptr<Task_Base>(new Carrier_task);
  417. dispatch_control_node.mp_dispatch_task->task_init(NULL,std::chrono::milliseconds(15000));
  418. Carrier_task * tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  419. //第一次发送 空的唯一码, 可以和设备建立联系
  420. tp_carrier_task->m_request_key = "";
  421. tp_carrier_task->m_request_x = tp_carrier->m_actual_x;
  422. tp_carrier_task->m_request_y = tp_carrier->m_actual_y;
  423. tp_carrier_task->m_request_z = tp_carrier->m_actual_z;
  424. tp_carrier_task->m_request_y1 = tp_carrier->m_actual_y1;
  425. tp_carrier_task->m_request_y2 = tp_carrier->m_actual_y2;
  426. tp_carrier_task->m_request_clamp_motion = (Carrier_task::Clamp_motion)tp_carrier->m_actual_clamp_motion1;
  427. tp_carrier_task->m_request_joint_motion_x = (Carrier_task::Joint_motion)tp_carrier->m_actual_joint_motion_x1;
  428. tp_carrier_task->m_request_joint_motion_y = Carrier_task::Joint_motion::E_JOINT_NO_ACTION;
  429. tp_carrier_task->m_request_space_id = 0;
  430. tp_carrier_task->m_request_floor_id = 0;
  431. tp_carrier_task->m_request_wheelbase = Dispatch_coordinates::get_instance_references().m_default_wheelbase;
  432. t_error = tp_carrier->execute_task(dispatch_control_node.mp_dispatch_task, Dispatch_device_base::DISPATCH_TASK_ONE_LEVEL);
  433. if ( t_error != Error_code::SUCCESS )
  434. {
  435. dispatch_control_node.m_error = t_error;
  436. return t_error;
  437. }
  438. }
  439. else
  440. {
  441. std::cout << " huli test :::: " << " 123123123123123123123 = " << 4566 << std::endl;
  442. std::cout << " huli test :::: " << " tp_carrier->check_status() = " << tp_carrier->check_status().to_string() << std::endl;
  443. std::cout << " huli test :::: " << " tp_carrier->m_actual_device_status = " << tp_carrier->m_actual_device_status << std::endl;
  444. t_error = Error_manager(Error_code::DISPATCH_PROCESS_DEVICE_STATUS_ERROR, Error_level::MINOR_ERROR,
  445. " tp_carrier->m_actual_device_status device_status error ");
  446. dispatch_control_node.m_error = t_error;
  447. return t_error;
  448. }
  449. //设置起点
  450. dispatch_control_node.m_source_coordinates = Dispatch_coordinates::get_instance_references().m_carrier_coordinates[dispatch_control_node.m_dispatch_control_request_msg.dispatch_source()];
  451. //设置终点
  452. dispatch_control_node.m_destination_coordinates = Dispatch_coordinates::get_instance_references().m_carrier_coordinates[dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination()];
  453. std::cout << " huli test :::: " << " ---------------------------------------- = " << 123 << std::endl;
  454. std::cout << " huli test :::: " << " dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination() = " << dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination() << std::endl;
  455. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.x = " << dispatch_control_node.m_destination_coordinates.x << std::endl;
  456. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.y = " << dispatch_control_node.m_destination_coordinates.y << std::endl;
  457. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.z = " << dispatch_control_node.m_destination_coordinates.z << std::endl;
  458. std::cout << " huli test :::: " << "*******************************************" << 123 << std::endl;
  459. }
  460. else
  461. {
  462. t_error = Error_manager(Error_code::DISPATCH_PROCESS_DEVICE_TYPE_ERROR, Error_level::MINOR_ERROR,
  463. " DISPATCH_PROCESS_DEVICE_TYPE_ERROR fun error ");
  464. dispatch_control_node.m_error = t_error;
  465. return t_error;
  466. }
  467. return Error_code::SUCCESS;
  468. }
  469. //执行调度控制指令, 并根据完成情况给答复
  470. Error_manager Dispatch_process::excute_dispatch_control(int dispatch_device_type, Dispatch_control_node & dispatch_control_node)
  471. {
  472. Error_manager t_error;
  473. if ( dispatch_device_type == message::Dispatch_device_type::ROBOT_1 ||
  474. dispatch_device_type == message::Dispatch_device_type::ROBOT_2 )
  475. {
  476. Catcher_task * tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  477. // while (1)
  478. // {
  479. // char in;
  480. // std::cin >> in ;
  481. // if ( in == 'p' )
  482. // {
  483. // break;
  484. // }
  485. // }
  486. // std::cout << " huli test :::: " << "ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp = " << tp_catcher_task->m_step << std::endl;
  487. // std::cout << " huli test :::: " << "1111111 tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  488. //设备的动作也使用外部的Main()的线程来循环
  489. switch ( dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type() )
  490. {
  491. case message::Dispatch_task_type::ROBOT_CATCH_CAR_FROM_INLET:
  492. {
  493. t_error = excute_robot_catch_car_from_inlet(dispatch_control_node);
  494. break;
  495. }
  496. case message::Dispatch_task_type::ROBOT_PUT_CAR_TO_CARRIER:
  497. {
  498. t_error = excute_robot_put_car_to_carrier(dispatch_control_node);
  499. break;
  500. }
  501. case message::Dispatch_task_type::ROBOT_CATCH_CAR_FROM_CARRIER:
  502. {
  503. t_error = excute_robot_catch_car_from_carrier(dispatch_control_node);
  504. break;
  505. }
  506. case message::Dispatch_task_type::ROBOT_PUT_CAR_TO_OUTLET:
  507. {
  508. t_error = excute_robot_put_car_to_outlet(dispatch_control_node);
  509. break;
  510. }
  511. case message::Dispatch_task_type::ROBOT_MOVE:
  512. {
  513. t_error = excute_robot_move(dispatch_control_node);
  514. break;
  515. }
  516. default:
  517. {
  518. return Error_manager(Error_code::DISPATCH_PROCESS_TASK_STATUS_ERROR, Error_level::MINOR_ERROR,
  519. "Dispatch_process::excute_dispatch_control() fun error ");
  520. break;
  521. }
  522. }
  523. // std::cout << " huli test :::: " << "222222 tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  524. // std::cout << " huli test :::: " << " t_error_catcher = " << t_error.to_string() << std::endl;
  525. }
  526. else if ( dispatch_device_type == message::Dispatch_device_type::CARRIER_1 ||
  527. dispatch_device_type == message::Dispatch_device_type::CARRIER_2 ||
  528. dispatch_device_type == message::Dispatch_device_type::CARRIER_3 )
  529. {
  530. Catcher_task *tp_carrier_task = (Catcher_task *) dispatch_control_node.mp_dispatch_task.get();
  531. // while (1)
  532. // {
  533. // char in;
  534. // std::cin >> in;
  535. // if (in == 'l')
  536. // {
  537. // break;
  538. // }
  539. // }
  540. // std::cout << " huli test :::: "
  541. // << "lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll = "
  542. // << tp_carrier_task->m_step << std::endl;
  543. // std::cout << " huli test :::: " << "3333333 tp_carrier_task->m_step = " << tp_carrier_task->m_step
  544. // << std::endl;
  545. //设备的动作也使用外部的Main()的线程来循环
  546. switch (dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type())
  547. {
  548. case message::Dispatch_task_type::CARRIER_RECEIVE_CAR_FROM_ROBOT:
  549. {
  550. t_error = excute_carrier_receive_car_from_robot(dispatch_control_node);
  551. break;
  552. }
  553. case message::Dispatch_task_type::CARRIER_STORE_CAR_TO_PARKINGSPACE:
  554. {
  555. t_error = excute_carrier_store_car_to_parkingspace(dispatch_control_node);
  556. break;
  557. }
  558. case message::Dispatch_task_type::CARRIER_STORE_CAR_TO_PARKINGSPACE_EX:
  559. {
  560. t_error = excute_carrier_store_car_to_parkingspace_ex(dispatch_control_node);
  561. break;
  562. }
  563. case message::Dispatch_task_type::CARRIER_PICKUP_CAR_FROM_PARKINGSPACE:
  564. {
  565. t_error = excute_carrier_pickup_car_from_parkingspace(dispatch_control_node);
  566. break;
  567. }
  568. case message::Dispatch_task_type::CARRIER_PICKUP_CAR_FROM_PARKINGSPACE_EX:
  569. {
  570. t_error = excute_carrier_pickup_car_from_parkingspace_ex(dispatch_control_node);
  571. break;
  572. }
  573. case message::Dispatch_task_type::CARRIER_DELIVER_CAR_TO_ROBOT:
  574. {
  575. t_error = excute_carrier_deliver_car_to_robot(dispatch_control_node);
  576. break;
  577. }
  578. case message::Dispatch_task_type::CARRIER_MOVE:
  579. {
  580. t_error = excute_carrier_move(dispatch_control_node);
  581. break;
  582. }
  583. default:
  584. {
  585. return Error_manager(Error_code::DISPATCH_PROCESS_TASK_STATUS_ERROR, Error_level::MINOR_ERROR,
  586. "Dispatch_process::excute_dispatch_control() fun error ");
  587. break;
  588. }
  589. }
  590. // std::cout << " huli test :::: " << "44444444 tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  591. // std::cout << " huli test :::: " << " t_error_carrier = " << t_error.to_string() << std::endl;
  592. }
  593. dispatch_control_node.m_error = t_error;
  594. return t_error;
  595. }
  596. //流程通知设备 收回任务单
  597. Error_manager Dispatch_process::dispatch_control_withdraw_task(int dispatch_device_type, Dispatch_control_node & dispatch_control_node)
  598. {
  599. if ( dispatch_control_node.mp_dispatch_device.get() != NULL && dispatch_control_node.mp_dispatch_task.get() != NULL )
  600. {
  601. dispatch_control_node.mp_dispatch_task->set_task_statu(Task_Base::Task_statu::TASK_WITHDRAW);
  602. }
  603. return Error_code::SUCCESS;
  604. }
  605. //发送调度控制答复, 发给调度控制的
  606. Error_manager Dispatch_process::send_dispatch_control_response_msg(int dispatch_device_type, Dispatch_control_node & dispatch_control_node, message::Dispatch_device_task_status dispatch_device_task_status)
  607. {
  608. dispatch_control_node.m_dispatch_control_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_control_response_msg);
  609. dispatch_control_node.m_dispatch_control_response_msg.mutable_base_info()->set_timeout_ms(dispatch_control_node.m_dispatch_control_request_msg.base_info().timeout_ms());
  610. dispatch_control_node.m_dispatch_control_response_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
  611. dispatch_control_node.m_dispatch_control_response_msg.mutable_base_info()->set_receiver(message::Communicator::eDispatch_control);
  612. dispatch_control_node.m_dispatch_control_response_msg.set_command_key(dispatch_control_node.m_dispatch_control_request_msg.command_key());
  613. dispatch_control_node.m_dispatch_control_response_msg.set_dispatch_task_type(dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type());
  614. dispatch_control_node.m_dispatch_control_response_msg.set_dispatch_device_type(dispatch_control_node.m_dispatch_control_request_msg.dispatch_device_type());
  615. dispatch_control_node.m_dispatch_control_response_msg.set_dispatch_source(dispatch_control_node.m_dispatch_control_request_msg.dispatch_source());
  616. dispatch_control_node.m_dispatch_control_response_msg.set_dispatch_destination(dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination());
  617. dispatch_control_node.m_dispatch_control_response_msg.mutable_error_manager()->set_error_code(dispatch_control_node.m_error.get_error_code());
  618. dispatch_control_node.m_dispatch_control_response_msg.mutable_error_manager()->set_error_level((message::Error_level)dispatch_control_node.m_error.get_error_level());
  619. dispatch_control_node.m_dispatch_control_response_msg.mutable_error_manager()->set_error_description(dispatch_control_node.m_error.get_error_description(), dispatch_control_node.m_error.get_description_length());
  620. dispatch_control_node.m_dispatch_control_response_msg.set_dispatch_device_target_status(dispatch_control_node.m_dispatch_control_request_msg.dispatch_device_target_status());
  621. dispatch_control_node.m_dispatch_control_response_msg.set_dispatch_device_task_status(dispatch_device_task_status);
  622. std::string t_msg = dispatch_control_node.m_dispatch_control_response_msg.SerializeAsString();
  623. System_communication::get_instance_references().encapsulate_msg(t_msg);
  624. if ( dispatch_device_task_status == message::Dispatch_device_task_status::E_TASK_OVER )
  625. {
  626. LOG(INFO) << " dispatch_control_node.m_dispatch_control_response_msg = "<< dispatch_control_node.m_dispatch_control_response_msg.DebugString() << " " << this;
  627. }
  628. return Error_code::SUCCESS;
  629. }
  630. //断开调度设备, 释放任务单 与设备解除连接
  631. Error_manager Dispatch_process::disconnect_dispatch_device(int dispatch_device_type, Dispatch_control_node & dispatch_control_node)
  632. {
  633. if ( dispatch_control_node.mp_dispatch_device.get() != NULL && dispatch_control_node.mp_dispatch_task.get() != NULL )
  634. {
  635. if ( dispatch_control_node.mp_dispatch_task->get_task_statu() == Task_Base::Task_statu::TASK_FREE )
  636. {
  637. dispatch_control_node.mp_dispatch_task.reset();
  638. dispatch_control_node.mp_dispatch_device.reset();
  639. return Error_code::SUCCESS;
  640. }
  641. else
  642. {
  643. return Error_code::NODATA;
  644. }
  645. }
  646. return Error_code::SUCCESS;
  647. }
  648. //等待调度总计划答复
  649. Error_manager Dispatch_process::wait_dispatch_plan_response_msg()
  650. {
  651. std::unique_lock<std::mutex> t_lock(m_lock);
  652. //key 相等 就表示 收到了总计划答复
  653. if ( m_dispatch_plan_request_msg.command_key() == m_dispatch_plan_response_msg.command_key() )
  654. {
  655. return Error_code::SUCCESS;
  656. }
  657. else
  658. {
  659. return Error_code::NODATA;
  660. }
  661. }
  662. //发送调度答复, 发给主控的
  663. Error_manager Dispatch_process::send_dispatch_response_msg()
  664. {
  665. std::unique_lock<std::mutex> t_lock(m_lock);
  666. m_dispatch_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_response_msg);
  667. m_dispatch_response_msg.mutable_base_info()->set_timeout_ms(m_dispatch_request_msg.base_info().timeout_ms());
  668. m_dispatch_response_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
  669. m_dispatch_response_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
  670. m_dispatch_response_msg.set_command_key(m_dispatch_request_msg.command_key());
  671. m_dispatch_response_msg.mutable_error_manager()->CopyFrom(m_dispatch_plan_response_msg.error_manager());
  672. std::string t_msg = m_dispatch_response_msg.SerializeAsString();
  673. System_communication::get_instance_references().encapsulate_msg(t_msg);
  674. return Error_code::SUCCESS;
  675. }
  676. //通知调度管理, 释放资源,
  677. Error_manager Dispatch_process::release_resource()
  678. {
  679. return Dispatch_manager::get_instance_references().release_dispatch_process(m_command_key);
  680. }
  681. //异常处理
  682. Error_manager Dispatch_process::Exception_handling()
  683. {
  684. LOG(INFO) << " -------------Dispatch_process::Exception_handling------------------- "<< this;
  685. LOG(INFO) << " m_result = "<< m_result.to_string() << " " << this;
  686. return Error_code::SUCCESS;
  687. }
  688. //机器手去入口抓车(例如:机器手移动到2号入口上方,然后下降到一楼抓车,最后上升到最上方)
  689. Error_manager Dispatch_process::excute_robot_catch_car_from_inlet(Dispatch_control_node & dispatch_control_node)
  690. {
  691. Error_manager t_error;
  692. Catcher * tp_catcher = NULL;
  693. Catcher_task * tp_catcher_task = NULL;
  694. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  695. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  696. {
  697. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  698. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  699. }
  700. else
  701. {
  702. tp_catcher = (Catcher *)dispatch_control_node.mp_dispatch_device.get();
  703. tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  704. }
  705. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  706. // getchar();
  707. if ( tp_catcher_task->m_step == 0 )
  708. {
  709. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  710. }
  711. if ( tp_catcher_task->m_step == 1 )//检查姿态
  712. {
  713. if ( tp_catcher->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  714. {
  715. if ( tp_catcher->m_actual_clamp_motion1 != Dispatch_device_base::Clamp_motion::E_CLAMP_LOOSE ||
  716. tp_catcher->m_actual_d1 + tp_catcher->m_actual_d2 + tp_dispatch_coordinates->m_catcher_d1_d2_distance >
  717. tp_dispatch_coordinates->m_catcher_wheel_base_limit ||
  718. tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_UNKNOW )
  719. {
  720. catcher_adjust_to_ready(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  721. tp_catcher_task->m_step++;
  722. }
  723. else
  724. {
  725. tp_catcher_task->m_step +=2;
  726. }
  727. }
  728. else
  729. {
  730. return Error_manager(Error_code::CATCHER_POSE_ERROR, Error_level::MINOR_ERROR,
  731. "Dispatch_process::excute_robot_catch_car_from_inlet() fun error ");
  732. }
  733. }
  734. if ( tp_catcher_task->m_step == 2 )
  735. {
  736. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  737. }
  738. if ( tp_catcher_task->m_step == 3 )//机器手z轴移到最高点.
  739. {
  740. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  741. tp_catcher_task->m_step++;
  742. }
  743. if ( tp_catcher_task->m_step == 4 )
  744. {
  745. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  746. }
  747. if ( tp_catcher_task->m_step == 5 )//机器手 调整x y b d1 d2, 根据感测模块的定位信息, 调整机器手的姿态, 准备抓车.
  748. {
  749. catcher_adjust_from_ground(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  750. tp_catcher_task->m_step++;
  751. }
  752. if ( tp_catcher_task->m_step == 6 )
  753. {
  754. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  755. }
  756. if ( tp_catcher_task->m_step == 7 )//机器手z轴移到最低点.
  757. {
  758. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_1th_floor_z);
  759. tp_catcher_task->m_step++;
  760. }
  761. if ( tp_catcher_task->m_step == 8 )
  762. {
  763. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  764. }
  765. if ( tp_catcher_task->m_step == 9 )//修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  766. {
  767. float temp_wheel_base = tp_catcher->m_actual_d1 + tp_catcher->m_actual_d2 + tp_dispatch_coordinates->m_catcher_d1_d2_distance;
  768. //修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  769. if ( Common_data::approximate_difference(m_wheel_base, temp_wheel_base, DISPATCH_DEFAULT_DIFFERENCE) )
  770. {
  771. tp_catcher_task->m_step +=2;
  772. }
  773. else
  774. {
  775. catcher_adjust_wheel_base(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  776. tp_catcher_task->m_step++;
  777. }
  778. }
  779. if ( tp_catcher_task->m_step == 10 )
  780. {
  781. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  782. }
  783. if ( tp_catcher_task->m_step == 11 )//机器手 夹车
  784. {
  785. catcher_move_c(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, Catcher_task::Clamp_motion::E_CLAMP_TIGHT);
  786. tp_catcher_task->m_step++;
  787. }
  788. if ( tp_catcher_task->m_step == 12 )
  789. {
  790. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  791. }
  792. if ( tp_catcher_task->m_step == 13 )//机器手 z轴上升到最高处
  793. {
  794. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  795. tp_catcher_task->m_step++;
  796. }
  797. if ( tp_catcher_task->m_step == 14 )
  798. {
  799. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  800. }
  801. if ( tp_catcher_task->m_step == 15 )//机器手调整到 准备把车放到搬运器的姿态
  802. {
  803. //这里机器手要反向,
  804. catcher_adjust_to_carrier(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, true);
  805. tp_catcher_task->m_step++;
  806. }
  807. if ( tp_catcher_task->m_step == 16 )
  808. {
  809. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  810. }
  811. if ( tp_catcher_task->m_step == 17 )
  812. {
  813. return Error_code::SUCCESS;
  814. }
  815. return Error_code::SUCCESS;
  816. }
  817. //机器手把车放到中跑车上面(例如:机器手下降到中跑车上放车,最后上升到最上方)(通过目标点 指定放到哪一个中跑车上)
  818. Error_manager Dispatch_process::excute_robot_put_car_to_carrier(Dispatch_control_node & dispatch_control_node)
  819. {
  820. Error_manager t_error;
  821. Catcher * tp_catcher = NULL;
  822. Catcher_task * tp_catcher_task = NULL;
  823. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  824. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  825. {
  826. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  827. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  828. }
  829. else
  830. {
  831. tp_catcher = (Catcher *)dispatch_control_node.mp_dispatch_device.get();
  832. tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  833. }
  834. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  835. // getchar();
  836. if ( tp_catcher_task->m_step == 0 )
  837. {
  838. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  839. }
  840. if ( tp_catcher_task->m_step == 1 )//检查姿态
  841. {
  842. if ( tp_catcher->m_actual_load_status == Dispatch_device_base::Load_status::HAVE_CAR &&
  843. tp_catcher->m_actual_clamp_motion1 == Dispatch_device_base::Clamp_motion::E_CLAMP_TIGHT &&
  844. (Common_data::approximate_difference(tp_catcher->m_actual_b, 90, DISPATCH_DEFAULT_DIFFERENCE) || Common_data::approximate_difference(tp_catcher->m_actual_b, 270, DISPATCH_DEFAULT_DIFFERENCE) ) )
  845. {
  846. //检测正常, 直接跳过即可
  847. tp_catcher_task->m_step +=2;
  848. }
  849. else
  850. {
  851. return Error_manager(Error_code::CATCHER_POSE_ERROR, Error_level::MINOR_ERROR,
  852. "Dispatch_process::excute_robot_put_car_to_carrier() fun error ");
  853. }
  854. }
  855. if ( tp_catcher_task->m_step == 2 )
  856. {
  857. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  858. }
  859. if ( tp_catcher_task->m_step == 3 )//机器手 调整z轴
  860. {
  861. if ( tp_catcher->m_actual_z*1.02 >= dispatch_control_node.m_destination_coordinates.z )
  862. {
  863. //检测正常, 直接跳过即可
  864. tp_catcher_task->m_step +=2;
  865. }
  866. else
  867. {
  868. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  869. tp_catcher_task->m_step++;
  870. }
  871. }
  872. if ( tp_catcher_task->m_step == 4 )
  873. {
  874. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  875. }
  876. if ( tp_catcher_task->m_step == 5 )//机器手调整到 准备把车放到搬运器的姿态
  877. {
  878. float temp_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  879. if ( Common_data::approximate_difference(tp_catcher->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) &&
  880. Common_data::approximate_difference(tp_catcher->m_actual_y, temp_y, DISPATCH_DEFAULT_DIFFERENCE))
  881. {
  882. //检测正常, 直接跳过即可
  883. tp_catcher_task->m_step +=2;
  884. }
  885. else
  886. {
  887. catcher_adjust_to_carrier(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, false);
  888. tp_catcher_task->m_step++;
  889. }
  890. }
  891. if ( tp_catcher_task->m_step == 6 )
  892. {
  893. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  894. }
  895. if ( tp_catcher_task->m_step == 7 )//机器手 z轴下降
  896. {
  897. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  898. tp_catcher_task->m_step++;
  899. }
  900. if ( tp_catcher_task->m_step == 8 )
  901. {
  902. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  903. }
  904. if ( tp_catcher_task->m_step == 9 )//机器手 松开夹杆
  905. {
  906. catcher_move_c(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, Catcher_task::Clamp_motion::E_CLAMP_LOOSE);
  907. tp_catcher_task->m_step++;
  908. }
  909. if ( tp_catcher_task->m_step == 10 )
  910. {
  911. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  912. }
  913. if ( tp_catcher_task->m_step == 11 )//机器手 z轴上升
  914. {
  915. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  916. tp_catcher_task->m_step++;
  917. }
  918. if ( tp_catcher_task->m_step == 12 )
  919. {
  920. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  921. }
  922. if ( tp_catcher_task->m_step == 13 )
  923. {
  924. return Error_code::SUCCESS;
  925. }
  926. return Error_code::SUCCESS;
  927. }
  928. //机器手去中跑车上抓车(例如:机器手移动到1号中跑车上方,然后下降到中跑车抓车,最后上升到最上方)
  929. Error_manager Dispatch_process::excute_robot_catch_car_from_carrier(Dispatch_control_node & dispatch_control_node)
  930. {
  931. Error_manager t_error;
  932. Catcher * tp_catcher = NULL;
  933. Catcher_task * tp_catcher_task = NULL;
  934. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  935. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  936. {
  937. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  938. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  939. }
  940. else
  941. {
  942. tp_catcher = (Catcher *)dispatch_control_node.mp_dispatch_device.get();
  943. tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  944. }
  945. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  946. // getchar();
  947. if ( tp_catcher_task->m_step == 0 )
  948. {
  949. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  950. }
  951. if ( tp_catcher_task->m_step == 1 )
  952. {
  953. if ( tp_catcher->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  954. {
  955. if ( tp_catcher->m_actual_clamp_motion1 != Dispatch_device_base::Clamp_motion::E_CLAMP_LOOSE ||
  956. tp_catcher->m_actual_d1 + tp_catcher->m_actual_d2 + tp_dispatch_coordinates->m_catcher_d1_d2_distance >
  957. tp_dispatch_coordinates->m_catcher_wheel_base_limit ||
  958. tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_UNKNOW )
  959. {
  960. catcher_adjust_to_ready(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  961. tp_catcher_task->m_step++;
  962. }
  963. else
  964. {
  965. tp_catcher_task->m_step +=2;
  966. }
  967. }
  968. else
  969. {
  970. return Error_manager(Error_code::CATCHER_POSE_ERROR, Error_level::MINOR_ERROR,
  971. "Dispatch_process::excute_robot_catch_car_from_carrier() fun error ");
  972. }
  973. }
  974. if ( tp_catcher_task->m_step == 2 )
  975. {
  976. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  977. }
  978. if ( tp_catcher_task->m_step == 3 )//机器手 调整z轴
  979. {
  980. if ( tp_catcher->m_actual_z*1.02 >= dispatch_control_node.m_destination_coordinates.z )
  981. {
  982. //检测正常, 直接跳过即可
  983. tp_catcher_task->m_step +=2;
  984. }
  985. else
  986. {
  987. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  988. tp_catcher_task->m_step++;
  989. }
  990. }
  991. if ( tp_catcher_task->m_step == 4 )
  992. {
  993. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  994. }
  995. if ( tp_catcher_task->m_step == 5 )//机器手调整到 准备把车放到搬运器的姿态
  996. {
  997. float temp_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  998. if ( Common_data::approximate_difference(tp_catcher->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) &&
  999. Common_data::approximate_difference(tp_catcher->m_actual_y, temp_y, DISPATCH_DEFAULT_DIFFERENCE))
  1000. {
  1001. //检测正常, 直接跳过即可
  1002. tp_catcher_task->m_step +=2;
  1003. }
  1004. else
  1005. {
  1006. catcher_adjust_from_carrier(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  1007. tp_catcher_task->m_step++;
  1008. }
  1009. }
  1010. if ( tp_catcher_task->m_step == 6 )
  1011. {
  1012. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1013. }
  1014. if ( tp_catcher_task->m_step == 7 )//机器手 z轴下降
  1015. {
  1016. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  1017. tp_catcher_task->m_step++;
  1018. }
  1019. if ( tp_catcher_task->m_step == 8 )
  1020. {
  1021. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1022. }
  1023. if ( tp_catcher_task->m_step == 9 )//修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  1024. {
  1025. float temp_wheel_base = tp_catcher->m_actual_d1 + tp_catcher->m_actual_d2 + tp_dispatch_coordinates->m_catcher_d1_d2_distance;
  1026. //修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  1027. if ( Common_data::approximate_difference(m_wheel_base, temp_wheel_base, DISPATCH_DEFAULT_DIFFERENCE) )
  1028. {
  1029. tp_catcher_task->m_step +=2;
  1030. }
  1031. else
  1032. {
  1033. catcher_adjust_wheel_base(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  1034. tp_catcher_task->m_step++;
  1035. }
  1036. }
  1037. if ( tp_catcher_task->m_step == 10 )
  1038. {
  1039. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1040. }
  1041. if ( tp_catcher_task->m_step == 11 )//机器手 夹车
  1042. {
  1043. catcher_move_c(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, Catcher_task::Clamp_motion::E_CLAMP_TIGHT);
  1044. tp_catcher_task->m_step++;
  1045. }
  1046. if ( tp_catcher_task->m_step == 12 )
  1047. {
  1048. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1049. }
  1050. if ( tp_catcher_task->m_step == 13 )//机器手 z轴上升
  1051. {
  1052. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  1053. tp_catcher_task->m_step++;
  1054. }
  1055. if ( tp_catcher_task->m_step == 14 )
  1056. {
  1057. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1058. }
  1059. if ( tp_catcher_task->m_step == 15 )
  1060. {
  1061. return Error_code::SUCCESS;
  1062. }
  1063. return Error_code::SUCCESS;
  1064. }
  1065. //机器手去出口放车(例如:机器手移动到3号出口上方,然后下降到一楼放车,最后上升到最上方)
  1066. Error_manager Dispatch_process::excute_robot_put_car_to_outlet(Dispatch_control_node & dispatch_control_node)
  1067. {
  1068. Error_manager t_error;
  1069. Catcher * tp_catcher = NULL;
  1070. Catcher_task * tp_catcher_task = NULL;
  1071. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  1072. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  1073. {
  1074. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1075. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  1076. }
  1077. else
  1078. {
  1079. tp_catcher = (Catcher *)dispatch_control_node.mp_dispatch_device.get();
  1080. tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  1081. }
  1082. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  1083. // getchar();
  1084. if ( tp_catcher_task->m_step == 0 )
  1085. {
  1086. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1087. }
  1088. if ( tp_catcher_task->m_step == 1 )//检查姿态
  1089. {
  1090. if ( tp_catcher->m_actual_load_status == Dispatch_device_base::Load_status::HAVE_CAR &&
  1091. tp_catcher->m_actual_clamp_motion1 == Dispatch_device_base::Clamp_motion::E_CLAMP_TIGHT &&
  1092. (Common_data::approximate_difference(tp_catcher->m_actual_b, 90, DISPATCH_DEFAULT_DIFFERENCE) || Common_data::approximate_difference(tp_catcher->m_actual_b, 270, DISPATCH_DEFAULT_DIFFERENCE) ) )
  1093. {
  1094. //检测正常, 直接跳过即可
  1095. tp_catcher_task->m_step +=2;
  1096. }
  1097. else
  1098. {
  1099. return Error_manager(Error_code::CATCHER_POSE_ERROR, Error_level::MINOR_ERROR,
  1100. "Dispatch_process::excute_robot_put_car_to_carrier() fun error ");
  1101. }
  1102. }
  1103. if ( tp_catcher_task->m_step == 2 )
  1104. {
  1105. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1106. }
  1107. if ( tp_catcher_task->m_step == 3 )//机器手 调整z轴
  1108. {
  1109. if ( tp_catcher->m_actual_z*1.02 >= dispatch_control_node.m_destination_coordinates.z )
  1110. {
  1111. //检测正常, 直接跳过即可
  1112. tp_catcher_task->m_step +=2;
  1113. }
  1114. else
  1115. {
  1116. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  1117. tp_catcher_task->m_step++;
  1118. }
  1119. }
  1120. if ( tp_catcher_task->m_step == 4 )
  1121. {
  1122. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1123. }
  1124. if ( tp_catcher_task->m_step == 5 )//机器手调整到 准备把车放到搬运器的姿态
  1125. {
  1126. float temp_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  1127. if ( Common_data::approximate_difference(tp_catcher->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) &&
  1128. Common_data::approximate_difference(tp_catcher->m_actual_y, temp_y, DISPATCH_DEFAULT_DIFFERENCE))
  1129. {
  1130. //检测正常, 直接跳过即可
  1131. tp_catcher_task->m_step +=2;
  1132. }
  1133. else
  1134. {
  1135. catcher_adjust_to_ground(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  1136. tp_catcher_task->m_step++;
  1137. }
  1138. }
  1139. if ( tp_catcher_task->m_step == 6 )
  1140. {
  1141. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1142. }
  1143. if ( tp_catcher_task->m_step == 7 )//机器手 z轴下降
  1144. {
  1145. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  1146. tp_catcher_task->m_step++;
  1147. }
  1148. if ( tp_catcher_task->m_step == 8 )
  1149. {
  1150. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1151. }
  1152. if ( tp_catcher_task->m_step == 9 )//机器手 松开夹杆
  1153. {
  1154. catcher_move_c(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, Catcher_task::Clamp_motion::E_CLAMP_LOOSE);
  1155. tp_catcher_task->m_step++;
  1156. }
  1157. if ( tp_catcher_task->m_step == 10 )
  1158. {
  1159. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1160. }
  1161. if ( tp_catcher_task->m_step == 11 )//机器手 z轴上升
  1162. {
  1163. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  1164. tp_catcher_task->m_step++;
  1165. }
  1166. if ( tp_catcher_task->m_step == 12 )
  1167. {
  1168. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1169. }
  1170. if ( tp_catcher_task->m_step == 13 )
  1171. {
  1172. return Error_code::SUCCESS;
  1173. }
  1174. return Error_code::SUCCESS;
  1175. }
  1176. //机器手的自由移动(例如:机器手移动到6号出入口的上方4楼处,给其他设备避让)(不进行抓车和放车的操作)
  1177. Error_manager Dispatch_process::excute_robot_move(Dispatch_control_node & dispatch_control_node)
  1178. {
  1179. Error_manager t_error;
  1180. Catcher * tp_catcher = NULL;
  1181. Catcher_task * tp_catcher_task = NULL;
  1182. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  1183. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  1184. {
  1185. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1186. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  1187. }
  1188. else
  1189. {
  1190. tp_catcher = (Catcher *)dispatch_control_node.mp_dispatch_device.get();
  1191. tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  1192. }
  1193. if ( tp_catcher_task->m_step == 0 )
  1194. {
  1195. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1196. }
  1197. if ( tp_catcher_task->m_step == 1 )//检查姿态
  1198. {
  1199. if ( tp_catcher->m_actual_d1 + tp_catcher->m_actual_d2 + tp_dispatch_coordinates->m_catcher_d1_d2_distance >
  1200. tp_dispatch_coordinates->m_catcher_wheel_base_limit ||
  1201. tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_UNKNOW )
  1202. {
  1203. catcher_adjust_to_ready(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  1204. tp_catcher_task->m_step++;
  1205. }
  1206. else
  1207. {
  1208. tp_catcher_task->m_step +=2;
  1209. }
  1210. }
  1211. if ( tp_catcher_task->m_step == 2 )
  1212. {
  1213. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1214. }
  1215. if ( tp_catcher_task->m_step == 3 )//机器手 调整z轴
  1216. {
  1217. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  1218. tp_catcher_task->m_step++;
  1219. }
  1220. if ( tp_catcher_task->m_step == 4 )
  1221. {
  1222. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1223. }
  1224. if ( tp_catcher_task->m_step == 5 )//机器手调整到 准备把车放到搬运器的姿态
  1225. {
  1226. catcher_adjust_to_ground(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  1227. tp_catcher_task->m_step++;
  1228. }
  1229. if ( tp_catcher_task->m_step == 6 )
  1230. {
  1231. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1232. }
  1233. if ( tp_catcher_task->m_step == 7 )
  1234. {
  1235. return Error_code::SUCCESS;
  1236. }
  1237. return Error_code::SUCCESS;
  1238. }
  1239. //搬运器从机器手上接车(例如:搬运器移动到2号入口的上方,然后等待机器手把车放到中跑车上,小跑车保持松夹杆状态)
  1240. Error_manager Dispatch_process::excute_carrier_receive_car_from_robot(Dispatch_control_node & dispatch_control_node)
  1241. {
  1242. Error_manager t_error;
  1243. Carrier * tp_carrier = NULL;
  1244. Carrier_task * tp_carrier_task = NULL;
  1245. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  1246. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  1247. {
  1248. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1249. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  1250. }
  1251. else
  1252. {
  1253. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  1254. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  1255. }
  1256. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_carrier_task->m_step << std::endl;
  1257. // getchar();
  1258. if ( tp_carrier_task->m_step == 0 )
  1259. {
  1260. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1261. }
  1262. if ( tp_carrier_task->m_step == 1 )//检查姿态
  1263. {
  1264. //检查姿态
  1265. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  1266. {
  1267. if ( tp_carrier_task->m_request_clamp_motion == Carrier_task::Clamp_motion::E_CLAMP_LOOSE &&
  1268. Common_data::approximate_difference(m_wheel_base, tp_carrier->m_actual_y1-tp_carrier->m_actual_y2, DISPATCH_DEFAULT_DIFFERENCE))
  1269. {
  1270. tp_carrier_task->m_step +=2;
  1271. }
  1272. else
  1273. {
  1274. carrier_adjust_to_ready(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates);
  1275. tp_carrier_task->m_step++;
  1276. }
  1277. }
  1278. else
  1279. {
  1280. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  1281. "tp_carrier->m_actual_load_status != Dispatch_device_base::Load_status::NO_CAR fun error ");
  1282. }
  1283. }
  1284. if ( tp_carrier_task->m_step == 2 )
  1285. {
  1286. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1287. }
  1288. if ( tp_carrier_task->m_step == 3 )//让小跑车回到中跑车上
  1289. {
  1290. if ( Common_data::approximate_difference(tp_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, DISPATCH_DEFAULT_DIFFERENCE) )
  1291. {
  1292. tp_carrier_task->m_step +=2;
  1293. }
  1294. else
  1295. {
  1296. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  1297. tp_carrier_task->m_step++;
  1298. }
  1299. }
  1300. if ( tp_carrier_task->m_step == 4 )
  1301. {
  1302. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1303. }
  1304. if ( tp_carrier_task->m_step == 5 )//让中跑车回到电梯井
  1305. {
  1306. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1307. {
  1308. tp_carrier_task->m_step +=2;
  1309. }
  1310. else
  1311. {
  1312. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  1313. {
  1314. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  1315. tp_carrier_task->m_step++;
  1316. }
  1317. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  1318. {
  1319. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  1320. tp_carrier_task->m_step++;
  1321. }
  1322. else
  1323. {
  1324. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  1325. " m_destination_coordinates.z PARAMRTER ERROR ");
  1326. }
  1327. }
  1328. }
  1329. if ( tp_carrier_task->m_step == 6 )
  1330. {
  1331. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1332. }
  1333. if ( tp_carrier_task->m_step == 7 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  1334. {
  1335. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1336. {
  1337. tp_carrier_task->m_step +=2;
  1338. }
  1339. else
  1340. {
  1341. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  1342. tp_carrier_task->m_step++;
  1343. }
  1344. }
  1345. if ( tp_carrier_task->m_step == 8 )
  1346. {
  1347. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1348. }
  1349. if ( tp_carrier_task->m_step == 9 )//电梯移动到对应的楼层
  1350. {
  1351. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1352. {
  1353. tp_carrier_task->m_step +=2;
  1354. }
  1355. else
  1356. {
  1357. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  1358. tp_carrier_task->m_step++;
  1359. }
  1360. }
  1361. if ( tp_carrier_task->m_step == 10 )
  1362. {
  1363. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1364. }
  1365. if ( tp_carrier_task->m_step == 11 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  1366. {
  1367. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK )
  1368. {
  1369. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  1370. tp_carrier_task->m_step++;
  1371. }
  1372. else
  1373. {
  1374. tp_carrier_task->m_step +=2;
  1375. }
  1376. }
  1377. if ( tp_carrier_task->m_step == 12 )
  1378. {
  1379. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1380. }
  1381. if ( tp_carrier_task->m_step == 13 )//中跑车 x轴移动
  1382. {
  1383. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  1384. {
  1385. tp_carrier_task->m_step +=2;
  1386. }
  1387. else
  1388. {
  1389. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  1390. tp_carrier_task->m_step++;
  1391. }
  1392. }
  1393. if ( tp_carrier_task->m_step == 14 )
  1394. {
  1395. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1396. }
  1397. if ( tp_carrier_task->m_step == 15 )
  1398. {
  1399. return Error_code::SUCCESS;
  1400. }
  1401. return Error_code::SUCCESS;
  1402. }
  1403. //搬运器把车存到停车位上(例如:小跑车夹车后,搬运器移动到56号停车位,然后小跑车将车存入车位,之后搬运器退回至电梯井)
  1404. Error_manager Dispatch_process::excute_carrier_store_car_to_parkingspace(Dispatch_control_node & dispatch_control_node)
  1405. {
  1406. Error_manager t_error;
  1407. Carrier * tp_carrier = NULL;
  1408. Carrier_task * tp_carrier_task = NULL;
  1409. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  1410. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  1411. {
  1412. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1413. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  1414. }
  1415. else
  1416. {
  1417. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  1418. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  1419. }
  1420. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_carrier_task->m_step << std::endl;
  1421. // getchar();
  1422. if ( tp_carrier_task->m_step == 0 )
  1423. {
  1424. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1425. }
  1426. if ( tp_carrier_task->m_step == 1 )//检查姿态
  1427. {
  1428. //检查姿态(注注注注注意了, 调试阶段是无车, 真实环境是有车的)
  1429. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR &&
  1430. tp_carrier->m_actual_clamp_motion1 == Dispatch_device_base::Clamp_motion::E_CLAMP_LOOSE)
  1431. {
  1432. //检测正常, 直接跳过即可
  1433. tp_carrier_task->m_step +=2;
  1434. }
  1435. else
  1436. {
  1437. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  1438. "Dispatch_process::excute_carrier_store_car_to_parkingspace() fun error ");
  1439. }
  1440. }
  1441. if ( tp_carrier_task->m_step == 2 )
  1442. {
  1443. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1444. }
  1445. if ( tp_carrier_task->m_step == 3 )//修正轴距
  1446. {
  1447. float temp_wheel_base = tp_carrier->m_actual_y1 - tp_carrier->m_actual_y2;
  1448. if ( Common_data::approximate_difference(m_wheel_base, temp_wheel_base, DISPATCH_DEFAULT_DIFFERENCE) )
  1449. {
  1450. tp_carrier_task->m_step +=2;
  1451. }
  1452. else
  1453. {
  1454. carrier_adjust_wheel_base(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates);
  1455. tp_carrier_task->m_step++;
  1456. }
  1457. }
  1458. if ( tp_carrier_task->m_step == 4 )
  1459. {
  1460. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1461. }
  1462. if ( tp_carrier_task->m_step == 5 )//让小跑车 夹车
  1463. {
  1464. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_TIGHT);
  1465. tp_carrier_task->m_step++;
  1466. }
  1467. if ( tp_carrier_task->m_step == 6 )
  1468. {
  1469. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1470. }
  1471. if ( tp_carrier_task->m_step == 7 )//让中跑车回到电梯井
  1472. {
  1473. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1474. {
  1475. tp_carrier_task->m_step +=2;
  1476. }
  1477. else
  1478. {
  1479. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  1480. {
  1481. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  1482. tp_carrier_task->m_step++;
  1483. }
  1484. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  1485. {
  1486. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  1487. tp_carrier_task->m_step++;
  1488. }
  1489. else
  1490. {
  1491. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  1492. " m_destination_coordinates.z PARAMRTER ERROR ");
  1493. }
  1494. }
  1495. }
  1496. if ( tp_carrier_task->m_step == 8 )
  1497. {
  1498. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1499. }
  1500. if ( tp_carrier_task->m_step == 9 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  1501. {
  1502. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1503. {
  1504. tp_carrier_task->m_step +=2;
  1505. }
  1506. else
  1507. {
  1508. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  1509. tp_carrier_task->m_step++;
  1510. }
  1511. }
  1512. if ( tp_carrier_task->m_step == 10 )
  1513. {
  1514. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1515. }
  1516. if ( tp_carrier_task->m_step == 11 )//电梯移动到对应的楼层
  1517. {
  1518. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1519. {
  1520. tp_carrier_task->m_step +=2;
  1521. }
  1522. else
  1523. {
  1524. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  1525. tp_carrier_task->m_step++;
  1526. }
  1527. }
  1528. if ( tp_carrier_task->m_step == 12 )
  1529. {
  1530. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1531. }
  1532. if ( tp_carrier_task->m_step == 13 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  1533. {
  1534. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK )
  1535. {
  1536. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  1537. tp_carrier_task->m_step++;
  1538. }
  1539. else
  1540. {
  1541. tp_carrier_task->m_step +=2;
  1542. }
  1543. }
  1544. if ( tp_carrier_task->m_step == 14 )
  1545. {
  1546. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1547. }
  1548. if ( tp_carrier_task->m_step == 15 )//中跑车 x轴移动
  1549. {
  1550. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  1551. {
  1552. tp_carrier_task->m_step +=2;
  1553. }
  1554. else
  1555. {
  1556. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  1557. tp_carrier_task->m_step++;
  1558. }
  1559. }
  1560. if ( tp_carrier_task->m_step == 16 )
  1561. {
  1562. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1563. }
  1564. if ( tp_carrier_task->m_step == 17 )//小跑车 进入车位
  1565. {
  1566. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_leave);
  1567. tp_carrier_task->m_step++;
  1568. }
  1569. if ( tp_carrier_task->m_step == 18 )
  1570. {
  1571. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1572. }
  1573. if ( tp_carrier_task->m_step == 19 )//小跑车 松开夹杆
  1574. {
  1575. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_LOOSE);
  1576. tp_carrier_task->m_step++;
  1577. }
  1578. if ( tp_carrier_task->m_step == 20 )
  1579. {
  1580. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1581. }
  1582. if ( tp_carrier_task->m_step == 21 )//小跑车 回到中跑车
  1583. {
  1584. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  1585. tp_carrier_task->m_step++;
  1586. }
  1587. if ( tp_carrier_task->m_step == 22 )
  1588. {
  1589. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1590. }
  1591. if ( tp_carrier_task->m_step == 23 )//让中跑车回到电梯井
  1592. {
  1593. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  1594. {
  1595. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  1596. tp_carrier_task->m_step++;
  1597. }
  1598. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  1599. {
  1600. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  1601. tp_carrier_task->m_step++;
  1602. }
  1603. else
  1604. {
  1605. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  1606. " m_destination_coordinates.z PARAMRTER ERROR ");
  1607. }
  1608. }
  1609. if ( tp_carrier_task->m_step == 24 )
  1610. {
  1611. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1612. }
  1613. if ( tp_carrier_task->m_step == 25 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  1614. {
  1615. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  1616. tp_carrier_task->m_step++;
  1617. }
  1618. if ( tp_carrier_task->m_step == 26 )
  1619. {
  1620. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1621. }
  1622. if ( tp_carrier_task->m_step == 27 )
  1623. {
  1624. return Error_code::SUCCESS;
  1625. }
  1626. return Error_code::SUCCESS;
  1627. }
  1628. //搬运器把车存到停车位上(例如:小跑车夹车后,搬运器移动到56号停车位,然后小跑车将车存入车位,之后搬运器退回至56车位外面即可)
  1629. Error_manager Dispatch_process::excute_carrier_store_car_to_parkingspace_ex(Dispatch_control_node & dispatch_control_node)
  1630. {
  1631. Error_manager t_error;
  1632. Carrier * tp_carrier = NULL;
  1633. Carrier_task * tp_carrier_task = NULL;
  1634. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  1635. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  1636. {
  1637. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1638. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  1639. }
  1640. else
  1641. {
  1642. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  1643. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  1644. }
  1645. // std::cout << " huli test :::: " << " tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  1646. // getchar();
  1647. if ( tp_carrier_task->m_step == 0 )
  1648. {
  1649. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1650. }
  1651. if ( tp_carrier_task->m_step == 1 )//检查姿态
  1652. {
  1653. //检查姿态(注注注注注意了, 调试阶段是无车, 真实环境是有车的)
  1654. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR &&
  1655. tp_carrier->m_actual_clamp_motion1 == Dispatch_device_base::Clamp_motion::E_CLAMP_LOOSE)
  1656. {
  1657. //检测正常, 直接跳过即可
  1658. tp_carrier_task->m_step +=2;
  1659. }
  1660. else
  1661. {
  1662. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  1663. "Dispatch_process::excute_carrier_store_car_to_parkingspace() fun error ");
  1664. }
  1665. }
  1666. if ( tp_carrier_task->m_step == 2 )
  1667. {
  1668. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1669. }
  1670. if ( tp_carrier_task->m_step == 3 )//修正轴距
  1671. {
  1672. float temp_wheel_base = tp_carrier->m_actual_y1 - tp_carrier->m_actual_y2;
  1673. if ( Common_data::approximate_difference(m_wheel_base, temp_wheel_base, DISPATCH_DEFAULT_DIFFERENCE) )
  1674. {
  1675. tp_carrier_task->m_step +=2;
  1676. }
  1677. else
  1678. {
  1679. carrier_adjust_wheel_base(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates);
  1680. tp_carrier_task->m_step++;
  1681. }
  1682. }
  1683. if ( tp_carrier_task->m_step == 4 )
  1684. {
  1685. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1686. }
  1687. if ( tp_carrier_task->m_step == 5 )//让小跑车 夹车
  1688. {
  1689. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_TIGHT);
  1690. tp_carrier_task->m_step++;
  1691. }
  1692. if ( tp_carrier_task->m_step == 6 )
  1693. {
  1694. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1695. }
  1696. if ( tp_carrier_task->m_step == 7 )//让中跑车回到电梯井
  1697. {
  1698. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1699. {
  1700. tp_carrier_task->m_step +=2;
  1701. }
  1702. else
  1703. {
  1704. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  1705. {
  1706. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  1707. tp_carrier_task->m_step++;
  1708. }
  1709. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  1710. {
  1711. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  1712. tp_carrier_task->m_step++;
  1713. }
  1714. else
  1715. {
  1716. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  1717. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  1718. }
  1719. }
  1720. }
  1721. if ( tp_carrier_task->m_step == 8 )
  1722. {
  1723. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1724. }
  1725. if ( tp_carrier_task->m_step == 9 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  1726. {
  1727. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1728. {
  1729. tp_carrier_task->m_step +=2;
  1730. }
  1731. else
  1732. {
  1733. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  1734. tp_carrier_task->m_step++;
  1735. }
  1736. }
  1737. if ( tp_carrier_task->m_step == 10 )
  1738. {
  1739. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1740. }
  1741. if ( tp_carrier_task->m_step == 11 )//电梯移动到对应的楼层
  1742. {
  1743. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1744. {
  1745. tp_carrier_task->m_step +=2;
  1746. }
  1747. else
  1748. {
  1749. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  1750. tp_carrier_task->m_step++;
  1751. }
  1752. }
  1753. if ( tp_carrier_task->m_step == 12 )
  1754. {
  1755. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1756. }
  1757. if ( tp_carrier_task->m_step == 13 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  1758. {
  1759. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK )
  1760. {
  1761. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  1762. tp_carrier_task->m_step++;
  1763. }
  1764. else
  1765. {
  1766. tp_carrier_task->m_step +=2;
  1767. }
  1768. }
  1769. if ( tp_carrier_task->m_step == 14 )
  1770. {
  1771. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1772. }
  1773. if ( tp_carrier_task->m_step == 15 )//中跑车 x轴移动
  1774. {
  1775. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  1776. {
  1777. tp_carrier_task->m_step +=2;
  1778. }
  1779. else
  1780. {
  1781. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  1782. tp_carrier_task->m_step++;
  1783. }
  1784. }
  1785. if ( tp_carrier_task->m_step == 16 )
  1786. {
  1787. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1788. }
  1789. if ( tp_carrier_task->m_step == 17 )//小跑车 进入车位
  1790. {
  1791. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_leave);
  1792. tp_carrier_task->m_step++;
  1793. }
  1794. if ( tp_carrier_task->m_step == 18 )
  1795. {
  1796. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1797. }
  1798. if ( tp_carrier_task->m_step == 19 )//小跑车 松开夹杆
  1799. {
  1800. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_LOOSE);
  1801. tp_carrier_task->m_step++;
  1802. }
  1803. if ( tp_carrier_task->m_step == 20 )
  1804. {
  1805. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1806. }
  1807. if ( tp_carrier_task->m_step == 21 )//小跑车 回到中跑车
  1808. {
  1809. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  1810. tp_carrier_task->m_step++;
  1811. }
  1812. if ( tp_carrier_task->m_step == 22 )
  1813. {
  1814. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1815. }
  1816. if ( tp_carrier_task->m_step == 23 )
  1817. {
  1818. return Error_code::SUCCESS;
  1819. }
  1820. return Error_code::SUCCESS;
  1821. }
  1822. //搬运器从停车位上取车(例如:搬运器移动到56号停车位,然后小跑车将车从车位取出,之后搬运器退回至电梯井)
  1823. Error_manager Dispatch_process::excute_carrier_pickup_car_from_parkingspace(Dispatch_control_node & dispatch_control_node)
  1824. {
  1825. Error_manager t_error;
  1826. Carrier * tp_carrier = NULL;
  1827. Carrier_task * tp_carrier_task = NULL;
  1828. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  1829. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  1830. {
  1831. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1832. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  1833. }
  1834. else
  1835. {
  1836. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  1837. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  1838. }
  1839. // std::cout << " huli test :::: " << " tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  1840. // getchar();
  1841. if ( tp_carrier_task->m_step == 0 )
  1842. {
  1843. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1844. }
  1845. if ( tp_carrier_task->m_step == 1 )//检查姿态
  1846. {
  1847. //检查姿态
  1848. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  1849. {
  1850. if ( tp_carrier_task->m_request_clamp_motion == Carrier_task::Clamp_motion::E_CLAMP_LOOSE &&
  1851. Common_data::approximate_difference(m_wheel_base, tp_carrier->m_actual_y1-tp_carrier->m_actual_y2, DISPATCH_DEFAULT_DIFFERENCE))
  1852. {
  1853. tp_carrier_task->m_step +=2;
  1854. }
  1855. else
  1856. {
  1857. carrier_adjust_to_ready(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates);
  1858. tp_carrier_task->m_step++;
  1859. }
  1860. }
  1861. else
  1862. {
  1863. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  1864. "tp_carrier->m_actual_load_status != Dispatch_device_base::Load_status::NO_CAR fun error ");
  1865. }
  1866. }
  1867. if ( tp_carrier_task->m_step == 2 )
  1868. {
  1869. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1870. }
  1871. if ( tp_carrier_task->m_step == 3 )//让小跑车回到中跑车上
  1872. {
  1873. if ( Common_data::approximate_difference(tp_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, DISPATCH_DEFAULT_DIFFERENCE) )
  1874. {
  1875. tp_carrier_task->m_step +=2;
  1876. }
  1877. else
  1878. {
  1879. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  1880. tp_carrier_task->m_step++;
  1881. }
  1882. }
  1883. if ( tp_carrier_task->m_step == 4 )
  1884. {
  1885. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1886. }
  1887. if ( tp_carrier_task->m_step == 5 )//让中跑车回到电梯井
  1888. {
  1889. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1890. {
  1891. tp_carrier_task->m_step +=2;
  1892. }
  1893. else
  1894. {
  1895. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  1896. {
  1897. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  1898. tp_carrier_task->m_step++;
  1899. }
  1900. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  1901. {
  1902. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  1903. tp_carrier_task->m_step++;
  1904. }
  1905. else
  1906. {
  1907. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  1908. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  1909. }
  1910. }
  1911. }
  1912. if ( tp_carrier_task->m_step == 6 )
  1913. {
  1914. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1915. }
  1916. if ( tp_carrier_task->m_step == 7 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  1917. {
  1918. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1919. {
  1920. tp_carrier_task->m_step +=2;
  1921. }
  1922. else
  1923. {
  1924. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  1925. tp_carrier_task->m_step++;
  1926. }
  1927. }
  1928. if ( tp_carrier_task->m_step == 8 )
  1929. {
  1930. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1931. }
  1932. if ( tp_carrier_task->m_step == 9 )//电梯移动到对应的楼层
  1933. {
  1934. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  1935. {
  1936. tp_carrier_task->m_step +=2;
  1937. }
  1938. else
  1939. {
  1940. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  1941. tp_carrier_task->m_step++;
  1942. }
  1943. }
  1944. if ( tp_carrier_task->m_step == 10 )
  1945. {
  1946. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1947. }
  1948. if ( tp_carrier_task->m_step == 11 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  1949. {
  1950. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK )
  1951. {
  1952. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  1953. tp_carrier_task->m_step++;
  1954. }
  1955. else
  1956. {
  1957. tp_carrier_task->m_step +=2;
  1958. }
  1959. }
  1960. if ( tp_carrier_task->m_step == 12 )
  1961. {
  1962. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1963. }
  1964. if ( tp_carrier_task->m_step == 13 )//中跑车 x轴移动
  1965. {
  1966. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  1967. {
  1968. tp_carrier_task->m_step +=2;
  1969. }
  1970. else
  1971. {
  1972. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  1973. tp_carrier_task->m_step++;
  1974. }
  1975. }
  1976. if ( tp_carrier_task->m_step == 14 )
  1977. {
  1978. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1979. }
  1980. if ( tp_carrier_task->m_step == 15 )//小跑车 进入车位
  1981. {
  1982. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_leave);
  1983. tp_carrier_task->m_step++;
  1984. }
  1985. if ( tp_carrier_task->m_step == 16 )
  1986. {
  1987. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1988. }
  1989. if ( tp_carrier_task->m_step == 17 )//小跑车 夹车
  1990. {
  1991. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_TIGHT);
  1992. tp_carrier_task->m_step++;
  1993. }
  1994. if ( tp_carrier_task->m_step == 18 )
  1995. {
  1996. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  1997. }
  1998. if ( tp_carrier_task->m_step == 19 )//小跑车 回到中跑车
  1999. {
  2000. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  2001. tp_carrier_task->m_step++;
  2002. }
  2003. if ( tp_carrier_task->m_step == 20 )
  2004. {
  2005. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2006. }
  2007. if ( tp_carrier_task->m_step == 21 )//让中跑车回到电梯井
  2008. {
  2009. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  2010. {
  2011. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  2012. tp_carrier_task->m_step++;
  2013. }
  2014. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  2015. {
  2016. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  2017. tp_carrier_task->m_step++;
  2018. }
  2019. else
  2020. {
  2021. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  2022. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  2023. }
  2024. }
  2025. if ( tp_carrier_task->m_step == 22 )
  2026. {
  2027. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2028. }
  2029. if ( tp_carrier_task->m_step == 23 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  2030. {
  2031. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  2032. tp_carrier_task->m_step++;
  2033. }
  2034. if ( tp_carrier_task->m_step == 24 )
  2035. {
  2036. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2037. }
  2038. if ( tp_carrier_task->m_step == 25 )
  2039. {
  2040. return Error_code::SUCCESS;
  2041. }
  2042. return Error_code::SUCCESS;
  2043. }
  2044. //搬运器从停车位上取车(例如:搬运器移动到56号停车位,然后小跑车将车从车位取出,之后搬运器退回至56车位外面即可)
  2045. Error_manager Dispatch_process::excute_carrier_pickup_car_from_parkingspace_ex(Dispatch_control_node & dispatch_control_node)
  2046. {
  2047. Error_manager t_error;
  2048. Carrier * tp_carrier = NULL;
  2049. Carrier_task * tp_carrier_task = NULL;
  2050. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  2051. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  2052. {
  2053. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  2054. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  2055. }
  2056. else
  2057. {
  2058. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  2059. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  2060. }
  2061. // std::cout << " huli test :::: " << " tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  2062. // getchar();
  2063. if ( tp_carrier_task->m_step == 0 )
  2064. {
  2065. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2066. }
  2067. if ( tp_carrier_task->m_step == 1 )//检查姿态
  2068. {
  2069. //检查姿态
  2070. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  2071. {
  2072. if ( tp_carrier_task->m_request_clamp_motion == Carrier_task::Clamp_motion::E_CLAMP_LOOSE &&
  2073. Common_data::approximate_difference(m_wheel_base, tp_carrier->m_actual_y1-tp_carrier->m_actual_y2, DISPATCH_DEFAULT_DIFFERENCE))
  2074. {
  2075. tp_carrier_task->m_step +=2;
  2076. }
  2077. else
  2078. {
  2079. carrier_adjust_to_ready(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates);
  2080. tp_carrier_task->m_step++;
  2081. }
  2082. }
  2083. else
  2084. {
  2085. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  2086. "tp_carrier->m_actual_load_status != Dispatch_device_base::Load_status::NO_CAR fun error ");
  2087. }
  2088. }
  2089. if ( tp_carrier_task->m_step == 2 )
  2090. {
  2091. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2092. }
  2093. if ( tp_carrier_task->m_step == 3 )//让小跑车回到中跑车上
  2094. {
  2095. if ( Common_data::approximate_difference(tp_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, DISPATCH_DEFAULT_DIFFERENCE) )
  2096. {
  2097. tp_carrier_task->m_step +=2;
  2098. }
  2099. else
  2100. {
  2101. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  2102. tp_carrier_task->m_step++;
  2103. }
  2104. }
  2105. if ( tp_carrier_task->m_step == 4 )
  2106. {
  2107. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2108. }
  2109. if ( tp_carrier_task->m_step == 5 )//让中跑车回到电梯井
  2110. {
  2111. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2112. {
  2113. tp_carrier_task->m_step +=2;
  2114. }
  2115. else
  2116. {
  2117. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  2118. {
  2119. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  2120. tp_carrier_task->m_step++;
  2121. }
  2122. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  2123. {
  2124. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  2125. tp_carrier_task->m_step++;
  2126. }
  2127. else
  2128. {
  2129. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  2130. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  2131. }
  2132. }
  2133. }
  2134. if ( tp_carrier_task->m_step == 6 )
  2135. {
  2136. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2137. }
  2138. if ( tp_carrier_task->m_step == 7 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  2139. {
  2140. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2141. {
  2142. tp_carrier_task->m_step +=2;
  2143. }
  2144. else
  2145. {
  2146. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  2147. tp_carrier_task->m_step++;
  2148. }
  2149. }
  2150. if ( tp_carrier_task->m_step == 8 )
  2151. {
  2152. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2153. }
  2154. if ( tp_carrier_task->m_step == 9 )//电梯移动到对应的楼层
  2155. {
  2156. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2157. {
  2158. tp_carrier_task->m_step +=2;
  2159. }
  2160. else
  2161. {
  2162. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  2163. tp_carrier_task->m_step++;
  2164. }
  2165. }
  2166. if ( tp_carrier_task->m_step == 10 )
  2167. {
  2168. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2169. }
  2170. if ( tp_carrier_task->m_step == 11 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  2171. {
  2172. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK )
  2173. {
  2174. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  2175. tp_carrier_task->m_step++;
  2176. }
  2177. else
  2178. {
  2179. tp_carrier_task->m_step +=2;
  2180. }
  2181. }
  2182. if ( tp_carrier_task->m_step == 12 )
  2183. {
  2184. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2185. }
  2186. if ( tp_carrier_task->m_step == 13 )//中跑车 x轴移动
  2187. {
  2188. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  2189. {
  2190. tp_carrier_task->m_step +=2;
  2191. }
  2192. else
  2193. {
  2194. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  2195. tp_carrier_task->m_step++;
  2196. }
  2197. }
  2198. if ( tp_carrier_task->m_step == 14 )
  2199. {
  2200. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2201. }
  2202. if ( tp_carrier_task->m_step == 15 )//小跑车 进入车位
  2203. {
  2204. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_leave);
  2205. tp_carrier_task->m_step++;
  2206. }
  2207. if ( tp_carrier_task->m_step == 16 )
  2208. {
  2209. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2210. }
  2211. if ( tp_carrier_task->m_step == 17 )//小跑车 夹车
  2212. {
  2213. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_TIGHT);
  2214. tp_carrier_task->m_step++;
  2215. }
  2216. if ( tp_carrier_task->m_step == 18 )
  2217. {
  2218. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2219. }
  2220. if ( tp_carrier_task->m_step == 19 )//小跑车 回到中跑车
  2221. {
  2222. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  2223. tp_carrier_task->m_step++;
  2224. }
  2225. if ( tp_carrier_task->m_step == 20 )
  2226. {
  2227. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2228. }
  2229. if ( tp_carrier_task->m_step == 21 )
  2230. {
  2231. return Error_code::SUCCESS;
  2232. }
  2233. return Error_code::SUCCESS;
  2234. }
  2235. //搬运器把车交付给机器手(例如:搬运器移动到3号入口的上方,小跑车松夹杆,然后等待机器手把车从中跑车上取走)
  2236. Error_manager Dispatch_process::excute_carrier_deliver_car_to_robot(Dispatch_control_node & dispatch_control_node)
  2237. {
  2238. Error_manager t_error;
  2239. Carrier * tp_carrier = NULL;
  2240. Carrier_task * tp_carrier_task = NULL;
  2241. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  2242. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  2243. {
  2244. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  2245. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  2246. }
  2247. else
  2248. {
  2249. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  2250. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  2251. }
  2252. // std::cout << " huli test :::: " << " tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  2253. // getchar();
  2254. if ( tp_carrier_task->m_step == 0 )
  2255. {
  2256. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2257. }
  2258. if ( tp_carrier_task->m_step == 1 )//检查姿态
  2259. {
  2260. //检查姿态
  2261. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::HAVE_CAR &&
  2262. tp_carrier->m_actual_clamp_motion1 == Dispatch_device_base::Clamp_motion::E_CLAMP_TIGHT)
  2263. {
  2264. //检测正常, 直接跳过
  2265. tp_carrier_task->m_step +=2;
  2266. }
  2267. else
  2268. {
  2269. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  2270. "tp_carrier->m_actual_load_status != Dispatch_device_base::Load_status::NO_CAR fun error ");
  2271. }
  2272. }
  2273. if ( tp_carrier_task->m_step == 2 )
  2274. {
  2275. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2276. }
  2277. if ( tp_carrier_task->m_step == 3 )//让小跑车回到中跑车上
  2278. {
  2279. if ( Common_data::approximate_difference(tp_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, DISPATCH_DEFAULT_DIFFERENCE) )
  2280. {
  2281. tp_carrier_task->m_step +=2;
  2282. }
  2283. else
  2284. {
  2285. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  2286. tp_carrier_task->m_step++;
  2287. }
  2288. }
  2289. if ( tp_carrier_task->m_step == 4 )
  2290. {
  2291. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2292. }
  2293. if ( tp_carrier_task->m_step == 5 )//让中跑车回到电梯井
  2294. {
  2295. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2296. {
  2297. tp_carrier_task->m_step +=2;
  2298. }
  2299. else
  2300. {
  2301. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  2302. {
  2303. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  2304. tp_carrier_task->m_step++;
  2305. }
  2306. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  2307. {
  2308. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  2309. tp_carrier_task->m_step++;
  2310. }
  2311. else
  2312. {
  2313. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  2314. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  2315. }
  2316. }
  2317. }
  2318. if ( tp_carrier_task->m_step == 6 )
  2319. {
  2320. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2321. }
  2322. if ( tp_carrier_task->m_step == 7 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  2323. {
  2324. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2325. {
  2326. tp_carrier_task->m_step +=2;
  2327. }
  2328. else
  2329. {
  2330. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  2331. tp_carrier_task->m_step++;
  2332. }
  2333. }
  2334. if ( tp_carrier_task->m_step == 8 )
  2335. {
  2336. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2337. }
  2338. if ( tp_carrier_task->m_step == 9 )//电梯移动到对应的楼层
  2339. {
  2340. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2341. {
  2342. tp_carrier_task->m_step +=2;
  2343. }
  2344. else
  2345. {
  2346. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  2347. tp_carrier_task->m_step++;
  2348. }
  2349. }
  2350. if ( tp_carrier_task->m_step == 10 )
  2351. {
  2352. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2353. }
  2354. if ( tp_carrier_task->m_step == 11 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  2355. {
  2356. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK )
  2357. {
  2358. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  2359. tp_carrier_task->m_step++;
  2360. }
  2361. else
  2362. {
  2363. tp_carrier_task->m_step +=2;
  2364. }
  2365. }
  2366. if ( tp_carrier_task->m_step == 12 )
  2367. {
  2368. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2369. }
  2370. if ( tp_carrier_task->m_step == 13 )//中跑车 x轴移动
  2371. {
  2372. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  2373. {
  2374. tp_carrier_task->m_step +=2;
  2375. }
  2376. else
  2377. {
  2378. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  2379. tp_carrier_task->m_step++;
  2380. }
  2381. }
  2382. if ( tp_carrier_task->m_step == 14 )
  2383. {
  2384. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2385. }
  2386. if ( tp_carrier_task->m_step == 15 )//小跑车 松开夹杆
  2387. {
  2388. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_LOOSE);
  2389. tp_carrier_task->m_step++;
  2390. }
  2391. if ( tp_carrier_task->m_step == 16 )
  2392. {
  2393. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2394. }
  2395. if ( tp_carrier_task->m_step == 17 )
  2396. {
  2397. return Error_code::SUCCESS;
  2398. }
  2399. return Error_code::SUCCESS;
  2400. }
  2401. //搬运器的自由移动(可以提前到2楼来准备接车,或者为了避让就退回至电梯井)(小跑车不进行取车和存车)
  2402. Error_manager Dispatch_process::excute_carrier_move(Dispatch_control_node & dispatch_control_node)
  2403. {
  2404. Error_manager t_error;
  2405. Carrier * tp_carrier = NULL;
  2406. Carrier_task * tp_carrier_task = NULL;
  2407. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  2408. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  2409. {
  2410. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  2411. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  2412. }
  2413. else
  2414. {
  2415. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  2416. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  2417. }
  2418. // std::cout << " huli test :::: " << " tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  2419. // getchar();
  2420. if ( tp_carrier_task->m_step == 0 )
  2421. {
  2422. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2423. }
  2424. if ( tp_carrier_task->m_step == 1 )//让小跑车回到中跑车上
  2425. {
  2426. if ( Common_data::approximate_difference(tp_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, DISPATCH_DEFAULT_DIFFERENCE) )
  2427. {
  2428. tp_carrier_task->m_step +=2;
  2429. }
  2430. else
  2431. {
  2432. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  2433. tp_carrier_task->m_step++;
  2434. }
  2435. }
  2436. if ( tp_carrier_task->m_step == 2 )
  2437. {
  2438. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2439. }
  2440. if ( tp_carrier_task->m_step == 3 )//让中跑车回到电梯井
  2441. {
  2442. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2443. {
  2444. tp_carrier_task->m_step +=2;
  2445. }
  2446. else
  2447. {
  2448. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  2449. {
  2450. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  2451. tp_carrier_task->m_step++;
  2452. }
  2453. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  2454. {
  2455. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  2456. tp_carrier_task->m_step++;
  2457. }
  2458. else
  2459. {
  2460. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  2461. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  2462. }
  2463. }
  2464. }
  2465. if ( tp_carrier_task->m_step == 4 )
  2466. {
  2467. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2468. }
  2469. if ( tp_carrier_task->m_step == 5 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  2470. {
  2471. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2472. {
  2473. tp_carrier_task->m_step +=2;
  2474. }
  2475. else
  2476. {
  2477. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  2478. tp_carrier_task->m_step++;
  2479. }
  2480. }
  2481. if ( tp_carrier_task->m_step == 6 )
  2482. {
  2483. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2484. }
  2485. if ( tp_carrier_task->m_step == 7 )//电梯移动到对应的楼层
  2486. {
  2487. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2488. {
  2489. tp_carrier_task->m_step +=2;
  2490. }
  2491. else
  2492. {
  2493. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  2494. tp_carrier_task->m_step++;
  2495. }
  2496. }
  2497. if ( tp_carrier_task->m_step == 8 )
  2498. {
  2499. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2500. }
  2501. if ( tp_carrier_task->m_step == 9 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  2502. {
  2503. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK )
  2504. {
  2505. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  2506. tp_carrier_task->m_step++;
  2507. }
  2508. else
  2509. {
  2510. tp_carrier_task->m_step +=2;
  2511. }
  2512. }
  2513. if ( tp_carrier_task->m_step == 10 )
  2514. {
  2515. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2516. }
  2517. if ( tp_carrier_task->m_step == 11 )//中跑车 x轴移动
  2518. {
  2519. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  2520. {
  2521. tp_carrier_task->m_step +=2;
  2522. }
  2523. else
  2524. {
  2525. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  2526. tp_carrier_task->m_step++;
  2527. }
  2528. }
  2529. if ( tp_carrier_task->m_step == 12 )
  2530. {
  2531. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2532. }
  2533. if ( tp_carrier_task->m_step == 13 )
  2534. {
  2535. return Error_code::SUCCESS;
  2536. }
  2537. return Error_code::SUCCESS;
  2538. }
  2539. //执行通道口动作
  2540. Error_manager Dispatch_process::excute_passageway_motion(Dispatch_control_node & dispatch_control_node)
  2541. {
  2542. return Error_code::SUCCESS;
  2543. }
  2544. //检查 任务单 是否完成任务, 里面会调整短步骤
  2545. Error_manager Dispatch_process::check_task_ex(std::shared_ptr<Task_Base> p_task, int& step)
  2546. {
  2547. if ( p_task.get() == NULL )
  2548. {
  2549. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  2550. "Dispatch_process::check_passageway_task POINTER IS NULL ");
  2551. }
  2552. else
  2553. {
  2554. // std::cout << " huli test :::: " << " ffffffffffffffffffffffffffffffffffffffffffffffffffffff = " << 333 << std::endl;
  2555. // std::cout << " huli test :::: " << " p_task->get_task_statu() = " << p_task->get_task_statu() << std::endl;
  2556. // std::cout << " huli test :::: " << " gggggggggggggggggggggggggggggggggggggggggggggggggggggg = " << 333 << std::endl;
  2557. if ( p_task->get_task_statu() == Task_Base::Task_statu::TASK_OVER )
  2558. {
  2559. step++;
  2560. return Error_code::NODATA; //这里返回nodata 表示任务继续下一步
  2561. }
  2562. else if ( p_task->get_task_statu() == Task_Base::Task_statu::TASK_ERROR )
  2563. {
  2564. step = 0;
  2565. return p_task->get_task_error_manager();
  2566. }
  2567. else if ( p_task->get_task_statu() == Task_Base::Task_statu::TASK_WORKING ||
  2568. p_task->get_task_statu() == Task_Base::Task_statu::TASK_SIGNED ||
  2569. p_task->get_task_statu() == Task_Base::Task_statu::TASK_CREATED)
  2570. {
  2571. //继续等待任务, 直到状态改变
  2572. return Error_code::NODATA;
  2573. }
  2574. else
  2575. {
  2576. LOG(INFO) << "Dispatch_process::check_task_ex failed p_catcher_task->get_task_statu() = "<< p_task->get_task_statu() << " " << this;
  2577. return Error_code::NODATA;
  2578. }
  2579. }
  2580. return Error_code::SUCCESS;
  2581. }
  2582. //机器手调整到正常待机的姿态(调节夹杆和轴距)
  2583. Error_manager Dispatch_process::catcher_adjust_to_ready(Dispatch_control_node & dispatch_control_node, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  2584. {
  2585. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  2586. char t_key[50] = {0};
  2587. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  2588. tp_catcher_task->m_request_key = t_key;
  2589. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  2590. //调整姿态
  2591. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  2592. tp_catcher_task->m_request_d1 = tp_dispatch_coordinates->m_catcher_d1_min;
  2593. tp_catcher_task->m_request_d2 = tp_dispatch_coordinates->m_catcher_d2_min;
  2594. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  2595. {
  2596. tp_catcher_task->m_request_b = 270;
  2597. }
  2598. else
  2599. {
  2600. tp_catcher_task->m_request_b = 90;
  2601. }
  2602. std::cout << " huli test :::: " << " catcher_adjust_to_ready = " << tp_catcher_task->m_request_key << std::endl;
  2603. std::cout << " huli test :::: " << " catcher_adjust_to_ready = " << tp_catcher_task->m_respons_key << std::endl;
  2604. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  2605. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  2606. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  2607. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  2608. std::cout << " huli test :::: " << " tp_catcher_task->m_request_b = " << tp_catcher_task->m_request_b << std::endl;
  2609. return Error_code::SUCCESS;
  2610. }
  2611. //机器手 移动z
  2612. Error_manager Dispatch_process::catcher_move_z(Dispatch_control_node & dispatch_control_node, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, float target)
  2613. {
  2614. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  2615. char t_key[50] = {0};
  2616. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  2617. tp_catcher_task->m_request_key = t_key;
  2618. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  2619. //机器手 移动z
  2620. tp_catcher_task->m_request_z = target;
  2621. std::cout << " huli test :::: " << " catcher_move_z = " << tp_catcher_task->m_request_key << std::endl;
  2622. std::cout << " huli test :::: " << " catcher_move_z = " << tp_catcher_task->m_respons_key << std::endl;
  2623. std::cout << " huli test :::: " << " tp_catcher_task->m_request_z = " << tp_catcher_task->m_request_z << std::endl;
  2624. return Error_code::SUCCESS;
  2625. }
  2626. //机器手调整到 准备从地面抓车前的姿态
  2627. Error_manager Dispatch_process::catcher_adjust_from_ground(Dispatch_control_node & dispatch_control_node, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  2628. {
  2629. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  2630. char t_key[50] = {0};
  2631. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  2632. tp_catcher_task->m_request_key = t_key;
  2633. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  2634. //机器手 调整x y b d1 d2, 根据感测模块的定位信息, 调整机器手的姿态, 准备抓车.
  2635. tp_catcher_task->m_request_x = m_car_measure_information.center_x;
  2636. tp_catcher_task->m_request_y = m_car_measure_information.center_y;
  2637. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  2638. {
  2639. //机器手如果旋转反向, 那就+180即可, 没有必要旋转归位.
  2640. tp_catcher_task->m_request_b = 180 + m_car_measure_information.car_angle;
  2641. }
  2642. else
  2643. {
  2644. tp_catcher_task->m_request_b = m_car_measure_information.car_angle;
  2645. }
  2646. //限制轮距, 在夹车杆松开时, 机器人下降时, 轴距不能超过3000mm, 必须下降到最下面才能调整轴距, 夹车后可以上升.
  2647. if ( m_wheel_base > tp_dispatch_coordinates->m_catcher_wheel_base_limit )
  2648. {
  2649. tp_catcher_task->m_request_d1 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  2650. tp_catcher_task->m_request_d2 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  2651. tp_catcher_task->m_request_wheelbase = tp_dispatch_coordinates->m_catcher_wheel_base_limit;
  2652. }
  2653. else
  2654. {
  2655. tp_catcher_task->m_request_d1 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  2656. tp_catcher_task->m_request_d2 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  2657. tp_catcher_task->m_request_wheelbase = m_wheel_base;
  2658. }
  2659. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  2660. std::cout << " huli test :::: " << " catcher_adjust_from_ground = " << tp_catcher_task->m_request_key << std::endl;
  2661. std::cout << " huli test :::: " << " catcher_adjust_from_ground = " << tp_catcher_task->m_respons_key << std::endl;
  2662. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  2663. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  2664. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  2665. std::cout << " huli test :::: " << " tp_catcher_task->m_request_b = " << tp_catcher_task->m_request_b << std::endl;
  2666. std::cout << " huli test :::: " << " m_wheel_base = " << m_wheel_base << std::endl;
  2667. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  2668. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  2669. std::cout << " huli test :::: " << " tp_catcher_task->m_request_wheelbase = " << tp_catcher_task->m_request_wheelbase << std::endl;
  2670. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  2671. return Error_code::SUCCESS;
  2672. }
  2673. //机器手 修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  2674. Error_manager Dispatch_process::catcher_adjust_wheel_base(Dispatch_control_node & dispatch_control_node, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  2675. {
  2676. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  2677. char t_key[50] = {0};
  2678. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  2679. tp_catcher_task->m_request_key = t_key;
  2680. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  2681. //修正轴距
  2682. tp_catcher_task->m_request_d1 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  2683. tp_catcher_task->m_request_d2 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  2684. tp_catcher_task->m_request_wheelbase = m_wheel_base;
  2685. std::cout << " huli test :::: " << " catcher_adjust_wheel_base = " << tp_catcher_task->m_request_key << std::endl;
  2686. std::cout << " huli test :::: " << " catcher_adjust_wheel_base = " << tp_catcher_task->m_respons_key << std::endl;
  2687. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  2688. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  2689. std::cout << " huli test :::: " << " tp_catcher_task->m_request_wheelbase = " << tp_catcher_task->m_request_wheelbase << std::endl;
  2690. return Error_code::SUCCESS;
  2691. }
  2692. //机器手 移动c轴 夹杆
  2693. Error_manager Dispatch_process::catcher_move_c(Dispatch_control_node & dispatch_control_node, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, Catcher_task::Clamp_motion target)
  2694. {
  2695. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  2696. char t_key[50] = {0};
  2697. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  2698. tp_catcher_task->m_request_key = t_key;
  2699. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  2700. tp_catcher_task->m_request_clamp_motion = target;
  2701. std::cout << " huli test :::: " << " catcher_move_c = " << tp_catcher_task->m_request_key << std::endl;
  2702. std::cout << " huli test :::: " << " catcher_move_c = " << tp_catcher_task->m_respons_key << std::endl;
  2703. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  2704. return Error_code::SUCCESS;
  2705. }
  2706. //机器手调整到 准备把车放到搬运器的姿态
  2707. Error_manager Dispatch_process::catcher_adjust_to_carrier(Dispatch_control_node & dispatch_control_node, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, bool reverse_flag)
  2708. {
  2709. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  2710. char t_key[50] = {0};
  2711. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  2712. tp_catcher_task->m_request_key = t_key;
  2713. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  2714. //机器手 调整x y b d1 d2, 调整机器手的姿态, 准备把车放置到中跑车上.
  2715. tp_catcher_task->m_request_x = dispatch_control_node.m_destination_coordinates.x;
  2716. tp_catcher_task->m_request_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  2717. //存车需要反向, 取车不需要
  2718. if ( reverse_flag )
  2719. {
  2720. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  2721. {
  2722. tp_catcher_task->m_request_b = 90;
  2723. }
  2724. else
  2725. {
  2726. tp_catcher_task->m_request_b = 270;
  2727. }
  2728. }
  2729. else
  2730. {
  2731. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  2732. {
  2733. tp_catcher_task->m_request_b = 270;
  2734. }
  2735. else
  2736. {
  2737. tp_catcher_task->m_request_b = 90;
  2738. }
  2739. }
  2740. std::cout << " huli test :::: " << " catcher_adjust_to_carrier = " << tp_catcher_task->m_request_key << std::endl;
  2741. std::cout << " huli test :::: " << " catcher_adjust_to_carrier = " << tp_catcher_task->m_respons_key << std::endl;
  2742. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  2743. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  2744. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  2745. std::cout << " huli test :::: " << " tp_catcher->m_request_b = " << tp_catcher->m_request_b << std::endl;
  2746. return Error_code::SUCCESS;
  2747. }
  2748. //机器手调整到 准备把车放到地面的姿态
  2749. Error_manager Dispatch_process::catcher_adjust_to_ground(Dispatch_control_node & dispatch_control_node, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  2750. {
  2751. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  2752. char t_key[50] = {0};
  2753. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  2754. tp_catcher_task->m_request_key = t_key;
  2755. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  2756. //机器手 调整x y b d1 d2, 调整机器手的姿态, 准备把车放置到中跑车上.
  2757. tp_catcher_task->m_request_x = dispatch_control_node.m_destination_coordinates.x;
  2758. tp_catcher_task->m_request_y = dispatch_control_node.m_destination_coordinates.y;
  2759. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  2760. {
  2761. tp_catcher_task->m_request_b = 270;
  2762. }
  2763. else
  2764. {
  2765. tp_catcher_task->m_request_b = 90;
  2766. }
  2767. std::cout << " huli test :::: " << " catcher_adjust_to_ground = " << tp_catcher_task->m_request_key << std::endl;
  2768. std::cout << " huli test :::: " << " catcher_adjust_to_ground = " << tp_catcher_task->m_respons_key << std::endl;
  2769. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  2770. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  2771. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  2772. std::cout << " huli test :::: " << " tp_catcher->m_request_b = " << tp_catcher->m_request_b << std::endl;
  2773. return Error_code::SUCCESS;
  2774. }
  2775. //机器手调整到 对接搬运器的姿态
  2776. Error_manager Dispatch_process::catcher_adjust_from_carrier(Dispatch_control_node & dispatch_control_node, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  2777. {
  2778. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  2779. char t_key[50] = {0};
  2780. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_catcher_task->m_step);
  2781. tp_catcher_task->m_request_key = t_key;
  2782. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  2783. //机器手 调整x y b d1 d2, 调整机器手的姿态, 准备把车放置到中跑车上.
  2784. tp_catcher_task->m_request_x = dispatch_control_node.m_destination_coordinates.x;
  2785. tp_catcher_task->m_request_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  2786. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  2787. {
  2788. tp_catcher_task->m_request_b = 270;
  2789. }
  2790. else
  2791. {
  2792. tp_catcher_task->m_request_b = 90;
  2793. }
  2794. //限制轮距, 在夹车杆松开时, 机器人下降时, 轴距不能超过3000mm, 必须下降到最下面才能调整轴距, 夹车后可以上升.
  2795. if ( m_wheel_base > tp_dispatch_coordinates->m_catcher_wheel_base_limit )
  2796. {
  2797. tp_catcher_task->m_request_d1 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  2798. tp_catcher_task->m_request_d2 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  2799. tp_catcher_task->m_request_wheelbase = tp_dispatch_coordinates->m_catcher_wheel_base_limit;
  2800. }
  2801. else
  2802. {
  2803. tp_catcher_task->m_request_d1 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  2804. tp_catcher_task->m_request_d2 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  2805. tp_catcher_task->m_request_wheelbase = m_wheel_base;
  2806. }
  2807. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  2808. std::cout << " huli test :::: " << " catcher_adjust_from_carrier = " << tp_catcher_task->m_request_key << std::endl;
  2809. std::cout << " huli test :::: " << " catcher_adjust_from_carrier = " << tp_catcher_task->m_respons_key << std::endl;
  2810. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  2811. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  2812. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  2813. std::cout << " huli test :::: " << " tp_catcher_task->m_request_b = " << tp_catcher_task->m_request_b << std::endl;
  2814. std::cout << " huli test :::: " << " m_wheel_base = " << m_wheel_base << std::endl;
  2815. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  2816. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  2817. std::cout << " huli test :::: " << " tp_catcher_task->m_request_wheelbase = " << tp_catcher_task->m_request_wheelbase << std::endl;
  2818. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  2819. return Error_code::SUCCESS;
  2820. }
  2821. //搬运器调整到 正常待机的姿态(调节夹杆和轴距)
  2822. Error_manager Dispatch_process::carrier_adjust_to_ready(Dispatch_control_node & dispatch_control_node, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates)
  2823. {
  2824. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  2825. char t_key[50] = {0};
  2826. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  2827. tp_carrier_task->m_request_key = t_key;
  2828. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  2829. tp_carrier_task->m_request_clamp_motion = Carrier_task::Clamp_motion::E_CLAMP_LOOSE;
  2830. tp_carrier_task->m_request_wheelbase = m_wheel_base;
  2831. tp_carrier_task->m_request_y1 = tp_carrier->m_actual_y + tp_dispatch_coordinates->m_carrier_y_y1_distance;
  2832. tp_carrier_task->m_request_y2 = tp_carrier_task->m_request_y1 - tp_carrier_task->m_request_wheelbase;
  2833. std::cout << " huli test :::: " << " carrier_adjust_to_ready = " << tp_carrier_task->m_request_key << std::endl;
  2834. std::cout << " huli test :::: " << " carrier_adjust_to_ready = " << tp_carrier_task->m_respons_key << std::endl;
  2835. std::cout << " huli test :::: " << " tp_carrier_task->m_request_wheelbase = " << tp_carrier_task->m_request_wheelbase << std::endl;
  2836. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y1 = " << tp_carrier_task->m_request_y1 << std::endl;
  2837. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y2 = " << tp_carrier_task->m_request_y2 << std::endl;
  2838. std::cout << " huli test :::: " << " tp_carrier_task->m_request_clamp_motion = " << tp_carrier_task->m_request_clamp_motion << std::endl;
  2839. return Error_code::SUCCESS;
  2840. }
  2841. //搬运器 移动x
  2842. Error_manager Dispatch_process::carrier_move_x(Dispatch_control_node & dispatch_control_node, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates, float target)
  2843. {
  2844. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  2845. char t_key[50] = {0};
  2846. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  2847. tp_carrier_task->m_request_key = t_key;
  2848. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  2849. tp_carrier_task->m_request_x = target;
  2850. std::cout << " huli test :::: " << " carrier_move_x = " << tp_carrier_task->m_request_key << std::endl;
  2851. std::cout << " huli test :::: " << " carrier_move_x = " << tp_carrier_task->m_respons_key << std::endl;
  2852. std::cout << " huli test :::: " << " tp_carrier_task->m_request_x = " << tp_carrier_task->m_request_x << std::endl;
  2853. return Error_code::SUCCESS;
  2854. }
  2855. //搬运器 移动y
  2856. Error_manager Dispatch_process::carrier_move_y(Dispatch_control_node & dispatch_control_node, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates, float target)
  2857. {
  2858. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  2859. char t_key[50] = {0};
  2860. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  2861. tp_carrier_task->m_request_key = t_key;
  2862. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  2863. tp_carrier_task->m_request_y = target;
  2864. tp_carrier_task->m_request_wheelbase = m_wheel_base;
  2865. tp_carrier_task->m_request_y1 = tp_carrier_task->m_request_y + tp_dispatch_coordinates->m_carrier_y_y1_distance;
  2866. tp_carrier_task->m_request_y2 = tp_carrier_task->m_request_y1 - tp_carrier_task->m_request_wheelbase;
  2867. std::cout << " huli test :::: " << " carrier_move_y = " << tp_carrier_task->m_request_key << std::endl;
  2868. std::cout << " huli test :::: " << " carrier_move_y = " << tp_carrier_task->m_respons_key << std::endl;
  2869. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y = " << tp_carrier_task->m_request_y << std::endl;
  2870. std::cout << " huli test :::: " << " tp_carrier_task->m_request_wheelbase = " << tp_carrier_task->m_request_wheelbase << std::endl;
  2871. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y1 = " << tp_carrier_task->m_request_y1 << std::endl;
  2872. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y2 = " << tp_carrier_task->m_request_y2 << std::endl;
  2873. return Error_code::SUCCESS;
  2874. }
  2875. //搬运器 移动z
  2876. Error_manager Dispatch_process::carrier_move_z(Dispatch_control_node & dispatch_control_node, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates, float target)
  2877. {
  2878. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  2879. char t_key[50] = {0};
  2880. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  2881. tp_carrier_task->m_request_key = t_key;
  2882. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  2883. tp_carrier_task->m_request_z = target;
  2884. std::cout << " huli test :::: " << " carrier_move_z = " << tp_carrier_task->m_request_key << std::endl;
  2885. std::cout << " huli test :::: " << " carrier_move_z = " << tp_carrier_task->m_respons_key << std::endl;
  2886. std::cout << " huli test :::: " << " tp_carrier_task->m_request_z = " << tp_carrier_task->m_request_z << std::endl;
  2887. return Error_code::SUCCESS;
  2888. }
  2889. //搬运器 移动c轴 夹车杆
  2890. Error_manager Dispatch_process::carrier_move_c(Dispatch_control_node & dispatch_control_node, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates, Carrier_task::Clamp_motion target)
  2891. {
  2892. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  2893. char t_key[50] = {0};
  2894. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  2895. tp_carrier_task->m_request_key = t_key;
  2896. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  2897. tp_carrier_task->m_request_clamp_motion = target;
  2898. std::cout << " huli test :::: " << " carrier_move_c = " << tp_carrier_task->m_request_key << std::endl;
  2899. std::cout << " huli test :::: " << " carrier_move_c = " << tp_carrier_task->m_respons_key << std::endl;
  2900. std::cout << " huli test :::: " << " tp_carrier_task->m_request_clamp_motion = " << tp_carrier_task->m_request_clamp_motion << std::endl;
  2901. return Error_code::SUCCESS;
  2902. }
  2903. //搬运器调整 水平的交接
  2904. Error_manager Dispatch_process::carrier_joint_x(Dispatch_control_node & dispatch_control_node, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates, Carrier_task::Joint_motion target)
  2905. {
  2906. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  2907. char t_key[50] = {0};
  2908. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  2909. tp_carrier_task->m_request_key = t_key;
  2910. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  2911. tp_carrier_task->m_request_joint_motion_x = target;
  2912. std::cout << " huli test :::: " << " carrier_joint_x = " << tp_carrier_task->m_request_key << std::endl;
  2913. std::cout << " huli test :::: " << " carrier_joint_x = " << tp_carrier_task->m_respons_key << std::endl;
  2914. std::cout << " huli test :::: " << " tp_carrier_task->m_request_joint_motion_x = " << tp_carrier_task->m_request_joint_motion_x << std::endl;
  2915. return Error_code::SUCCESS;
  2916. }
  2917. //搬运器 修正轴距
  2918. Error_manager Dispatch_process::carrier_adjust_wheel_base(Dispatch_control_node & dispatch_control_node, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates)
  2919. {
  2920. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  2921. char t_key[50] = {0};
  2922. sprintf(t_key, "%s+%d+%d", dispatch_control_node.m_dispatch_control_request_msg.command_key().c_str(), dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type(), tp_carrier_task->m_step);
  2923. tp_carrier_task->m_request_key = t_key;
  2924. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  2925. tp_carrier_task->m_request_wheelbase = m_wheel_base;
  2926. tp_carrier_task->m_request_y1 = tp_carrier->m_actual_y + tp_dispatch_coordinates->m_carrier_y_y1_distance;
  2927. tp_carrier_task->m_request_y2 = tp_carrier_task->m_request_y1 - tp_carrier_task->m_request_wheelbase;
  2928. std::cout << " huli test :::: " << " carrier_adjust_wheel_base = " << tp_carrier_task->m_request_key << std::endl;
  2929. std::cout << " huli test :::: " << " carrier_adjust_wheel_base = " << tp_carrier_task->m_respons_key << std::endl;
  2930. std::cout << " huli test :::: " << " tp_carrier_task->m_request_wheelbase = " << tp_carrier_task->m_request_wheelbase << std::endl;
  2931. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y1 = " << tp_carrier_task->m_request_y1 << std::endl;
  2932. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y2 = " << tp_carrier_task->m_request_y2 << std::endl;
  2933. return Error_code::SUCCESS;
  2934. }