dispatch_process.cpp 128 KB

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