dispatch_process.cpp 124 KB

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