dispatch_process.cpp 131 KB

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