dispatch_process.cpp 133 KB

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