dispatch_process.cpp 124 KB

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