dispatch_process.cpp 125 KB

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