dispatch_process.cpp 133 KB

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