dispatch_process.cpp 136 KB

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