dispatch_process.cpp 203 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641
  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 = Common_data::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. //设定超时时间, 默认比任务指令里面的时间少10秒,
  23. if ( dispatch_request_msg.base_info().has_timeout_ms() )
  24. {
  25. m_timeout_ms = dispatch_request_msg.base_info().timeout_ms() - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
  26. }
  27. else
  28. {
  29. m_timeout_ms = DISPATCH_PROCESS_TIMEOUT_MS - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
  30. }
  31. m_command_key = dispatch_request_msg.command_key();
  32. m_start_time = std::chrono::system_clock::now();
  33. //检查调度请求消息
  34. if ( dispatch_request_msg.terminal_id() < Dispatch_coordinates::get_instance_references().m_passageway_terminal_id_min ||
  35. dispatch_request_msg.terminal_id() > Dispatch_coordinates::get_instance_references().m_passageway_terminal_id_max)
  36. {
  37. return Error_manager(Error_code::DISPATCH_PROCESS_INIT_ERROR, Error_level::MINOR_ERROR,
  38. " dispatch_request_msg.terminal_id() is error ");
  39. }
  40. //解析调度请求消息
  41. if ( dispatch_request_msg.dispatch_motion_direction() == message::E_STORE_CAR )
  42. {
  43. //检查调度请求消息
  44. if ( Dispatch_coordinates::get_instance_references().m_passageway_functioning_pattern_map[dispatch_request_msg.terminal_id()] != Dispatch_coordinates::PASSAGEWAY_FUNCTIONING_PATTERN_INLET &&
  45. Dispatch_coordinates::get_instance_references().m_passageway_functioning_pattern_map[dispatch_request_msg.terminal_id()] != Dispatch_coordinates::PASSAGEWAY_FUNCTIONING_PATTERN_BIDIRECTION )
  46. {
  47. return Error_manager(Error_code::DISPATCH_PROCESS_INIT_ERROR, Error_level::MINOR_ERROR,
  48. " m_passageway_functioning_pattern_map[dispatch_request_msg.terminal_id()] is error ");
  49. }
  50. //存车的车位可以是1~3个
  51. if ( dispatch_request_msg.parkspace_info_ex_size() <=0 || dispatch_request_msg.parkspace_info_ex_size() >3 )
  52. {
  53. return Error_manager(Error_code::DISPATCH_PROCESS_INIT_ERROR, Error_level::MINOR_ERROR,
  54. " dispatch_request_msg.parkspace_info_ex_size() is error ");
  55. }
  56. //检查定位信息
  57. if ( dispatch_request_msg.has_locate_information() == false )
  58. {
  59. return Error_manager(Error_code::DISPATCH_PROCESS_INIT_ERROR, Error_level::MINOR_ERROR,
  60. " dispatch_request_msg.has_locate_information() is error ");
  61. }
  62. m_dispatch_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_STORE;
  63. m_dispatch_source = dispatch_request_msg.terminal_id() + PASSAGEWAY_ID_BASE ;
  64. //终点在运动过程中动态分配//存车需要在完全确定车位之后, 才能判断车位类型
  65. // m_dispatch_destination = dispatch_request_msg.parkspace_info().parkingspace_index_id() + PARKSPACE_ID_BASE;
  66. for (int i = 0; i < m_dispatch_request_msg.parkspace_info_ex_size(); ++i)
  67. {
  68. if(m_dispatch_request_msg.parkspace_info_ex(i).parkspace_path() == message::Parkspace_path::LEFT_PATH)
  69. {
  70. Common_data::copy_data(m_parkspace_information_left, dispatch_request_msg.parkspace_info_ex(i));
  71. Common_data::scaling(m_parkspace_information_left, 1000);
  72. }
  73. if(m_dispatch_request_msg.parkspace_info_ex(i).parkspace_path() == message::Parkspace_path::RIGHT_PATH)
  74. {
  75. Common_data::copy_data(m_parkspace_information_right, dispatch_request_msg.parkspace_info_ex(i));
  76. Common_data::scaling(m_parkspace_information_right, 1000);
  77. }
  78. if(m_dispatch_request_msg.parkspace_info_ex(i).parkspace_path() == message::Parkspace_path::TEMPORARY_CACHE_PATH)
  79. {
  80. Common_data::copy_data(m_parkspace_information_temporary, dispatch_request_msg.parkspace_info_ex(i));
  81. Common_data::scaling(m_parkspace_information_temporary, 1000);
  82. }
  83. }
  84. // Common_data::copy_data(m_parkspace_information, dispatch_request_msg.parkspace_info());
  85. // Common_data::scaling(m_parkspace_information, 1000);
  86. Common_data::copy_data(m_car_measure_information, dispatch_request_msg.locate_information());
  87. Common_data::scaling(m_car_measure_information, 1000);
  88. m_wheel_base = m_car_measure_information.car_wheel_base;
  89. }
  90. else if( dispatch_request_msg.dispatch_motion_direction() == message::E_PICKUP_CAR )
  91. {
  92. //检查调度请求消息
  93. if ( Dispatch_coordinates::get_instance_references().m_passageway_functioning_pattern_map[dispatch_request_msg.terminal_id()] != Dispatch_coordinates::PASSAGEWAY_FUNCTIONING_PATTERN_OUTLET &&
  94. Dispatch_coordinates::get_instance_references().m_passageway_functioning_pattern_map[dispatch_request_msg.terminal_id()] != Dispatch_coordinates::PASSAGEWAY_FUNCTIONING_PATTERN_BIDIRECTION )
  95. {
  96. return Error_manager(Error_code::DISPATCH_PROCESS_INIT_ERROR, Error_level::MINOR_ERROR,
  97. " m_passageway_functioning_pattern_map[dispatch_request_msg.terminal_id()] is error ");
  98. }
  99. //取车的车位必须是1个
  100. if ( dispatch_request_msg.parkspace_info_ex_size() != 1 )
  101. {
  102. return Error_manager(Error_code::DISPATCH_PROCESS_INIT_ERROR, Error_level::MINOR_ERROR,
  103. " dispatch_request_msg.parkspace_info_ex_size() is error ");
  104. }
  105. m_dispatch_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_PICKUP;
  106. m_dispatch_source = dispatch_request_msg.parkspace_info_ex(0).parkingspace_index_id() + PARKSPACE_ID_BASE;
  107. m_parkspace_type = (Common_data::Parkspace_type)( dispatch_request_msg.parkspace_info_ex(0).parkingspace_type() );
  108. //终点在运动过程中动态分配
  109. //目前不控制门, 所以出口有主控决定. 如果后续控制门, 那么出口可以由调度决定.
  110. //目前取车还是固定出口.
  111. m_dispatch_destination = dispatch_request_msg.terminal_id() + PASSAGEWAY_ID_BASE ;
  112. Common_data::copy_data(m_parkspace_information_optimal, dispatch_request_msg.parkspace_info_ex(0));
  113. Common_data::scaling(m_parkspace_information_optimal, 1000);
  114. m_wheel_base = m_parkspace_information_optimal.car_information.car_wheel_base;
  115. }
  116. else
  117. {
  118. m_dispatch_process_type = Common_data::Dispatch_process_type::DISPATCH_PROCESS_TYPE_UNKNOW;
  119. return Error_manager(Error_code::DISPATCH_PROCESS_INIT_ERROR, Error_level::MINOR_ERROR,
  120. " Dispatch_process::Dispatch_process_init ERROR ");
  121. }
  122. //轮距
  123. if ( m_wheel_base < Dispatch_coordinates::get_instance_references().m_car_wheel_base_min ||
  124. m_wheel_base > Dispatch_coordinates::get_instance_references().m_car_wheel_base_max)
  125. {
  126. return Error_manager(Error_code::DISPATCH_PROCESS_INIT_ERROR, Error_level::MINOR_ERROR,
  127. " m_wheel_base < 1000 ERROR ");
  128. }
  129. m_car_type = (Common_data::Car_type)( dispatch_request_msg.car_type() );
  130. m_temporary_cache_flag = false;
  131. m_dispatch_request_msg = dispatch_request_msg;
  132. m_dispatch_process_status = DISPATCH_PROCESS_CREATED;
  133. return Error_code::SUCCESS;
  134. }
  135. //反初始化
  136. Error_manager Dispatch_process::Dispatch_process_uninit()
  137. {
  138. std::unique_lock<std::mutex> t_lock(m_lock);
  139. for (auto iter = m_dispatch_control_node_map.begin(); iter != m_dispatch_control_node_map.end(); ++iter)
  140. {
  141. if ( iter->second.mp_dispatch_task.get() != NULL )
  142. {
  143. iter->second.mp_dispatch_task->set_task_statu(Task_Base::Task_statu::TASK_WITHDRAW);
  144. iter->second.mp_dispatch_task.reset();
  145. iter->second.mp_dispatch_device.reset();
  146. }
  147. }
  148. return Error_code::SUCCESS;
  149. }
  150. //检查流程是否空闲待机
  151. Error_manager Dispatch_process::check_process_ready()
  152. {
  153. return Error_code::SUCCESS;
  154. if ( m_dispatch_process_status == DISPATCH_PROCESS_READY )
  155. {
  156. return Error_code::SUCCESS;
  157. }
  158. else
  159. {
  160. return Error_manager(Error_code::DISPATCH_PROCESS_IS_NOT_READY, Error_level::MINOR_ERROR,
  161. " Dispatch_process::check_process_ready() fun error ");
  162. }
  163. }
  164. //判断是否为待机,
  165. bool Dispatch_process::is_ready()
  166. {
  167. // std::unique_lock<std::mutex> t_lock(m_lock);
  168. if ( m_dispatch_process_status == DISPATCH_PROCESS_READY && m_dispatch_carrier_node.mp_main_carrier.get() == NULL)
  169. {
  170. return true;
  171. }
  172. else
  173. {
  174. return false;
  175. }
  176. }
  177. //能否在左侧路径存车
  178. bool Dispatch_process::is_able_store_left_path()
  179. {
  180. if ( m_parkspace_information_left.parkingspace_index_id !=0 )
  181. {
  182. return true;
  183. }
  184. return false;
  185. }
  186. //能否在右侧路径存车
  187. bool Dispatch_process::is_able_store_right_path()
  188. {
  189. if ( m_parkspace_information_right.parkingspace_index_id !=0 )
  190. {
  191. return true;
  192. }
  193. return false;
  194. }
  195. //能否在3楼路径存车
  196. bool Dispatch_process::is_able_store_temporary_cache_path()
  197. {
  198. if ( m_parkspace_information_temporary.parkingspace_index_id !=0 )
  199. {
  200. return true;
  201. }
  202. return false;
  203. }
  204. //能否在临时缓存位存车
  205. bool Dispatch_process::is_able_store_temporary_cache_path_2nd_floor()
  206. {
  207. if ( m_parkspace_information_temporary.parkingspace_index_id >= 4 && m_parkspace_information_temporary.parkingspace_index_id <= 12 )
  208. {
  209. return true;
  210. }
  211. return false;
  212. }
  213. //能否在临时缓存位存车
  214. bool Dispatch_process::is_able_store_temporary_cache_path_3rd_floor()
  215. {
  216. if ( m_parkspace_information_temporary.parkingspace_index_id >= 19 && m_parkspace_information_temporary.parkingspace_index_id <= 27 )
  217. {
  218. return true;
  219. }
  220. return false;
  221. }
  222. void Dispatch_process::set_main_carrier(std::shared_ptr<Dispatch_device_base> p_carrier)
  223. {
  224. std::unique_lock<std::mutex> t_lock(m_lock);
  225. m_dispatch_carrier_node.mp_main_carrier = p_carrier;
  226. }
  227. std::string Dispatch_process::get_dispatch_control_command_key(Dispatch_catcher_node & dispatch_catcher_node)
  228. {
  229. char t_key[50] = {0};
  230. sprintf(t_key, "%s+%d+%d", m_command_key.c_str(), m_dispatch_process_type, dispatch_catcher_node.m_dispatch_control_status);
  231. std::string t_str = t_key;
  232. return t_str;
  233. }
  234. std::string Dispatch_process::get_dispatch_control_command_key(Dispatch_carrier_node & dispatch_carrier_node)
  235. {
  236. char t_key[50] = {0};
  237. sprintf(t_key, "%s+%d+%d", m_command_key.c_str(), m_dispatch_process_type, dispatch_carrier_node.m_dispatch_control_status);
  238. std::string t_str = t_key;
  239. return t_str;
  240. }
  241. void Dispatch_process::Main()
  242. {
  243. Error_manager t_error;
  244. //主流程, 循环执行
  245. while ( std::chrono::system_clock::now() - m_start_time < std::chrono::milliseconds(m_timeout_ms) )
  246. {
  247. std::this_thread::sleep_for(std::chrono::microseconds(1));
  248. std::this_thread::sleep_for(std::chrono::milliseconds(1));
  249. // std::this_thread::sleep_for(std::chrono::seconds(1));
  250. // std::cout << " huli test :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: " << " m_dispatch_process_status = " << m_dispatch_process_status << std::endl;
  251. switch ( (Dispatch_process_status)m_dispatch_process_status )
  252. {
  253. case DISPATCH_PROCESS_CREATED://流程创建,
  254. {
  255. //检查调度请求
  256. m_result = check_dispatch_request_msg();
  257. if ( m_result !=Error_code::SUCCESS)
  258. {
  259. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  260. break;
  261. }
  262. //发送调度总计划
  263. // m_result = send_dispatch_plan_request_msg();
  264. // if ( m_result !=Error_code::SUCCESS)
  265. // {
  266. // m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  267. // break;
  268. // }
  269. //流程正常, 就进入等待状态, 等待调度控制发送动作指令
  270. m_dispatch_process_status = DISPATCH_PROCESS_READY;
  271. break;
  272. }
  273. case DISPATCH_PROCESS_READY://流程准备,待机
  274. {
  275. m_result = wait_resource_allocation();
  276. if ( m_result == Error_code::SUCCESS)
  277. {
  278. if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_PICKUP )
  279. {
  280. m_dispatch_catcher_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_READY;
  281. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_READY;
  282. m_dispatch_process_status = DISPATCH_PROCESS_WORKING_PICKUP;
  283. }
  284. else if(m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_STORE)
  285. {
  286. m_dispatch_catcher_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_READY;
  287. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_READY;
  288. m_dispatch_process_status = DISPATCH_PROCESS_WORKING_STORE;
  289. }
  290. //根据设备选择, 来设置终点
  291. if ( m_dispatch_carrier_node.mp_main_carrier->get_device_id() == 2 )
  292. {
  293. m_parkspace_information_optimal = m_parkspace_information_temporary;
  294. }
  295. else if ( m_dispatch_carrier_node.mp_main_carrier->get_device_id() == 0 && m_temporary_cache_flag == false )
  296. {
  297. m_parkspace_information_optimal = m_parkspace_information_left;
  298. }
  299. else if ( m_dispatch_carrier_node.mp_main_carrier->get_device_id() == 0 && m_temporary_cache_flag == true)
  300. {
  301. m_parkspace_information_optimal = m_parkspace_information_temporary;
  302. }
  303. else if ( m_dispatch_carrier_node.mp_main_carrier->get_device_id() == 1 && m_temporary_cache_flag == false )
  304. {
  305. m_parkspace_information_optimal = m_parkspace_information_right;
  306. }
  307. else if ( m_dispatch_carrier_node.mp_main_carrier->get_device_id() == 1 && m_temporary_cache_flag == true)
  308. {
  309. m_parkspace_information_optimal = m_parkspace_information_temporary;
  310. }
  311. }
  312. //else 一直等待资源分配
  313. break;
  314. //调度控制, 并根据完成情况给答复
  315. // dispatch_control_motion();
  316. //
  317. // //等待调度总计划答复
  318. // m_result = wait_dispatch_plan_response_msg();
  319. // if ( m_result ==Error_code::SUCCESS)
  320. // {
  321. // //流程正常, 就进入完成状态,
  322. // m_dispatch_process_status = DISPATCH_PROCESS_OVER;
  323. // break;
  324. // }
  325. // else if ( m_result !=Error_code::NODATA )
  326. // {
  327. // m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  328. // break;
  329. // }
  330. //else nodata, 就表示没有新的指令, 那么什么都不做, 原地待命
  331. break;
  332. }
  333. case DISPATCH_PROCESS_WORKING_PICKUP://流程完成
  334. {
  335. //调度控制取车
  336. m_result = dispatch_control_motion_pickup();
  337. if ( m_result ==Error_code::SUCCESS)
  338. {
  339. //流程正常, 就进入完成状态,
  340. m_dispatch_process_status = DISPATCH_PROCESS_OVER;
  341. break;
  342. }
  343. else if ( m_result !=Error_code::NODATA )
  344. {
  345. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  346. break;
  347. }
  348. //else nodata, 就表示没有新的指令, 那么什么都不做, 原地待命
  349. break;
  350. }
  351. case DISPATCH_PROCESS_WORKING_STORE://流程完成
  352. {
  353. //调度控制存车
  354. m_result = dispatch_control_motion_store();
  355. if ( m_result ==Error_code::SUCCESS)
  356. {
  357. //流程正常, 就进入完成状态,
  358. m_dispatch_process_status = DISPATCH_PROCESS_OVER;
  359. break;
  360. }
  361. else if ( m_result !=Error_code::NODATA )
  362. {
  363. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  364. break;
  365. }
  366. //else nodata, 就表示没有新的指令, 那么什么都不做, 原地待命
  367. break;
  368. }
  369. case DISPATCH_PROCESS_OVER://流程完成
  370. {
  371. //发送调度答复, 发给主控的
  372. m_result = send_dispatch_response_msg();
  373. if ( m_result !=Error_code::SUCCESS)
  374. {
  375. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  376. break;
  377. }
  378. //流程正常, 就进入等待状态, 等待调度控制发送动作指令
  379. m_dispatch_process_status = DISPATCH_PROCESS_RELEASE;
  380. break;
  381. }
  382. case DISPATCH_PROCESS_RELEASE://流程释放
  383. {
  384. //通知调度管理, 释放资源,
  385. m_result = release_resource();
  386. if ( m_result !=Error_code::SUCCESS)
  387. {
  388. m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
  389. break;
  390. }
  391. //在这里, 整个流程彻底结束, 之后线程池会自动回收 这个流程对象的资源
  392. return;
  393. break;
  394. }
  395. case DISPATCH_PROCESS_FAULT://故障
  396. {
  397. release_resource();
  398. Exception_handling();
  399. //在这里, 整个流程彻底结束, 之后线程池会自动回收 这个流程对象的资源
  400. return;
  401. break;
  402. }
  403. default:
  404. {
  405. break;
  406. }
  407. }
  408. }
  409. //任务超时
  410. LOG(INFO) << " Dispatch_process::Main() time out "<< this;
  411. return;
  412. }
  413. //检查调度请求
  414. Error_manager Dispatch_process::check_dispatch_request_msg()
  415. {
  416. // std::unique_lock<std::mutex> t_lock(m_lock);
  417. return Error_code::SUCCESS;
  418. }
  419. //等待资源分配
  420. Error_manager Dispatch_process::wait_resource_allocation()
  421. {
  422. //只判断搬运器的指针是否有效.
  423. if ( m_dispatch_carrier_node.mp_main_carrier.get() == NULL )
  424. {
  425. return Error_code::NODATA;
  426. }
  427. else
  428. {
  429. return Error_code::SUCCESS;
  430. }
  431. }
  432. //调度控制取车
  433. Error_manager Dispatch_process::dispatch_control_motion_pickup()
  434. {
  435. std::unique_lock<std::mutex> t_lock(m_lock);
  436. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  437. Error_manager t_carrier_error;
  438. Carrier * tp_main_carrier = NULL;
  439. Carrier_task * tp_main_carrier_task = NULL;
  440. if ( m_dispatch_carrier_node.mp_main_carrier.get() != NULL && m_dispatch_carrier_node.mp_main_carrier_task.get() != NULL )
  441. {
  442. tp_main_carrier = (Carrier *)m_dispatch_carrier_node.mp_main_carrier.get();
  443. tp_main_carrier_task = (Carrier_task *)m_dispatch_carrier_node.mp_main_carrier_task.get();
  444. }
  445. Catcher * tp_avoid_catcher = NULL;
  446. Catcher_task * tp_avoid_catcher_task = NULL;
  447. if ( m_dispatch_carrier_node.mp_avoid_catcher.get() != NULL && m_dispatch_carrier_node.mp_avoid_catcher_task.get() != NULL )
  448. {
  449. tp_avoid_catcher = (Catcher *)m_dispatch_carrier_node.mp_avoid_catcher.get();
  450. tp_avoid_catcher_task = (Catcher_task *)m_dispatch_carrier_node.mp_avoid_catcher_task.get();
  451. }
  452. //搬运器的控制动作
  453. switch ( m_dispatch_carrier_node.m_dispatch_control_status )
  454. {
  455. case DISPATCH_CONTROL_CREATED:
  456. case DISPATCH_CONTROL_READY:
  457. {
  458. m_dispatch_carrier_node.m_error = check_main_carrier(m_dispatch_carrier_node);
  459. if ( m_dispatch_carrier_node.m_error == Error_code::SUCCESS )
  460. {
  461. if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_PICKUP )
  462. {
  463. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CARRIER_PICKUP_START;
  464. }
  465. else if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_STORE )
  466. {
  467. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CARRIER_STORE_START;
  468. }
  469. }
  470. //else 原地等待
  471. break;
  472. }
  473. case DISPATCH_CARRIER_PICKUP_START://连接搬运器, 创建新的任务单 与设备建立连接
  474. {
  475. //连接搬运器, 创建新的任务单 与设备建立连接, 只能成功, 失败就要进入故障处理
  476. m_dispatch_carrier_node.m_error = m_dispatch_carrier_node.mp_main_carrier->check_task_level(Dispatch_device_base::Dispatch_task_level::DISPATCH_TASK_ONE_LEVEL);
  477. if ( m_dispatch_carrier_node.m_error == Error_code::SUCCESS )
  478. {
  479. m_dispatch_carrier_node.m_error = connect_dispatch_carrier(m_dispatch_carrier_node.mp_main_carrier, m_dispatch_carrier_node.mp_main_carrier_task, Dispatch_device_base::Dispatch_task_level::DISPATCH_TASK_ONE_LEVEL);
  480. if ( m_dispatch_carrier_node.m_error == Error_code::SUCCESS )
  481. {
  482. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  483. }
  484. else
  485. {
  486. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_FAULT;
  487. }
  488. }
  489. else
  490. {
  491. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_FAULT;
  492. }
  493. break;
  494. }
  495. case DISPATCH_CARRIER_PICKUP_1:
  496. {
  497. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  498. break;
  499. }
  500. case DISPATCH_CARRIER_PICKUP_2://搬运器 准备开始, 需要同步任务单和设备真实数据
  501. {
  502. //搬运器 准备开始, 需要同步任务单和设备真实数据.//注意了:连接设备只是预约, 设备不一定立刻执行.所以需要在连接成功之后进行数据同步
  503. carrier_ready_to_start(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates);
  504. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  505. break;
  506. }
  507. case DISPATCH_CARRIER_PICKUP_3:
  508. {
  509. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  510. break;
  511. }
  512. case DISPATCH_CARRIER_PICKUP_4://检查姿态 //搬运器调整到 正常待机的姿态(调节夹杆和轴距)
  513. {
  514. if ( tp_main_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  515. {
  516. if ( tp_main_carrier_task->m_request_clamp_motion == Carrier_task::Clamp_motion::E_CLAMP_LOOSE &&
  517. Common_data::approximate_difference(m_wheel_base, tp_main_carrier->m_actual_y1-tp_main_carrier->m_actual_y2, DISPATCH_DEFAULT_DIFFERENCE))
  518. {
  519. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+2);
  520. }
  521. else
  522. {
  523. //搬运器调整到 正常待机的姿态(调节夹杆和轴距)
  524. carrier_adjust_to_ready(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates);
  525. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  526. }
  527. }
  528. else
  529. {
  530. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_FAULT;
  531. m_dispatch_carrier_node.m_error = Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  532. "tp_carrier->m_actual_load_status != Dispatch_device_base::Load_status::NO_CAR fun error ");
  533. }
  534. break;
  535. }
  536. case DISPATCH_CARRIER_PICKUP_5:
  537. {
  538. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  539. break;
  540. }
  541. case DISPATCH_CARRIER_PICKUP_6://让小跑车回到中跑车上, y轴移动
  542. {
  543. if ( Common_data::approximate_difference(tp_main_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, DISPATCH_DEFAULT_DIFFERENCE) )
  544. {
  545. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+2);
  546. }
  547. else
  548. {
  549. carrier_move_y(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  550. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  551. }
  552. break;
  553. }
  554. case DISPATCH_CARRIER_PICKUP_7:
  555. {
  556. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  557. break;
  558. }
  559. case DISPATCH_CARRIER_PICKUP_8://让中跑车回到电梯井, 进行x轴路径检查
  560. {
  561. float t_z = tp_dispatch_coordinates->m_carrier_coordinates[m_parkspace_information_optimal.parkingspace_index_id].z;
  562. if ( Common_data::approximate_difference(tp_main_carrier->m_actual_z, t_z, DISPATCH_DEFAULT_DIFFERENCE) )
  563. {
  564. //直接到 20步 , 准备同层移动到车位
  565. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status::DISPATCH_CARRIER_PICKUP_20);
  566. }
  567. else
  568. {
  569. //如果是3楼, 直接报错, 因为3楼搬运器只能在3楼移动, z轴真实值和目标值 一定是相同的
  570. if ( tp_main_carrier->get_device_id() !=0 && tp_main_carrier->get_device_id() !=1 )
  571. {
  572. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_FAULT;
  573. m_dispatch_carrier_node.m_error = Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  574. " tp_main_carrier->get_device_id() PARAMRTER ERROR ");
  575. }
  576. else
  577. {
  578. int t_avoid_catcher_id = -1; //需要避让的机器人
  579. //空间锁判断, 是否需要机器人避让
  580. if ( tp_main_carrier->get_device_id() == 0 )
  581. {
  582. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->carrier_try_space_lock(tp_main_carrier->m_actual_coordinates_rows, 0,
  583. tp_main_carrier->m_actual_coordinates_rows, tp_main_carrier->m_actual_coordinates_columns,
  584. tp_main_carrier->get_device_id(), t_avoid_catcher_id);
  585. }
  586. else if ( tp_main_carrier->get_device_id() == 1 )
  587. {
  588. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->carrier_try_space_lock(tp_main_carrier->m_actual_coordinates_rows, tp_main_carrier->m_actual_coordinates_columns,
  589. tp_main_carrier->m_actual_coordinates_rows, tp_dispatch_coordinates->m_space_lock_columns,
  590. tp_main_carrier->get_device_id(), t_avoid_catcher_id);
  591. }
  592. //判断结果
  593. if ( m_dispatch_carrier_node.m_error == Error_code::SUCCESS )
  594. {
  595. //成功则直接跳转到 13步, 不用避让, 直接控制搬运器直到电梯井
  596. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status::DISPATCH_CARRIER_PICKUP_13);
  597. }
  598. else if(t_avoid_catcher_id != -1)
  599. {
  600. //连接避让设备 使得避让机器人进行避让
  601. m_dispatch_carrier_node.m_error = m_dispatch_carrier_node.mp_avoid_catcher->check_task_level(Dispatch_device_base::Dispatch_task_level::DISPATCH_TASK_TWO_LEVEL);
  602. if ( m_dispatch_catcher_node.m_error == Error_code::SUCCESS )
  603. {
  604. m_dispatch_catcher_node.m_error = connect_dispatch_catcher(m_dispatch_carrier_node.mp_avoid_catcher, m_dispatch_carrier_node.mp_avoid_catcher_task, Dispatch_device_base::Dispatch_task_level::DISPATCH_TASK_TWO_LEVEL);
  605. if ( m_dispatch_catcher_node.m_error == Error_code::SUCCESS )
  606. {
  607. m_dispatch_catcher_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_catcher_node.m_dispatch_control_status+1);
  608. }
  609. }
  610. //else 抓取器的资源自由争抢, 如果没有抢到, 那么重复连接
  611. }
  612. else
  613. {
  614. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_FAULT;
  615. m_dispatch_carrier_node.m_error = Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  616. " carrier_try_space_lock fun ERROR ");
  617. }
  618. }
  619. }
  620. break;
  621. }
  622. case DISPATCH_CARRIER_PICKUP_9:
  623. {
  624. check_task_status(m_dispatch_carrier_node.mp_avoid_catcher_task, m_dispatch_carrier_node.m_dispatch_control_status);
  625. break;
  626. }
  627. case DISPATCH_CARRIER_PICKUP_10://机器人避让到最高点, 机器人上升不需要判断空间锁
  628. {
  629. catcher_move_z(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_avoid_catcher, tp_avoid_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  630. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  631. break;
  632. }
  633. case DISPATCH_CARRIER_PICKUP_11://机器人释放 空间锁
  634. {
  635. m_dispatch_catcher_node.m_error = check_task_status(m_dispatch_carrier_node.mp_avoid_catcher_task, m_dispatch_carrier_node.m_dispatch_control_status);
  636. if ( m_dispatch_catcher_node.m_error == Error_code::SUCCESS )
  637. {
  638. tp_dispatch_coordinates->catcher_space_unlock(tp_avoid_catcher->m_actual_coordinates_id, tp_avoid_catcher->get_device_id());
  639. }
  640. break;
  641. }
  642. case DISPATCH_CARRIER_PICKUP_12://空间锁判断, 必须成功
  643. {
  644. int t_avoid_catcher_id = -1; //需要避让的机器人
  645. if ( tp_main_carrier->get_device_id() == 0 )
  646. {
  647. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->carrier_try_space_lock(tp_main_carrier->m_actual_coordinates_rows, 0,
  648. tp_main_carrier->m_actual_coordinates_rows, tp_main_carrier->m_actual_coordinates_columns,
  649. tp_main_carrier->get_device_id(), t_avoid_catcher_id);
  650. }
  651. else if ( tp_main_carrier->get_device_id() == 1 )
  652. {
  653. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->carrier_try_space_lock(tp_main_carrier->m_actual_coordinates_rows, tp_main_carrier->m_actual_coordinates_columns,
  654. tp_main_carrier->m_actual_coordinates_rows, tp_dispatch_coordinates->m_space_lock_columns,
  655. tp_main_carrier->get_device_id(), t_avoid_catcher_id);
  656. }
  657. //判断结果
  658. if ( m_dispatch_carrier_node.m_error == Error_code::SUCCESS )
  659. {
  660. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  661. }
  662. else
  663. {
  664. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_FAULT;
  665. }
  666. break;
  667. }
  668. case DISPATCH_CARRIER_PICKUP_13://让中跑车回到电梯井, x轴移动
  669. {
  670. if ( tp_main_carrier->get_device_id() == 0 )
  671. {
  672. carrier_move_x(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  673. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  674. }
  675. else if ( tp_main_carrier->get_device_id() == 1 )
  676. {
  677. carrier_move_x(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  678. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  679. }
  680. else
  681. {
  682. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_FAULT;
  683. m_dispatch_carrier_node.m_error = Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  684. " tp_main_carrier->get_device_id() PARAMRTER ERROR ");
  685. }
  686. break;
  687. }
  688. case DISPATCH_CARRIER_PICKUP_14://搬运器 释放空间锁
  689. {
  690. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  691. if ( m_dispatch_catcher_node.m_error == Error_code::SUCCESS )
  692. {
  693. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->carrier_space_unlock(tp_main_carrier->get_device_id());
  694. }
  695. break;
  696. }
  697. case DISPATCH_CARRIER_PICKUP_15://避让机器人 断连
  698. {
  699. if ( m_dispatch_carrier_node.mp_avoid_catcher.get() != NULL && m_dispatch_carrier_node.mp_avoid_catcher_task.get() != NULL )
  700. {
  701. disconnect_dispatch_device(m_dispatch_carrier_node.mp_avoid_catcher, m_dispatch_carrier_node.mp_avoid_catcher_task);
  702. }
  703. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  704. break;
  705. }
  706. case DISPATCH_CARRIER_PICKUP_16://收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  707. {
  708. carrier_joint_x(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  709. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  710. break;
  711. }
  712. case DISPATCH_CARRIER_PICKUP_17:
  713. {
  714. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  715. break;
  716. }
  717. case DISPATCH_CARRIER_PICKUP_18: //电梯移动到对应的楼层, 搬运器在电梯里面z轴移动, 不需要判断空间锁
  718. {
  719. float t_z = tp_dispatch_coordinates->m_carrier_coordinates[m_parkspace_information_optimal.parkingspace_index_id].z;
  720. carrier_move_z(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, t_z);
  721. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  722. break;
  723. }
  724. case DISPATCH_CARRIER_PICKUP_19:
  725. {
  726. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  727. break;
  728. }
  729. case DISPATCH_CARRIER_PICKUP_20://伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  730. {
  731. if ( tp_main_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK )
  732. {
  733. carrier_joint_x(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  734. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  735. }
  736. else
  737. {
  738. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+2);
  739. }
  740. break;
  741. }
  742. case DISPATCH_CARRIER_PICKUP_21:
  743. {
  744. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  745. break;
  746. }
  747. case DISPATCH_CARRIER_PICKUP_22://中跑车 x轴移动, 进行x轴路径检查
  748. {
  749. float t_x = tp_dispatch_coordinates->m_carrier_coordinates[m_parkspace_information_optimal.parkingspace_index_id].x;
  750. float t_column = (m_parkspace_information_optimal.parkingspace_index_id-1) % tp_dispatch_coordinates->m_space_lock_columns;
  751. if ( Common_data::approximate_difference(tp_main_carrier->m_actual_x, t_x, DISPATCH_DEFAULT_DIFFERENCE) )
  752. {
  753. //搬运器不用x轴运动, 直接到29步, 去车位取车
  754. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status::DISPATCH_CARRIER_PICKUP_29);
  755. }
  756. else
  757. {
  758. int t_avoid_catcher_id = -1; //需要避让的机器人
  759. if ( tp_main_carrier->get_device_id() == 0 && t_column <13-1)
  760. {
  761. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->carrier_try_space_lock(tp_main_carrier->m_actual_coordinates_rows, tp_main_carrier->m_actual_coordinates_columns,
  762. tp_main_carrier->m_actual_coordinates_rows, t_column+1,
  763. tp_main_carrier->get_device_id(), t_avoid_catcher_id);
  764. }
  765. else if ( tp_main_carrier->get_device_id() == 1 && t_column >3-1)
  766. {
  767. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->carrier_try_space_lock(tp_main_carrier->m_actual_coordinates_rows, t_column-1,
  768. tp_main_carrier->m_actual_coordinates_rows, tp_main_carrier->m_actual_coordinates_columns,
  769. tp_main_carrier->get_device_id(), t_avoid_catcher_id);
  770. }
  771. else if ( tp_main_carrier->get_device_id() == 2 )
  772. {
  773. //3楼搬运器不用加锁, 直接x轴移动
  774. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status::DISPATCH_CARRIER_PICKUP_27);
  775. break;//切换流程
  776. }
  777. else
  778. {
  779. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_FAULT;
  780. m_dispatch_carrier_node.m_error = Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  781. " tp_main_carrier->get_device_id() and m_parkspace_information_optimal.parkingspace_index_id PARAMRTER ERROR ");
  782. break;//切换流程
  783. }
  784. //判断结果
  785. if ( m_dispatch_carrier_node.m_error == Error_code::SUCCESS )
  786. {
  787. //左右搬运器加锁成功, 直接x轴移动
  788. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status::DISPATCH_CARRIER_PICKUP_27);
  789. }
  790. else if(t_avoid_catcher_id != -1 && tp_main_carrier->m_actual_coordinates_rows == 2)//4楼取车, 机器人进行避让
  791. {
  792. //连接避让设备 使得避让机器人进行避让
  793. m_dispatch_carrier_node.m_error = m_dispatch_carrier_node.mp_avoid_catcher->check_task_level(Dispatch_device_base::Dispatch_task_level::DISPATCH_TASK_TWO_LEVEL);
  794. if ( m_dispatch_catcher_node.m_error == Error_code::SUCCESS )
  795. {
  796. m_dispatch_catcher_node.m_error = connect_dispatch_catcher(m_dispatch_carrier_node.mp_avoid_catcher, m_dispatch_carrier_node.mp_avoid_catcher_task, Dispatch_device_base::Dispatch_task_level::DISPATCH_TASK_TWO_LEVEL);
  797. if ( m_dispatch_catcher_node.m_error == Error_code::SUCCESS )
  798. {
  799. m_dispatch_catcher_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_catcher_node.m_dispatch_control_status+1);
  800. }
  801. }
  802. //else 抓取器的资源自由争抢, 如果没有抢到, 那么重复连接
  803. }
  804. //else 无限等待
  805. }
  806. break;
  807. }
  808. case DISPATCH_CARRIER_PICKUP_23:
  809. {
  810. check_task_status(m_dispatch_carrier_node.mp_avoid_catcher_task, m_dispatch_carrier_node.m_dispatch_control_status);
  811. break;
  812. }
  813. case DISPATCH_CARRIER_PICKUP_24://让4楼机器人进行避让, 先加锁, 在避让
  814. {
  815. if ( tp_main_carrier->get_device_id() == 0 )
  816. {
  817. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->catcher_try_space_lock(tp_main_carrier->m_actual_coordinates_rows, tp_avoid_catcher->m_actual_coordinates_columns,
  818. tp_main_carrier->m_actual_coordinates_rows, 14-1,
  819. tp_avoid_catcher->get_device_id());
  820. //判断结果
  821. if ( m_dispatch_carrier_node.m_error == Error_code::SUCCESS )
  822. {
  823. float t_x = tp_dispatch_coordinates->m_carrier_coordinates[42].x;
  824. catcher_move_x(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_avoid_catcher, tp_avoid_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  825. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  826. }
  827. //else 无限等待
  828. }
  829. else if ( tp_main_carrier->get_device_id() == 1 )
  830. {
  831. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->catcher_try_space_lock(tp_main_carrier->m_actual_coordinates_rows, 2-1,
  832. tp_main_carrier->m_actual_coordinates_rows, tp_avoid_catcher->m_actual_coordinates_columns,
  833. tp_avoid_catcher->get_device_id());
  834. //判断结果
  835. if ( m_dispatch_carrier_node.m_error == Error_code::SUCCESS )
  836. {
  837. float t_x = tp_dispatch_coordinates->m_carrier_coordinates[34].x;
  838. catcher_move_x(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_avoid_catcher, tp_avoid_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  839. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  840. }
  841. //else 无限等待
  842. }
  843. break;
  844. }
  845. case DISPATCH_CARRIER_PICKUP_25://机器人释放 空间锁
  846. {
  847. check_task_status(m_dispatch_carrier_node.mp_avoid_catcher_task, m_dispatch_carrier_node.m_dispatch_control_status);
  848. if ( m_dispatch_catcher_node.m_error == Error_code::SUCCESS )
  849. {
  850. tp_dispatch_coordinates->catcher_space_unlock(tp_avoid_catcher->m_actual_coordinates_id, tp_avoid_catcher->get_device_id());
  851. }
  852. break;
  853. }
  854. case DISPATCH_CARRIER_PICKUP_26://空间锁判断, 必须成功
  855. {
  856. float t_column = (m_parkspace_information_optimal.parkingspace_index_id-1) % tp_dispatch_coordinates->m_space_lock_columns;
  857. int t_avoid_catcher_id = -1; //需要避让的机器人
  858. if ( tp_main_carrier->get_device_id() == 0 && t_column <13-1)
  859. {
  860. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->carrier_try_space_lock(tp_main_carrier->m_actual_coordinates_rows, tp_main_carrier->m_actual_coordinates_columns,
  861. tp_main_carrier->m_actual_coordinates_rows, t_column+1,
  862. tp_main_carrier->get_device_id(), t_avoid_catcher_id);
  863. }
  864. else if ( tp_main_carrier->get_device_id() == 1 && t_column >3-1)
  865. {
  866. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->carrier_try_space_lock(tp_main_carrier->m_actual_coordinates_rows, t_column-1,
  867. tp_main_carrier->m_actual_coordinates_rows, tp_main_carrier->m_actual_coordinates_columns,
  868. tp_main_carrier->get_device_id(), t_avoid_catcher_id);
  869. }
  870. //判断结果
  871. if ( m_dispatch_carrier_node.m_error == Error_code::SUCCESS )
  872. {
  873. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  874. }
  875. else
  876. {
  877. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CONTROL_FAULT;
  878. }
  879. break;
  880. }
  881. case DISPATCH_CARRIER_PICKUP_27://搬运器x轴移动到车位
  882. {
  883. float t_x = tp_dispatch_coordinates->m_carrier_coordinates[m_parkspace_information_optimal.parkingspace_index_id].x;
  884. carrier_move_x(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, t_x);
  885. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  886. break;
  887. }
  888. case DISPATCH_CARRIER_PICKUP_28:
  889. {
  890. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  891. break;
  892. }
  893. case DISPATCH_CARRIER_PICKUP_29://小跑车 进入车位
  894. {
  895. carrier_move_y(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_leave);
  896. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  897. break;
  898. }
  899. case DISPATCH_CARRIER_PICKUP_30:
  900. {
  901. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  902. break;
  903. }
  904. case DISPATCH_CARRIER_PICKUP_31://小跑车 夹车
  905. {
  906. carrier_move_c(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_TIGHT);
  907. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  908. break;
  909. }
  910. case DISPATCH_CARRIER_PICKUP_32:
  911. {
  912. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  913. break;
  914. }
  915. case DISPATCH_CARRIER_PICKUP_33://小跑车 回到中跑车
  916. {
  917. carrier_move_y(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  918. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  919. break;
  920. }
  921. case DISPATCH_CARRIER_PICKUP_34:
  922. {
  923. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  924. break;
  925. }
  926. case DISPATCH_CARRIER_PICKUP_35://让中跑车回到电梯井
  927. {
  928. //如果不在2楼, 那么就要退回电梯井
  929. if ( tp_main_carrier->get_device_id() == 0 && tp_main_carrier->m_actual_coordinates_rows != 0)
  930. {
  931. carrier_move_x(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  932. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  933. }
  934. else if ( tp_main_carrier->get_device_id() == 1 && tp_main_carrier->m_actual_coordinates_rows != 0 )
  935. {
  936. carrier_move_x(get_dispatch_control_command_key(m_dispatch_carrier_node), tp_main_carrier, tp_main_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  937. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+1);
  938. }
  939. else
  940. {
  941. m_dispatch_carrier_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_carrier_node.m_dispatch_control_status+999);
  942. }
  943. break;
  944. }
  945. case DISPATCH_CARRIER_PICKUP_36://搬运器 释放空间锁
  946. {
  947. check_task_status(m_dispatch_carrier_node.mp_main_carrier_task, m_dispatch_carrier_node.m_dispatch_control_status);
  948. if ( m_dispatch_catcher_node.m_error == Error_code::SUCCESS )
  949. {
  950. m_dispatch_carrier_node.m_error = tp_dispatch_coordinates->carrier_space_unlock(tp_main_carrier->get_device_id());
  951. }
  952. break;
  953. }
  954. default:
  955. {
  956. break;
  957. }
  958. }
  959. Error_manager t_catcher_error;
  960. Catcher * tp_main_catcher = NULL;
  961. Catcher_task * tp_main_catcher_task = NULL;
  962. if ( m_dispatch_catcher_node.mp_main_catcher.get() != NULL && m_dispatch_catcher_node.mp_main_catcher_task.get() != NULL )
  963. {
  964. tp_main_catcher = (Catcher *)m_dispatch_catcher_node.mp_main_catcher.get();
  965. tp_main_catcher_task = (Catcher_task *)m_dispatch_catcher_node.mp_main_catcher_task.get();
  966. }
  967. //抓取器的控制动作
  968. switch ( m_dispatch_catcher_node.m_dispatch_control_status )
  969. {
  970. case DISPATCH_CONTROL_CREATED:
  971. case DISPATCH_CONTROL_READY:
  972. {
  973. m_dispatch_catcher_node.m_error = check_main_catcher(m_dispatch_catcher_node);
  974. if ( m_dispatch_catcher_node.m_error == Error_code::SUCCESS )
  975. {
  976. if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_PICKUP )
  977. {
  978. m_dispatch_catcher_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CATCHER_PICKUP_START;
  979. }
  980. else if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_STORE )
  981. {
  982. m_dispatch_catcher_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CATCHER_STORE_START;
  983. }
  984. }
  985. //else 原地等待
  986. break;
  987. }
  988. case DISPATCH_CATCHER_PICKUP_START:
  989. {
  990. m_dispatch_catcher_node.m_error = connect_dispatch_catcher(m_dispatch_catcher_node.mp_main_catcher, m_dispatch_catcher_node.mp_main_catcher_task, Dispatch_device_base::Dispatch_task_level::DISPATCH_TASK_ONE_LEVEL);
  991. if ( m_dispatch_catcher_node.m_error == Error_code::SUCCESS )
  992. {
  993. m_dispatch_catcher_node.m_dispatch_control_status = (Dispatch_process::Dispatch_control_status)(m_dispatch_catcher_node.m_dispatch_control_status+1);
  994. }
  995. //else 抓取器的资源自由争抢, 如果没有抢到, 那么重复连接
  996. break;
  997. }
  998. default:
  999. {
  1000. break;
  1001. }
  1002. }
  1003. }
  1004. //调度控制存车
  1005. Error_manager Dispatch_process::dispatch_control_motion_store()
  1006. {
  1007. Error_manager t_error;
  1008. std::unique_lock<std::mutex> t_lock(m_lock);
  1009. //搬运器的控制动作
  1010. switch ( m_dispatch_catcher_node.m_dispatch_control_status )
  1011. {
  1012. case DISPATCH_CONTROL_CREATED:
  1013. case DISPATCH_CONTROL_READY:
  1014. {
  1015. ;
  1016. break;
  1017. }
  1018. case DISPATCH_CONTROL_CONNECT_DEVICE:
  1019. {
  1020. ;
  1021. break;
  1022. }
  1023. default:
  1024. {
  1025. break;
  1026. }
  1027. }
  1028. //抓取器的控制动作
  1029. switch ( m_dispatch_catcher_node.m_dispatch_control_status )
  1030. {
  1031. case DISPATCH_CONTROL_CREATED:
  1032. case DISPATCH_CONTROL_READY:
  1033. {
  1034. ;
  1035. break;
  1036. }
  1037. case DISPATCH_CONTROL_CONNECT_DEVICE:
  1038. {
  1039. ;
  1040. break;
  1041. }
  1042. default:
  1043. {
  1044. break;
  1045. }
  1046. }
  1047. }
  1048. //检查核心搬运器
  1049. Error_manager Dispatch_process::check_main_carrier(Dispatch_carrier_node & dispatch_carrier_node)
  1050. {
  1051. //只判断搬运器的指针是否有效.
  1052. if ( dispatch_carrier_node.mp_main_carrier.get() != NULL )
  1053. {
  1054. if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_PICKUP )
  1055. {
  1056. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CARRIER_PICKUP_START;
  1057. }
  1058. else if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_STORE )
  1059. {
  1060. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CARRIER_STORE_START;
  1061. }
  1062. return Error_code::SUCCESS;
  1063. }
  1064. else
  1065. {
  1066. return Error_code::NODATA;
  1067. }
  1068. }
  1069. //检查核心抓取器
  1070. Error_manager Dispatch_process::check_main_catcher(Dispatch_catcher_node & dispatch_catcher_node)
  1071. {
  1072. //只判断搬 调度设备机器人启动标志位
  1073. if ( dispatch_catcher_node.m_dispatch_control_start_flag )
  1074. {
  1075. //为抓取器分配对应的设备, 目前只有2号机器人
  1076. if ( dispatch_catcher_node.mp_main_catcher.get() ==NULL )
  1077. {
  1078. dispatch_catcher_node.mp_main_catcher = Dispatch_manager::get_instance_references().m_catcher_map[1];
  1079. }
  1080. if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_PICKUP )
  1081. {
  1082. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CATCHER_PICKUP_START;
  1083. }
  1084. else if ( m_dispatch_process_type == Common_data::Dispatch_process_type::DISPATCH_PROCESS_STORE )
  1085. {
  1086. m_dispatch_carrier_node.m_dispatch_control_status = Dispatch_process::Dispatch_control_status::DISPATCH_CATCHER_STORE_START;
  1087. }
  1088. return Error_code::SUCCESS;
  1089. }
  1090. else
  1091. {
  1092. return Error_code::NODATA;
  1093. }
  1094. }
  1095. //连接搬运器, 创建新的任务单 与设备建立连接, 只能成功, 失败就要进入故障处理
  1096. Error_manager Dispatch_process::connect_dispatch_carrier(std::shared_ptr<Dispatch_device_base> & p_carrier, std::shared_ptr<Task_Base> & p_carrier_task, Dispatch_device_base::Dispatch_task_level dispatch_task_level)
  1097. {
  1098. Error_manager t_error;
  1099. if ( p_carrier.get() != NULL )
  1100. {
  1101. Carrier* tp_carrier = (Carrier*)p_carrier.get();
  1102. //检查设备能否执行任务, 主搬运器是管理层分配好的, 一般是可以直接连接.
  1103. t_error = tp_carrier->check_task_level(dispatch_task_level);
  1104. if ( t_error == Error_code::SUCCESS )
  1105. {
  1106. //创建任务单
  1107. p_carrier_task = std::shared_ptr<Task_Base>(new Carrier_task);
  1108. p_carrier_task->task_init(NULL,std::chrono::milliseconds(15000));
  1109. Carrier_task * tp_carrier_task = (Carrier_task *)p_carrier_task.get();
  1110. //第一次发送 空的唯一码, 可以和设备建立联系
  1111. tp_carrier_task->m_request_key = "";
  1112. tp_carrier_task->m_request_x = tp_carrier->m_actual_x;
  1113. tp_carrier_task->m_request_y = tp_carrier->m_actual_y;
  1114. tp_carrier_task->m_request_z = tp_carrier->m_actual_z;
  1115. tp_carrier_task->m_request_y1 = tp_carrier->m_actual_y1;
  1116. tp_carrier_task->m_request_y2 = tp_carrier->m_actual_y2;
  1117. tp_carrier_task->m_request_clamp_motion = (Carrier_task::Clamp_motion)tp_carrier->m_actual_clamp_motion1;
  1118. tp_carrier_task->m_request_joint_motion_x = (Carrier_task::Joint_motion)tp_carrier->m_actual_joint_motion_x1;
  1119. tp_carrier_task->m_request_joint_motion_y = Carrier_task::Joint_motion::E_JOINT_NO_ACTION;
  1120. tp_carrier_task->m_request_space_id = 0;
  1121. tp_carrier_task->m_request_floor_id = 0;
  1122. tp_carrier_task->m_request_wheelbase = Dispatch_coordinates::get_instance_references().m_default_wheelbase;
  1123. t_error = tp_carrier->execute_task(p_carrier_task, dispatch_task_level);
  1124. }
  1125. }
  1126. else
  1127. {
  1128. t_error.error_manager_reset(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1129. " Dispatch_process::connect_dispatch_carrier() POINTER IS NULL ");
  1130. }
  1131. return t_error;
  1132. }
  1133. //连接抓取器, 创建新的任务单 与设备建立连接, 可以失败, 失败就重新执行
  1134. Error_manager Dispatch_process::connect_dispatch_catcher(std::shared_ptr<Dispatch_device_base> & p_catcher, std::shared_ptr<Task_Base> & p_catcher_task, Dispatch_device_base::Dispatch_task_level dispatch_task_level)
  1135. {
  1136. Error_manager t_error;
  1137. if ( p_catcher.get() != NULL )
  1138. {
  1139. Catcher* tp_catcher = (Catcher*)p_catcher.get();
  1140. //检查设备能否执行任务, 主抓取器是需要调度流程去争抢的.
  1141. t_error = tp_catcher->check_task_level(dispatch_task_level);
  1142. if ( t_error == Error_code::SUCCESS )
  1143. {
  1144. //创建任务单
  1145. p_catcher_task = std::shared_ptr<Task_Base>(new Catcher_task);
  1146. p_catcher_task->task_init(NULL,std::chrono::milliseconds(15000));
  1147. Catcher_task * tp_catcher_task = (Catcher_task *)p_catcher_task.get();
  1148. //第一次发送 空的唯一码, 可以和设备建立联系
  1149. tp_catcher_task->m_request_key = "";
  1150. tp_catcher_task->m_request_x = tp_catcher->m_actual_x;
  1151. tp_catcher_task->m_request_y = tp_catcher->m_actual_y;
  1152. tp_catcher_task->m_request_b = tp_catcher->m_actual_b;
  1153. tp_catcher_task->m_request_z = tp_catcher->m_actual_z;
  1154. tp_catcher_task->m_request_d1 = tp_catcher->m_actual_d1;
  1155. tp_catcher_task->m_request_d2 = tp_catcher->m_actual_d2;
  1156. tp_catcher_task->m_request_wheelbase = Dispatch_coordinates::get_instance_references().m_default_wheelbase;
  1157. tp_catcher_task->m_request_clamp_motion = (Catcher_task::Clamp_motion)tp_catcher->m_actual_clamp_motion1;
  1158. t_error = tp_catcher->execute_task(m_dispatch_catcher_node.mp_main_catcher_task, dispatch_task_level);
  1159. }
  1160. }
  1161. else
  1162. {
  1163. t_error.error_manager_reset(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1164. " Dispatch_process::connect_dispatch_catcher() POINTER IS NULL ");
  1165. }
  1166. return t_error;
  1167. }
  1168. //断开调度设备, 收回任务单, 释放任务单 与设备解除连接
  1169. Error_manager Dispatch_process::disconnect_dispatch_device(std::shared_ptr<Dispatch_device_base> & p_device, std::shared_ptr<Task_Base> & p_device_task)
  1170. {
  1171. if ( p_device.get() != NULL && p_device_task.get() != NULL )
  1172. {
  1173. p_device_task->set_task_statu(Task_Base::Task_statu::TASK_WITHDRAW);
  1174. p_device.reset();
  1175. p_device_task.reset();
  1176. return Error_code::SUCCESS;
  1177. }
  1178. else
  1179. {
  1180. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1181. " POINTER IS NULL ");
  1182. }
  1183. }
  1184. //发送调度总计划
  1185. Error_manager Dispatch_process::send_dispatch_plan_request_msg()
  1186. {
  1187. std::unique_lock<std::mutex> t_lock(m_lock);
  1188. m_dispatch_plan_request_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_plan_request_msg);
  1189. m_dispatch_plan_request_msg.mutable_base_info()->set_timeout_ms(m_timeout_ms);
  1190. m_dispatch_plan_request_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
  1191. m_dispatch_plan_request_msg.mutable_base_info()->set_receiver(message::Communicator::eDispatch_control);
  1192. m_dispatch_plan_request_msg.set_command_key(m_dispatch_request_msg.command_key());
  1193. m_dispatch_plan_request_msg.set_dispatch_task_type((message::Dispatch_task_type)m_dispatch_process_type);
  1194. m_dispatch_plan_request_msg.set_dispatch_source(m_dispatch_source);
  1195. m_dispatch_plan_request_msg.set_dispatch_destination(m_dispatch_destination);
  1196. //这里不写错误码
  1197. std::string t_msg = m_dispatch_plan_request_msg.SerializeAsString();
  1198. System_communication::get_instance_references().encapsulate_msg(t_msg);
  1199. return Error_code::SUCCESS;
  1200. }
  1201. //执行调度控制指令, 并根据完成情况给答复
  1202. Error_manager Dispatch_process::dispatch_control_motion()
  1203. {
  1204. Error_manager t_error;
  1205. std::unique_lock<std::mutex> t_lock(m_lock);
  1206. // m_result.error_manager_clear_all();
  1207. for (auto iter = m_dispatch_control_node_map.begin(); iter != m_dispatch_control_node_map.end(); ++iter)
  1208. {
  1209. switch ( iter->second.m_dispatch_control_status )
  1210. {
  1211. case DISPATCH_CONTROL_STATUS_UNKNOW:
  1212. case DISPATCH_CONTROL_CREATED:
  1213. case DISPATCH_CONTROL_READY:
  1214. {
  1215. t_error = wait_dispatch_control_request_msg(iter->first, iter->second);
  1216. if ( t_error == Error_code::SUCCESS)
  1217. {
  1218. //流程正常, 就进入完成状态,
  1219. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_CONNECT_DEVICE;
  1220. }
  1221. //else 原地待命
  1222. break;
  1223. }
  1224. case DISPATCH_CONTROL_CONNECT_DEVICE:
  1225. {
  1226. //连接调度设备
  1227. t_error = connect_dispatch_device(iter->first, iter->second);
  1228. if ( t_error !=Error_code::SUCCESS)
  1229. {
  1230. iter->second.m_error = t_error;
  1231. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_RESPONSE;
  1232. }
  1233. else
  1234. {
  1235. //流程正常, 就进入工作状态,
  1236. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_WORKING;
  1237. iter->second.m_time_to_send_control_response = std::chrono::system_clock::now();
  1238. }
  1239. break;
  1240. }
  1241. case DISPATCH_CONTROL_WORKING:
  1242. {
  1243. //执行调度控制指令, 并根据完成情况给答复
  1244. t_error = excute_dispatch_control(iter->first, iter->second);
  1245. if ( t_error == Error_code::NODATA )
  1246. {
  1247. //继续 长流程, 什么也不做
  1248. if ( std::chrono::system_clock::now() - iter->second.m_time_to_send_control_response >= std::chrono::seconds(1) )
  1249. {
  1250. //发送调度控制答复, 发给调度控制的
  1251. t_error = send_dispatch_control_response_msg(iter->first, iter->second, message::E_TASK_WORKING);
  1252. iter->second.m_time_to_send_control_response = std::chrono::system_clock::now();
  1253. }
  1254. }
  1255. else
  1256. {
  1257. //长流程结束, 就答复 control_response_msg
  1258. // 注:这里执行调度控制, 即使报错了 也要答复给调度控制, 交给调度控制来进行决策.
  1259. iter->second.m_error = t_error;
  1260. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_TASK_WITHDRAW;
  1261. }
  1262. break;
  1263. }
  1264. case DISPATCH_CONTROL_TASK_WITHDRAW://流程 收回任务单
  1265. {
  1266. //发送调度控制答复, 发给调度控制的
  1267. t_error = dispatch_control_withdraw_task(iter->first, iter->second);
  1268. //流程正常, 就进入等待状态, 等待调度控制发送动作指令
  1269. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_RESPONSE;
  1270. break;
  1271. }
  1272. case DISPATCH_CONTROL_RESPONSE://流程 给调度控制答复
  1273. {
  1274. //发送调度控制答复, 发给调度控制的
  1275. t_error = send_dispatch_control_response_msg(iter->first, iter->second, message::E_TASK_OVER);
  1276. //流程正常, 就进入等待状态, 等待调度控制发送动作指令
  1277. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_DISCONNECT_DEVICE;
  1278. break;
  1279. }
  1280. case DISPATCH_CONTROL_DISCONNECT_DEVICE://流程 解除设备
  1281. {
  1282. //断开调度设备, 释放任务单 与设备解除连接
  1283. t_error = disconnect_dispatch_device(iter->first, iter->second);
  1284. if ( t_error == Error_code::SUCCESS )
  1285. {
  1286. //流程正常, 就回到 等待状态, 等待调度控制发送动作指令
  1287. iter->second.m_error.error_manager_clear_all();
  1288. iter->second.m_dispatch_control_status = DISPATCH_CONTROL_READY;
  1289. }
  1290. //else 保持不变继续等待
  1291. break;
  1292. }
  1293. default:
  1294. {
  1295. break;
  1296. }
  1297. }
  1298. }
  1299. return Error_code::SUCCESS;
  1300. }
  1301. //等待控制指令
  1302. Error_manager Dispatch_process::wait_dispatch_control_request_msg(int dispatch_device_type, Dispatch_control_node & dispatch_control_node)
  1303. {
  1304. //key不相等 就表示 收到了新的控制指令
  1305. if ( dispatch_control_node.m_dispatch_control_request_msg.command_key() != dispatch_control_node.m_dispatch_control_response_msg.command_key() )
  1306. {
  1307. return Error_code::SUCCESS;
  1308. }
  1309. else
  1310. {
  1311. return Error_code::NODATA;
  1312. }
  1313. return Error_code::SUCCESS;
  1314. }
  1315. //连接调度设备, 创建新的任务单 与设备建立连接
  1316. Error_manager Dispatch_process::connect_dispatch_device(int dispatch_device_type, Dispatch_control_node & dispatch_control_node)
  1317. {
  1318. Error_manager t_error;
  1319. if ( dispatch_device_type == message::Dispatch_device_type::ROBOT_1 ||
  1320. dispatch_device_type == message::Dispatch_device_type::ROBOT_2 )
  1321. {
  1322. //找到对应的设备
  1323. if ( dispatch_device_type == message::Dispatch_device_type::ROBOT_1 )
  1324. {
  1325. dispatch_control_node.mp_dispatch_device = Dispatch_manager::get_instance_references().m_catcher_map[0];
  1326. }
  1327. if ( dispatch_device_type == message::Dispatch_device_type::ROBOT_2 )
  1328. {
  1329. dispatch_control_node.mp_dispatch_device = Dispatch_manager::get_instance_references().m_catcher_map[1];
  1330. }
  1331. Catcher* tp_catcher = (Catcher*)dispatch_control_node.mp_dispatch_device.get();
  1332. //检查设备状态
  1333. if ( tp_catcher->check_status() == Error_code::SUCCESS &&
  1334. tp_catcher->m_actual_device_status == Dispatch_device_base::HARDWARE_DEVICE_READY )
  1335. {
  1336. //创建任务单
  1337. dispatch_control_node.mp_dispatch_task = std::shared_ptr<Task_Base>(new Catcher_task);
  1338. dispatch_control_node.mp_dispatch_task->task_init(NULL,std::chrono::milliseconds(15000));
  1339. Catcher_task * tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  1340. //第一次发送 空的唯一码, 可以和设备建立联系
  1341. tp_catcher_task->m_request_key = "";
  1342. tp_catcher_task->m_request_x = tp_catcher->m_actual_x;
  1343. tp_catcher_task->m_request_y = tp_catcher->m_actual_y;
  1344. tp_catcher_task->m_request_b = tp_catcher->m_actual_b;
  1345. tp_catcher_task->m_request_z = tp_catcher->m_actual_z;
  1346. tp_catcher_task->m_request_d1 = tp_catcher->m_actual_d1;
  1347. tp_catcher_task->m_request_d2 = tp_catcher->m_actual_d2;
  1348. tp_catcher_task->m_request_wheelbase = Dispatch_coordinates::get_instance_references().m_default_wheelbase;
  1349. tp_catcher_task->m_request_clamp_motion = (Catcher_task::Clamp_motion)tp_catcher->m_actual_clamp_motion1;
  1350. t_error = tp_catcher->execute_task(dispatch_control_node.mp_dispatch_task, Dispatch_device_base::DISPATCH_TASK_ONE_LEVEL);
  1351. if ( t_error != Error_code::SUCCESS )
  1352. {
  1353. dispatch_control_node.m_error = t_error;
  1354. return t_error;
  1355. }
  1356. }
  1357. else
  1358. {
  1359. std::cout << " huli test :::: " << " 123123123123123123123 = " << 1233 << std::endl;
  1360. std::cout << " huli test :::: " << " tp_catcher->check_status() = " << tp_catcher->check_status().to_string() << std::endl;
  1361. std::cout << " huli test :::: " << " tp_catcher->m_actual_device_status = " << tp_catcher->m_actual_device_status << std::endl;
  1362. t_error = Error_manager(Error_code::DISPATCH_PROCESS_DEVICE_STATUS_ERROR, Error_level::MINOR_ERROR,
  1363. " tp_catcher->m_actual_device_status device_status error ");
  1364. dispatch_control_node.m_error = t_error;
  1365. return t_error;
  1366. }
  1367. //设置起点
  1368. dispatch_control_node.m_source_coordinates = Dispatch_coordinates::get_instance_references().m_catcher_coordinates[dispatch_control_node.m_dispatch_control_request_msg.dispatch_source()];
  1369. //设置终点
  1370. dispatch_control_node.m_destination_coordinates = Dispatch_coordinates::get_instance_references().m_catcher_coordinates[dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination()];
  1371. std::cout << " huli test :::: " << " ---------------------------------------- = " << 123 << std::endl;
  1372. 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;
  1373. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.x = " << dispatch_control_node.m_destination_coordinates.x << std::endl;
  1374. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.y = " << dispatch_control_node.m_destination_coordinates.y << std::endl;
  1375. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.z = " << dispatch_control_node.m_destination_coordinates.z << std::endl;
  1376. std::cout << " huli test :::: " << "*******************************************" << 123 << std::endl;
  1377. }
  1378. //搬运器的配置 准备工作
  1379. else if ( dispatch_device_type == message::Dispatch_device_type::CARRIER_1 ||
  1380. dispatch_device_type == message::Dispatch_device_type::CARRIER_2 ||
  1381. dispatch_device_type == message::Dispatch_device_type::CARRIER_3 )
  1382. {
  1383. //找到对应的设备
  1384. if ( dispatch_device_type == message::Dispatch_device_type::CARRIER_1 )
  1385. {
  1386. dispatch_control_node.mp_dispatch_device = Dispatch_manager::get_instance_references().m_carrier_map[0];
  1387. }
  1388. if ( dispatch_device_type == message::Dispatch_device_type::CARRIER_2 )
  1389. {
  1390. dispatch_control_node.mp_dispatch_device = Dispatch_manager::get_instance_references().m_carrier_map[1];
  1391. }
  1392. if ( dispatch_device_type == message::Dispatch_device_type::CARRIER_3 )
  1393. {
  1394. dispatch_control_node.mp_dispatch_device = Dispatch_manager::get_instance_references().m_carrier_map[2];
  1395. }
  1396. Carrier* tp_carrier = (Carrier*)dispatch_control_node.mp_dispatch_device.get();
  1397. //检查设备状态
  1398. if ( tp_carrier->check_status() == Error_code::SUCCESS &&
  1399. tp_carrier->m_actual_device_status == Dispatch_device_base::HARDWARE_DEVICE_READY )
  1400. {
  1401. //创建任务单
  1402. dispatch_control_node.mp_dispatch_task = std::shared_ptr<Task_Base>(new Carrier_task);
  1403. dispatch_control_node.mp_dispatch_task->task_init(NULL,std::chrono::milliseconds(15000));
  1404. Carrier_task * tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  1405. //第一次发送 空的唯一码, 可以和设备建立联系
  1406. tp_carrier_task->m_request_key = "";
  1407. tp_carrier_task->m_request_x = tp_carrier->m_actual_x;
  1408. tp_carrier_task->m_request_y = tp_carrier->m_actual_y;
  1409. tp_carrier_task->m_request_z = tp_carrier->m_actual_z;
  1410. tp_carrier_task->m_request_y1 = tp_carrier->m_actual_y1;
  1411. tp_carrier_task->m_request_y2 = tp_carrier->m_actual_y2;
  1412. tp_carrier_task->m_request_clamp_motion = (Carrier_task::Clamp_motion)tp_carrier->m_actual_clamp_motion1;
  1413. tp_carrier_task->m_request_joint_motion_x = (Carrier_task::Joint_motion)tp_carrier->m_actual_joint_motion_x1;
  1414. tp_carrier_task->m_request_joint_motion_y = Carrier_task::Joint_motion::E_JOINT_NO_ACTION;
  1415. tp_carrier_task->m_request_space_id = 0;
  1416. tp_carrier_task->m_request_floor_id = 0;
  1417. tp_carrier_task->m_request_wheelbase = Dispatch_coordinates::get_instance_references().m_default_wheelbase;
  1418. t_error = tp_carrier->execute_task(dispatch_control_node.mp_dispatch_task, Dispatch_device_base::DISPATCH_TASK_ONE_LEVEL);
  1419. if ( t_error != Error_code::SUCCESS )
  1420. {
  1421. dispatch_control_node.m_error = t_error;
  1422. return t_error;
  1423. }
  1424. }
  1425. else
  1426. {
  1427. std::cout << " huli test :::: " << " 123123123123123123123 = " << 4566 << std::endl;
  1428. std::cout << " huli test :::: " << " tp_carrier->check_status() = " << tp_carrier->check_status().to_string() << std::endl;
  1429. std::cout << " huli test :::: " << " tp_carrier->m_actual_device_status = " << tp_carrier->m_actual_device_status << std::endl;
  1430. t_error = Error_manager(Error_code::DISPATCH_PROCESS_DEVICE_STATUS_ERROR, Error_level::MINOR_ERROR,
  1431. " tp_carrier->m_actual_device_status device_status error ");
  1432. dispatch_control_node.m_error = t_error;
  1433. return t_error;
  1434. }
  1435. //设置起点
  1436. dispatch_control_node.m_source_coordinates = Dispatch_coordinates::get_instance_references().m_carrier_coordinates[dispatch_control_node.m_dispatch_control_request_msg.dispatch_source()];
  1437. //设置终点
  1438. dispatch_control_node.m_destination_coordinates = Dispatch_coordinates::get_instance_references().m_carrier_coordinates[dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination()];
  1439. std::cout << " huli test :::: " << " ---------------------------------------- = " << 123 << std::endl;
  1440. 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;
  1441. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.x = " << dispatch_control_node.m_destination_coordinates.x << std::endl;
  1442. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.y = " << dispatch_control_node.m_destination_coordinates.y << std::endl;
  1443. std::cout << " huli test :::: " << " dispatch_control_node.m_destination_coordinates.z = " << dispatch_control_node.m_destination_coordinates.z << std::endl;
  1444. std::cout << " huli test :::: " << "*******************************************" << 123 << std::endl;
  1445. }
  1446. else
  1447. {
  1448. t_error = Error_manager(Error_code::DISPATCH_PROCESS_DEVICE_TYPE_ERROR, Error_level::MINOR_ERROR,
  1449. " DISPATCH_PROCESS_DEVICE_TYPE_ERROR fun error ");
  1450. dispatch_control_node.m_error = t_error;
  1451. return t_error;
  1452. }
  1453. return Error_code::SUCCESS;
  1454. }
  1455. //执行调度控制指令, 并根据完成情况给答复
  1456. Error_manager Dispatch_process::excute_dispatch_control(int dispatch_device_type, Dispatch_control_node & dispatch_control_node)
  1457. {
  1458. Error_manager t_error;
  1459. if ( dispatch_device_type == message::Dispatch_device_type::ROBOT_1 ||
  1460. dispatch_device_type == message::Dispatch_device_type::ROBOT_2 )
  1461. {
  1462. Catcher_task * tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  1463. // while (1)
  1464. // {
  1465. // char in;
  1466. // std::cin >> in ;
  1467. // if ( in == 'p' )
  1468. // {
  1469. // break;
  1470. // }
  1471. // }
  1472. // std::cout << " huli test :::: " << "ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp = " << tp_catcher_task->m_step << std::endl;
  1473. // std::cout << " huli test :::: " << "1111111 tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  1474. //设备的动作也使用外部的Main()的线程来循环
  1475. switch ( dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type() )
  1476. {
  1477. case message::Dispatch_task_type::ROBOT_CATCH_CAR_FROM_INLET:
  1478. {
  1479. t_error = excute_robot_catch_car_from_inlet(dispatch_control_node);
  1480. break;
  1481. }
  1482. case message::Dispatch_task_type::ROBOT_PUT_CAR_TO_CARRIER:
  1483. {
  1484. t_error = excute_robot_put_car_to_carrier(dispatch_control_node);
  1485. break;
  1486. }
  1487. case message::Dispatch_task_type::ROBOT_CATCH_CAR_FROM_CARRIER:
  1488. {
  1489. t_error = excute_robot_catch_car_from_carrier(dispatch_control_node);
  1490. break;
  1491. }
  1492. case message::Dispatch_task_type::ROBOT_PUT_CAR_TO_OUTLET:
  1493. {
  1494. t_error = excute_robot_put_car_to_outlet(dispatch_control_node);
  1495. break;
  1496. }
  1497. case message::Dispatch_task_type::ROBOT_MOVE:
  1498. {
  1499. t_error = excute_robot_move(dispatch_control_node);
  1500. break;
  1501. }
  1502. default:
  1503. {
  1504. return Error_manager(Error_code::DISPATCH_PROCESS_TASK_STATUS_ERROR, Error_level::MINOR_ERROR,
  1505. "Dispatch_process::excute_dispatch_control() fun error ");
  1506. break;
  1507. }
  1508. }
  1509. // std::cout << " huli test :::: " << "222222 tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  1510. // std::cout << " huli test :::: " << " t_error_catcher = " << t_error.to_string() << std::endl;
  1511. }
  1512. else if ( dispatch_device_type == message::Dispatch_device_type::CARRIER_1 ||
  1513. dispatch_device_type == message::Dispatch_device_type::CARRIER_2 ||
  1514. dispatch_device_type == message::Dispatch_device_type::CARRIER_3 )
  1515. {
  1516. Catcher_task *tp_carrier_task = (Catcher_task *) dispatch_control_node.mp_dispatch_task.get();
  1517. // while (1)
  1518. // {
  1519. // char in;
  1520. // std::cin >> in;
  1521. // if (in == 'l')
  1522. // {
  1523. // break;
  1524. // }
  1525. // }
  1526. // std::cout << " huli test :::: "
  1527. // << "lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll = "
  1528. // << tp_carrier_task->m_step << std::endl;
  1529. // std::cout << " huli test :::: " << "3333333 tp_carrier_task->m_step = " << tp_carrier_task->m_step
  1530. // << std::endl;
  1531. //设备的动作也使用外部的Main()的线程来循环
  1532. switch (dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type())
  1533. {
  1534. case message::Dispatch_task_type::CARRIER_RECEIVE_CAR_FROM_ROBOT:
  1535. {
  1536. t_error = excute_carrier_receive_car_from_robot(dispatch_control_node);
  1537. break;
  1538. }
  1539. case message::Dispatch_task_type::CARRIER_STORE_CAR_TO_PARKINGSPACE:
  1540. {
  1541. t_error = excute_carrier_store_car_to_parkingspace(dispatch_control_node);
  1542. break;
  1543. }
  1544. case message::Dispatch_task_type::CARRIER_STORE_CAR_TO_PARKINGSPACE_EX:
  1545. {
  1546. t_error = excute_carrier_store_car_to_parkingspace_ex(dispatch_control_node);
  1547. break;
  1548. }
  1549. case message::Dispatch_task_type::CARRIER_PICKUP_CAR_FROM_PARKINGSPACE:
  1550. {
  1551. t_error = excute_carrier_pickup_car_from_parkingspace(dispatch_control_node);
  1552. break;
  1553. }
  1554. case message::Dispatch_task_type::CARRIER_PICKUP_CAR_FROM_PARKINGSPACE_EX:
  1555. {
  1556. t_error = excute_carrier_pickup_car_from_parkingspace_ex(dispatch_control_node);
  1557. break;
  1558. }
  1559. case message::Dispatch_task_type::CARRIER_DELIVER_CAR_TO_ROBOT:
  1560. {
  1561. t_error = excute_carrier_deliver_car_to_robot(dispatch_control_node);
  1562. break;
  1563. }
  1564. case message::Dispatch_task_type::CARRIER_MOVE:
  1565. {
  1566. t_error = excute_carrier_move(dispatch_control_node);
  1567. break;
  1568. }
  1569. default:
  1570. {
  1571. return Error_manager(Error_code::DISPATCH_PROCESS_TASK_STATUS_ERROR, Error_level::MINOR_ERROR,
  1572. "Dispatch_process::excute_dispatch_control() fun error ");
  1573. break;
  1574. }
  1575. }
  1576. // std::cout << " huli test :::: " << "44444444 tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  1577. // std::cout << " huli test :::: " << " t_error_carrier = " << t_error.to_string() << std::endl;
  1578. }
  1579. dispatch_control_node.m_error = t_error;
  1580. return t_error;
  1581. }
  1582. //流程通知设备 收回任务单
  1583. Error_manager Dispatch_process::dispatch_control_withdraw_task(int dispatch_device_type, Dispatch_control_node & dispatch_control_node)
  1584. {
  1585. if ( dispatch_control_node.mp_dispatch_device.get() != NULL && dispatch_control_node.mp_dispatch_task.get() != NULL )
  1586. {
  1587. dispatch_control_node.mp_dispatch_task->set_task_statu(Task_Base::Task_statu::TASK_WITHDRAW);
  1588. }
  1589. return Error_code::SUCCESS;
  1590. }
  1591. //发送调度控制答复, 发给调度控制的
  1592. 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)
  1593. {
  1594. dispatch_control_node.m_dispatch_control_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_control_response_msg);
  1595. 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());
  1596. dispatch_control_node.m_dispatch_control_response_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
  1597. dispatch_control_node.m_dispatch_control_response_msg.mutable_base_info()->set_receiver(message::Communicator::eDispatch_control);
  1598. dispatch_control_node.m_dispatch_control_response_msg.set_command_key(dispatch_control_node.m_dispatch_control_request_msg.command_key());
  1599. dispatch_control_node.m_dispatch_control_response_msg.set_dispatch_task_type(dispatch_control_node.m_dispatch_control_request_msg.dispatch_task_type());
  1600. dispatch_control_node.m_dispatch_control_response_msg.set_dispatch_device_type(dispatch_control_node.m_dispatch_control_request_msg.dispatch_device_type());
  1601. dispatch_control_node.m_dispatch_control_response_msg.set_dispatch_source(dispatch_control_node.m_dispatch_control_request_msg.dispatch_source());
  1602. dispatch_control_node.m_dispatch_control_response_msg.set_dispatch_destination(dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination());
  1603. dispatch_control_node.m_dispatch_control_response_msg.mutable_error_manager()->set_error_code(dispatch_control_node.m_error.get_error_code());
  1604. 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());
  1605. 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());
  1606. 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());
  1607. dispatch_control_node.m_dispatch_control_response_msg.set_dispatch_device_task_status(dispatch_device_task_status);
  1608. std::string t_msg = dispatch_control_node.m_dispatch_control_response_msg.SerializeAsString();
  1609. System_communication::get_instance_references().encapsulate_msg(t_msg);
  1610. if ( dispatch_device_task_status == message::Dispatch_device_task_status::E_TASK_OVER )
  1611. {
  1612. LOG(INFO) << " dispatch_control_node.m_dispatch_control_response_msg = "<< dispatch_control_node.m_dispatch_control_response_msg.DebugString() << " " << this;
  1613. }
  1614. return Error_code::SUCCESS;
  1615. }
  1616. //断开调度设备, 释放任务单 与设备解除连接
  1617. Error_manager Dispatch_process::disconnect_dispatch_device(int dispatch_device_type, Dispatch_control_node & dispatch_control_node)
  1618. {
  1619. if ( dispatch_control_node.mp_dispatch_device.get() != NULL && dispatch_control_node.mp_dispatch_task.get() != NULL )
  1620. {
  1621. if ( dispatch_control_node.mp_dispatch_task->get_task_statu() == Task_Base::Task_statu::TASK_FREE )
  1622. {
  1623. dispatch_control_node.mp_dispatch_task.reset();
  1624. dispatch_control_node.mp_dispatch_device.reset();
  1625. return Error_code::SUCCESS;
  1626. }
  1627. else
  1628. {
  1629. return Error_code::NODATA;
  1630. }
  1631. }
  1632. return Error_code::SUCCESS;
  1633. }
  1634. //等待调度总计划答复
  1635. Error_manager Dispatch_process::wait_dispatch_plan_response_msg()
  1636. {
  1637. std::unique_lock<std::mutex> t_lock(m_lock);
  1638. //key 相等 就表示 收到了总计划答复
  1639. if ( m_dispatch_plan_request_msg.command_key() == m_dispatch_plan_response_msg.command_key() )
  1640. {
  1641. return Error_code::SUCCESS;
  1642. }
  1643. else
  1644. {
  1645. return Error_code::NODATA;
  1646. }
  1647. }
  1648. //发送调度答复, 发给主控的
  1649. Error_manager Dispatch_process::send_dispatch_response_msg()
  1650. {
  1651. std::unique_lock<std::mutex> t_lock(m_lock);
  1652. m_dispatch_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_response_msg);
  1653. m_dispatch_response_msg.mutable_base_info()->set_timeout_ms(m_dispatch_request_msg.base_info().timeout_ms());
  1654. m_dispatch_response_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
  1655. m_dispatch_response_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
  1656. m_dispatch_response_msg.set_command_key(m_dispatch_request_msg.command_key());
  1657. m_dispatch_response_msg.mutable_error_manager()->CopyFrom(m_dispatch_plan_response_msg.error_manager());
  1658. std::string t_msg = m_dispatch_response_msg.SerializeAsString();
  1659. System_communication::get_instance_references().encapsulate_msg(t_msg);
  1660. return Error_code::SUCCESS;
  1661. }
  1662. //通知调度管理, 释放资源,
  1663. Error_manager Dispatch_process::release_resource()
  1664. {
  1665. return Dispatch_manager::get_instance_references().release_dispatch_process(m_command_key);
  1666. }
  1667. //异常处理
  1668. Error_manager Dispatch_process::Exception_handling()
  1669. {
  1670. LOG(INFO) << " -------------Dispatch_process::Exception_handling------------------- "<< this;
  1671. LOG(INFO) << " m_result = "<< m_result.to_string() << " " << this;
  1672. return Error_code::SUCCESS;
  1673. }
  1674. //机器手去入口抓车(例如:机器手移动到2号入口上方,然后下降到一楼抓车,最后上升到最上方)
  1675. Error_manager Dispatch_process::excute_robot_catch_car_from_inlet(Dispatch_control_node & dispatch_control_node)
  1676. {
  1677. Error_manager t_error;
  1678. Catcher * tp_catcher = NULL;
  1679. Catcher_task * tp_catcher_task = NULL;
  1680. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  1681. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  1682. {
  1683. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1684. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  1685. }
  1686. else
  1687. {
  1688. tp_catcher = (Catcher *)dispatch_control_node.mp_dispatch_device.get();
  1689. tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  1690. }
  1691. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  1692. // getchar();
  1693. if ( tp_catcher_task->m_step == 0 )
  1694. {
  1695. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1696. }
  1697. if ( tp_catcher_task->m_step == 1 )//检查姿态
  1698. {
  1699. if ( tp_catcher->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  1700. {
  1701. if ( tp_catcher->m_actual_clamp_motion1 != Dispatch_device_base::Clamp_motion::E_CLAMP_LOOSE ||
  1702. tp_catcher->m_actual_d1 + tp_catcher->m_actual_d2 + tp_dispatch_coordinates->m_catcher_d1_d2_distance >
  1703. tp_dispatch_coordinates->m_catcher_wheel_base_limit ||
  1704. tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_UNKNOW )
  1705. {
  1706. catcher_adjust_to_ready(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  1707. tp_catcher_task->m_step++;
  1708. }
  1709. else
  1710. {
  1711. tp_catcher_task->m_step +=2;
  1712. }
  1713. }
  1714. else
  1715. {
  1716. return Error_manager(Error_code::CATCHER_POSE_ERROR, Error_level::MINOR_ERROR,
  1717. "Dispatch_process::excute_robot_catch_car_from_inlet() fun error ");
  1718. }
  1719. }
  1720. if ( tp_catcher_task->m_step == 2 )
  1721. {
  1722. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1723. }
  1724. if ( tp_catcher_task->m_step == 3 )//机器手z轴移到最高点.
  1725. {
  1726. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  1727. tp_catcher_task->m_step++;
  1728. }
  1729. if ( tp_catcher_task->m_step == 4 )
  1730. {
  1731. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1732. }
  1733. if ( tp_catcher_task->m_step == 5 )//机器手 调整x y b d1 d2, 根据感测模块的定位信息, 调整机器手的姿态, 准备抓车.
  1734. {
  1735. catcher_adjust_from_ground(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  1736. tp_catcher_task->m_step++;
  1737. }
  1738. if ( tp_catcher_task->m_step == 6 )
  1739. {
  1740. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1741. }
  1742. if ( tp_catcher_task->m_step == 7 )//机器手z轴移到最低点.
  1743. {
  1744. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_1th_floor_z);
  1745. tp_catcher_task->m_step++;
  1746. }
  1747. if ( tp_catcher_task->m_step == 8 )
  1748. {
  1749. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1750. }
  1751. if ( tp_catcher_task->m_step == 9 )//修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  1752. {
  1753. float temp_wheel_base = tp_catcher->m_actual_d1 + tp_catcher->m_actual_d2 + tp_dispatch_coordinates->m_catcher_d1_d2_distance;
  1754. //修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  1755. if ( Common_data::approximate_difference(m_wheel_base, temp_wheel_base, DISPATCH_DEFAULT_DIFFERENCE) )
  1756. {
  1757. tp_catcher_task->m_step +=2;
  1758. }
  1759. else
  1760. {
  1761. catcher_adjust_wheel_base(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  1762. tp_catcher_task->m_step++;
  1763. }
  1764. }
  1765. if ( tp_catcher_task->m_step == 10 )
  1766. {
  1767. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1768. }
  1769. if ( tp_catcher_task->m_step == 11 )//机器手 夹车
  1770. {
  1771. catcher_move_c(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, Catcher_task::Clamp_motion::E_CLAMP_TIGHT);
  1772. tp_catcher_task->m_step++;
  1773. }
  1774. if ( tp_catcher_task->m_step == 12 )
  1775. {
  1776. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1777. }
  1778. if ( tp_catcher_task->m_step == 13 )//机器手 z轴上升到最高处
  1779. {
  1780. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  1781. tp_catcher_task->m_step++;
  1782. }
  1783. if ( tp_catcher_task->m_step == 14 )
  1784. {
  1785. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1786. }
  1787. if ( tp_catcher_task->m_step == 15 )//机器手调整到 准备把车放到搬运器的姿态
  1788. {
  1789. //这里机器手要反向,
  1790. catcher_adjust_to_carrier(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, true);
  1791. tp_catcher_task->m_step++;
  1792. }
  1793. if ( tp_catcher_task->m_step == 16 )
  1794. {
  1795. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1796. }
  1797. if ( tp_catcher_task->m_step == 17 )
  1798. {
  1799. return Error_code::SUCCESS;
  1800. }
  1801. return Error_code::SUCCESS;
  1802. }
  1803. //机器手把车放到中跑车上面(例如:机器手下降到中跑车上放车,最后上升到最上方)(通过目标点 指定放到哪一个中跑车上)
  1804. Error_manager Dispatch_process::excute_robot_put_car_to_carrier(Dispatch_control_node & dispatch_control_node)
  1805. {
  1806. Error_manager t_error;
  1807. Catcher * tp_catcher = NULL;
  1808. Catcher_task * tp_catcher_task = NULL;
  1809. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  1810. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  1811. {
  1812. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1813. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  1814. }
  1815. else
  1816. {
  1817. tp_catcher = (Catcher *)dispatch_control_node.mp_dispatch_device.get();
  1818. tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  1819. }
  1820. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  1821. // getchar();
  1822. if ( tp_catcher_task->m_step == 0 )
  1823. {
  1824. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1825. }
  1826. if ( tp_catcher_task->m_step == 1 )//检查姿态
  1827. {
  1828. if ( tp_catcher->m_actual_load_status == Dispatch_device_base::Load_status::HAVE_CAR &&
  1829. tp_catcher->m_actual_clamp_motion1 == Dispatch_device_base::Clamp_motion::E_CLAMP_TIGHT &&
  1830. (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) ) )
  1831. {
  1832. //检测正常, 直接跳过即可
  1833. tp_catcher_task->m_step +=2;
  1834. }
  1835. else
  1836. {
  1837. return Error_manager(Error_code::CATCHER_POSE_ERROR, Error_level::MINOR_ERROR,
  1838. "Dispatch_process::excute_robot_put_car_to_carrier() fun error ");
  1839. }
  1840. }
  1841. if ( tp_catcher_task->m_step == 2 )
  1842. {
  1843. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1844. }
  1845. if ( tp_catcher_task->m_step == 3 )//机器手 调整z轴
  1846. {
  1847. if ( tp_catcher->m_actual_z*1.02 >= dispatch_control_node.m_destination_coordinates.z )
  1848. {
  1849. //检测正常, 直接跳过即可
  1850. tp_catcher_task->m_step +=2;
  1851. }
  1852. else
  1853. {
  1854. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  1855. tp_catcher_task->m_step++;
  1856. }
  1857. }
  1858. if ( tp_catcher_task->m_step == 4 )
  1859. {
  1860. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1861. }
  1862. if ( tp_catcher_task->m_step == 5 )//机器手调整到 准备把车放到搬运器的姿态
  1863. {
  1864. float temp_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  1865. if ( Common_data::approximate_difference(tp_catcher->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) &&
  1866. Common_data::approximate_difference(tp_catcher->m_actual_y, temp_y, DISPATCH_DEFAULT_DIFFERENCE))
  1867. {
  1868. //检测正常, 直接跳过即可
  1869. tp_catcher_task->m_step +=2;
  1870. }
  1871. else
  1872. {
  1873. catcher_adjust_to_carrier(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, false);
  1874. tp_catcher_task->m_step++;
  1875. }
  1876. }
  1877. if ( tp_catcher_task->m_step == 6 )
  1878. {
  1879. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1880. }
  1881. if ( tp_catcher_task->m_step == 7 )//机器手 z轴下降
  1882. {
  1883. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  1884. tp_catcher_task->m_step++;
  1885. }
  1886. if ( tp_catcher_task->m_step == 8 )
  1887. {
  1888. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1889. }
  1890. if ( tp_catcher_task->m_step == 9 )//机器手 松开夹杆
  1891. {
  1892. catcher_move_c(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, Catcher_task::Clamp_motion::E_CLAMP_LOOSE);
  1893. tp_catcher_task->m_step++;
  1894. }
  1895. if ( tp_catcher_task->m_step == 10 )
  1896. {
  1897. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1898. }
  1899. if ( tp_catcher_task->m_step == 11 )//机器手 z轴上升
  1900. {
  1901. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  1902. tp_catcher_task->m_step++;
  1903. }
  1904. if ( tp_catcher_task->m_step == 12 )
  1905. {
  1906. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1907. }
  1908. if ( tp_catcher_task->m_step == 13 )
  1909. {
  1910. return Error_code::SUCCESS;
  1911. }
  1912. return Error_code::SUCCESS;
  1913. }
  1914. //机器手去中跑车上抓车(例如:机器手移动到1号中跑车上方,然后下降到中跑车抓车,最后上升到最上方)
  1915. Error_manager Dispatch_process::excute_robot_catch_car_from_carrier(Dispatch_control_node & dispatch_control_node)
  1916. {
  1917. Error_manager t_error;
  1918. Catcher * tp_catcher = NULL;
  1919. Catcher_task * tp_catcher_task = NULL;
  1920. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  1921. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  1922. {
  1923. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  1924. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  1925. }
  1926. else
  1927. {
  1928. tp_catcher = (Catcher *)dispatch_control_node.mp_dispatch_device.get();
  1929. tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  1930. }
  1931. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  1932. // getchar();
  1933. if ( tp_catcher_task->m_step == 0 )
  1934. {
  1935. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1936. }
  1937. if ( tp_catcher_task->m_step == 1 )
  1938. {
  1939. if ( tp_catcher->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  1940. {
  1941. if ( tp_catcher->m_actual_clamp_motion1 != Dispatch_device_base::Clamp_motion::E_CLAMP_LOOSE ||
  1942. tp_catcher->m_actual_d1 + tp_catcher->m_actual_d2 + tp_dispatch_coordinates->m_catcher_d1_d2_distance >
  1943. tp_dispatch_coordinates->m_catcher_wheel_base_limit ||
  1944. tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_UNKNOW )
  1945. {
  1946. catcher_adjust_to_ready(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  1947. tp_catcher_task->m_step++;
  1948. }
  1949. else
  1950. {
  1951. tp_catcher_task->m_step +=2;
  1952. }
  1953. }
  1954. else
  1955. {
  1956. return Error_manager(Error_code::CATCHER_POSE_ERROR, Error_level::MINOR_ERROR,
  1957. "Dispatch_process::excute_robot_catch_car_from_carrier() fun error ");
  1958. }
  1959. }
  1960. if ( tp_catcher_task->m_step == 2 )
  1961. {
  1962. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1963. }
  1964. if ( tp_catcher_task->m_step == 3 )//机器手 调整z轴
  1965. {
  1966. if ( tp_catcher->m_actual_z*1.02 >= dispatch_control_node.m_destination_coordinates.z )
  1967. {
  1968. //检测正常, 直接跳过即可
  1969. tp_catcher_task->m_step +=2;
  1970. }
  1971. else
  1972. {
  1973. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  1974. tp_catcher_task->m_step++;
  1975. }
  1976. }
  1977. if ( tp_catcher_task->m_step == 4 )
  1978. {
  1979. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1980. }
  1981. if ( tp_catcher_task->m_step == 5 )//机器手调整到 准备把车放到搬运器的姿态
  1982. {
  1983. float temp_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  1984. if ( Common_data::approximate_difference(tp_catcher->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) &&
  1985. Common_data::approximate_difference(tp_catcher->m_actual_y, temp_y, DISPATCH_DEFAULT_DIFFERENCE))
  1986. {
  1987. //检测正常, 直接跳过即可
  1988. tp_catcher_task->m_step +=2;
  1989. }
  1990. else
  1991. {
  1992. catcher_adjust_from_carrier(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  1993. tp_catcher_task->m_step++;
  1994. }
  1995. }
  1996. if ( tp_catcher_task->m_step == 6 )
  1997. {
  1998. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  1999. }
  2000. if ( tp_catcher_task->m_step == 7 )//机器手 z轴下降
  2001. {
  2002. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  2003. tp_catcher_task->m_step++;
  2004. }
  2005. if ( tp_catcher_task->m_step == 8 )
  2006. {
  2007. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2008. }
  2009. if ( tp_catcher_task->m_step == 9 )//修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  2010. {
  2011. float temp_wheel_base = tp_catcher->m_actual_d1 + tp_catcher->m_actual_d2 + tp_dispatch_coordinates->m_catcher_d1_d2_distance;
  2012. //修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  2013. if ( Common_data::approximate_difference(m_wheel_base, temp_wheel_base, DISPATCH_DEFAULT_DIFFERENCE) )
  2014. {
  2015. tp_catcher_task->m_step +=2;
  2016. }
  2017. else
  2018. {
  2019. catcher_adjust_wheel_base(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  2020. tp_catcher_task->m_step++;
  2021. }
  2022. }
  2023. if ( tp_catcher_task->m_step == 10 )
  2024. {
  2025. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2026. }
  2027. if ( tp_catcher_task->m_step == 11 )//机器手 夹车
  2028. {
  2029. catcher_move_c(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, Catcher_task::Clamp_motion::E_CLAMP_TIGHT);
  2030. tp_catcher_task->m_step++;
  2031. }
  2032. if ( tp_catcher_task->m_step == 12 )
  2033. {
  2034. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2035. }
  2036. if ( tp_catcher_task->m_step == 13 )//机器手 z轴上升
  2037. {
  2038. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  2039. tp_catcher_task->m_step++;
  2040. }
  2041. if ( tp_catcher_task->m_step == 14 )
  2042. {
  2043. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2044. }
  2045. if ( tp_catcher_task->m_step == 15 )
  2046. {
  2047. return Error_code::SUCCESS;
  2048. }
  2049. return Error_code::SUCCESS;
  2050. }
  2051. //机器手去出口放车(例如:机器手移动到3号出口上方,然后下降到一楼放车,最后上升到最上方)
  2052. Error_manager Dispatch_process::excute_robot_put_car_to_outlet(Dispatch_control_node & dispatch_control_node)
  2053. {
  2054. Error_manager t_error;
  2055. Catcher * tp_catcher = NULL;
  2056. Catcher_task * tp_catcher_task = NULL;
  2057. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  2058. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  2059. {
  2060. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  2061. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  2062. }
  2063. else
  2064. {
  2065. tp_catcher = (Catcher *)dispatch_control_node.mp_dispatch_device.get();
  2066. tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  2067. }
  2068. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_catcher_task->m_step << std::endl;
  2069. // getchar();
  2070. if ( tp_catcher_task->m_step == 0 )
  2071. {
  2072. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2073. }
  2074. if ( tp_catcher_task->m_step == 1 )//检查姿态
  2075. {
  2076. if ( tp_catcher->m_actual_load_status == Dispatch_device_base::Load_status::HAVE_CAR &&
  2077. tp_catcher->m_actual_clamp_motion1 == Dispatch_device_base::Clamp_motion::E_CLAMP_TIGHT &&
  2078. (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) ) )
  2079. {
  2080. //检测正常, 直接跳过即可
  2081. tp_catcher_task->m_step +=2;
  2082. }
  2083. else
  2084. {
  2085. return Error_manager(Error_code::CATCHER_POSE_ERROR, Error_level::MINOR_ERROR,
  2086. "Dispatch_process::excute_robot_put_car_to_carrier() fun error ");
  2087. }
  2088. }
  2089. if ( tp_catcher_task->m_step == 2 )
  2090. {
  2091. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2092. }
  2093. if ( tp_catcher_task->m_step == 3 )//机器手 调整z轴
  2094. {
  2095. if ( tp_catcher->m_actual_z*1.02 >= dispatch_control_node.m_destination_coordinates.z )
  2096. {
  2097. //检测正常, 直接跳过即可
  2098. tp_catcher_task->m_step +=2;
  2099. }
  2100. else
  2101. {
  2102. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  2103. tp_catcher_task->m_step++;
  2104. }
  2105. }
  2106. if ( tp_catcher_task->m_step == 4 )
  2107. {
  2108. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2109. }
  2110. if ( tp_catcher_task->m_step == 5 )//机器手调整到 准备把车放到搬运器的姿态
  2111. {
  2112. float temp_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  2113. if ( Common_data::approximate_difference(tp_catcher->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) &&
  2114. Common_data::approximate_difference(tp_catcher->m_actual_y, temp_y, DISPATCH_DEFAULT_DIFFERENCE))
  2115. {
  2116. //检测正常, 直接跳过即可
  2117. tp_catcher_task->m_step +=2;
  2118. }
  2119. else
  2120. {
  2121. catcher_adjust_to_ground(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  2122. tp_catcher_task->m_step++;
  2123. }
  2124. }
  2125. if ( tp_catcher_task->m_step == 6 )
  2126. {
  2127. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2128. }
  2129. if ( tp_catcher_task->m_step == 7 )//机器手 z轴下降
  2130. {
  2131. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  2132. tp_catcher_task->m_step++;
  2133. }
  2134. if ( tp_catcher_task->m_step == 8 )
  2135. {
  2136. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2137. }
  2138. if ( tp_catcher_task->m_step == 9 )//机器手 松开夹杆
  2139. {
  2140. catcher_move_c(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, Catcher_task::Clamp_motion::E_CLAMP_LOOSE);
  2141. tp_catcher_task->m_step++;
  2142. }
  2143. if ( tp_catcher_task->m_step == 10 )
  2144. {
  2145. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2146. }
  2147. if ( tp_catcher_task->m_step == 11 )//机器手 z轴上升
  2148. {
  2149. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_catcher_4th_floor_z);
  2150. tp_catcher_task->m_step++;
  2151. }
  2152. if ( tp_catcher_task->m_step == 12 )
  2153. {
  2154. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2155. }
  2156. if ( tp_catcher_task->m_step == 13 )
  2157. {
  2158. return Error_code::SUCCESS;
  2159. }
  2160. return Error_code::SUCCESS;
  2161. }
  2162. //机器手的自由移动(例如:机器手移动到6号出入口的上方4楼处,给其他设备避让)(不进行抓车和放车的操作)
  2163. Error_manager Dispatch_process::excute_robot_move(Dispatch_control_node & dispatch_control_node)
  2164. {
  2165. Error_manager t_error;
  2166. Catcher * tp_catcher = NULL;
  2167. Catcher_task * tp_catcher_task = NULL;
  2168. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  2169. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  2170. {
  2171. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  2172. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  2173. }
  2174. else
  2175. {
  2176. tp_catcher = (Catcher *)dispatch_control_node.mp_dispatch_device.get();
  2177. tp_catcher_task = (Catcher_task *)dispatch_control_node.mp_dispatch_task.get();
  2178. }
  2179. if ( tp_catcher_task->m_step == 0 )
  2180. {
  2181. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2182. }
  2183. if ( tp_catcher_task->m_step == 1 )//检查姿态
  2184. {
  2185. if ( tp_catcher->m_actual_d1 + tp_catcher->m_actual_d2 + tp_dispatch_coordinates->m_catcher_d1_d2_distance >
  2186. tp_dispatch_coordinates->m_catcher_wheel_base_limit ||
  2187. tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_UNKNOW )
  2188. {
  2189. catcher_adjust_to_ready(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  2190. tp_catcher_task->m_step++;
  2191. }
  2192. else
  2193. {
  2194. tp_catcher_task->m_step +=2;
  2195. }
  2196. }
  2197. if ( tp_catcher_task->m_step == 2 )
  2198. {
  2199. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2200. }
  2201. if ( tp_catcher_task->m_step == 3 )//机器手 调整z轴
  2202. {
  2203. catcher_move_z(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  2204. tp_catcher_task->m_step++;
  2205. }
  2206. if ( tp_catcher_task->m_step == 4 )
  2207. {
  2208. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2209. }
  2210. if ( tp_catcher_task->m_step == 5 )//机器手调整到 准备把车放到搬运器的姿态
  2211. {
  2212. catcher_adjust_to_ground(dispatch_control_node, tp_catcher, tp_catcher_task, tp_dispatch_coordinates);
  2213. tp_catcher_task->m_step++;
  2214. }
  2215. if ( tp_catcher_task->m_step == 6 )
  2216. {
  2217. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_catcher_task->m_step);
  2218. }
  2219. if ( tp_catcher_task->m_step == 7 )
  2220. {
  2221. return Error_code::SUCCESS;
  2222. }
  2223. return Error_code::SUCCESS;
  2224. }
  2225. //搬运器从机器手上接车(例如:搬运器移动到2号入口的上方,然后等待机器手把车放到中跑车上,小跑车保持松夹杆状态)
  2226. Error_manager Dispatch_process::excute_carrier_receive_car_from_robot(Dispatch_control_node & dispatch_control_node)
  2227. {
  2228. Error_manager t_error;
  2229. Carrier * tp_carrier = NULL;
  2230. Carrier_task * tp_carrier_task = NULL;
  2231. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  2232. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  2233. {
  2234. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  2235. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  2236. }
  2237. else
  2238. {
  2239. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  2240. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  2241. }
  2242. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_carrier_task->m_step << std::endl;
  2243. // getchar();
  2244. if ( tp_carrier_task->m_step == 0 )
  2245. {
  2246. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2247. }
  2248. if ( tp_carrier_task->m_step == 1 )//检查姿态
  2249. {
  2250. //检查姿态
  2251. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  2252. {
  2253. if ( tp_carrier_task->m_request_clamp_motion == Carrier_task::Clamp_motion::E_CLAMP_LOOSE &&
  2254. Common_data::approximate_difference(m_wheel_base, tp_carrier->m_actual_y1-tp_carrier->m_actual_y2, DISPATCH_DEFAULT_DIFFERENCE))
  2255. {
  2256. tp_carrier_task->m_step +=2;
  2257. }
  2258. else
  2259. {
  2260. carrier_adjust_to_ready(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates);
  2261. tp_carrier_task->m_step++;
  2262. }
  2263. }
  2264. else
  2265. {
  2266. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  2267. "tp_carrier->m_actual_load_status != Dispatch_device_base::Load_status::NO_CAR fun error ");
  2268. }
  2269. }
  2270. if ( tp_carrier_task->m_step == 2 )
  2271. {
  2272. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2273. }
  2274. if ( tp_carrier_task->m_step == 3 )//让小跑车回到中跑车上
  2275. {
  2276. if ( Common_data::approximate_difference(tp_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, DISPATCH_DEFAULT_DIFFERENCE) )
  2277. {
  2278. tp_carrier_task->m_step +=2;
  2279. }
  2280. else
  2281. {
  2282. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  2283. tp_carrier_task->m_step++;
  2284. }
  2285. }
  2286. if ( tp_carrier_task->m_step == 4 )
  2287. {
  2288. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2289. }
  2290. if ( tp_carrier_task->m_step == 5 )//让中跑车回到电梯井
  2291. {
  2292. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2293. {
  2294. tp_carrier_task->m_step +=2;
  2295. }
  2296. else
  2297. {
  2298. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  2299. {
  2300. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  2301. tp_carrier_task->m_step++;
  2302. }
  2303. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  2304. {
  2305. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  2306. tp_carrier_task->m_step++;
  2307. }
  2308. else
  2309. {
  2310. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  2311. " m_destination_coordinates.z PARAMRTER ERROR ");
  2312. }
  2313. }
  2314. }
  2315. if ( tp_carrier_task->m_step == 6 )
  2316. {
  2317. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2318. }
  2319. if ( tp_carrier_task->m_step == 7 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  2320. {
  2321. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2322. {
  2323. tp_carrier_task->m_step +=2;
  2324. }
  2325. else
  2326. {
  2327. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  2328. tp_carrier_task->m_step++;
  2329. }
  2330. }
  2331. if ( tp_carrier_task->m_step == 8 )
  2332. {
  2333. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2334. }
  2335. if ( tp_carrier_task->m_step == 9 )//电梯移动到对应的楼层
  2336. {
  2337. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2338. {
  2339. tp_carrier_task->m_step +=2;
  2340. }
  2341. else
  2342. {
  2343. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  2344. tp_carrier_task->m_step++;
  2345. }
  2346. }
  2347. if ( tp_carrier_task->m_step == 10 )
  2348. {
  2349. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2350. }
  2351. if ( tp_carrier_task->m_step == 11 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  2352. {
  2353. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK && tp_carrier->get_device_id() !=2)
  2354. {
  2355. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  2356. tp_carrier_task->m_step++;
  2357. }
  2358. else
  2359. {
  2360. tp_carrier_task->m_step +=2;
  2361. }
  2362. }
  2363. if ( tp_carrier_task->m_step == 12 )
  2364. {
  2365. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2366. }
  2367. if ( tp_carrier_task->m_step == 13 )//中跑车 x轴移动
  2368. {
  2369. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  2370. {
  2371. tp_carrier_task->m_step +=2;
  2372. }
  2373. else
  2374. {
  2375. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  2376. tp_carrier_task->m_step++;
  2377. }
  2378. }
  2379. if ( tp_carrier_task->m_step == 14 )
  2380. {
  2381. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2382. }
  2383. if ( tp_carrier_task->m_step == 15 )
  2384. {
  2385. return Error_code::SUCCESS;
  2386. }
  2387. return Error_code::SUCCESS;
  2388. }
  2389. //搬运器把车存到停车位上(例如:小跑车夹车后,搬运器移动到56号停车位,然后小跑车将车存入车位,之后搬运器退回至电梯井)
  2390. Error_manager Dispatch_process::excute_carrier_store_car_to_parkingspace(Dispatch_control_node & dispatch_control_node)
  2391. {
  2392. Error_manager t_error;
  2393. Carrier * tp_carrier = NULL;
  2394. Carrier_task * tp_carrier_task = NULL;
  2395. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  2396. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  2397. {
  2398. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  2399. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  2400. }
  2401. else
  2402. {
  2403. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  2404. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  2405. }
  2406. // std::cout << " huli test :::: " << " tp_catcher_task->m_step = " << tp_carrier_task->m_step << std::endl;
  2407. // getchar();
  2408. if ( tp_carrier_task->m_step == 0 )
  2409. {
  2410. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2411. }
  2412. if ( tp_carrier_task->m_step == 1 )//检查姿态
  2413. {
  2414. //检查姿态(注注注注注意了, 调试阶段是无车, 真实环境是有车的)
  2415. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR &&
  2416. tp_carrier->m_actual_clamp_motion1 == Dispatch_device_base::Clamp_motion::E_CLAMP_LOOSE)
  2417. {
  2418. //检测正常, 直接跳过即可
  2419. tp_carrier_task->m_step +=2;
  2420. }
  2421. //注意了, 如果是去7号出口, 那么就直接跳过轮距修正和夹车.
  2422. else if(dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination() == 1107)
  2423. {
  2424. tp_carrier_task->m_step = 7;
  2425. }
  2426. else
  2427. {
  2428. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  2429. "Dispatch_process::excute_carrier_store_car_to_parkingspace() fun error ");
  2430. }
  2431. }
  2432. if ( tp_carrier_task->m_step == 2 )
  2433. {
  2434. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2435. }
  2436. if ( tp_carrier_task->m_step == 3 )//修正轴距
  2437. {
  2438. float temp_wheel_base = tp_carrier->m_actual_y1 - tp_carrier->m_actual_y2;
  2439. if ( Common_data::approximate_difference(m_wheel_base, temp_wheel_base, DISPATCH_DEFAULT_DIFFERENCE) )
  2440. {
  2441. tp_carrier_task->m_step +=2;
  2442. }
  2443. else
  2444. {
  2445. carrier_adjust_wheel_base(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates);
  2446. tp_carrier_task->m_step++;
  2447. }
  2448. }
  2449. if ( tp_carrier_task->m_step == 4 )
  2450. {
  2451. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2452. }
  2453. if ( tp_carrier_task->m_step == 5 )//让小跑车 夹车
  2454. {
  2455. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_TIGHT);
  2456. tp_carrier_task->m_step++;
  2457. }
  2458. if ( tp_carrier_task->m_step == 6 )
  2459. {
  2460. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2461. }
  2462. if ( tp_carrier_task->m_step == 7 )//让中跑车回到电梯井
  2463. {
  2464. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2465. {
  2466. tp_carrier_task->m_step +=2;
  2467. }
  2468. else
  2469. {
  2470. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  2471. {
  2472. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  2473. tp_carrier_task->m_step++;
  2474. }
  2475. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  2476. {
  2477. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  2478. tp_carrier_task->m_step++;
  2479. }
  2480. else
  2481. {
  2482. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  2483. " m_destination_coordinates.z PARAMRTER ERROR ");
  2484. }
  2485. }
  2486. }
  2487. if ( tp_carrier_task->m_step == 8 )
  2488. {
  2489. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2490. }
  2491. if ( tp_carrier_task->m_step == 9 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  2492. {
  2493. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2494. {
  2495. tp_carrier_task->m_step +=2;
  2496. }
  2497. else
  2498. {
  2499. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  2500. tp_carrier_task->m_step++;
  2501. }
  2502. }
  2503. if ( tp_carrier_task->m_step == 10 )
  2504. {
  2505. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2506. }
  2507. if ( tp_carrier_task->m_step == 11 )//电梯移动到对应的楼层
  2508. {
  2509. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2510. {
  2511. tp_carrier_task->m_step +=2;
  2512. }
  2513. else
  2514. {
  2515. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  2516. tp_carrier_task->m_step++;
  2517. }
  2518. }
  2519. if ( tp_carrier_task->m_step == 12 )
  2520. {
  2521. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2522. }
  2523. if ( tp_carrier_task->m_step == 13 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  2524. {
  2525. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK && tp_carrier->get_device_id() !=2)
  2526. {
  2527. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  2528. tp_carrier_task->m_step++;
  2529. }
  2530. else
  2531. {
  2532. tp_carrier_task->m_step +=2;
  2533. }
  2534. }
  2535. if ( tp_carrier_task->m_step == 14 )
  2536. {
  2537. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2538. }
  2539. if ( tp_carrier_task->m_step == 15 )//中跑车 x轴移动
  2540. {
  2541. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  2542. {
  2543. tp_carrier_task->m_step +=2;
  2544. }
  2545. else
  2546. {
  2547. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  2548. tp_carrier_task->m_step++;
  2549. }
  2550. }
  2551. if ( tp_carrier_task->m_step == 16 )
  2552. {
  2553. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2554. }
  2555. if ( tp_carrier_task->m_step == 17 )//小跑车 进入车位
  2556. {
  2557. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_leave);
  2558. tp_carrier_task->m_step++;
  2559. }
  2560. if ( tp_carrier_task->m_step == 18 )
  2561. {
  2562. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2563. }
  2564. if ( tp_carrier_task->m_step == 19 )//小跑车 松开夹杆
  2565. {
  2566. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_LOOSE);
  2567. tp_carrier_task->m_step++;
  2568. }
  2569. if ( tp_carrier_task->m_step == 20 )
  2570. {
  2571. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2572. }
  2573. if ( tp_carrier_task->m_step == 21 )//小跑车 回到中跑车
  2574. {
  2575. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  2576. tp_carrier_task->m_step++;
  2577. }
  2578. if ( tp_carrier_task->m_step == 22 )
  2579. {
  2580. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2581. }
  2582. if ( tp_carrier_task->m_step == 23 )//让中跑车回到电梯井
  2583. {
  2584. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  2585. {
  2586. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  2587. tp_carrier_task->m_step++;
  2588. }
  2589. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  2590. {
  2591. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  2592. tp_carrier_task->m_step++;
  2593. }
  2594. else
  2595. {
  2596. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  2597. " m_destination_coordinates.z PARAMRTER ERROR ");
  2598. }
  2599. }
  2600. if ( tp_carrier_task->m_step == 24 )
  2601. {
  2602. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2603. }
  2604. if ( tp_carrier_task->m_step == 25 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  2605. {
  2606. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  2607. tp_carrier_task->m_step++;
  2608. }
  2609. if ( tp_carrier_task->m_step == 26 )
  2610. {
  2611. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2612. }
  2613. if ( tp_carrier_task->m_step == 27 )
  2614. {
  2615. return Error_code::SUCCESS;
  2616. }
  2617. return Error_code::SUCCESS;
  2618. }
  2619. //搬运器把车存到停车位上(例如:小跑车夹车后,搬运器移动到56号停车位,然后小跑车将车存入车位,之后搬运器退回至56车位外面即可)
  2620. Error_manager Dispatch_process::excute_carrier_store_car_to_parkingspace_ex(Dispatch_control_node & dispatch_control_node)
  2621. {
  2622. Error_manager t_error;
  2623. Carrier * tp_carrier = NULL;
  2624. Carrier_task * tp_carrier_task = NULL;
  2625. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  2626. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  2627. {
  2628. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  2629. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  2630. }
  2631. else
  2632. {
  2633. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  2634. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  2635. }
  2636. // std::cout << " huli test :::: " << " tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  2637. // getchar();
  2638. if ( tp_carrier_task->m_step == 0 )
  2639. {
  2640. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2641. }
  2642. if ( tp_carrier_task->m_step == 1 )//检查姿态
  2643. {
  2644. //检查姿态(注注注注注意了, 调试阶段是无车, 真实环境是有车的)
  2645. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR &&
  2646. tp_carrier->m_actual_clamp_motion1 == Dispatch_device_base::Clamp_motion::E_CLAMP_LOOSE)
  2647. {
  2648. //检测正常, 直接跳过即可
  2649. tp_carrier_task->m_step +=2;
  2650. }
  2651. //注意了, 如果是去7号出口, 那么就直接跳过轮距修正和夹车.
  2652. else if(dispatch_control_node.m_dispatch_control_request_msg.dispatch_destination() == 1107)
  2653. {
  2654. tp_carrier_task->m_step = 7;
  2655. }
  2656. else
  2657. {
  2658. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  2659. "Dispatch_process::excute_carrier_store_car_to_parkingspace() fun error ");
  2660. }
  2661. }
  2662. if ( tp_carrier_task->m_step == 2 )
  2663. {
  2664. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2665. }
  2666. if ( tp_carrier_task->m_step == 3 )//修正轴距
  2667. {
  2668. float temp_wheel_base = tp_carrier->m_actual_y1 - tp_carrier->m_actual_y2;
  2669. if ( Common_data::approximate_difference(m_wheel_base, temp_wheel_base, DISPATCH_DEFAULT_DIFFERENCE) )
  2670. {
  2671. tp_carrier_task->m_step +=2;
  2672. }
  2673. else
  2674. {
  2675. carrier_adjust_wheel_base(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates);
  2676. tp_carrier_task->m_step++;
  2677. }
  2678. }
  2679. if ( tp_carrier_task->m_step == 4 )
  2680. {
  2681. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2682. }
  2683. if ( tp_carrier_task->m_step == 5 )//让小跑车 夹车
  2684. {
  2685. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_TIGHT);
  2686. tp_carrier_task->m_step++;
  2687. }
  2688. if ( tp_carrier_task->m_step == 6 )
  2689. {
  2690. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2691. }
  2692. if ( tp_carrier_task->m_step == 7 )//让中跑车回到电梯井
  2693. {
  2694. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2695. {
  2696. tp_carrier_task->m_step +=2;
  2697. }
  2698. else
  2699. {
  2700. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  2701. {
  2702. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  2703. tp_carrier_task->m_step++;
  2704. }
  2705. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  2706. {
  2707. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  2708. tp_carrier_task->m_step++;
  2709. }
  2710. else
  2711. {
  2712. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  2713. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  2714. }
  2715. }
  2716. }
  2717. if ( tp_carrier_task->m_step == 8 )
  2718. {
  2719. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2720. }
  2721. if ( tp_carrier_task->m_step == 9 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  2722. {
  2723. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2724. {
  2725. tp_carrier_task->m_step +=2;
  2726. }
  2727. else
  2728. {
  2729. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  2730. tp_carrier_task->m_step++;
  2731. }
  2732. }
  2733. if ( tp_carrier_task->m_step == 10 )
  2734. {
  2735. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2736. }
  2737. if ( tp_carrier_task->m_step == 11 )//电梯移动到对应的楼层
  2738. {
  2739. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2740. {
  2741. tp_carrier_task->m_step +=2;
  2742. }
  2743. else
  2744. {
  2745. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  2746. tp_carrier_task->m_step++;
  2747. }
  2748. }
  2749. if ( tp_carrier_task->m_step == 12 )
  2750. {
  2751. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2752. }
  2753. if ( tp_carrier_task->m_step == 13 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  2754. {
  2755. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK && tp_carrier->get_device_id() !=2)
  2756. {
  2757. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  2758. tp_carrier_task->m_step++;
  2759. }
  2760. else
  2761. {
  2762. tp_carrier_task->m_step +=2;
  2763. }
  2764. }
  2765. if ( tp_carrier_task->m_step == 14 )
  2766. {
  2767. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2768. }
  2769. if ( tp_carrier_task->m_step == 15 )//中跑车 x轴移动
  2770. {
  2771. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  2772. {
  2773. tp_carrier_task->m_step +=2;
  2774. }
  2775. else
  2776. {
  2777. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  2778. tp_carrier_task->m_step++;
  2779. }
  2780. }
  2781. if ( tp_carrier_task->m_step == 16 )
  2782. {
  2783. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2784. }
  2785. if ( tp_carrier_task->m_step == 17 )//小跑车 进入车位
  2786. {
  2787. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_leave);
  2788. tp_carrier_task->m_step++;
  2789. }
  2790. if ( tp_carrier_task->m_step == 18 )
  2791. {
  2792. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2793. }
  2794. if ( tp_carrier_task->m_step == 19 )//小跑车 松开夹杆
  2795. {
  2796. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_LOOSE);
  2797. tp_carrier_task->m_step++;
  2798. }
  2799. if ( tp_carrier_task->m_step == 20 )
  2800. {
  2801. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2802. }
  2803. if ( tp_carrier_task->m_step == 21 )//小跑车 回到中跑车
  2804. {
  2805. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  2806. tp_carrier_task->m_step++;
  2807. }
  2808. if ( tp_carrier_task->m_step == 22 )
  2809. {
  2810. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2811. }
  2812. if ( tp_carrier_task->m_step == 23 )
  2813. {
  2814. return Error_code::SUCCESS;
  2815. }
  2816. return Error_code::SUCCESS;
  2817. }
  2818. //搬运器从停车位上取车(例如:搬运器移动到56号停车位,然后小跑车将车从车位取出,之后搬运器退回至电梯井)
  2819. Error_manager Dispatch_process::excute_carrier_pickup_car_from_parkingspace(Dispatch_control_node & dispatch_control_node)
  2820. {
  2821. Error_manager t_error;
  2822. Carrier * tp_carrier = NULL;
  2823. Carrier_task * tp_carrier_task = NULL;
  2824. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  2825. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  2826. {
  2827. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  2828. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  2829. }
  2830. else
  2831. {
  2832. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  2833. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  2834. }
  2835. // std::cout << " huli test :::: " << " tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  2836. // getchar();
  2837. if ( tp_carrier_task->m_step == 0 )
  2838. {
  2839. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2840. }
  2841. if ( tp_carrier_task->m_step == 1 )//检查姿态
  2842. {
  2843. //检查姿态
  2844. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  2845. {
  2846. if ( tp_carrier_task->m_request_clamp_motion == Carrier_task::Clamp_motion::E_CLAMP_LOOSE &&
  2847. Common_data::approximate_difference(m_wheel_base, tp_carrier->m_actual_y1-tp_carrier->m_actual_y2, DISPATCH_DEFAULT_DIFFERENCE))
  2848. {
  2849. tp_carrier_task->m_step +=2;
  2850. }
  2851. else
  2852. {
  2853. carrier_adjust_to_ready(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates);
  2854. tp_carrier_task->m_step++;
  2855. }
  2856. }
  2857. else
  2858. {
  2859. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  2860. "tp_carrier->m_actual_load_status != Dispatch_device_base::Load_status::NO_CAR fun error ");
  2861. }
  2862. }
  2863. if ( tp_carrier_task->m_step == 2 )
  2864. {
  2865. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2866. }
  2867. if ( tp_carrier_task->m_step == 3 )//让小跑车回到中跑车上
  2868. {
  2869. if ( Common_data::approximate_difference(tp_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, DISPATCH_DEFAULT_DIFFERENCE) )
  2870. {
  2871. tp_carrier_task->m_step +=2;
  2872. }
  2873. else
  2874. {
  2875. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  2876. tp_carrier_task->m_step++;
  2877. }
  2878. }
  2879. if ( tp_carrier_task->m_step == 4 )
  2880. {
  2881. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2882. }
  2883. if ( tp_carrier_task->m_step == 5 )//让中跑车回到电梯井
  2884. {
  2885. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2886. {
  2887. tp_carrier_task->m_step +=2;
  2888. }
  2889. else
  2890. {
  2891. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  2892. {
  2893. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  2894. tp_carrier_task->m_step++;
  2895. }
  2896. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  2897. {
  2898. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  2899. tp_carrier_task->m_step++;
  2900. }
  2901. else
  2902. {
  2903. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  2904. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  2905. }
  2906. }
  2907. }
  2908. if ( tp_carrier_task->m_step == 6 )
  2909. {
  2910. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2911. }
  2912. if ( tp_carrier_task->m_step == 7 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  2913. {
  2914. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2915. {
  2916. tp_carrier_task->m_step +=2;
  2917. }
  2918. else
  2919. {
  2920. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  2921. tp_carrier_task->m_step++;
  2922. }
  2923. }
  2924. if ( tp_carrier_task->m_step == 8 )
  2925. {
  2926. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2927. }
  2928. if ( tp_carrier_task->m_step == 9 )//电梯移动到对应的楼层
  2929. {
  2930. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  2931. {
  2932. tp_carrier_task->m_step +=2;
  2933. }
  2934. else
  2935. {
  2936. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  2937. tp_carrier_task->m_step++;
  2938. }
  2939. }
  2940. if ( tp_carrier_task->m_step == 10 )
  2941. {
  2942. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2943. }
  2944. if ( tp_carrier_task->m_step == 11 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  2945. {
  2946. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK && tp_carrier->get_device_id() != 2)
  2947. {
  2948. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  2949. tp_carrier_task->m_step++;
  2950. }
  2951. else
  2952. {
  2953. tp_carrier_task->m_step +=2;
  2954. }
  2955. }
  2956. if ( tp_carrier_task->m_step == 12 )
  2957. {
  2958. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2959. }
  2960. if ( tp_carrier_task->m_step == 13 )//中跑车 x轴移动
  2961. {
  2962. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  2963. {
  2964. tp_carrier_task->m_step +=2;
  2965. }
  2966. else
  2967. {
  2968. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  2969. tp_carrier_task->m_step++;
  2970. }
  2971. }
  2972. if ( tp_carrier_task->m_step == 14 )
  2973. {
  2974. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2975. }
  2976. if ( tp_carrier_task->m_step == 15 )//小跑车 进入车位
  2977. {
  2978. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_leave);
  2979. tp_carrier_task->m_step++;
  2980. }
  2981. if ( tp_carrier_task->m_step == 16 )
  2982. {
  2983. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2984. }
  2985. if ( tp_carrier_task->m_step == 17 )//小跑车 夹车
  2986. {
  2987. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_TIGHT);
  2988. tp_carrier_task->m_step++;
  2989. }
  2990. if ( tp_carrier_task->m_step == 18 )
  2991. {
  2992. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  2993. }
  2994. if ( tp_carrier_task->m_step == 19 )//小跑车 回到中跑车
  2995. {
  2996. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  2997. tp_carrier_task->m_step++;
  2998. }
  2999. if ( tp_carrier_task->m_step == 20 )
  3000. {
  3001. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3002. }
  3003. if ( tp_carrier_task->m_step == 21 )//让中跑车回到电梯井
  3004. {
  3005. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  3006. {
  3007. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  3008. tp_carrier_task->m_step++;
  3009. }
  3010. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  3011. {
  3012. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  3013. tp_carrier_task->m_step++;
  3014. }
  3015. else
  3016. {
  3017. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  3018. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  3019. }
  3020. }
  3021. if ( tp_carrier_task->m_step == 22 )
  3022. {
  3023. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3024. }
  3025. if ( tp_carrier_task->m_step == 23 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  3026. {
  3027. if ( tp_carrier->get_device_id() != 2 )
  3028. {
  3029. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  3030. tp_carrier_task->m_step++;
  3031. }
  3032. else
  3033. {
  3034. tp_carrier_task->m_step +=2;
  3035. }
  3036. }
  3037. if ( tp_carrier_task->m_step == 24 )
  3038. {
  3039. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3040. }
  3041. if ( tp_carrier_task->m_step == 25 )
  3042. {
  3043. return Error_code::SUCCESS;
  3044. }
  3045. return Error_code::SUCCESS;
  3046. }
  3047. //搬运器从停车位上取车(例如:搬运器移动到56号停车位,然后小跑车将车从车位取出,之后搬运器退回至56车位外面即可)
  3048. Error_manager Dispatch_process::excute_carrier_pickup_car_from_parkingspace_ex(Dispatch_control_node & dispatch_control_node)
  3049. {
  3050. Error_manager t_error;
  3051. Carrier * tp_carrier = NULL;
  3052. Carrier_task * tp_carrier_task = NULL;
  3053. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  3054. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  3055. {
  3056. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  3057. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  3058. }
  3059. else
  3060. {
  3061. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  3062. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  3063. }
  3064. // std::cout << " huli test :::: " << " tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  3065. // getchar();
  3066. if ( tp_carrier_task->m_step == 0 )
  3067. {
  3068. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3069. }
  3070. if ( tp_carrier_task->m_step == 1 )//检查姿态
  3071. {
  3072. //检查姿态
  3073. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::NO_CAR )
  3074. {
  3075. if ( tp_carrier_task->m_request_clamp_motion == Carrier_task::Clamp_motion::E_CLAMP_LOOSE &&
  3076. Common_data::approximate_difference(m_wheel_base, tp_carrier->m_actual_y1-tp_carrier->m_actual_y2, DISPATCH_DEFAULT_DIFFERENCE))
  3077. {
  3078. tp_carrier_task->m_step +=2;
  3079. }
  3080. else
  3081. {
  3082. carrier_adjust_to_ready(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates);
  3083. tp_carrier_task->m_step++;
  3084. }
  3085. }
  3086. else
  3087. {
  3088. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  3089. "tp_carrier->m_actual_load_status != Dispatch_device_base::Load_status::NO_CAR fun error ");
  3090. }
  3091. }
  3092. if ( tp_carrier_task->m_step == 2 )
  3093. {
  3094. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3095. }
  3096. if ( tp_carrier_task->m_step == 3 )//让小跑车回到中跑车上
  3097. {
  3098. if ( Common_data::approximate_difference(tp_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, DISPATCH_DEFAULT_DIFFERENCE) )
  3099. {
  3100. tp_carrier_task->m_step +=2;
  3101. }
  3102. else
  3103. {
  3104. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  3105. tp_carrier_task->m_step++;
  3106. }
  3107. }
  3108. if ( tp_carrier_task->m_step == 4 )
  3109. {
  3110. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3111. }
  3112. if ( tp_carrier_task->m_step == 5 )//让中跑车回到电梯井
  3113. {
  3114. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  3115. {
  3116. tp_carrier_task->m_step +=2;
  3117. }
  3118. else
  3119. {
  3120. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  3121. {
  3122. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  3123. tp_carrier_task->m_step++;
  3124. }
  3125. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  3126. {
  3127. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  3128. tp_carrier_task->m_step++;
  3129. }
  3130. else
  3131. {
  3132. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  3133. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  3134. }
  3135. }
  3136. }
  3137. if ( tp_carrier_task->m_step == 6 )
  3138. {
  3139. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3140. }
  3141. if ( tp_carrier_task->m_step == 7 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  3142. {
  3143. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  3144. {
  3145. tp_carrier_task->m_step +=2;
  3146. }
  3147. else
  3148. {
  3149. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  3150. tp_carrier_task->m_step++;
  3151. }
  3152. }
  3153. if ( tp_carrier_task->m_step == 8 )
  3154. {
  3155. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3156. }
  3157. if ( tp_carrier_task->m_step == 9 )//电梯移动到对应的楼层
  3158. {
  3159. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  3160. {
  3161. tp_carrier_task->m_step +=2;
  3162. }
  3163. else
  3164. {
  3165. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  3166. tp_carrier_task->m_step++;
  3167. }
  3168. }
  3169. if ( tp_carrier_task->m_step == 10 )
  3170. {
  3171. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3172. }
  3173. if ( tp_carrier_task->m_step == 11 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  3174. {
  3175. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK && tp_carrier->get_device_id() != 2)
  3176. {
  3177. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  3178. tp_carrier_task->m_step++;
  3179. }
  3180. else
  3181. {
  3182. tp_carrier_task->m_step +=2;
  3183. }
  3184. }
  3185. if ( tp_carrier_task->m_step == 12 )
  3186. {
  3187. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3188. }
  3189. if ( tp_carrier_task->m_step == 13 )//中跑车 x轴移动
  3190. {
  3191. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  3192. {
  3193. tp_carrier_task->m_step +=2;
  3194. }
  3195. else
  3196. {
  3197. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  3198. tp_carrier_task->m_step++;
  3199. }
  3200. }
  3201. if ( tp_carrier_task->m_step == 14 )
  3202. {
  3203. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3204. }
  3205. if ( tp_carrier_task->m_step == 15 )//小跑车 进入车位
  3206. {
  3207. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_leave);
  3208. tp_carrier_task->m_step++;
  3209. }
  3210. if ( tp_carrier_task->m_step == 16 )
  3211. {
  3212. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3213. }
  3214. if ( tp_carrier_task->m_step == 17 )//小跑车 夹车
  3215. {
  3216. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_TIGHT);
  3217. tp_carrier_task->m_step++;
  3218. }
  3219. if ( tp_carrier_task->m_step == 18 )
  3220. {
  3221. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3222. }
  3223. if ( tp_carrier_task->m_step == 19 )//小跑车 回到中跑车
  3224. {
  3225. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  3226. tp_carrier_task->m_step++;
  3227. }
  3228. if ( tp_carrier_task->m_step == 20 )
  3229. {
  3230. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3231. }
  3232. if ( tp_carrier_task->m_step == 21 )
  3233. {
  3234. return Error_code::SUCCESS;
  3235. }
  3236. return Error_code::SUCCESS;
  3237. }
  3238. //搬运器把车交付给机器手(例如:搬运器移动到3号入口的上方,小跑车松夹杆,然后等待机器手把车从中跑车上取走)
  3239. Error_manager Dispatch_process::excute_carrier_deliver_car_to_robot(Dispatch_control_node & dispatch_control_node)
  3240. {
  3241. Error_manager t_error;
  3242. Carrier * tp_carrier = NULL;
  3243. Carrier_task * tp_carrier_task = NULL;
  3244. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  3245. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  3246. {
  3247. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  3248. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  3249. }
  3250. else
  3251. {
  3252. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  3253. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  3254. }
  3255. // std::cout << " huli test :::: " << " tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  3256. // getchar();
  3257. if ( tp_carrier_task->m_step == 0 )
  3258. {
  3259. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3260. }
  3261. if ( tp_carrier_task->m_step == 1 )//检查姿态
  3262. {
  3263. //检查姿态
  3264. if ( tp_carrier->m_actual_load_status == Dispatch_device_base::Load_status::HAVE_CAR &&
  3265. tp_carrier->m_actual_clamp_motion1 == Dispatch_device_base::Clamp_motion::E_CLAMP_TIGHT)
  3266. {
  3267. //检测正常, 直接跳过
  3268. tp_carrier_task->m_step +=2;
  3269. }
  3270. else
  3271. {
  3272. return Error_manager(Error_code::CARRIER_POSE_ERROR, Error_level::MINOR_ERROR,
  3273. "tp_carrier->m_actual_load_status != Dispatch_device_base::Load_status::NO_CAR fun error ");
  3274. }
  3275. }
  3276. if ( tp_carrier_task->m_step == 2 )
  3277. {
  3278. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3279. }
  3280. if ( tp_carrier_task->m_step == 3 )//让小跑车回到中跑车上
  3281. {
  3282. if ( Common_data::approximate_difference(tp_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, DISPATCH_DEFAULT_DIFFERENCE) )
  3283. {
  3284. tp_carrier_task->m_step +=2;
  3285. }
  3286. else
  3287. {
  3288. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  3289. tp_carrier_task->m_step++;
  3290. }
  3291. }
  3292. if ( tp_carrier_task->m_step == 4 )
  3293. {
  3294. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3295. }
  3296. if ( tp_carrier_task->m_step == 5 )//让中跑车回到电梯井
  3297. {
  3298. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  3299. {
  3300. tp_carrier_task->m_step +=2;
  3301. }
  3302. else
  3303. {
  3304. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  3305. {
  3306. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  3307. tp_carrier_task->m_step++;
  3308. }
  3309. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  3310. {
  3311. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  3312. tp_carrier_task->m_step++;
  3313. }
  3314. else
  3315. {
  3316. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  3317. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  3318. }
  3319. }
  3320. }
  3321. if ( tp_carrier_task->m_step == 6 )
  3322. {
  3323. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3324. }
  3325. if ( tp_carrier_task->m_step == 7 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  3326. {
  3327. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  3328. {
  3329. tp_carrier_task->m_step +=2;
  3330. }
  3331. else
  3332. {
  3333. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  3334. tp_carrier_task->m_step++;
  3335. }
  3336. }
  3337. if ( tp_carrier_task->m_step == 8 )
  3338. {
  3339. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3340. }
  3341. if ( tp_carrier_task->m_step == 9 )//电梯移动到对应的楼层
  3342. {
  3343. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  3344. {
  3345. tp_carrier_task->m_step +=2;
  3346. }
  3347. else
  3348. {
  3349. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  3350. tp_carrier_task->m_step++;
  3351. }
  3352. }
  3353. if ( tp_carrier_task->m_step == 10 )
  3354. {
  3355. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3356. }
  3357. if ( tp_carrier_task->m_step == 11 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  3358. {
  3359. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK && tp_carrier->get_device_id() !=2)
  3360. {
  3361. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  3362. tp_carrier_task->m_step++;
  3363. }
  3364. else
  3365. {
  3366. tp_carrier_task->m_step +=2;
  3367. }
  3368. }
  3369. if ( tp_carrier_task->m_step == 12 )
  3370. {
  3371. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3372. }
  3373. if ( tp_carrier_task->m_step == 13 )//中跑车 x轴移动
  3374. {
  3375. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  3376. {
  3377. tp_carrier_task->m_step +=2;
  3378. }
  3379. else
  3380. {
  3381. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  3382. tp_carrier_task->m_step++;
  3383. }
  3384. }
  3385. if ( tp_carrier_task->m_step == 14 )
  3386. {
  3387. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3388. }
  3389. if ( tp_carrier_task->m_step == 15 )//小跑车 松开夹杆
  3390. {
  3391. carrier_move_c(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Clamp_motion::E_CLAMP_LOOSE);
  3392. tp_carrier_task->m_step++;
  3393. }
  3394. if ( tp_carrier_task->m_step == 16 )
  3395. {
  3396. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3397. }
  3398. if ( tp_carrier_task->m_step == 17 )
  3399. {
  3400. return Error_code::SUCCESS;
  3401. }
  3402. return Error_code::SUCCESS;
  3403. }
  3404. //搬运器的自由移动(可以提前到2楼来准备接车,或者为了避让就退回至电梯井)(小跑车不进行取车和存车)
  3405. Error_manager Dispatch_process::excute_carrier_move(Dispatch_control_node & dispatch_control_node)
  3406. {
  3407. Error_manager t_error;
  3408. Carrier * tp_carrier = NULL;
  3409. Carrier_task * tp_carrier_task = NULL;
  3410. Dispatch_coordinates * tp_dispatch_coordinates = Dispatch_coordinates::get_instance_pointer();
  3411. if ( dispatch_control_node.mp_dispatch_device.get() == NULL || dispatch_control_node.mp_dispatch_task.get() == NULL )
  3412. {
  3413. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  3414. "Dispatch_process::excute_robot_catch_car_from_inlet() POINTER IS NULL ");
  3415. }
  3416. else
  3417. {
  3418. tp_carrier = (Carrier *)dispatch_control_node.mp_dispatch_device.get();
  3419. tp_carrier_task = (Carrier_task *)dispatch_control_node.mp_dispatch_task.get();
  3420. }
  3421. // std::cout << " huli test :::: " << " tp_carrier_task->m_step = " << tp_carrier_task->m_step << std::endl;
  3422. // getchar();
  3423. if ( tp_carrier_task->m_step == 0 )
  3424. {
  3425. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3426. }
  3427. if ( tp_carrier_task->m_step == 1 )//让小跑车回到中跑车上
  3428. {
  3429. if ( Common_data::approximate_difference(tp_carrier->m_actual_y, tp_dispatch_coordinates->m_carrier_default_y_back, DISPATCH_DEFAULT_DIFFERENCE) )
  3430. {
  3431. tp_carrier_task->m_step +=2;
  3432. }
  3433. else
  3434. {
  3435. carrier_move_y(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_y_back);
  3436. tp_carrier_task->m_step++;
  3437. }
  3438. }
  3439. if ( tp_carrier_task->m_step == 2 )
  3440. {
  3441. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3442. }
  3443. if ( tp_carrier_task->m_step == 3 )//让中跑车回到电梯井
  3444. {
  3445. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  3446. {
  3447. tp_carrier_task->m_step +=2;
  3448. }
  3449. else
  3450. {
  3451. if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 0 )
  3452. {
  3453. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_left);
  3454. tp_carrier_task->m_step++;
  3455. }
  3456. else if ( dispatch_control_node.mp_dispatch_device->get_device_id() == 1 )
  3457. {
  3458. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, tp_dispatch_coordinates->m_carrier_default_x_right);
  3459. tp_carrier_task->m_step++;
  3460. }
  3461. else
  3462. {
  3463. return Error_manager(Error_code::CARRIER_CONRTOL_PARAMETER_ERROR, Error_level::MINOR_ERROR,
  3464. " dispatch_control_node.m_destination_coordinates.z PARAMRTER ERROR ");
  3465. }
  3466. }
  3467. }
  3468. if ( tp_carrier_task->m_step == 4 )
  3469. {
  3470. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3471. }
  3472. if ( tp_carrier_task->m_step == 5 )//收回对接,之后中跑车固定在电梯上不能X轴移动,电梯可以Z轴移动
  3473. {
  3474. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  3475. {
  3476. tp_carrier_task->m_step +=2;
  3477. }
  3478. else
  3479. {
  3480. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_TAKE_BACK);
  3481. tp_carrier_task->m_step++;
  3482. }
  3483. }
  3484. if ( tp_carrier_task->m_step == 6 )
  3485. {
  3486. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3487. }
  3488. if ( tp_carrier_task->m_step == 7 )//电梯移动到对应的楼层
  3489. {
  3490. if ( Common_data::approximate_difference(tp_carrier->m_actual_z, dispatch_control_node.m_destination_coordinates.z, DISPATCH_DEFAULT_DIFFERENCE) )
  3491. {
  3492. tp_carrier_task->m_step +=2;
  3493. }
  3494. else
  3495. {
  3496. carrier_move_z(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.z);
  3497. tp_carrier_task->m_step++;
  3498. }
  3499. }
  3500. if ( tp_carrier_task->m_step == 8 )
  3501. {
  3502. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3503. }
  3504. if ( tp_carrier_task->m_step == 9 )//伸出对接,之后中跑车可以x轴移动,电梯不能Z轴移动
  3505. {
  3506. if ( tp_carrier->m_actual_joint_motion_x1 == Dispatch_device_base::Joint_motion::E_JOINT_TAKE_BACK && tp_carrier->get_device_id() !=2)
  3507. {
  3508. carrier_joint_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, Carrier_task::Joint_motion::E_JOINT_HOLD_OUT);
  3509. tp_carrier_task->m_step++;
  3510. }
  3511. else
  3512. {
  3513. tp_carrier_task->m_step +=2;
  3514. }
  3515. }
  3516. if ( tp_carrier_task->m_step == 10 )
  3517. {
  3518. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3519. }
  3520. if ( tp_carrier_task->m_step == 11 )//中跑车 x轴移动
  3521. {
  3522. if ( Common_data::approximate_difference(tp_carrier->m_actual_x, dispatch_control_node.m_destination_coordinates.x, DISPATCH_DEFAULT_DIFFERENCE) )
  3523. {
  3524. tp_carrier_task->m_step +=2;
  3525. }
  3526. else
  3527. {
  3528. carrier_move_x(dispatch_control_node, tp_carrier, tp_carrier_task, tp_dispatch_coordinates, dispatch_control_node.m_destination_coordinates.x);
  3529. tp_carrier_task->m_step++;
  3530. }
  3531. }
  3532. if ( tp_carrier_task->m_step == 12 )
  3533. {
  3534. return check_task_ex(dispatch_control_node.mp_dispatch_task, tp_carrier_task->m_step);
  3535. }
  3536. if ( tp_carrier_task->m_step == 13 )
  3537. {
  3538. return Error_code::SUCCESS;
  3539. }
  3540. return Error_code::SUCCESS;
  3541. }
  3542. //执行通道口动作
  3543. Error_manager Dispatch_process::excute_passageway_motion(Dispatch_control_node & dispatch_control_node)
  3544. {
  3545. return Error_code::SUCCESS;
  3546. }
  3547. //检查 任务单 是否完成任务, 里面会调整短步骤
  3548. Error_manager Dispatch_process::check_task_status(std::shared_ptr<Task_Base> p_task, Dispatch_control_status & dispatch_control_status)
  3549. {
  3550. if ( p_task.get() == NULL )
  3551. {
  3552. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  3553. "Dispatch_process::check_passageway_task POINTER IS NULL ");
  3554. }
  3555. else
  3556. {
  3557. if ( p_task->get_task_statu() == Task_Base::Task_statu::TASK_OVER )
  3558. {
  3559. dispatch_control_status = (Dispatch_control_status)(dispatch_control_status+1);
  3560. // return Error_code::NODATA; //这里返回nodata 表示任务继续下一步
  3561. //注意了, 这里返回成功, 用作动作完成判断
  3562. return Error_code::SUCCESS; //这里返回nodata 表示任务继续下一步
  3563. }
  3564. else if ( p_task->get_task_statu() == Task_Base::Task_statu::TASK_ERROR )
  3565. {
  3566. dispatch_control_status = DISPATCH_CONTROL_FAULT;
  3567. return p_task->get_task_error_manager();
  3568. }
  3569. else if ( p_task->get_task_statu() == Task_Base::Task_statu::TASK_WORKING ||
  3570. p_task->get_task_statu() == Task_Base::Task_statu::TASK_SIGNED ||
  3571. p_task->get_task_statu() == Task_Base::Task_statu::TASK_CREATED)
  3572. {
  3573. //继续等待任务, 直到状态改变
  3574. return Error_code::NODATA;
  3575. }
  3576. else
  3577. {
  3578. LOG(INFO) << "Dispatch_process::check_task_ex failed p_catcher_task->get_task_statu() = "<< p_task->get_task_statu() << " " << this;
  3579. return Error_code::NODATA;
  3580. }
  3581. }
  3582. return Error_code::SUCCESS;
  3583. }
  3584. //检查 任务单 是否完成任务, 里面会调整短步骤
  3585. Error_manager Dispatch_process::check_task_ex(std::shared_ptr<Task_Base> p_task, int& step)
  3586. {
  3587. if ( p_task.get() == NULL )
  3588. {
  3589. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  3590. "Dispatch_process::check_passageway_task POINTER IS NULL ");
  3591. }
  3592. else
  3593. {
  3594. // std::cout << " huli test :::: " << " ffffffffffffffffffffffffffffffffffffffffffffffffffffff = " << 333 << std::endl;
  3595. // std::cout << " huli test :::: " << " p_task->get_task_statu() = " << p_task->get_task_statu() << std::endl;
  3596. // std::cout << " huli test :::: " << " gggggggggggggggggggggggggggggggggggggggggggggggggggggg = " << 333 << std::endl;
  3597. if ( p_task->get_task_statu() == Task_Base::Task_statu::TASK_OVER )
  3598. {
  3599. step++;
  3600. return Error_code::NODATA; //这里返回nodata 表示任务继续下一步
  3601. }
  3602. else if ( p_task->get_task_statu() == Task_Base::Task_statu::TASK_ERROR )
  3603. {
  3604. step = 0;
  3605. return p_task->get_task_error_manager();
  3606. }
  3607. else if ( p_task->get_task_statu() == Task_Base::Task_statu::TASK_WORKING ||
  3608. p_task->get_task_statu() == Task_Base::Task_statu::TASK_SIGNED ||
  3609. p_task->get_task_statu() == Task_Base::Task_statu::TASK_CREATED)
  3610. {
  3611. //继续等待任务, 直到状态改变
  3612. return Error_code::NODATA;
  3613. }
  3614. else
  3615. {
  3616. LOG(INFO) << "Dispatch_process::check_task_ex failed p_catcher_task->get_task_statu() = "<< p_task->get_task_statu() << " " << this;
  3617. return Error_code::NODATA;
  3618. }
  3619. }
  3620. return Error_code::SUCCESS;
  3621. }
  3622. //机器手调整到正常待机的姿态(调节夹杆和轴距)
  3623. 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)
  3624. {
  3625. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  3626. char t_key[50] = {0};
  3627. 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);
  3628. tp_catcher_task->m_request_key = t_key;
  3629. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  3630. //调整姿态
  3631. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  3632. tp_catcher_task->m_request_d1 = tp_dispatch_coordinates->m_catcher_d1_min;
  3633. tp_catcher_task->m_request_d2 = tp_dispatch_coordinates->m_catcher_d2_min;
  3634. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  3635. {
  3636. tp_catcher_task->m_request_b = 270;
  3637. }
  3638. else
  3639. {
  3640. tp_catcher_task->m_request_b = 90;
  3641. }
  3642. std::cout << " huli test :::: " << " catcher_adjust_to_ready = " << tp_catcher_task->m_request_key << std::endl;
  3643. std::cout << " huli test :::: " << " catcher_adjust_to_ready = " << tp_catcher_task->m_respons_key << std::endl;
  3644. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  3645. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  3646. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  3647. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  3648. std::cout << " huli test :::: " << " tp_catcher_task->m_request_b = " << tp_catcher_task->m_request_b << std::endl;
  3649. return Error_code::SUCCESS;
  3650. }
  3651. //机器手 移动z
  3652. 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)
  3653. {
  3654. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  3655. char t_key[50] = {0};
  3656. 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);
  3657. tp_catcher_task->m_request_key = t_key;
  3658. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  3659. //机器手 移动z
  3660. tp_catcher_task->m_request_z = target;
  3661. std::cout << " huli test :::: " << " catcher_move_z = " << tp_catcher_task->m_request_key << std::endl;
  3662. std::cout << " huli test :::: " << " catcher_move_z = " << tp_catcher_task->m_respons_key << std::endl;
  3663. std::cout << " huli test :::: " << " tp_catcher_task->m_request_z = " << tp_catcher_task->m_request_z << std::endl;
  3664. return Error_code::SUCCESS;
  3665. }
  3666. //机器手调整到 准备从地面抓车前的姿态
  3667. 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)
  3668. {
  3669. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  3670. char t_key[50] = {0};
  3671. 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);
  3672. tp_catcher_task->m_request_key = t_key;
  3673. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  3674. //机器手 调整x y b d1 d2, 根据感测模块的定位信息, 调整机器手的姿态, 准备抓车.
  3675. tp_catcher_task->m_request_x = m_car_measure_information.center_x;
  3676. tp_catcher_task->m_request_y = m_car_measure_information.center_y;
  3677. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  3678. {
  3679. //机器手如果旋转反向, 那就+180即可, 没有必要旋转归位.
  3680. tp_catcher_task->m_request_b = 180 + m_car_measure_information.car_angle;
  3681. }
  3682. else
  3683. {
  3684. tp_catcher_task->m_request_b = m_car_measure_information.car_angle;
  3685. }
  3686. //限制轮距, 在夹车杆松开时, 机器人下降时, 轴距不能超过3000mm, 必须下降到最下面才能调整轴距, 夹车后可以上升.
  3687. if ( m_wheel_base > tp_dispatch_coordinates->m_catcher_wheel_base_limit )
  3688. {
  3689. tp_catcher_task->m_request_d1 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  3690. tp_catcher_task->m_request_d2 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  3691. tp_catcher_task->m_request_wheelbase = tp_dispatch_coordinates->m_catcher_wheel_base_limit;
  3692. }
  3693. else
  3694. {
  3695. tp_catcher_task->m_request_d1 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  3696. tp_catcher_task->m_request_d2 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  3697. tp_catcher_task->m_request_wheelbase = m_wheel_base;
  3698. }
  3699. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  3700. std::cout << " huli test :::: " << " catcher_adjust_from_ground = " << tp_catcher_task->m_request_key << std::endl;
  3701. std::cout << " huli test :::: " << " catcher_adjust_from_ground = " << tp_catcher_task->m_respons_key << std::endl;
  3702. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  3703. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  3704. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  3705. std::cout << " huli test :::: " << " tp_catcher_task->m_request_b = " << tp_catcher_task->m_request_b << std::endl;
  3706. std::cout << " huli test :::: " << " m_wheel_base = " << m_wheel_base << std::endl;
  3707. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  3708. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  3709. std::cout << " huli test :::: " << " tp_catcher_task->m_request_wheelbase = " << tp_catcher_task->m_request_wheelbase << std::endl;
  3710. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  3711. return Error_code::SUCCESS;
  3712. }
  3713. //机器手 修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  3714. 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)
  3715. {
  3716. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  3717. char t_key[50] = {0};
  3718. 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);
  3719. tp_catcher_task->m_request_key = t_key;
  3720. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  3721. //修正轴距
  3722. tp_catcher_task->m_request_d1 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  3723. tp_catcher_task->m_request_d2 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  3724. tp_catcher_task->m_request_wheelbase = m_wheel_base;
  3725. std::cout << " huli test :::: " << " catcher_adjust_wheel_base = " << tp_catcher_task->m_request_key << std::endl;
  3726. std::cout << " huli test :::: " << " catcher_adjust_wheel_base = " << tp_catcher_task->m_respons_key << std::endl;
  3727. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  3728. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  3729. std::cout << " huli test :::: " << " tp_catcher_task->m_request_wheelbase = " << tp_catcher_task->m_request_wheelbase << std::endl;
  3730. return Error_code::SUCCESS;
  3731. }
  3732. //机器手 移动c轴 夹杆
  3733. 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)
  3734. {
  3735. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  3736. char t_key[50] = {0};
  3737. 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);
  3738. tp_catcher_task->m_request_key = t_key;
  3739. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  3740. tp_catcher_task->m_request_clamp_motion = target;
  3741. std::cout << " huli test :::: " << " catcher_move_c = " << tp_catcher_task->m_request_key << std::endl;
  3742. std::cout << " huli test :::: " << " catcher_move_c = " << tp_catcher_task->m_respons_key << std::endl;
  3743. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  3744. return Error_code::SUCCESS;
  3745. }
  3746. //机器手调整到 准备把车放到搬运器的姿态
  3747. 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)
  3748. {
  3749. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  3750. char t_key[50] = {0};
  3751. 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);
  3752. tp_catcher_task->m_request_key = t_key;
  3753. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  3754. //机器手 调整x y b d1 d2, 调整机器手的姿态, 准备把车放置到中跑车上.
  3755. tp_catcher_task->m_request_x = dispatch_control_node.m_destination_coordinates.x;
  3756. tp_catcher_task->m_request_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  3757. //存车需要反向, 取车不需要
  3758. if ( reverse_flag )
  3759. {
  3760. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  3761. {
  3762. tp_catcher_task->m_request_b = 90;
  3763. }
  3764. else
  3765. {
  3766. tp_catcher_task->m_request_b = 270;
  3767. }
  3768. }
  3769. else
  3770. {
  3771. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  3772. {
  3773. tp_catcher_task->m_request_b = 270;
  3774. }
  3775. else
  3776. {
  3777. tp_catcher_task->m_request_b = 90;
  3778. }
  3779. }
  3780. std::cout << " huli test :::: " << " catcher_adjust_to_carrier = " << tp_catcher_task->m_request_key << std::endl;
  3781. std::cout << " huli test :::: " << " catcher_adjust_to_carrier = " << tp_catcher_task->m_respons_key << std::endl;
  3782. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  3783. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  3784. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  3785. std::cout << " huli test :::: " << " tp_catcher->m_request_b = " << tp_catcher->m_request_b << std::endl;
  3786. return Error_code::SUCCESS;
  3787. }
  3788. //机器手调整到 准备把车放到地面的姿态
  3789. 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)
  3790. {
  3791. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  3792. char t_key[50] = {0};
  3793. 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);
  3794. tp_catcher_task->m_request_key = t_key;
  3795. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  3796. //机器手 调整x y b d1 d2, 调整机器手的姿态, 准备把车放置到中跑车上.
  3797. tp_catcher_task->m_request_x = dispatch_control_node.m_destination_coordinates.x;
  3798. tp_catcher_task->m_request_y = dispatch_control_node.m_destination_coordinates.y;
  3799. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  3800. {
  3801. tp_catcher_task->m_request_b = 270;
  3802. }
  3803. else
  3804. {
  3805. tp_catcher_task->m_request_b = 90;
  3806. }
  3807. std::cout << " huli test :::: " << " catcher_adjust_to_ground = " << tp_catcher_task->m_request_key << std::endl;
  3808. std::cout << " huli test :::: " << " catcher_adjust_to_ground = " << tp_catcher_task->m_respons_key << std::endl;
  3809. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  3810. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  3811. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  3812. std::cout << " huli test :::: " << " tp_catcher->m_request_b = " << tp_catcher->m_request_b << std::endl;
  3813. return Error_code::SUCCESS;
  3814. }
  3815. //机器手调整到 对接搬运器的姿态
  3816. 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)
  3817. {
  3818. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  3819. char t_key[50] = {0};
  3820. 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);
  3821. tp_catcher_task->m_request_key = t_key;
  3822. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  3823. //机器手 调整x y b d1 d2, 调整机器手的姿态, 准备把车放置到中跑车上.
  3824. tp_catcher_task->m_request_x = dispatch_control_node.m_destination_coordinates.x;
  3825. tp_catcher_task->m_request_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  3826. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  3827. {
  3828. tp_catcher_task->m_request_b = 270;
  3829. }
  3830. else
  3831. {
  3832. tp_catcher_task->m_request_b = 90;
  3833. }
  3834. //限制轮距, 在夹车杆松开时, 机器人下降时, 轴距不能超过3000mm, 必须下降到最下面才能调整轴距, 夹车后可以上升.
  3835. if ( m_wheel_base > tp_dispatch_coordinates->m_catcher_wheel_base_limit )
  3836. {
  3837. tp_catcher_task->m_request_d1 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  3838. tp_catcher_task->m_request_d2 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  3839. tp_catcher_task->m_request_wheelbase = tp_dispatch_coordinates->m_catcher_wheel_base_limit;
  3840. }
  3841. else
  3842. {
  3843. tp_catcher_task->m_request_d1 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  3844. tp_catcher_task->m_request_d2 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  3845. tp_catcher_task->m_request_wheelbase = m_wheel_base;
  3846. }
  3847. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  3848. std::cout << " huli test :::: " << " catcher_adjust_from_carrier = " << tp_catcher_task->m_request_key << std::endl;
  3849. std::cout << " huli test :::: " << " catcher_adjust_from_carrier = " << tp_catcher_task->m_respons_key << std::endl;
  3850. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  3851. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  3852. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  3853. std::cout << " huli test :::: " << " tp_catcher_task->m_request_b = " << tp_catcher_task->m_request_b << std::endl;
  3854. std::cout << " huli test :::: " << " m_wheel_base = " << m_wheel_base << std::endl;
  3855. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  3856. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  3857. std::cout << " huli test :::: " << " tp_catcher_task->m_request_wheelbase = " << tp_catcher_task->m_request_wheelbase << std::endl;
  3858. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  3859. return Error_code::SUCCESS;
  3860. }
  3861. //搬运器调整到 正常待机的姿态(调节夹杆和轴距)
  3862. 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)
  3863. {
  3864. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  3865. char t_key[50] = {0};
  3866. 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);
  3867. tp_carrier_task->m_request_key = t_key;
  3868. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  3869. tp_carrier_task->m_request_clamp_motion = Carrier_task::Clamp_motion::E_CLAMP_LOOSE;
  3870. tp_carrier_task->m_request_wheelbase = m_wheel_base;
  3871. tp_carrier_task->m_request_y1 = tp_carrier->m_actual_y + tp_dispatch_coordinates->m_carrier_y_y1_distance;
  3872. tp_carrier_task->m_request_y2 = tp_carrier_task->m_request_y1 - tp_carrier_task->m_request_wheelbase;
  3873. std::cout << " huli test :::: " << " carrier_adjust_to_ready = " << tp_carrier_task->m_request_key << std::endl;
  3874. std::cout << " huli test :::: " << " carrier_adjust_to_ready = " << tp_carrier_task->m_respons_key << std::endl;
  3875. std::cout << " huli test :::: " << " tp_carrier_task->m_request_wheelbase = " << tp_carrier_task->m_request_wheelbase << std::endl;
  3876. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y1 = " << tp_carrier_task->m_request_y1 << std::endl;
  3877. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y2 = " << tp_carrier_task->m_request_y2 << std::endl;
  3878. std::cout << " huli test :::: " << " tp_carrier_task->m_request_clamp_motion = " << tp_carrier_task->m_request_clamp_motion << std::endl;
  3879. return Error_code::SUCCESS;
  3880. }
  3881. //搬运器 移动x
  3882. 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)
  3883. {
  3884. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  3885. char t_key[50] = {0};
  3886. 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);
  3887. tp_carrier_task->m_request_key = t_key;
  3888. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  3889. tp_carrier_task->m_request_x = target;
  3890. std::cout << " huli test :::: " << " carrier_move_x = " << tp_carrier_task->m_request_key << std::endl;
  3891. std::cout << " huli test :::: " << " carrier_move_x = " << tp_carrier_task->m_respons_key << std::endl;
  3892. std::cout << " huli test :::: " << " tp_carrier_task->m_request_x = " << tp_carrier_task->m_request_x << std::endl;
  3893. return Error_code::SUCCESS;
  3894. }
  3895. //搬运器 移动y
  3896. 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)
  3897. {
  3898. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  3899. char t_key[50] = {0};
  3900. 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);
  3901. tp_carrier_task->m_request_key = t_key;
  3902. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  3903. tp_carrier_task->m_request_y = target;
  3904. tp_carrier_task->m_request_wheelbase = m_wheel_base;
  3905. tp_carrier_task->m_request_y1 = tp_carrier_task->m_request_y + tp_dispatch_coordinates->m_carrier_y_y1_distance;
  3906. tp_carrier_task->m_request_y2 = tp_carrier_task->m_request_y1 - tp_carrier_task->m_request_wheelbase;
  3907. std::cout << " huli test :::: " << " carrier_move_y = " << tp_carrier_task->m_request_key << std::endl;
  3908. std::cout << " huli test :::: " << " carrier_move_y = " << tp_carrier_task->m_respons_key << std::endl;
  3909. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y = " << tp_carrier_task->m_request_y << std::endl;
  3910. std::cout << " huli test :::: " << " tp_carrier_task->m_request_wheelbase = " << tp_carrier_task->m_request_wheelbase << std::endl;
  3911. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y1 = " << tp_carrier_task->m_request_y1 << std::endl;
  3912. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y2 = " << tp_carrier_task->m_request_y2 << std::endl;
  3913. return Error_code::SUCCESS;
  3914. }
  3915. //搬运器 移动z
  3916. 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)
  3917. {
  3918. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  3919. char t_key[50] = {0};
  3920. 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);
  3921. tp_carrier_task->m_request_key = t_key;
  3922. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  3923. tp_carrier_task->m_request_z = target;
  3924. std::cout << " huli test :::: " << " carrier_move_z = " << tp_carrier_task->m_request_key << std::endl;
  3925. std::cout << " huli test :::: " << " carrier_move_z = " << tp_carrier_task->m_respons_key << std::endl;
  3926. std::cout << " huli test :::: " << " tp_carrier_task->m_request_z = " << tp_carrier_task->m_request_z << std::endl;
  3927. return Error_code::SUCCESS;
  3928. }
  3929. //搬运器 移动c轴 夹车杆
  3930. 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)
  3931. {
  3932. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  3933. char t_key[50] = {0};
  3934. 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);
  3935. tp_carrier_task->m_request_key = t_key;
  3936. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  3937. tp_carrier_task->m_request_clamp_motion = target;
  3938. std::cout << " huli test :::: " << " carrier_move_c = " << tp_carrier_task->m_request_key << std::endl;
  3939. std::cout << " huli test :::: " << " carrier_move_c = " << tp_carrier_task->m_respons_key << std::endl;
  3940. std::cout << " huli test :::: " << " tp_carrier_task->m_request_clamp_motion = " << tp_carrier_task->m_request_clamp_motion << std::endl;
  3941. return Error_code::SUCCESS;
  3942. }
  3943. //搬运器调整 水平的交接
  3944. 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)
  3945. {
  3946. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  3947. char t_key[50] = {0};
  3948. 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);
  3949. tp_carrier_task->m_request_key = t_key;
  3950. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  3951. tp_carrier_task->m_request_joint_motion_x = target;
  3952. std::cout << " huli test :::: " << " carrier_joint_x = " << tp_carrier_task->m_request_key << std::endl;
  3953. std::cout << " huli test :::: " << " carrier_joint_x = " << tp_carrier_task->m_respons_key << std::endl;
  3954. std::cout << " huli test :::: " << " tp_carrier_task->m_request_joint_motion_x = " << tp_carrier_task->m_request_joint_motion_x << std::endl;
  3955. return Error_code::SUCCESS;
  3956. }
  3957. //搬运器 修正轴距
  3958. 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)
  3959. {
  3960. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  3961. char t_key[50] = {0};
  3962. 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);
  3963. tp_carrier_task->m_request_key = t_key;
  3964. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  3965. tp_carrier_task->m_request_wheelbase = m_wheel_base;
  3966. tp_carrier_task->m_request_y1 = tp_carrier->m_actual_y + tp_dispatch_coordinates->m_carrier_y_y1_distance;
  3967. tp_carrier_task->m_request_y2 = tp_carrier_task->m_request_y1 - tp_carrier_task->m_request_wheelbase;
  3968. std::cout << " huli test :::: " << " carrier_adjust_wheel_base = " << tp_carrier_task->m_request_key << std::endl;
  3969. std::cout << " huli test :::: " << " carrier_adjust_wheel_base = " << tp_carrier_task->m_respons_key << std::endl;
  3970. std::cout << " huli test :::: " << " tp_carrier_task->m_request_wheelbase = " << tp_carrier_task->m_request_wheelbase << std::endl;
  3971. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y1 = " << tp_carrier_task->m_request_y1 << std::endl;
  3972. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y2 = " << tp_carrier_task->m_request_y2 << std::endl;
  3973. return Error_code::SUCCESS;
  3974. }
  3975. //机器手调整到正常待机的姿态(调节夹杆和轴距)
  3976. Error_manager Dispatch_process::catcher_adjust_to_ready(std::string dispatch_control_command_key, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  3977. {
  3978. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  3979. tp_catcher_task->m_request_key = dispatch_control_command_key;
  3980. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  3981. //调整姿态
  3982. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  3983. tp_catcher_task->m_request_d1 = tp_dispatch_coordinates->m_catcher_d1_min;
  3984. tp_catcher_task->m_request_d2 = tp_dispatch_coordinates->m_catcher_d2_min;
  3985. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  3986. {
  3987. tp_catcher_task->m_request_b = 270;
  3988. }
  3989. else
  3990. {
  3991. tp_catcher_task->m_request_b = 90;
  3992. }
  3993. std::cout << " huli test :::: " << " catcher_adjust_to_ready = " << tp_catcher_task->m_request_key << std::endl;
  3994. std::cout << " huli test :::: " << " catcher_adjust_to_ready = " << tp_catcher_task->m_respons_key << std::endl;
  3995. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  3996. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  3997. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  3998. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  3999. std::cout << " huli test :::: " << " tp_catcher_task->m_request_b = " << tp_catcher_task->m_request_b << std::endl;
  4000. return Error_code::SUCCESS;
  4001. }
  4002. //机器手 移动x
  4003. Error_manager Dispatch_process::catcher_move_x(std::string dispatch_control_command_key, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, float target_x)
  4004. {
  4005. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  4006. tp_catcher_task->m_request_key = dispatch_control_command_key;
  4007. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  4008. //机器手 移动x
  4009. tp_catcher_task->m_request_x = target_x;
  4010. std::cout << " huli test :::: " << " catcher_move_x = " << tp_catcher_task->m_request_key << std::endl;
  4011. std::cout << " huli test :::: " << " catcher_move_x = " << tp_catcher_task->m_respons_key << std::endl;
  4012. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  4013. return Error_code::SUCCESS;
  4014. }
  4015. //机器手 移动y
  4016. Error_manager Dispatch_process::catcher_move_y(std::string dispatch_control_command_key, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, float target_y)
  4017. {
  4018. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  4019. tp_catcher_task->m_request_key = dispatch_control_command_key;
  4020. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  4021. //机器手 移动y
  4022. tp_catcher_task->m_request_y = target_y;
  4023. std::cout << " huli test :::: " << " catcher_move_y = " << tp_catcher_task->m_request_key << std::endl;
  4024. std::cout << " huli test :::: " << " catcher_move_y = " << tp_catcher_task->m_respons_key << std::endl;
  4025. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  4026. return Error_code::SUCCESS;
  4027. }
  4028. //机器手 移动z
  4029. Error_manager Dispatch_process::catcher_move_z(std::string dispatch_control_command_key, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, float target_z)
  4030. {
  4031. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  4032. tp_catcher_task->m_request_key = dispatch_control_command_key;
  4033. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  4034. //机器手 移动z
  4035. tp_catcher_task->m_request_z = target_z;
  4036. std::cout << " huli test :::: " << " catcher_move_z = " << tp_catcher_task->m_request_key << std::endl;
  4037. std::cout << " huli test :::: " << " catcher_move_z = " << tp_catcher_task->m_respons_key << std::endl;
  4038. std::cout << " huli test :::: " << " tp_catcher_task->m_request_z = " << tp_catcher_task->m_request_z << std::endl;
  4039. return Error_code::SUCCESS;
  4040. }
  4041. //机器手调整到 准备从地面抓车前的姿态
  4042. Error_manager Dispatch_process::catcher_adjust_from_ground(std::string dispatch_control_command_key, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  4043. {
  4044. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  4045. tp_catcher_task->m_request_key = dispatch_control_command_key;
  4046. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  4047. //机器手 调整x y b d1 d2, 根据感测模块的定位信息, 调整机器手的姿态, 准备抓车.
  4048. tp_catcher_task->m_request_x = m_car_measure_information.center_x;
  4049. tp_catcher_task->m_request_y = m_car_measure_information.center_y;
  4050. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  4051. {
  4052. //机器手如果旋转反向, 那就+180即可, 没有必要旋转归位.
  4053. tp_catcher_task->m_request_b = 180 + m_car_measure_information.car_angle;
  4054. }
  4055. else
  4056. {
  4057. tp_catcher_task->m_request_b = m_car_measure_information.car_angle;
  4058. }
  4059. //限制轮距, 在夹车杆松开时, 机器人下降时, 轴距不能超过3000mm, 必须下降到最下面才能调整轴距, 夹车后可以上升.
  4060. if ( m_wheel_base > tp_dispatch_coordinates->m_catcher_wheel_base_limit )
  4061. {
  4062. tp_catcher_task->m_request_d1 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  4063. tp_catcher_task->m_request_d2 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  4064. tp_catcher_task->m_request_wheelbase = tp_dispatch_coordinates->m_catcher_wheel_base_limit;
  4065. }
  4066. else
  4067. {
  4068. tp_catcher_task->m_request_d1 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  4069. tp_catcher_task->m_request_d2 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  4070. tp_catcher_task->m_request_wheelbase = m_wheel_base;
  4071. }
  4072. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  4073. std::cout << " huli test :::: " << " catcher_adjust_from_ground = " << tp_catcher_task->m_request_key << std::endl;
  4074. std::cout << " huli test :::: " << " catcher_adjust_from_ground = " << tp_catcher_task->m_respons_key << std::endl;
  4075. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  4076. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  4077. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  4078. std::cout << " huli test :::: " << " tp_catcher_task->m_request_b = " << tp_catcher_task->m_request_b << std::endl;
  4079. std::cout << " huli test :::: " << " m_wheel_base = " << m_wheel_base << std::endl;
  4080. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  4081. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  4082. std::cout << " huli test :::: " << " tp_catcher_task->m_request_wheelbase = " << tp_catcher_task->m_request_wheelbase << std::endl;
  4083. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  4084. return Error_code::SUCCESS;
  4085. }
  4086. //机器手 修正轴距, 如果轴距大于3000mm, 那么就要修正轴距.
  4087. Error_manager Dispatch_process::catcher_adjust_wheel_base(std::string dispatch_control_command_key, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates)
  4088. {
  4089. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  4090. tp_catcher_task->m_request_key = dispatch_control_command_key;
  4091. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  4092. //修正轴距
  4093. tp_catcher_task->m_request_d1 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  4094. tp_catcher_task->m_request_d2 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  4095. tp_catcher_task->m_request_wheelbase = m_wheel_base;
  4096. std::cout << " huli test :::: " << " catcher_adjust_wheel_base = " << tp_catcher_task->m_request_key << std::endl;
  4097. std::cout << " huli test :::: " << " catcher_adjust_wheel_base = " << tp_catcher_task->m_respons_key << std::endl;
  4098. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  4099. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  4100. std::cout << " huli test :::: " << " tp_catcher_task->m_request_wheelbase = " << tp_catcher_task->m_request_wheelbase << std::endl;
  4101. return Error_code::SUCCESS;
  4102. }
  4103. //机器手 移动c轴 夹杆
  4104. Error_manager Dispatch_process::catcher_move_c(std::string dispatch_control_command_key, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, Catcher_task::Clamp_motion target)
  4105. {
  4106. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  4107. tp_catcher_task->m_request_key = dispatch_control_command_key;
  4108. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  4109. tp_catcher_task->m_request_clamp_motion = target;
  4110. std::cout << " huli test :::: " << " catcher_move_c = " << tp_catcher_task->m_request_key << std::endl;
  4111. std::cout << " huli test :::: " << " catcher_move_c = " << tp_catcher_task->m_respons_key << std::endl;
  4112. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  4113. return Error_code::SUCCESS;
  4114. }
  4115. //机器手调整到 准备把车放到搬运器的姿态
  4116. Error_manager Dispatch_process::catcher_adjust_to_carrier(std::string dispatch_control_command_key, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, float target_x, bool reverse_flag)
  4117. {
  4118. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  4119. tp_catcher_task->m_request_key = dispatch_control_command_key;
  4120. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  4121. //机器手 调整x y b d1 d2, 调整机器手的姿态, 准备把车放置到中跑车上.
  4122. tp_catcher_task->m_request_x = target_x;
  4123. tp_catcher_task->m_request_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  4124. //存车需要反向, 取车不需要
  4125. if ( reverse_flag )
  4126. {
  4127. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  4128. {
  4129. tp_catcher_task->m_request_b = 90;
  4130. }
  4131. else
  4132. {
  4133. tp_catcher_task->m_request_b = 270;
  4134. }
  4135. }
  4136. else
  4137. {
  4138. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  4139. {
  4140. tp_catcher_task->m_request_b = 270;
  4141. }
  4142. else
  4143. {
  4144. tp_catcher_task->m_request_b = 90;
  4145. }
  4146. }
  4147. std::cout << " huli test :::: " << " catcher_adjust_to_carrier = " << tp_catcher_task->m_request_key << std::endl;
  4148. std::cout << " huli test :::: " << " catcher_adjust_to_carrier = " << tp_catcher_task->m_respons_key << std::endl;
  4149. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  4150. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  4151. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  4152. std::cout << " huli test :::: " << " tp_catcher->m_request_b = " << tp_catcher->m_request_b << std::endl;
  4153. return Error_code::SUCCESS;
  4154. }
  4155. //机器手调整到 准备把车放到地面的姿态
  4156. Error_manager Dispatch_process::catcher_adjust_to_ground(std::string dispatch_control_command_key, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, float target_x, float target_y)
  4157. {
  4158. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  4159. tp_catcher_task->m_request_key = dispatch_control_command_key;
  4160. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  4161. //机器手 调整x y b d1 d2, 调整机器手的姿态, 准备把车放置到中跑车上.
  4162. tp_catcher_task->m_request_x = target_x;
  4163. tp_catcher_task->m_request_y = target_y;
  4164. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  4165. {
  4166. tp_catcher_task->m_request_b = 270;
  4167. }
  4168. else
  4169. {
  4170. tp_catcher_task->m_request_b = 90;
  4171. }
  4172. std::cout << " huli test :::: " << " catcher_adjust_to_ground = " << tp_catcher_task->m_request_key << std::endl;
  4173. std::cout << " huli test :::: " << " catcher_adjust_to_ground = " << tp_catcher_task->m_respons_key << std::endl;
  4174. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  4175. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  4176. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  4177. std::cout << " huli test :::: " << " tp_catcher->m_request_b = " << tp_catcher->m_request_b << std::endl;
  4178. return Error_code::SUCCESS;
  4179. }
  4180. //机器手调整到 对接搬运器的姿态
  4181. Error_manager Dispatch_process::catcher_adjust_from_carrier(std::string dispatch_control_command_key, Catcher * tp_catcher, Catcher_task * tp_catcher_task, Dispatch_coordinates * tp_dispatch_coordinates, float target_x)
  4182. {
  4183. std::unique_lock<std::mutex> t_lock2(tp_catcher_task->m_lock);
  4184. tp_catcher_task->m_request_key = dispatch_control_command_key;
  4185. tp_catcher_task->set_task_statu(Task_Base::TASK_CREATED);
  4186. //机器手 调整x y b d1 d2, 调整机器手的姿态, 准备把车放置到中跑车上.
  4187. tp_catcher_task->m_request_x = target_x;
  4188. tp_catcher_task->m_request_y = tp_dispatch_coordinates->m_carrier_default_y1_back - (m_wheel_base /2);
  4189. if ( tp_catcher->m_catcher_direction == Dispatch_device_base::Catcher_direction::CATCHER_DIRECTION_NEGATIVE )
  4190. {
  4191. tp_catcher_task->m_request_b = 270;
  4192. }
  4193. else
  4194. {
  4195. tp_catcher_task->m_request_b = 90;
  4196. }
  4197. //限制轮距, 在夹车杆松开时, 机器人下降时, 轴距不能超过3000mm, 必须下降到最下面才能调整轴距, 夹车后可以上升.
  4198. if ( m_wheel_base > tp_dispatch_coordinates->m_catcher_wheel_base_limit )
  4199. {
  4200. tp_catcher_task->m_request_d1 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  4201. tp_catcher_task->m_request_d2 = (tp_dispatch_coordinates->m_catcher_wheel_base_limit - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  4202. tp_catcher_task->m_request_wheelbase = tp_dispatch_coordinates->m_catcher_wheel_base_limit;
  4203. }
  4204. else
  4205. {
  4206. tp_catcher_task->m_request_d1 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  4207. tp_catcher_task->m_request_d2 = (m_wheel_base - tp_dispatch_coordinates->m_catcher_d1_d2_distance)/2;
  4208. tp_catcher_task->m_request_wheelbase = m_wheel_base;
  4209. }
  4210. tp_catcher_task->m_request_clamp_motion = Catcher_task::Clamp_motion::E_CLAMP_LOOSE;
  4211. std::cout << " huli test :::: " << " catcher_adjust_from_carrier = " << tp_catcher_task->m_request_key << std::endl;
  4212. std::cout << " huli test :::: " << " catcher_adjust_from_carrier = " << tp_catcher_task->m_respons_key << std::endl;
  4213. std::cout << " huli test :::: " << " tp_catcher_task->m_request_x = " << tp_catcher_task->m_request_x << std::endl;
  4214. std::cout << " huli test :::: " << " tp_catcher_task->m_request_y = " << tp_catcher_task->m_request_y << std::endl;
  4215. std::cout << " huli test :::: " << " tp_catcher->m_catcher_direction = " << tp_catcher->m_catcher_direction << std::endl;
  4216. std::cout << " huli test :::: " << " tp_catcher_task->m_request_b = " << tp_catcher_task->m_request_b << std::endl;
  4217. std::cout << " huli test :::: " << " m_wheel_base = " << m_wheel_base << std::endl;
  4218. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d1 = " << tp_catcher_task->m_request_d1 << std::endl;
  4219. std::cout << " huli test :::: " << " tp_catcher_task->m_request_d2 = " << tp_catcher_task->m_request_d2 << std::endl;
  4220. std::cout << " huli test :::: " << " tp_catcher_task->m_request_wheelbase = " << tp_catcher_task->m_request_wheelbase << std::endl;
  4221. std::cout << " huli test :::: " << " tp_catcher_task->m_request_clamp_motion = " << tp_catcher_task->m_request_clamp_motion << std::endl;
  4222. return Error_code::SUCCESS;
  4223. }
  4224. //搬运器 准备开始, 需要同步任务单和设备真实数据.
  4225. Error_manager Dispatch_process::carrier_ready_to_start(std::string dispatch_control_command_key, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates)
  4226. {
  4227. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  4228. tp_carrier_task->m_request_key = dispatch_control_command_key;
  4229. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  4230. tp_carrier_task->m_request_x = tp_carrier->m_actual_x;
  4231. tp_carrier_task->m_request_y = tp_carrier->m_actual_y;
  4232. tp_carrier_task->m_request_z = tp_carrier->m_actual_z;
  4233. tp_carrier_task->m_request_y1 = tp_carrier->m_actual_y1;
  4234. tp_carrier_task->m_request_y2 = tp_carrier->m_actual_y2;
  4235. tp_carrier_task->m_request_clamp_motion = (Carrier_task::Clamp_motion)tp_carrier->m_actual_clamp_motion1;
  4236. tp_carrier_task->m_request_joint_motion_x = (Carrier_task::Joint_motion)tp_carrier->m_actual_joint_motion_x1;
  4237. tp_carrier_task->m_request_joint_motion_y = Carrier_task::Joint_motion::E_JOINT_NO_ACTION;
  4238. tp_carrier_task->m_request_space_id = 0;
  4239. tp_carrier_task->m_request_floor_id = 0;
  4240. tp_carrier_task->m_request_wheelbase = Dispatch_coordinates::get_instance_references().m_default_wheelbase;
  4241. return Error_code::SUCCESS;
  4242. }
  4243. //搬运器调整到 正常待机的姿态(调节夹杆和轴距)
  4244. Error_manager Dispatch_process::carrier_adjust_to_ready(std::string dispatch_control_command_key, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates)
  4245. {
  4246. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  4247. tp_carrier_task->m_request_key = dispatch_control_command_key;
  4248. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  4249. tp_carrier_task->m_request_clamp_motion = Carrier_task::Clamp_motion::E_CLAMP_LOOSE;
  4250. tp_carrier_task->m_request_wheelbase = m_wheel_base;
  4251. tp_carrier_task->m_request_y1 = tp_carrier->m_actual_y + tp_dispatch_coordinates->m_carrier_y_y1_distance;
  4252. tp_carrier_task->m_request_y2 = tp_carrier_task->m_request_y1 - tp_carrier_task->m_request_wheelbase;
  4253. std::cout << " huli test :::: " << " carrier_adjust_to_ready = " << tp_carrier_task->m_request_key << std::endl;
  4254. std::cout << " huli test :::: " << " carrier_adjust_to_ready = " << tp_carrier_task->m_respons_key << std::endl;
  4255. std::cout << " huli test :::: " << " tp_carrier_task->m_request_wheelbase = " << tp_carrier_task->m_request_wheelbase << std::endl;
  4256. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y1 = " << tp_carrier_task->m_request_y1 << std::endl;
  4257. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y2 = " << tp_carrier_task->m_request_y2 << std::endl;
  4258. std::cout << " huli test :::: " << " tp_carrier_task->m_request_clamp_motion = " << tp_carrier_task->m_request_clamp_motion << std::endl;
  4259. return Error_code::SUCCESS;
  4260. }
  4261. //搬运器 移动x
  4262. Error_manager Dispatch_process::carrier_move_x(std::string dispatch_control_command_key, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates, float target_x)
  4263. {
  4264. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  4265. tp_carrier_task->m_request_key = dispatch_control_command_key;
  4266. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  4267. tp_carrier_task->m_request_x = target_x;
  4268. std::cout << " huli test :::: " << " carrier_move_x = " << tp_carrier_task->m_request_key << std::endl;
  4269. std::cout << " huli test :::: " << " carrier_move_x = " << tp_carrier_task->m_respons_key << std::endl;
  4270. std::cout << " huli test :::: " << " tp_carrier_task->m_request_x = " << tp_carrier_task->m_request_x << std::endl;
  4271. return Error_code::SUCCESS;
  4272. }
  4273. //搬运器 移动y
  4274. Error_manager Dispatch_process::carrier_move_y(std::string dispatch_control_command_key, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates, float target_y)
  4275. {
  4276. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  4277. tp_carrier_task->m_request_key = dispatch_control_command_key;
  4278. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  4279. tp_carrier_task->m_request_y = target_y;
  4280. tp_carrier_task->m_request_wheelbase = m_wheel_base;
  4281. tp_carrier_task->m_request_y1 = tp_carrier_task->m_request_y + tp_dispatch_coordinates->m_carrier_y_y1_distance;
  4282. tp_carrier_task->m_request_y2 = tp_carrier_task->m_request_y1 - tp_carrier_task->m_request_wheelbase;
  4283. std::cout << " huli test :::: " << " carrier_move_y = " << tp_carrier_task->m_request_key << std::endl;
  4284. std::cout << " huli test :::: " << " carrier_move_y = " << tp_carrier_task->m_respons_key << std::endl;
  4285. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y = " << tp_carrier_task->m_request_y << std::endl;
  4286. std::cout << " huli test :::: " << " tp_carrier_task->m_request_wheelbase = " << tp_carrier_task->m_request_wheelbase << std::endl;
  4287. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y1 = " << tp_carrier_task->m_request_y1 << std::endl;
  4288. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y2 = " << tp_carrier_task->m_request_y2 << std::endl;
  4289. return Error_code::SUCCESS;
  4290. }
  4291. //搬运器 移动z
  4292. Error_manager Dispatch_process::carrier_move_z(std::string dispatch_control_command_key, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates, float target_z)
  4293. {
  4294. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  4295. tp_carrier_task->m_request_key = dispatch_control_command_key;
  4296. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  4297. tp_carrier_task->m_request_z = target_z;
  4298. std::cout << " huli test :::: " << " carrier_move_z = " << tp_carrier_task->m_request_key << std::endl;
  4299. std::cout << " huli test :::: " << " carrier_move_z = " << tp_carrier_task->m_respons_key << std::endl;
  4300. std::cout << " huli test :::: " << " tp_carrier_task->m_request_z = " << tp_carrier_task->m_request_z << std::endl;
  4301. return Error_code::SUCCESS;
  4302. }
  4303. //搬运器 移动c轴 夹车杆
  4304. Error_manager Dispatch_process::carrier_move_c(std::string dispatch_control_command_key, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates, Carrier_task::Clamp_motion target)
  4305. {
  4306. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  4307. tp_carrier_task->m_request_key = dispatch_control_command_key;
  4308. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  4309. tp_carrier_task->m_request_clamp_motion = target;
  4310. std::cout << " huli test :::: " << " carrier_move_c = " << tp_carrier_task->m_request_key << std::endl;
  4311. std::cout << " huli test :::: " << " carrier_move_c = " << tp_carrier_task->m_respons_key << std::endl;
  4312. std::cout << " huli test :::: " << " tp_carrier_task->m_request_clamp_motion = " << tp_carrier_task->m_request_clamp_motion << std::endl;
  4313. return Error_code::SUCCESS;
  4314. }
  4315. //搬运器调整 水平的交接
  4316. Error_manager Dispatch_process::carrier_joint_x(std::string dispatch_control_command_key, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates, Carrier_task::Joint_motion target)
  4317. {
  4318. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  4319. tp_carrier_task->m_request_key = dispatch_control_command_key;
  4320. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  4321. tp_carrier_task->m_request_joint_motion_x = target;
  4322. std::cout << " huli test :::: " << " carrier_joint_x = " << tp_carrier_task->m_request_key << std::endl;
  4323. std::cout << " huli test :::: " << " carrier_joint_x = " << tp_carrier_task->m_respons_key << std::endl;
  4324. std::cout << " huli test :::: " << " tp_carrier_task->m_request_joint_motion_x = " << tp_carrier_task->m_request_joint_motion_x << std::endl;
  4325. return Error_code::SUCCESS;
  4326. }
  4327. //搬运器 修正轴距
  4328. Error_manager Dispatch_process::carrier_adjust_wheel_base(std::string dispatch_control_command_key, Carrier * tp_carrier, Carrier_task * tp_carrier_task, Dispatch_coordinates * tp_dispatch_coordinates)
  4329. {
  4330. std::unique_lock<std::mutex> t_lock2(tp_carrier_task->m_lock);
  4331. tp_carrier_task->m_request_key = dispatch_control_command_key;
  4332. tp_carrier_task->set_task_statu(Task_Base::TASK_CREATED);
  4333. tp_carrier_task->m_request_wheelbase = m_wheel_base;
  4334. tp_carrier_task->m_request_y1 = tp_carrier->m_actual_y + tp_dispatch_coordinates->m_carrier_y_y1_distance;
  4335. tp_carrier_task->m_request_y2 = tp_carrier_task->m_request_y1 - tp_carrier_task->m_request_wheelbase;
  4336. std::cout << " huli test :::: " << " carrier_adjust_wheel_base = " << tp_carrier_task->m_request_key << std::endl;
  4337. std::cout << " huli test :::: " << " carrier_adjust_wheel_base = " << tp_carrier_task->m_respons_key << std::endl;
  4338. std::cout << " huli test :::: " << " tp_carrier_task->m_request_wheelbase = " << tp_carrier_task->m_request_wheelbase << std::endl;
  4339. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y1 = " << tp_carrier_task->m_request_y1 << std::endl;
  4340. std::cout << " huli test :::: " << " tp_carrier_task->m_request_y2 = " << tp_carrier_task->m_request_y2 << std::endl;
  4341. return Error_code::SUCCESS;
  4342. }