dispatch_process.cpp 129 KB

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