ivdecision_brain.cpp 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168
  1. #include "ivdecision_brain.h"
  2. #include <QCoreApplication>
  3. #include "common/obs_predict.h"
  4. #include "ivlog.h"
  5. #include "xmlparam.h"
  6. extern iv::Ivlog * givlog;
  7. bool handPark;
  8. long handParkTime;
  9. bool rapidStop;
  10. int gpsMissCount;
  11. bool changeRoad;
  12. double avoidX;
  13. bool parkBesideRoad;
  14. double steerSpeed;
  15. bool transferPieriod;
  16. bool transferPieriod2;
  17. double traceDevi;
  18. using namespace iv::decition;
  19. namespace iv {
  20. ivdecision_brain::ivdecision_brain()
  21. {
  22. mvehState = VehState::normalRun;
  23. loadxml();
  24. }
  25. int ivdecision_brain::getdecision(brain::decition &xdecition,iv::brain::brainstate & xbs)
  26. {
  27. static qint64 nlastdecisiontime = 0;
  28. static qint64 nLastMapUpdate = 0;
  29. iv::GPSData now_gps_ins;
  30. std::shared_ptr<iv::hmi::hmimsg> hmi_ptr;
  31. if(GetHMImsg(hmi_ptr) == true)
  32. {
  33. ServiceCarStatus.mbRunPause = hmi_ptr->mbpause();
  34. if(hmi_ptr->mbbochemode())
  35. {
  36. ServiceCarStatus.bocheMode = true;
  37. }
  38. ServiceCarStatus.busmode = hmi_ptr->mbbusmode();
  39. }
  40. if(ServiceCarStatus.mbRunPause)
  41. {
  42. return 0;
  43. }
  44. if(GetGPS(now_gps_ins) == false)
  45. {
  46. return -1; //No GPS Position
  47. }
  48. if(IsMAPUpdate(nLastMapUpdate))
  49. {
  50. GetMAP(mgpsMapLine,nLastMapUpdate);
  51. mbisFirstRun = true;
  52. }
  53. iv::LidarGridPtr lidarptr;
  54. GetLIDARGrid(lidarptr);
  55. std::vector<iv::Perception::PerceptionOutput> xvectorper;
  56. iv::TrafficLight xtrafficlight;
  57. std::shared_ptr<iv::vbox::vbox> xvbox_ptr;
  58. if(Getvboxmsg(xvbox_ptr))
  59. {
  60. xtrafficlight.leftColor=xvbox_ptr->st_left();
  61. xtrafficlight.rightColor=xvbox_ptr->st_right();
  62. xtrafficlight.straightColor=xvbox_ptr->st_straight();
  63. xtrafficlight.uturnColor=xvbox_ptr->st_turn();
  64. xtrafficlight.leftTime=xvbox_ptr->time_left();
  65. xtrafficlight.rightTime=xvbox_ptr->time_right();
  66. xtrafficlight.straightTime=xvbox_ptr->time_straight();
  67. xtrafficlight.uturnTime=xvbox_ptr->time_turn();
  68. }
  69. updatev2x();
  70. updateultra();
  71. updateradar();
  72. updategroupinfo();
  73. if(mgpsMapLine.size()<10)
  74. {
  75. return 0;
  76. }
  77. iv::decition::Decition decition= getDecideFromGPS(*now_gps_ins,mgpsMapLine,lidarptr,xvectorper,xtrafficlight);
  78. xdecition.set_accelerator(decition->accelerator);
  79. xdecition.set_brake(decition->brake);
  80. xdecition.set_leftlamp(decition->leftlamp);
  81. xdecition.set_rightlamp(decition->rightlamp);
  82. xdecition.set_speed(decition->speed);
  83. xdecition.set_wheelangle(decition->wheel_angle);
  84. xdecition.set_wheelspeed(decition->angSpeed);
  85. xdecition.set_torque(decition->torque);
  86. xdecition.set_mode(decition->mode);
  87. xdecition.set_gear(decition->dangWei);
  88. xdecition.set_handbrake(decition->handBrake);
  89. xdecition.set_grade(decition->grade);
  90. xdecition.set_engine(decition->engine);
  91. xdecition.set_brakelamp(decition->brakeLight);
  92. xdecition.set_ttc(ServiceCarStatus.mfttc);
  93. xdecition.set_air_enable(decition->air_enable);
  94. xdecition.set_air_temp(decition->air_temp);
  95. xdecition.set_air_mode(decition->air_mode);
  96. xdecition.set_wind_level(decition->wind_level);
  97. xdecition.set_roof_light(decition->roof_light);
  98. xdecition.set_home_light(decition->home_light);
  99. xdecition.set_air_worktime(decition->air_worktime);
  100. xdecition.set_air_offtime(decition->air_offtime);
  101. xdecition.set_air_on(decition->air_on);
  102. xdecition.set_door(decition->door);
  103. xbs.set_mbbocheenable(ServiceCarStatus.bocheEnable);
  104. xbs.set_mbbrainrunning(true); //apollo_fu debug ui 20200417
  105. xbs.set_mflidarobs(ServiceCarStatus.mLidarObs);
  106. xbs.set_mfradarobs(ServiceCarStatus.mRadarObs);
  107. xbs.set_mfobs(ServiceCarStatus.mObs);
  108. xbs.set_decision_period((QDateTime::currentMSecsSinceEpoch() - nlastdecisiontime));
  109. nlastdecisiontime = QDateTime::currentMSecsSinceEpoch();
  110. return 1;
  111. }
  112. void ivdecision_brain::updategroupinfo()
  113. {
  114. std::shared_ptr<iv::radio::radio_send> groupmsg_ptr;
  115. if(false == Getp900(groupmsg_ptr))
  116. {
  117. return;
  118. }
  119. ServiceCarStatus.group_server_status = groupmsg_ptr->server_status();
  120. ServiceCarStatus.group_comm_speed= (float)groupmsg_ptr->car_control_speed();
  121. ServiceCarStatus.group_state= groupmsg_ptr->cmd_mode();
  122. if(ServiceCarStatus.group_state!=2){
  123. ServiceCarStatus.group_comm_speed=0;
  124. }
  125. }
  126. void ivdecision_brain::updatechassistocarstatus()
  127. {
  128. std::shared_ptr<iv::chassis> xchassis_ptr;
  129. if(false == Getchassis(xchassis_ptr))
  130. {
  131. return;
  132. }
  133. ServiceCarStatus.epb = xchassis_ptr->epbfault();
  134. ServiceCarStatus.grade = xchassis_ptr->shift();
  135. ServiceCarStatus.driverMode = xchassis_ptr->drivemode();
  136. if(xchassis_ptr->has_epsmode()){
  137. ServiceCarStatus.epsMode = xchassis_ptr->epsmode();
  138. ServiceCarStatus.receiveEps=true;
  139. if(ServiceCarStatus.epsMode == 0)
  140. {
  141. ServiceCarStatus.mbRunPause = true;
  142. }
  143. }
  144. if(xchassis_ptr->has_torque())
  145. {
  146. ServiceCarStatus.torque_st = xchassis_ptr->torque();
  147. if(ServiceCarStatus.msysparam.mvehtype=="bus"){
  148. ServiceCarStatus.torque_st = xchassis_ptr->torque()*0.4;
  149. }
  150. std::cout<<"******* xchassis.torque:"<< xchassis_ptr->torque()<<std::endl;
  151. std::cout<<"******* ServiceCarStatus.torque_st:"<< ServiceCarStatus.torque_st<<std::endl;
  152. givlog->warn(" ServiceCarStatus.torque_st: is %f",ServiceCarStatus.torque_st);
  153. }
  154. if(xchassis_ptr->has_engine_speed())
  155. {
  156. ServiceCarStatus.engine_speed = xchassis_ptr->engine_speed();
  157. std::cout<<"******* xchassis.engine_speed:"<< xchassis_ptr->engine_speed()<<std::endl;
  158. }
  159. }
  160. void ivdecision_brain::loadxml()
  161. {
  162. QString strpath = QCoreApplication::applicationDirPath();
  163. strpath = strpath + "/ADS_decision.xml";
  164. iv::xmlparam::Xmlparam xp(strpath.toStdString());
  165. ServiceCarStatus.msysparam.mstrvin = xp.GetParam("vin","10000000000000001");
  166. ServiceCarStatus.msysparam.mstrid = xp.GetParam("id","1");
  167. ServiceCarStatus.msysparam.mstriccid = xp.GetParam("iccid","11111111111111111111");
  168. ServiceCarStatus.msysparam.mvehtype= xp.GetParam("vehType","yuhesen");
  169. ServiceCarStatus.msysparam.vehWidth = atof(xp.GetParam("vehWidth","2.1").data());
  170. ServiceCarStatus.msysparam.vehLenth = atof(xp.GetParam("vehLenth","4.6").data());
  171. /*============= 20200113 apollo_fu add ===========*/
  172. std::string str_zhuchetime = xp.GetParam("zhuchetime","16");
  173. ServiceCarStatus.msysparam.mzhuchetime =atoi(str_zhuchetime.data());
  174. /*============= end ================================== */
  175. std::string strepsoff = xp.GetParam("epsoff","0.0");
  176. ServiceCarStatus.mfEPSOff = atof(strepsoff.data());
  177. std::string strroadmode_vel = xp.GetParam("roadmode0","10");
  178. ServiceCarStatus.mroadmode_vel.mfmode0 = atof(strroadmode_vel.data());
  179. strroadmode_vel = xp.GetParam("roadmode11","30");
  180. ServiceCarStatus.mroadmode_vel.mfmode11 = atof(strroadmode_vel.data());
  181. strroadmode_vel = xp.GetParam("roadmode14","15");
  182. ServiceCarStatus.mroadmode_vel.mfmode14 = atof(strroadmode_vel.data());
  183. //float a = ServiceCarStatus.mroadmode_vel.mfmode14;
  184. //cout<<"........"<<a<<endl;
  185. strroadmode_vel = xp.GetParam("roadmode15","15");
  186. ServiceCarStatus.mroadmode_vel.mfmode15 = atof(strroadmode_vel.data());
  187. /*==================== 20200113 apollo_fu add =================*/
  188. strroadmode_vel = xp.GetParam("roadmode5","10");
  189. ServiceCarStatus.mroadmode_vel.mfmode5 = atof(strroadmode_vel.data());
  190. strroadmode_vel = xp.GetParam("roadmode13","5");
  191. ServiceCarStatus.mroadmode_vel.mfmode13 = atof(strroadmode_vel.data());
  192. strroadmode_vel = xp.GetParam("roadmode16","8");
  193. ServiceCarStatus.mroadmode_vel.mfmode16 = atof(strroadmode_vel.data());
  194. strroadmode_vel = xp.GetParam("roadmode17","8");
  195. ServiceCarStatus.mroadmode_vel.mfmode17 = atof(strroadmode_vel.data());
  196. strroadmode_vel = xp.GetParam("roadmode18","5");
  197. ServiceCarStatus.mroadmode_vel.mfmode18 = atof(strroadmode_vel.data());
  198. /*========================= end =============================*/
  199. std::string group_cotrol = xp.GetParam("group","false");
  200. if(group_cotrol=="true"){
  201. ServiceCarStatus.group_control=true;
  202. }else{
  203. ServiceCarStatus.group_control=false;
  204. }
  205. std::string speed_control = xp.GetParam("speed","false");
  206. if(speed_control=="true"){
  207. ServiceCarStatus.speed_control=true;
  208. }else{
  209. ServiceCarStatus.speed_control=false;
  210. }
  211. std::string strparklat = xp.GetParam("parklat","39.0624557");
  212. std::string strparklng = xp.GetParam("parklng","117.3575493");
  213. std::string strparkheading = xp.GetParam("parkheading","112.5");
  214. std::string strparktype = xp.GetParam("parktype","1");
  215. ServiceCarStatus.mfParkLat = atof(strparklat.data());
  216. ServiceCarStatus.mfParkLng = atof(strparklng.data());
  217. ServiceCarStatus.mfParkHeading = atof(strparkheading.data());
  218. ServiceCarStatus.mnParkType = atoi(strparktype.data());
  219. ServiceCarStatus.mLidarRotation = atof(xp.GetParam("LidarRotation","90.0").data());
  220. ServiceCarStatus.mLidarRangeUnit = atof(xp.GetParam("LidarRangeUnit","5.0").data());
  221. std::string lightlon = xp.GetParam("lightlon","0");
  222. std::string lightlat = xp.GetParam("lightlat","0");
  223. ServiceCarStatus.iTrafficeLightLat=atof(lightlat.data());
  224. ServiceCarStatus.iTrafficeLightLon=atof(lightlon.data());
  225. //mobileEye
  226. std::string timeWidth =xp.GetParam("waitGpsTimeWidth","5000");
  227. std::string garageLong =xp.GetParam("outGarageLong","10");
  228. ServiceCarStatus.waitGpsTimeWidth=atof(timeWidth.data());
  229. ServiceCarStatus.outGarageLong=atof(garageLong.data());
  230. //mobileEye end
  231. //lidar start
  232. std::string lidarGpsXiuzheng = xp.GetParam("lidarGpsXiuzheng","1.0");
  233. std::string radarGpsXiuzheng = xp.GetParam("radarGpsXiuzheng","3.0");
  234. std::string rearRadarGpsXiuzheng = xp.GetParam("rearRadarGpsXiuzheng","0.5");
  235. std::string rearLidarGpsXiuzheng = xp.GetParam("rearLidarGpsXiuzheng","1.0");
  236. std::string frontGpsXiuzheng = xp.GetParam("frontGpsXiuzheng","3.0");
  237. std::string rearGpsXiuzheng = xp.GetParam("rearGpsXiuzheng","1.0");
  238. std::string gpsOffset_x = xp.GetParam("gpsOffset_X","0");
  239. std::string gpsOffset_y = xp.GetParam("gpsOffset_Y","0");
  240. std::string strexternmpc = xp.GetParam("ExternMPC","false"); //If Use MPC set true
  241. adjuseGpsLidarPosition();
  242. if(strexternmpc == "true")
  243. {
  244. // mbUseExternMPC = true;
  245. }
  246. ServiceCarStatus.msysparam.lidarGpsXiuzheng = atof(lidarGpsXiuzheng.data());
  247. ServiceCarStatus.msysparam.radarGpsXiuzheng = atof(radarGpsXiuzheng.data());
  248. ServiceCarStatus.msysparam.rearRadarGpsXiuzheng = atof(rearRadarGpsXiuzheng.data());
  249. ServiceCarStatus.msysparam.rearLidarGpsXiuzheng = atof(rearLidarGpsXiuzheng.data());
  250. ServiceCarStatus.msysparam.frontGpsXiuzheng = atof(frontGpsXiuzheng.data());
  251. ServiceCarStatus.msysparam.rearGpsXiuzheng = atof(rearGpsXiuzheng.data());
  252. ServiceCarStatus.msysparam.gpsOffset_x = atof(gpsOffset_x.data());
  253. ServiceCarStatus.msysparam.gpsOffset_y = atof(gpsOffset_y.data());
  254. // lidar end
  255. std::string strObsPredict = xp.GetParam("obsPredict","false"); //If Use MPC set true
  256. if(strObsPredict == "true")
  257. {
  258. ServiceCarStatus.useObsPredict = true;
  259. }
  260. std::string inRoadAvoid = xp.GetParam("inRoadAvoid","false"); //If Use MPC set true
  261. if(inRoadAvoid == "true")
  262. {
  263. ServiceCarStatus.inRoadAvoid = true;
  264. }else{
  265. ServiceCarStatus.inRoadAvoid = false;
  266. }
  267. std::string avoidObs = xp.GetParam("avoidObs","false"); //If Use MPC set true
  268. if(avoidObs == "true")
  269. {
  270. ServiceCarStatus.avoidObs = true;
  271. }else{
  272. ServiceCarStatus.avoidObs = false;
  273. }
  274. //map
  275. // mstrmemmap_index = xp.GetParam("msg_mapindex","map_index");
  276. }
  277. void ivdecision_brain::updatev2x()
  278. {
  279. std::shared_ptr<iv::v2x::v2x> xv2x_ptr;
  280. if(false == Getv2xmsg(xv2x_ptr))
  281. {
  282. return;
  283. }
  284. ServiceCarStatus.stationCmd.received=true;
  285. ServiceCarStatus.stationCmd.has_carID=xv2x_ptr->has_carid();
  286. if(ServiceCarStatus.stationCmd.has_carID)
  287. {
  288. ServiceCarStatus.stationCmd.carID=xv2x_ptr->carid();
  289. }
  290. ServiceCarStatus.stationCmd.has_carMode=xv2x_ptr->has_carmode();
  291. if(ServiceCarStatus.stationCmd.has_carMode)
  292. {
  293. ServiceCarStatus.stationCmd.carMode=xv2x_ptr->carmode();
  294. qDebug("ServiceCarStatus.stationCmd.carMode:",ServiceCarStatus.stationCmd.carMode);
  295. givlog->debug("brain_v2x","ServiceCarStatus.stationCmd.carMode:%d",ServiceCarStatus.stationCmd.carMode);
  296. }
  297. ServiceCarStatus.stationCmd.has_emergencyStop=xv2x_ptr->has_emergencystop();
  298. if(ServiceCarStatus.stationCmd.has_emergencyStop)
  299. {
  300. ServiceCarStatus.stationCmd.emergencyStop=xv2x_ptr->emergencystop();
  301. qDebug("ServiceCarStatus.stationCmd.emergencyStop:",ServiceCarStatus.stationCmd.emergencyStop);
  302. givlog->debug("brain_v2x","ServiceCarStatus.stationCmd.emergencyStop:%d",ServiceCarStatus.stationCmd.emergencyStop);
  303. }
  304. ServiceCarStatus.stationCmd.has_stationStop=xv2x_ptr->has_stationstop();
  305. if(ServiceCarStatus.stationCmd.has_stationStop)
  306. {
  307. ServiceCarStatus.stationCmd.stationStop=xv2x_ptr->stationstop();
  308. qDebug("ServiceCarStatus.stationCmd.stationStop:",ServiceCarStatus.stationCmd.stationStop);
  309. givlog->debug("brain_v2x","ServiceCarStatus.stationCmd.stationStop:%d",ServiceCarStatus.stationCmd.stationStop);
  310. }
  311. int num=xv2x_ptr->stationid_size();
  312. if(num>0)
  313. {
  314. ServiceCarStatus.stationCmd.stationTotalNum=num;
  315. for(int i=0;i<ServiceCarStatus.stationCmd.stationTotalNum;i++)
  316. {
  317. ServiceCarStatus.stationCmd.stationGps[i].gps_lat=xv2x_ptr->stgps(i).lat();
  318. ServiceCarStatus.stationCmd.stationGps[i].gps_lng=xv2x_ptr->stgps(i).lon();
  319. qDebug("stationGps: %d, lat: %.7f, lon: %.7f", xv2x_ptr->stationid(i), ServiceCarStatus.stationCmd.stationGps[i].gps_lat, ServiceCarStatus.stationCmd.stationGps[i].gps_lng);
  320. givlog->debug("brain_v2x","stationGps: %d, lat: %.7f, lon: %.7f",
  321. xv2x_ptr->stationid(i),ServiceCarStatus.stationCmd.stationGps[i].gps_lat,
  322. ServiceCarStatus.stationCmd.stationGps[i].gps_lng);
  323. }
  324. ServiceCarStatus.mbRunPause=false;
  325. }
  326. }
  327. void ivdecision_brain::adjuseGpsLidarPosition()
  328. {
  329. ServiceCarStatus.msysparam.lidarGpsXiuzheng -= ServiceCarStatus.msysparam.gpsOffset_y;
  330. ServiceCarStatus.msysparam.radarGpsXiuzheng -= ServiceCarStatus.msysparam.gpsOffset_y;
  331. ServiceCarStatus.msysparam.rearRadarGpsXiuzheng += ServiceCarStatus.msysparam.gpsOffset_y;
  332. ServiceCarStatus.msysparam.rearLidarGpsXiuzheng += ServiceCarStatus.msysparam.gpsOffset_y;
  333. ServiceCarStatus.msysparam.frontGpsXiuzheng -= ServiceCarStatus.msysparam.gpsOffset_y;
  334. ServiceCarStatus.msysparam.rearGpsXiuzheng += ServiceCarStatus.msysparam.gpsOffset_y;
  335. }
  336. void ivdecision_brain::updateultra()
  337. {
  338. std::shared_ptr<iv::ultrasonic::ultrasonic> xultra_ptr;
  339. if(false == Getultrasonic(xultra_ptr))
  340. {
  341. return;
  342. }
  343. ServiceCarStatus.ultraDistance[1]=xultra_ptr->sigobjdist_flcorner();
  344. ServiceCarStatus.ultraDistance[2]=xultra_ptr->sigobjdist_flmiddle();
  345. ServiceCarStatus.ultraDistance[3]=xultra_ptr->sigobjdist_flside();
  346. ServiceCarStatus.ultraDistance[4]=xultra_ptr->sigobjdist_frcorner();
  347. ServiceCarStatus.ultraDistance[5]=xultra_ptr->sigobjdist_frmiddle();
  348. ServiceCarStatus.ultraDistance[6]=xultra_ptr->sigobjdist_frside();
  349. ServiceCarStatus.ultraDistance[7]=xultra_ptr->sigobjdist_rlcorner();
  350. ServiceCarStatus.ultraDistance[8]=xultra_ptr->sigobjdist_rlmiddle();
  351. ServiceCarStatus.ultraDistance[9]=xultra_ptr->sigobjdist_rlside();
  352. ServiceCarStatus.ultraDistance[10]=xultra_ptr->sigobjdist_rrcorner();
  353. ServiceCarStatus.ultraDistance[11]=xultra_ptr->sigobjdist_rrmiddle();
  354. ServiceCarStatus.ultraDistance[12]=xultra_ptr->sigobjdist_rrside();
  355. }
  356. void ivdecision_brain::updateradar()
  357. {
  358. std::shared_ptr<iv::radar::radarobjectarray> xradar_ptr
  359. = std::shared_ptr<iv::radar::radarobjectarray>(new iv::radar::radarobjectarray);
  360. unsigned int i;
  361. if(false == GetRADAR(xradar_ptr))
  362. {
  363. for(i=0;i<64;i++)
  364. {
  365. ServiceCarStatus.obs_radar[i].valid = false;
  366. }
  367. return;
  368. }
  369. for(i=0;i<64;i++)
  370. {
  371. iv::radar::radarobject * pradarobj = xradar_ptr->mutable_obj(i);
  372. ServiceCarStatus.obs_radar[i].valid = pradarobj->bvalid();
  373. ServiceCarStatus.obs_radar[i].nomal_x = pradarobj->x();
  374. ServiceCarStatus.obs_radar[i].nomal_y = pradarobj->y();
  375. ServiceCarStatus.obs_radar[i].speed_relative = pradarobj->vel();
  376. ServiceCarStatus.obs_radar[i].speed_x = pradarobj->vx();
  377. ServiceCarStatus.obs_radar[i].speed_y = pradarobj->vy();
  378. }
  379. }
  380. //int ivdecision_brain::getdecision_normal(brain::decition &xdecition)
  381. //{
  382. // iv::decition::Decition gps_decition(new iv::decition::DecitionBasic);
  383. // double obsDistance = -1;
  384. // int esrLineIndex = -1;
  385. // double lidarDistance = -1;
  386. // int roadPre = -1;
  387. // return 0;
  388. //}
  389. //std::vector<iv::Perception::PerceptionOutput> lidar_per,
  390. iv::decition::Decition ivdecision_brain::decision_reverseCar(GPS_INS now_gps_ins)
  391. {
  392. iv::decition::Compute00().bocheCompute(now_gps_ins, aim_gps_ins);
  393. vehState = reversing;
  394. qiedianCount=true;
  395. return decision_reversing(now_gps_ins);
  396. }
  397. iv::decition::Decition ivdecision_brain::decision_reversing(GPS_INS now_gps_ins)
  398. {
  399. iv::decition::Decition gps_decition(new iv::decition::DecitionBasic);
  400. double dis = GetDistance(now_gps_ins, iv::decition::Compute00().nearTpoint);
  401. if (dis<2.0)//0.5
  402. {
  403. vehState = reverseCircle;
  404. qiedianCount = true;
  405. cout<<"到达近切点+++++++++++++++++++++++++++++++++"<<endl;
  406. return decision_reverseCircle(now_gps_ins);
  407. }
  408. else {
  409. controlAng = 0;
  410. dSpeed = 2;
  411. dSecSpeed = dSpeed / 3.6;
  412. gps_decition->wheel_angle = 0;
  413. gps_decition->speed = dSpeed;
  414. obsDistance=-1;
  415. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  416. // gps_decition->accelerator = 0;
  417. return gps_decition;
  418. }
  419. }
  420. iv::decition::Decition ivdecision_brain::decision_reverseCircle(GPS_INS now_gps_ins)
  421. {
  422. iv::decition::Decition gps_decition(new iv::decition::DecitionBasic);
  423. double dis = GetDistance(now_gps_ins, iv::decition::Compute00().farTpoint);
  424. double angdis =abs(now_gps_ins.ins_heading_angle - aim_gps_ins.ins_heading_angle);
  425. if((((angdis<5)||(angdis>355)))&&(dis<3.0))
  426. // if((((angdis<4)||(angdis>356)))&&(dis<2.0))
  427. {
  428. vehState = reverseDirect;
  429. qiedianCount = true;
  430. cout<<"到达远切点+++++++++++++++++++++++++++++++++"<<endl;
  431. return decision_reverseDirect(now_gps_ins);
  432. }
  433. else {
  434. if (qiedianCount && trumpet()<0)
  435. // if (qiedianCount && trumpet()<1500)
  436. {
  437. // gps_decition->brake = 10;
  438. // gps_decition->torque = 0;
  439. dSpeed=0;
  440. minDecelerate=min(minDecelerate,-0.5f);
  441. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  442. }
  443. else
  444. {
  445. qiedianCount = false;
  446. trumpetFirstCount = true;
  447. dSpeed = 2;
  448. dSecSpeed = dSpeed / 3.6;
  449. gps_decition->speed = dSpeed;
  450. obsDistance=-1;
  451. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  452. }
  453. controlAng = iv::decition::Compute00().bocheAngle*16.5;
  454. gps_decition->wheel_angle = 0 - controlAng*1.05;
  455. cout<<"farTpointDistance================"<<dis<<endl;
  456. return gps_decition;
  457. }
  458. }
  459. iv::decition::Decition ivdecision_brain::decision_reverseDirect(GPS_INS now_gps_ins)
  460. {
  461. iv::decition::Decition gps_decition(new iv::decition::DecitionBasic);
  462. Point2D pt = Coordinate_Transfer(now_gps_ins.gps_x,now_gps_ins.gps_y, aim_gps_ins);
  463. if ((pt.y)<0.5)
  464. {
  465. qiedianCount=true;
  466. vehState=reverseArr;
  467. cout<<"到达泊车点+++++++++++++++++++++++++++++++++"<<endl;
  468. // gps_decition->accelerator = -3;
  469. // gps_decition->brake = 10;
  470. // gps_decition->torque = 0;
  471. gps_decition->wheel_angle=0;
  472. dSpeed=0;
  473. minDecelerate=min(minDecelerate,-0.5f);
  474. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  475. return gps_decition;
  476. }
  477. else {
  478. //if (qiedianCount && trumpet()<0)
  479. if (qiedianCount && trumpet()<1000)
  480. {
  481. // gps_decition->brake = 10;
  482. // gps_decition->torque = 0;
  483. dSpeed=0;
  484. minDecelerate=min(minDecelerate,-0.5f);
  485. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  486. }
  487. else
  488. {
  489. qiedianCount = false;
  490. trumpetFirstCount = true;
  491. dSpeed = 1;
  492. dSecSpeed = dSpeed / 3.6;
  493. gps_decition->speed = dSpeed;
  494. obsDistance=-1;
  495. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  496. }
  497. controlAng = 0;
  498. gps_decition->wheel_angle = 0;
  499. return gps_decition;
  500. }
  501. }
  502. iv::decition::Decition ivdecision_brain::decision_reverseArr(iv::GPS_INS now_gps_ins)
  503. {
  504. iv::decition::Decition gps_decition(new iv::decition::DecitionBasic);
  505. ServiceCarStatus.bocheMode=false;
  506. if (qiedianCount && trumpet()<1500)
  507. {
  508. // gps_decition->brake = 10;
  509. // gps_decition->torque = 0;
  510. dSpeed=0;
  511. minDecelerate=min(minDecelerate,-0.5f);
  512. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  513. ServiceCarStatus.bocheMode=false;
  514. }
  515. else
  516. {
  517. qiedianCount = false;
  518. trumpetFirstCount = true;
  519. ServiceCarStatus.bocheEnable=0;
  520. vehState=normalRun;
  521. ServiceCarStatus.mbRunPause=true;
  522. ServiceCarStatus.mnBocheComplete=100;
  523. cout<<"泊车daowei mbRunPause+++++++++++++++++++++++++++++++++"<<endl;
  524. }
  525. gps_decition->wheel_angle = 0 ;
  526. return gps_decition;
  527. }
  528. iv::decition::Decition ivdecision_brain::decision_dRever(GPS_INS now_gps_ins)
  529. {
  530. GaussProjCal(aim_gps_ins.gps_lng, aim_gps_ins.gps_lat, &aim_gps_ins.gps_x, &aim_gps_ins.gps_y);
  531. iv::decition::Compute00().bocheDirectCompute(now_gps_ins, aim_gps_ins);
  532. vehState = dRever0;
  533. qiedianCount=true;
  534. std::cout<<"enter side boche mode"<<std::endl;
  535. return decision_dRever0(now_gps_ins);
  536. }
  537. iv::decition::Decition ivdecision_brain::decision_dRever0(GPS_INS now_gps_ins)
  538. {
  539. iv::decition::Decition gps_decition(new iv::decition::DecitionBasic);
  540. double dis = GetDistance(now_gps_ins, iv::decition::Compute00().dTpoint0);
  541. if (dis<2.0)
  542. {
  543. vehState = dRever1;
  544. qiedianCount = true;
  545. cout<<"到达近切点+++++++++++++++++++++++++++++++++"<<endl;
  546. return decision_dRever1(now_gps_ins);
  547. }
  548. else {
  549. controlAng = 0;
  550. dSpeed = 2;
  551. dSecSpeed = dSpeed / 3.6;
  552. gps_decition->wheel_angle = 0;
  553. gps_decition->speed = dSpeed;
  554. obsDistance=-1;
  555. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  556. // gps_decition->accelerator = 0;
  557. return gps_decition;
  558. }
  559. }
  560. iv::decition::Decition ivdecision_brain::decision_dRever1(GPS_INS now_gps_ins)
  561. {
  562. iv::decition::Decition gps_decition(new iv::decition::DecitionBasic);
  563. double dis = GetDistance(now_gps_ins, iv::decition::Compute00().dTpoint1);
  564. if(dis<2.0)
  565. {
  566. vehState = dRever2;
  567. qiedianCount = true;
  568. cout<<"到达远切点+++++++++++++++++++++++++++++++++"<<endl;
  569. return decision_dRever2(now_gps_ins);
  570. }
  571. else {
  572. if (qiedianCount && trumpet()<1000)
  573. {
  574. // gps_decition->brake = 10;
  575. // gps_decition->torque = 0;
  576. dSpeed=0;
  577. minDecelerate=min(minDecelerate,-0.5f);
  578. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  579. }
  580. else
  581. {
  582. qiedianCount = false;
  583. trumpetFirstCount = true;
  584. dSpeed = 2;
  585. dSecSpeed = dSpeed / 3.6;
  586. gps_decition->speed = dSpeed;
  587. obsDistance=-1;
  588. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  589. }
  590. controlAng = iv::decition::Compute00().dBocheAngle*16.5;
  591. gps_decition->wheel_angle = 0 - controlAng;
  592. cout<<"farTpointDistance================"<<dis<<endl;
  593. return gps_decition;
  594. }
  595. }
  596. iv::decition::Decition ivdecision_brain::decision_dRever2(GPS_INS now_gps_ins)
  597. {
  598. iv::decition::Decition gps_decition(new iv::decition::DecitionBasic);
  599. double dis = GetDistance(now_gps_ins, iv::decition::Compute00().dTpoint2);
  600. Point2D pt1 = Coordinate_Transfer(now_gps_ins.gps_x,now_gps_ins.gps_y, aim_gps_ins);
  601. Point2D pt2 = Coordinate_Transfer(iv::decition::Compute00().dTpoint2.gps_x,iv::decition::Compute00().dTpoint2.gps_y, aim_gps_ins);
  602. double xx= (pt1.x-pt2.x);
  603. // if(xx>0)
  604. if(xx>-0.5)
  605. {
  606. GaussProjCal(aim_gps_ins.gps_lng, aim_gps_ins.gps_lat, &aim_gps_ins.gps_x, &aim_gps_ins.gps_y);
  607. Point2D ptt = Coordinate_Transfer(now_gps_ins.gps_x,now_gps_ins.gps_y, aim_gps_ins);
  608. double xxx=ptt.x;
  609. double yyy =ptt.y;
  610. // if(xxx<-1.5||xx>1){
  611. // int a=0;
  612. // }
  613. vehState = dRever3;
  614. qiedianCount = true;
  615. cout<<"到达远切点+++++++++++++++++++++++++++++++++"<<endl;
  616. cout<<"xxx+++++++++++++++++++++++++++++++++"<<xxx<<endl;
  617. cout<<"yyy+++++++++++++++++++++++++++++++++"<<yyy<<endl;
  618. return decision_dRever3(now_gps_ins);
  619. }
  620. else {
  621. if (qiedianCount && trumpet()<1000)
  622. {
  623. /* gps_decition->brake = 10;
  624. gps_decition->torque = 0; */
  625. dSpeed=0;
  626. minDecelerate=min(minDecelerate,-0.5f);
  627. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  628. }
  629. else
  630. {
  631. qiedianCount = false;
  632. trumpetFirstCount = true;
  633. dSpeed = 2;
  634. dSecSpeed = dSpeed / 3.6;
  635. gps_decition->speed = dSpeed;
  636. obsDistance=-1;
  637. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  638. }
  639. gps_decition->wheel_angle = 0 ;
  640. cout<<"farTpointDistance================"<<dis<<endl;
  641. return gps_decition;
  642. }
  643. }
  644. iv::decition::Decition ivdecision_brain::decision_dRever3(GPS_INS now_gps_ins)
  645. {
  646. iv::decition::Decition gps_decition(new iv::decition::DecitionBasic);
  647. double dis = GetDistance(now_gps_ins, iv::decition::Compute00().dTpoint3);
  648. double angdis =abs(now_gps_ins.ins_heading_angle - aim_gps_ins.ins_heading_angle);
  649. if((((angdis<5)||(angdis>355)))&&(dis<10.0))
  650. {
  651. vehState = dRever4;
  652. qiedianCount = true;
  653. cout<<"到达远切点+++++++++++++++++++++++++++++++++"<<endl;
  654. return decision_dRever4(now_gps_ins);
  655. }
  656. else {
  657. if (qiedianCount && trumpet()<1000)
  658. {
  659. // gps_decition->brake = 10;
  660. // gps_decition->torque = 0;
  661. dSpeed=0;
  662. minDecelerate=min(minDecelerate,-0.5f);
  663. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  664. }
  665. else
  666. {
  667. qiedianCount = false;
  668. trumpetFirstCount = true;
  669. dSpeed = 2;
  670. dSecSpeed = dSpeed / 3.6;
  671. gps_decition->speed = dSpeed;
  672. obsDistance=-1;
  673. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  674. }
  675. controlAng = 0-iv::decition::Compute00().dBocheAngle*16.5;
  676. gps_decition->wheel_angle = 0 - controlAng*0.95;
  677. cout<<"farTpointDistance================"<<dis<<endl;
  678. return gps_decition;
  679. }
  680. }
  681. iv::decition::Decition ivdecision_brain::decision_dRever4(GPS_INS now_gps_ins)
  682. {
  683. iv::decition::Decition gps_decition(new iv::decition::DecitionBasic);
  684. // double dis = GetDistance(now_gps_ins, aim_gps_ins);
  685. Point2D pt = Coordinate_Transfer(now_gps_ins.gps_x,now_gps_ins.gps_y, aim_gps_ins);
  686. if ((pt.y)<0.5)
  687. {
  688. qiedianCount=true;
  689. vehState=reverseArr;
  690. cout<<"到达泊车点+++++++++++++++++++++++++++++++++"<<endl;
  691. // gps_decition->accelerator = -3;
  692. // gps_decition->brake =10 ;
  693. dSpeed=0;
  694. minDecelerate=min(minDecelerate,-0.5f);
  695. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  696. gps_decition->wheel_angle=0;
  697. return gps_decition;
  698. }
  699. else {
  700. //if (qiedianCount && trumpet()<0)
  701. if (qiedianCount && trumpet()<1000)
  702. {
  703. // gps_decition->brake = 10;
  704. // gps_decition->torque = 0;
  705. dSpeed=0;
  706. minDecelerate=min(minDecelerate,-0.5f);
  707. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  708. }
  709. else
  710. {
  711. qiedianCount = false;
  712. trumpetFirstCount = true;
  713. dSpeed = 2;
  714. dSecSpeed = dSpeed / 3.6;
  715. gps_decition->speed = dSpeed;
  716. obsDistance=-1;
  717. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  718. }
  719. controlAng = 0;
  720. gps_decition->wheel_angle = 0;
  721. return gps_decition;
  722. }
  723. }
  724. void ivdecision_brain::decision_firstRun(GPS_INS now_gps_ins,
  725. const std::vector<GPSData> & gpsMapLine)
  726. {
  727. if (isFirstRun)
  728. {
  729. initMethods();
  730. vehState = normalRun;
  731. startAvoid_gps_ins = now_gps_ins;
  732. init();
  733. PathPoint = iv::decition::Compute00().getFirstNearestPointIndex(now_gps_ins, gpsMapLine,
  734. lastGpsIndex,
  735. minDis,
  736. maxAngle);
  737. lastGpsIndex = PathPoint;
  738. if(ServiceCarStatus.speed_control==true){
  739. iv::decition::Compute00().getDesiredSpeed(gpsMapLine); //add by zj
  740. }
  741. // ServiceCarStatus.carState = 1;
  742. // roadOri = gpsMapLine[PathPoint]->roadOri;
  743. // roadNow = roadOri;
  744. // roadSum = gpsMapLine[PathPoint]->roadSum;
  745. // busMode = false;
  746. // vehState = dRever;
  747. double dis = iv::decition::GetDistance(*gpsMapLine[0], *gpsMapLine[gpsMapLine.size()-1]);
  748. if(dis<15){
  749. circleMode=true; //201200102
  750. }else{
  751. circleMode=false;
  752. }
  753. // circleMode = true;
  754. getV2XTrafficPositionVector(gpsMapLine);
  755. // group_ori_gps=*gpsMapLine[0];
  756. ServiceCarStatus.bocheMode=false;
  757. ServiceCarStatus.daocheMode=false;
  758. parkMode=false;
  759. readyParkMode=false;
  760. finishPointNum=-1;
  761. isFirstRun = false;
  762. }
  763. }
  764. int ivdecision_brain::decision_ParkCalc(GPS_INS now_gps_ins,iv::decition::Decition & gps_decition)
  765. {
  766. //sidePark
  767. if(ServiceCarStatus.mnParkType==1){
  768. if( vehState!=dRever && vehState!=dRever0 && vehState!=dRever1 && vehState!=dRever2 && vehState!=dRever3 && vehState!=dRever4 && vehState!=reverseArr ){
  769. int bocheEN=iv::decition::Compute00().bocheDirectCompute(now_gps_ins, aim_gps_ins);
  770. if(bocheEN==1){
  771. ServiceCarStatus.bocheEnable=1;
  772. }else if(bocheEN==0){
  773. ServiceCarStatus.bocheEnable=0;
  774. }
  775. }else{
  776. ServiceCarStatus.bocheEnable=2;
  777. }
  778. if(ServiceCarStatus.bocheMode && vehState!=dRever && vehState!=dRever0 && vehState!=dRever1 &&
  779. vehState!=dRever2 && vehState!=dRever3 && vehState!=dRever4&& vehState!=reverseArr ){
  780. if(abs(realspeed)>0.1){
  781. dSpeed=0;
  782. minDecelerate=min(minDecelerate,-0.5f);
  783. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  784. gps_decition->wheel_angle=0;
  785. return 1;
  786. }else{
  787. if(trumpet()>3000){
  788. trumpetFirstCount=true;
  789. vehState=dRever;
  790. }
  791. }
  792. // ServiceCarStatus.bocheMode=false;
  793. }
  794. }
  795. //chuizhiPark
  796. if(ServiceCarStatus.mnParkType==0){
  797. if( vehState!=reverseCar && vehState!=reversing && vehState!=reverseCircle && vehState!=reverseDirect && vehState!=reverseArr ){
  798. int bocheEN=iv::decition::Compute00().bocheCompute(now_gps_ins, aim_gps_ins);
  799. if(bocheEN==1){
  800. ServiceCarStatus.bocheEnable=1;
  801. }else if(bocheEN==0){
  802. ServiceCarStatus.bocheEnable=0;
  803. }
  804. }else{
  805. ServiceCarStatus.bocheEnable=2;
  806. }
  807. if(ServiceCarStatus.bocheMode && vehState!=reverseCar && vehState!=reversing && vehState!=reverseCircle && vehState!=reverseDirect&& vehState!=reverseArr ){
  808. if(abs(realspeed)>0.1){
  809. dSpeed=0;
  810. minDecelerate=min(minDecelerate,-0.5f);
  811. phaseSpeedDecition(gps_decition, secSpeed, -1, 0, now_gps_ins);
  812. gps_decition->wheel_angle=0;
  813. return 1;
  814. }else{
  815. if(trumpet()>3000){
  816. trumpetFirstCount=true;
  817. vehState=reverseCar;
  818. }
  819. }
  820. // ServiceCarStatus.bocheMode=false;
  821. }
  822. }
  823. return 0;
  824. }
  825. void ivdecision_brain::decision_readyZhucheMode(GPS_INS now_gps_ins, const std::vector<GPSData> &gpsMapLine)
  826. {
  827. cout<<"ready ZHECHE STATE+++++++++++++++++++++++++++++++++"<<endl;
  828. cout<<"zhuche point : "<<zhuchePointNum<<endl;
  829. double dis = GetDistance(*gpsMapLine[zhuchePointNum], now_gps_ins);
  830. if (dis<35)
  831. {
  832. Point2D pt = Coordinate_Transfer((*gpsMapLine[zhuchePointNum]).gps_x, (*gpsMapLine[zhuchePointNum]).gps_y, now_gps_ins);
  833. double zhucheDistance = pt.y;
  834. #if 0
  835. if (dSpeed > 15)
  836. {
  837. dSpeed = 15;
  838. }
  839. if (zhucheDistance < 20 && dis < 25)
  840. {
  841. dSpeed = min(dSpeed, 5.0);
  842. }
  843. #else
  844. if (dSpeed > 12)
  845. {
  846. dSpeed = 12;
  847. }
  848. if (zhucheDistance < 9 && dis < 9)
  849. {
  850. dSpeed = min(dSpeed, 5.0);
  851. }
  852. #endif
  853. if (zhucheDistance < 3.0 && dis < 3.5)
  854. {
  855. dSpeed = min(dSpeed, 5.0);
  856. zhucheMode = true;
  857. readyZhucheMode = false;
  858. cout<<"jinru ZHECHE STATE+++++++++++++++++++++++++++++++++"<<endl;
  859. //1125
  860. // gps_decition->brake=20;
  861. // gps_decition->accelerator = -3;
  862. // gps_decition->wheel_angle = 0-controlAng;
  863. // gps_decition->speed = 0;
  864. // gps_decition->torque=0;
  865. // return gps_decition;
  866. }
  867. }
  868. }
  869. void ivdecision_brain::decision_readyParkMode(GPS_INS now_gps_ins, const std::vector<GPSData> &gpsMapLine)
  870. {
  871. double parkDis = GetDistance(now_gps_ins, *gpsMapLine[finishPointNum]);
  872. hasZhuched = true;
  873. if (parkDis < 25)
  874. {
  875. Point2D pt = Coordinate_Transfer((*gpsMapLine[finishPointNum]).gps_x, (*gpsMapLine[finishPointNum]).gps_y, now_gps_ins);
  876. double parkDistance = pt.y;
  877. if (dSpeed > 15)
  878. {
  879. dSpeed = 15;
  880. }
  881. //dSpeed = 15;//////////////////////////////
  882. if (parkDistance < 15 && parkDistance >= 12.5 && parkDis<20)
  883. {
  884. dSpeed = min(dSpeed, 8.0);
  885. }else if (parkDistance < 12.5 && parkDistance >= 8.5 && parkDis<15.0){
  886. dSpeed = min(dSpeed, 5.0);
  887. }else if (parkDistance < 8.5 && parkDistance >= 5.5 && parkDis<9.0){
  888. dSpeed = min(dSpeed, 3.0);
  889. }else if(parkDistance < 5.5 && parkDis<6.0){
  890. dSpeed = min(dSpeed, 1.0);
  891. }
  892. // float stopDis=2;
  893. // if(ServiceCarStatus.msysparam.mvehtype=="ge3"){
  894. // stopDis=1.6;
  895. // } else if(ServiceCarStatus.msysparam.mvehtype=="vv7"){
  896. // stopDis=1.8;
  897. // }
  898. if (parkDistance < 1.6 && parkDis<2.0)
  899. {
  900. // dSpeed = 0;
  901. parkMode = true;
  902. readyParkMode = false;
  903. }
  904. }
  905. }
  906. void ivdecision_brain::decision_speedctrl(Decition &gps_decition,const std::vector<GPSData> & gpsMapLine)
  907. {
  908. if (gpsMapLine[PathPoint]->roadMode ==0)
  909. {
  910. //dSpeed = min(10.0,dSpeed);
  911. dSpeed = min(ServiceCarStatus.mroadmode_vel.mfmode0,dSpeed);
  912. gps_decition->leftlamp = false;
  913. gps_decition->rightlamp = false;
  914. }else if (gpsMapLine[PathPoint]->roadMode == 5)
  915. {
  916. //dSpeed = min(8.0,dSpeed);
  917. dSpeed = min(ServiceCarStatus.mroadmode_vel.mfmode5,dSpeed);
  918. gps_decition->leftlamp = false;
  919. gps_decition->rightlamp = false;
  920. }else if (gpsMapLine[PathPoint]->roadMode == 11)
  921. {
  922. dSpeed = min(ServiceCarStatus.mroadmode_vel.mfmode11,dSpeed);
  923. gps_decition->leftlamp = false;
  924. gps_decition->rightlamp = false;
  925. }else if (gpsMapLine[PathPoint]->roadMode == 14)
  926. {
  927. //dSpeed = min(8.0,dSpeed);
  928. dSpeed = min(ServiceCarStatus.mroadmode_vel.mfmode14,dSpeed);
  929. gps_decition->leftlamp = true;
  930. gps_decition->rightlamp = false;
  931. }else if (gpsMapLine[PathPoint]->roadMode == 15)
  932. {
  933. //dSpeed = min(8.0,dSpeed);
  934. dSpeed = min(ServiceCarStatus.mroadmode_vel.mfmode15,dSpeed);
  935. gps_decition->leftlamp = false;
  936. gps_decition->rightlamp = true;
  937. }else if (gpsMapLine[PathPoint]->roadMode == 16)
  938. {
  939. // dSpeed = min(10.0,dSpeed);
  940. dSpeed = min(ServiceCarStatus.mroadmode_vel.mfmode16,dSpeed);
  941. //gps_decition->leftlamp = true;
  942. //gps_decition->rightlamp = false;
  943. }else if (gpsMapLine[PathPoint]->roadMode == 17)
  944. {
  945. // dSpeed = min(10.0,dSpeed);
  946. dSpeed = min(ServiceCarStatus.mroadmode_vel.mfmode17,dSpeed);
  947. //gps_decition->leftlamp = false;
  948. //gps_decition->rightlamp = true;
  949. }else if (gpsMapLine[PathPoint]->roadMode == 18)
  950. {
  951. // dSpeed = min(10.0,dSpeed);
  952. dSpeed = min(ServiceCarStatus.mroadmode_vel.mfmode18,dSpeed);
  953. gps_decition->leftlamp = false;
  954. gps_decition->rightlamp = false;
  955. /*if(gpsMapLine[PathPoint]->light_left_or_right == 1)
  956. {
  957. gps_decition->leftlamp = true;
  958. gps_decition->rightlamp = false;
  959. }
  960. else if(gpsMapLine[PathPoint]->light_left_or_right == 2)
  961. {
  962. gps_decition->leftlamp = false;
  963. gps_decition->rightlamp = true;
  964. }*/
  965. }else if (gpsMapLine[PathPoint]->roadMode == 1)
  966. {
  967. dSpeed = min(10.0,dSpeed);
  968. }else if (gpsMapLine[PathPoint]->roadMode == 2)
  969. {
  970. dSpeed = min(15.0,dSpeed);
  971. }
  972. else if (gpsMapLine[PathPoint]->roadMode == 7)
  973. {
  974. dSpeed = min(15.0,dSpeed);
  975. xiuzhengCs=1.5;
  976. }else if (gpsMapLine[PathPoint]->roadMode == 4) //1220
  977. {
  978. dSpeed = min(4.0,dSpeed);
  979. }else{
  980. dSpeed = min(ServiceCarStatus.mroadmode_vel.mfmode0,dSpeed);
  981. gps_decition->leftlamp = false;
  982. gps_decition->rightlamp = false;
  983. }
  984. if (gpsMapLine[PathPoint]->speed_mode == 2)
  985. {
  986. dSpeed = min(25.0,dSpeed);
  987. }
  988. if((gpsMapLine[PathPoint]->speed)>0.001)
  989. {
  990. dSpeed = min((gpsMapLine[PathPoint]->speed*3.6),dSpeed);
  991. }
  992. dSecSpeed = dSpeed / 3.6;
  993. std::cout<<"juecesudu2="<<dSpeed<<std::endl;
  994. }
  995. //std::vector<iv::Perception::PerceptionOutput> lidar_per,
  996. iv::decition::Decition ivdecision_brain::getDecideFromGPS(GPS_INS now_gps_ins,
  997. const std::vector<GPSData> gpsMapLine,
  998. iv::LidarGridPtr lidarGridPtr,
  999. std::vector<iv::Perception::PerceptionOutput> lidar_per,
  1000. iv::TrafficLight trafficLight)
  1001. {
  1002. iv::decition::Decition gps_decition(new iv::decition::DecitionBasic);
  1003. //如果useFrenet、useOldAvoid两者不互为相异,则采用原来的方法。“^”为异或运算符。
  1004. if(!(useFrenet^useOldAvoid)){
  1005. useFrenet = false;
  1006. useOldAvoid = true;
  1007. }
  1008. if (isFirstRun)
  1009. {
  1010. decision_firstRun(now_gps_ins,gpsMapLine);
  1011. }
  1012. if(ServiceCarStatus.msysparam.gpsOffset_x!=0 || ServiceCarStatus.msysparam.gpsOffset_y!=0 ){
  1013. GPS_INS gpsOffset = Coordinate_UnTransfer(ServiceCarStatus.msysparam.gpsOffset_x, ServiceCarStatus.msysparam.gpsOffset_y, now_gps_ins);
  1014. now_gps_ins.gps_x=gpsOffset.gps_x;
  1015. now_gps_ins.gps_y=gpsOffset.gps_y;
  1016. GaussProjInvCal(now_gps_ins.gps_x, now_gps_ins.gps_y, &now_gps_ins.gps_lng, &now_gps_ins.gps_lat);
  1017. }
  1018. changingDangWei=false;
  1019. minDecelerate=0;
  1020. if(now_gps_ins.gps_lat<0||now_gps_ins.gps_lat>90){
  1021. // int a=0;
  1022. gps_decition->wheel_angle = 0;
  1023. gps_decition->speed = dSpeed;
  1024. gps_decition->accelerator = -0.5;
  1025. gps_decition->brake=10;
  1026. return gps_decition;
  1027. }
  1028. if(ServiceCarStatus.daocheMode){
  1029. now_gps_ins.ins_heading_angle=now_gps_ins.ins_heading_angle+180;
  1030. if( now_gps_ins.ins_heading_angle>=360)
  1031. now_gps_ins.ins_heading_angle= now_gps_ins.ins_heading_angle-360;
  1032. }
  1033. //1125 traficc
  1034. traffic_light_gps.gps_lat=ServiceCarStatus.iTrafficeLightLat;
  1035. traffic_light_gps.gps_lng=ServiceCarStatus.iTrafficeLightLon;
  1036. GaussProjCal(traffic_light_gps.gps_lng,traffic_light_gps.gps_lat, &traffic_light_gps.gps_x, &traffic_light_gps.gps_y);
  1037. //xiesi
  1038. ///kkcai, 2020-01-03
  1039. //ServiceCarStatus.busmode=true;
  1040. //ServiceCarStatus.busmode=false;//20200102
  1041. ///////////////////////////////////////////////////
  1042. //busMode = ServiceCarStatus.busmode;
  1043. nearStation=false;
  1044. gps_decition->leftlamp = false;
  1045. gps_decition->rightlamp = false;
  1046. // qDebug("heading is %g",now_gps_ins.ins_heading_angle);
  1047. aim_gps_ins.gps_lat= ServiceCarStatus.mfParkLat;
  1048. aim_gps_ins.gps_lng= ServiceCarStatus.mfParkLng;
  1049. aim_gps_ins.ins_heading_angle= ServiceCarStatus.mfParkHeading;
  1050. GaussProjCal(aim_gps_ins.gps_lng,aim_gps_ins.gps_lat, &aim_gps_ins.gps_x, &aim_gps_ins.gps_y);
  1051. is_arrivaled = false;
  1052. xiuzhengCs=0;
  1053. realspeed = now_gps_ins.speed;
  1054. secSpeed = realspeed / 3.6;
  1055. if(decision_ParkCalc(now_gps_ins,gps_decition) == 1)
  1056. {
  1057. return gps_decition;
  1058. }
  1059. switch (vehState) {
  1060. // ChuiZhiTingChe
  1061. case reverseCar:
  1062. return decision_reverseCar(now_gps_ins);
  1063. break;
  1064. case reversing:
  1065. return decision_reversing(now_gps_ins);
  1066. break;
  1067. case reverseCircle:
  1068. return decision_reverseCircle(now_gps_ins);
  1069. break;
  1070. case reverseDirect:
  1071. return decision_reverseDirect(now_gps_ins);
  1072. break;
  1073. case reverseArr:
  1074. return decision_reverseArr(now_gps_ins);
  1075. break;
  1076. //ceFangWeiBoChe
  1077. case dRever:
  1078. return decision_dRever(now_gps_ins);
  1079. break;
  1080. case dRever0:
  1081. return decision_dRever0(now_gps_ins);
  1082. break;
  1083. case dRever1:
  1084. return decision_dRever1(now_gps_ins);
  1085. break;
  1086. case dRever2:
  1087. return decision_dRever2(now_gps_ins);
  1088. break;
  1089. case dRever3:
  1090. return decision_dRever3(now_gps_ins);
  1091. break;
  1092. case dRever4:
  1093. return decision_dRever4(now_gps_ins);
  1094. break;
  1095. default:
  1096. break;
  1097. }
  1098. obsDistance = -1;
  1099. esrIndex = -1;
  1100. lidarDistance = -1;
  1101. obsDistanceAvoid = -1;
  1102. esrIndexAvoid = -1;
  1103. roadPre = -1;
  1104. gpsTraceOri.clear();
  1105. gpsTraceNow.clear();
  1106. gpsTraceAim.clear();
  1107. gpsTraceAvoid.clear();
  1108. gpsTraceBack.clear();
  1109. if (!isFirstRun)
  1110. {
  1111. // PathPoint = iv::decition::Compute00().getNearestPointIndex(now_gps_ins, gpsMapLine, lastGpsIndex, minDis, maxAngle);
  1112. // if(PathPoint<0){
  1113. PathPoint = iv::decition::Compute00().getFirstNearestPointIndex(now_gps_ins, gpsMapLine, lastGpsIndex, minDis, maxAngle);
  1114. // }
  1115. }
  1116. if (PathPoint<0)
  1117. {
  1118. minDecelerate=-1.0;
  1119. phaseSpeedDecition(gps_decition, secSpeed, -1, 0,now_gps_ins);
  1120. return gps_decition;
  1121. }
  1122. lastGpsIndex = PathPoint;
  1123. //2020-01-03, kkcai
  1124. //if(!circleMode && PathPoint>gpsMapLine.size()-200){
  1125. if(!circleMode && PathPoint>gpsMapLine.size()-100){
  1126. minDecelerate=-1.0;
  1127. std::cout<<"map finish brake"<<std::endl;
  1128. }
  1129. if(!ServiceCarStatus.inRoadAvoid){
  1130. roadOri = gpsMapLine[PathPoint]->roadOri;
  1131. roadSum = gpsMapLine[PathPoint]->roadSum;
  1132. }else{
  1133. roadOri=gpsMapLine[PathPoint]->roadOri*3+1;
  1134. roadSum = gpsMapLine[PathPoint]->roadSum*3;
  1135. }
  1136. if(ServiceCarStatus.avoidObs){
  1137. gpsMapLine[PathPoint]->runMode=1;
  1138. }else{
  1139. gpsMapLine[PathPoint]->runMode=0;
  1140. }
  1141. if(roadNowStart){
  1142. roadNow=roadOri;
  1143. roadNowStart=false;
  1144. }
  1145. // avoidX = (roadOri-roadNow)*roadWidth;
  1146. avoidX=computeAvoidX(roadNow,roadOri,gpsMapLine[PathPoint],ServiceCarStatus.msysparam.vehWidth);
  1147. if ( gpsMapLine[PathPoint]->runMode == 0 &&(vehState == avoidObs||vehState ==stopObs||vehState == preAvoid
  1148. ||vehState == avoiding||vehState == backOri||vehState ==preBack||vehState ==waitAvoid ) )
  1149. {
  1150. vehState = normalRun;
  1151. roadNow = roadOri;
  1152. }
  1153. gpsTraceOri= getGpsTrace(now_gps_ins, gpsMapLine, lastGpsIndex,circleMode);
  1154. // gpsTraceOri = laneChangePlanner->getPath(now_gps_ins,gpsMapLine,PathPoint,0,lidarGridPtr);
  1155. if(gpsTraceOri.empty()){
  1156. gps_decition->wheel_angle = 0;
  1157. gps_decition->speed = dSpeed;
  1158. gps_decition->accelerator = -0.5;
  1159. gps_decition->brake=10;
  1160. return gps_decition;
  1161. }
  1162. traceDevi=gpsTraceOri[0].x;
  1163. //起步进行frenet规划后,车辆行驶至地图路线上,起步操作完毕。
  1164. //如果车辆本身启动位置在地图路线上,可不用进行frenet规划。
  1165. // if(GetDistance(now_gps_ins,*gpsMapLine[PathPoint]) < 1){
  1166. // startingFlag = false;
  1167. // }
  1168. startingFlag = false;
  1169. if(startingFlag){
  1170. // gpsTraceAim = gpsTraceOri;
  1171. if(abs(gpsTraceOri[0].x)>1){
  1172. cout<<"frenetPlanner->getPath:pre"<<endl;
  1173. gpsTraceNow = frenetPlanner->getPath(now_gps_ins,gpsMapLine,PathPoint,0,lidarGridPtr);
  1174. cout<<"frenetPlanner->getPath,gpsTraceNow.size: "<<gpsTraceNow.size()<<endl;
  1175. if(gpsTraceNow.size()==0){
  1176. gps_decition->accelerator = 0;
  1177. gps_decition->brake=10;
  1178. gps_decition->wheel_angle = lastAngle;
  1179. gps_decition->speed = 0;
  1180. return gps_decition;
  1181. }
  1182. }else{
  1183. startingFlag = false;
  1184. }
  1185. }
  1186. if(useFrenet){
  1187. //如果车辆在变道中,启用frenet规划局部路径
  1188. if(vehState == avoiding || vehState == backOri){
  1189. //avoidX = (roadOri - roadNow)*roadWidth;
  1190. avoidX=computeAvoidX(roadNow,roadOri,gpsMapLine[PathPoint],ServiceCarStatus.msysparam.vehWidth);
  1191. gpsTraceNow = frenetPlanner->getPath(now_gps_ins,gpsMapLine,PathPoint,avoidX,lidarGridPtr);
  1192. //gpsTraceAim = laneChangePlanner->getPath(now_gps_ins,gpsMapLine,PathPoint,avoidX,lidarGridPtr);
  1193. gpsTraceAim = getGpsTraceOffset(gpsTraceOri, avoidX);
  1194. if(gpsTraceNow.size()==0){
  1195. gps_decition->accelerator = 0;
  1196. gps_decition->brake=10;
  1197. gps_decition->wheel_angle = lastAngle;
  1198. gps_decition->speed = 0;
  1199. return gps_decition;
  1200. }
  1201. }
  1202. }
  1203. if(gpsTraceNow.size()==0){
  1204. if (roadNow==roadOri)
  1205. {
  1206. gpsTraceNow.assign(gpsTraceOri.begin(), gpsTraceOri.end());
  1207. //gpsTraceNow = getGpsTrace(now_gps_ins, gpsMapLine, lastGpsIndex);
  1208. }else
  1209. {
  1210. // gpsTraceNow = getGpsTrace(now_gps_ins, gmapsR[int(abs(roadWidth * 2)*(roadOri-roadNow))], lastGpsIndex);
  1211. gpsTraceNow = getGpsTraceOffset(gpsTraceOri, avoidX);
  1212. //gpsTraceNow = laneChangePlanner->getPath(now_gps_ins,gpsMapLine,PathPoint,avoidX,lidarGridPtr);
  1213. }
  1214. }
  1215. // dSpeed = getSpeed(gpsTraceNow);
  1216. dSpeed = 80;
  1217. // planTrace = gpsTraceNow; //Add By YuChuli, 2020.11.26
  1218. planTrace.clear();
  1219. for(int i=0;i<gpsTraceNow.size();i++){
  1220. TracePoint pt(gpsTraceNow[i].x,gpsTraceNow[i].y);
  1221. planTrace.push_back(pt);
  1222. }
  1223. dSpeed = limitSpeed(controlAng, dSpeed);
  1224. controlAng= getAngle(gpsTraceNow,now_gps_ins,gps_decition);
  1225. if(!circleMode && PathPoint>(gpsMapLine.size()-100)){
  1226. controlAng=0;
  1227. }
  1228. //1220
  1229. if(ServiceCarStatus.daocheMode){
  1230. controlAng=0-controlAng;
  1231. }
  1232. //2020-0106
  1233. if(vehState==avoiding){
  1234. controlAng=max(-150.0,controlAng);
  1235. controlAng=min(150.0,controlAng);
  1236. }
  1237. if(vehState==backOri){
  1238. controlAng=max(-120.0,controlAng);
  1239. controlAng=min(120.0,controlAng);
  1240. }
  1241. //准备驻车
  1242. if (readyZhucheMode)
  1243. {
  1244. decision_readyZhucheMode(now_gps_ins,gpsMapLine);
  1245. }
  1246. if (readyParkMode)
  1247. {
  1248. decision_readyParkMode(now_gps_ins,gpsMapLine);
  1249. }
  1250. decision_speedctrl(gps_decition,gpsMapLine);
  1251. if(vehState==changingRoad){
  1252. if(gpsTraceNow[0].x>1.0){
  1253. gps_decition->leftlamp = false;
  1254. gps_decition->rightlamp = true;
  1255. }else if(gpsTraceNow[0].x<-1.0){
  1256. gps_decition->leftlamp = true;
  1257. gps_decition->rightlamp = false;
  1258. }else{
  1259. vehState==normalRun;
  1260. }
  1261. }
  1262. // qDebug("decide0 time is %d",xTime.elapsed());
  1263. //1220
  1264. if(!ServiceCarStatus.daocheMode){
  1265. computeObsOnRoad(lidarGridPtr, gpsTraceNow, roadNow,gpsMapLine,lidar_per);
  1266. }else{
  1267. gpsTraceRear.clear();
  1268. for(int i=0;i<gpsTraceNow.size();i++){
  1269. Point2D pt;
  1270. pt.x=0-gpsTraceNow[i].x;
  1271. pt.y=0-gpsTraceNow[i].y;
  1272. gpsTraceRear.push_back(pt);
  1273. }
  1274. computeObsOnRoad(lidarGridPtr, gpsTraceNow, roadNow,gpsMapLine,lidar_per);
  1275. // obsDistance=-1; //1227
  1276. }
  1277. //old_bz--------------------------------------------------------------------------------------------------
  1278. if (vehState == avoiding)
  1279. {
  1280. cout<<"\n==================avoiding=================\n"<<endl;
  1281. // vehState=normalRun; //1025
  1282. if (dSpeed > 10) {
  1283. dSpeed = 10;
  1284. }
  1285. //若车辆到达变道后的路径,改变车辆状态,关闭frenet规划
  1286. if (useFrenet && abs(gpsTraceAim[0].x)<1.0) {
  1287. vehState = normalRun;
  1288. // useFrenet = false;
  1289. // useOldAvoid = true;
  1290. }
  1291. else if (useOldAvoid && abs(gpsTraceNow[0].x)<1.0) {
  1292. // vehState = avoidObs; 0929
  1293. vehState = normalRun;
  1294. }
  1295. else if (gpsTraceNow[0].x>0)
  1296. {
  1297. gps_decition->leftlamp = false;
  1298. gps_decition->rightlamp = true;
  1299. }
  1300. else if(gpsTraceNow[0].x<0)
  1301. {
  1302. gps_decition->leftlamp = true;
  1303. gps_decition->rightlamp = false;
  1304. }
  1305. }
  1306. if (vehState==preBack)
  1307. {
  1308. vehState = backOri;
  1309. }
  1310. if (vehState==backOri)
  1311. {
  1312. cout<<"\n================backOri===========\n"<<endl;
  1313. // vehState=normalRun; //1025
  1314. if (dSpeed > 10) {
  1315. dSpeed = 10;
  1316. }
  1317. //若车辆到达变道后的路径,改变车辆状态,关闭frenet规划
  1318. if (useFrenet && abs(gpsTraceAim[0].x)<1.0) {
  1319. vehState = normalRun;
  1320. // useFrenet = false;
  1321. // useOldAvoid = true;
  1322. }
  1323. else if (useOldAvoid && abs(gpsTraceNow[0].x)<1.0) {
  1324. // vehState = avoidObs; 0929
  1325. vehState = normalRun;
  1326. }
  1327. else if (gpsTraceNow[0].x>0)
  1328. {
  1329. gps_decition->leftlamp = false;
  1330. gps_decition->rightlamp = true;
  1331. }
  1332. else if (gpsTraceNow[0].x<0)
  1333. {
  1334. gps_decition->leftlamp = true;
  1335. gps_decition->rightlamp = false;
  1336. }
  1337. }
  1338. std::cout<<"\n原始RoadOri:%d\n"<<roadOri<<endl;
  1339. cout<<"\n当前RoadNum:%d\n"<<roadNow<<endl;
  1340. // 计算回归原始路线
  1341. if (roadNow!=roadOri)
  1342. {
  1343. // useFrenet = true;
  1344. // useOldAvoid = false;
  1345. if(useFrenet){
  1346. if ((GetDistance(now_gps_ins, startAvoidGpsInsVector[roadOri])>max(avoidMinDistanceVector[roadOri],30.0)))
  1347. {
  1348. double offsetL = -(roadSum - 1)*roadWidth;
  1349. double offsetR = (roadOri - 0)*roadWidth;
  1350. roadPre = frenetPlanner->chooseRoadByFrenet(now_gps_ins,gpsMapLine,PathPoint,offsetL,offsetR,lidarGridPtr,roadNow);
  1351. }
  1352. }
  1353. else if(useOldAvoid){
  1354. roadPre = chooseBackRoad(lidarGridPtr, now_gps_ins, gpsMapLine,lidar_per);
  1355. // avoidX = (roadOri - roadNow)*roadWidth; //1012
  1356. avoidX=computeAvoidX(roadNow,roadOri,gpsMapLine[PathPoint],ServiceCarStatus.msysparam.vehWidth);
  1357. }
  1358. }
  1359. if (roadNow != roadOri && roadPre!=-1)
  1360. {
  1361. roadNow = roadPre;
  1362. // avoidX = (roadOri - roadNow)*roadWidth;
  1363. avoidX=computeAvoidX(roadNow,roadOri,gpsMapLine[PathPoint],ServiceCarStatus.msysparam.vehWidth);
  1364. gpsTraceNow.clear();
  1365. if(useOldAvoid){
  1366. gpsTraceNow = getGpsTraceOffset(gpsTraceOri, avoidX);
  1367. }
  1368. else if(useFrenet){
  1369. gpsTraceNow = frenetPlanner->getPath(now_gps_ins,gpsMapLine,PathPoint,avoidX,lidarGridPtr);
  1370. }
  1371. vehState = backOri;
  1372. hasCheckedBackLidar = false;
  1373. // checkBackObsTimes = 0;
  1374. cout<<"\n回归RoadNum:%d\n"<< roadNow<<endl;
  1375. }
  1376. //shiyanbizhang 0929
  1377. if(obsDistance>0&& (obsDistance<ServiceCarStatus.socfDis+20.0) &&(abs(realspeed)<1.0) &&
  1378. (vehState==normalRun||vehState==backOri || vehState==avoiding) &&(ObsTimeStart==-1)
  1379. && (gpsMapLine[PathPoint]->runMode==1)){
  1380. ObsTimeStart=GetTickCount();
  1381. cout<<"\n====================preAvoid time count start==================\n"<<endl;
  1382. }
  1383. if(ObsTimeStart!=-1){
  1384. ObsTimeEnd=GetTickCount();
  1385. }
  1386. if(ObsTimeEnd!=-1){
  1387. ObsTimeSpan=ObsTimeEnd-ObsTimeStart;
  1388. }
  1389. if(ObsTimeSpan>ObsTimeWidth &&(obsDistance>1.5||obsDistance<0) && (gpsMapLine[PathPoint]->runMode==1)){ //1026
  1390. vehState=avoidObs;
  1391. ObsTimeStart=-1;
  1392. ObsTimeEnd=-1;
  1393. ObsTimeSpan=-1;
  1394. cout<<"\n====================preAvoid time count finish==================\n"<<endl;
  1395. }
  1396. if(obsDistance<0 ||obsDistance>ServiceCarStatus.socfDis){
  1397. ObsTimeStart=-1;
  1398. ObsTimeEnd=-1;
  1399. ObsTimeSpan=-1;
  1400. }
  1401. //避障模式
  1402. if (vehState == avoidObs || vehState==waitAvoid ) {
  1403. // if (obsDistance <20 && obsDistance >0)
  1404. if (obsDistance <ServiceCarStatus.aocfDis && obsDistance >0)
  1405. {
  1406. dSpeed = min(7.0,dSpeed);
  1407. avoidTimes++;
  1408. // if (avoidTimes>=6)
  1409. if (avoidTimes>=ServiceCarStatus.aocfTimes)
  1410. {
  1411. vehState = preAvoid;
  1412. avoidTimes = 0;
  1413. }
  1414. }
  1415. // else if (obsDistance < 35 && obsDistance >0 && dSpeed>10)
  1416. // {
  1417. // dSpeed = 10;
  1418. // avoidTimes = 0;
  1419. // }
  1420. else if (obsDistance < 40 && obsDistance >0 && dSpeed>15)
  1421. {
  1422. dSpeed = min(15.0,dSpeed);
  1423. avoidTimes = 0;
  1424. }
  1425. else
  1426. {
  1427. avoidTimes = 0;
  1428. }
  1429. }
  1430. if (vehState == preAvoid)
  1431. {
  1432. cout<<"\n====================preAvoid==================\n"<<endl;
  1433. /* if (obsDisVector[roadNow]>30)*/ //if (obsDisVector[roadNow]>30||obsDisVector[roadNow]<0)
  1434. if (obsDisVector[roadNow]>ServiceCarStatus.aocfDis)
  1435. {
  1436. // vehState = avoidObs; 0929
  1437. vehState=normalRun;
  1438. }
  1439. else
  1440. {
  1441. //roadPre = chooseAvoidRoad(lidarGridPtr, now_gps_ins,gpsMapLine);
  1442. if(useOldAvoid){
  1443. roadPre = chooseAvoidRoad(lidarGridPtr, now_gps_ins,gpsMapLine,lidar_per);
  1444. // avoidX = (roadOri - roadNow)*roadWidth; //1012
  1445. avoidX=computeAvoidX(roadNow,roadOri,gpsMapLine[PathPoint],ServiceCarStatus.msysparam.vehWidth);
  1446. }
  1447. else if(useFrenet){
  1448. double offsetL = -(roadSum - 1)*roadWidth;
  1449. double offsetR = (roadOri - 0)*roadWidth;
  1450. roadPre = frenetPlanner->chooseRoadByFrenet(now_gps_ins,gpsMapLine,PathPoint,offsetL,offsetR,lidarGridPtr,roadNow);
  1451. }
  1452. if (roadPre == -1 && obsDisVector[roadNow]<1.5 && obsDisVector[roadNow]>0)
  1453. {
  1454. // vehState = waitAvoid; 0929
  1455. vehState = avoidObs;
  1456. }
  1457. else if (roadPre != -1)
  1458. {
  1459. if(useOldAvoid){
  1460. roadNow = roadPre;
  1461. // avoidX = (roadOri - roadNow)*roadWidth;
  1462. avoidX=computeAvoidX(roadNow,roadOri,gpsMapLine[PathPoint],ServiceCarStatus.msysparam.vehWidth);
  1463. gpsTraceNow.clear();
  1464. gpsTraceNow = getGpsTraceOffset(gpsTraceOri, avoidX);
  1465. }
  1466. else if(useFrenet){
  1467. if(roadPre != roadNow){
  1468. avoidMinDistanceVector[roadNow] = obsDisVector[roadNow] + ServiceCarStatus.msysparam.vehLenth;
  1469. startAvoidGpsInsVector[roadNow] = now_gps_ins;
  1470. }
  1471. roadNow = roadPre;
  1472. // avoidX = (roadOri - roadNow)*roadWidth;
  1473. avoidX=computeAvoidX(roadNow,roadOri,gpsMapLine[PathPoint],ServiceCarStatus.msysparam.vehWidth);
  1474. gpsTraceNow = frenetPlanner->getPath(now_gps_ins,gpsMapLine,PathPoint,avoidX,lidarGridPtr);
  1475. }
  1476. vehState = avoiding;
  1477. hasCheckedAvoidLidar = false;
  1478. cout<<"\n避障到RoadNum:%d\n"<<roadNow<<endl;
  1479. }
  1480. }
  1481. }
  1482. //--------------------------------------------------------------------------------old_bz_end
  1483. if (parkMode)
  1484. {
  1485. minDecelerate=-0.4;
  1486. if(finishPointNum<0||finishPointNum>=gpsMapLine.size()){
  1487. parkMode=false;
  1488. }else if(GetDistance(now_gps_ins, *gpsMapLine[finishPointNum])>4){
  1489. parkMode=false;
  1490. }
  1491. }
  1492. //驻车
  1493. if (zhucheMode)
  1494. {
  1495. int mzcTime = ServiceCarStatus.msysparam.mzhuchetime * 1000;
  1496. // if(trumpet()<16000)
  1497. if (trumpet()<mzcTime)
  1498. {
  1499. // if (trumpet()<12000){
  1500. cout<<"ZHECHE ING STATE+++++++++++++++++++++++++++++++++"<<endl;
  1501. minDecelerate=-1.0;
  1502. if(abs(realspeed)<0.2){
  1503. controlAng=0; //tju
  1504. }
  1505. }
  1506. else
  1507. {
  1508. hasZhuched = true; //1125
  1509. zhucheMode = false;
  1510. trumpetFirstCount = true;
  1511. cout<<"ZHECHE STATE JIESHU +++++++++++++++++++++++++++++++++"<<endl;
  1512. }
  1513. }
  1514. //判断驻车标志位
  1515. if (hasZhuched && GetDistance(now_gps_ins,*gpsMapLine[zhuchePointNum])>20)
  1516. {
  1517. hasZhuched = false;
  1518. }
  1519. if ( vehState==changingRoad || vehState==chaocheBack)
  1520. {
  1521. double lastAng = 0.0 - lastAngle;
  1522. if (controlAng>40)
  1523. {
  1524. controlAng =40;
  1525. }
  1526. else if (controlAng<-40)
  1527. {
  1528. controlAng = - 40;
  1529. }
  1530. }
  1531. //速度结合角度的限制
  1532. controlAng = limitAngle(realspeed, controlAng);
  1533. std::cout << "\n呼车指令状态:%d\n" << ServiceCarStatus.carState << std::endl;
  1534. //1220
  1535. if(PathPoint+80<gpsMapLine.size()-1){
  1536. if(gpsMapLine[PathPoint+80]->roadMode==4 && !ServiceCarStatus.daocheMode){
  1537. changingDangWei=true;
  1538. }
  1539. }
  1540. if(changingDangWei){
  1541. if(abs(realspeed)>0.1){
  1542. dSpeed=0;
  1543. }else{
  1544. dSpeed=0;
  1545. gps_decition->dangWei=2;
  1546. ServiceCarStatus.daocheMode=true;
  1547. }
  1548. }
  1549. //1220 end
  1550. for(int i = 0;i<ServiceCarStatus.car_stations.size();i++)
  1551. {
  1552. GPS_INS gpsIns;
  1553. GaussProjCal(ServiceCarStatus.car_stations[i].longtitude, ServiceCarStatus.car_stations[i].latitude, &gpsIns.gps_x, &gpsIns.gps_y);
  1554. double dis = GetDistance(gpsIns, now_gps_ins);
  1555. if(dis<20)
  1556. ServiceCarStatus.currentstation = ServiceCarStatus.car_stations[i].ID;
  1557. }
  1558. // 解析云平台数据
  1559. if(ServiceCarStatus.stationCmd.received==true)
  1560. {
  1561. std::vector<Station> station_received;
  1562. Station station_aa,station_nearest;
  1563. if(ServiceCarStatus.stationCmd.has_emergencyStop)
  1564. {
  1565. if(ServiceCarStatus.stationCmd.emergencyStop==0x01)
  1566. {
  1567. //ServiceCarStatus.carState = 0;
  1568. //busMode=true;
  1569. ServiceCarStatus.emergencyStop=1;
  1570. }
  1571. else
  1572. {
  1573. //ServiceCarStatus.carState = 1;
  1574. //busMode=false;
  1575. ServiceCarStatus.emergencyStop=0;
  1576. }
  1577. }
  1578. if(ServiceCarStatus.stationCmd.has_stationStop)
  1579. {
  1580. //寻找最近站点
  1581. station_received.clear();
  1582. for(int i=0;i<ServiceCarStatus.stationCmd.stationTotalNum;i++)
  1583. {
  1584. station_aa.index=i;
  1585. station_aa.station_location.gps_lat=ServiceCarStatus.stationCmd.stationGps[i].gps_lat;
  1586. station_aa.station_location.gps_lng=ServiceCarStatus.stationCmd.stationGps[i].gps_lng;
  1587. GaussProjCal(station_aa.station_location.gps_lng,station_aa.station_location.gps_lat, &station_aa.station_location.gps_x, &station_aa.station_location.gps_y);
  1588. station_received.push_back(station_aa);
  1589. }
  1590. station_nearest=getNearestStation(now_gps_ins,station_received,gpsMapLine);
  1591. qDebug("station_nearest: %d, lat: %.7f, lon: %.7f", station_nearest.map_index, station_nearest.station_location.gps_lat, ServiceCarStatus.amilng=station_nearest.station_location.gps_lng);
  1592. givlog->debug("brain_v2x","station_nearest: %d, lat: %.7f, lon: %.7f",
  1593. station_nearest.map_index, station_nearest.station_location.gps_lat,
  1594. station_nearest.station_location.gps_lng);
  1595. //进入站点模式
  1596. if((ServiceCarStatus.stationCmd.stationStop==0x00))
  1597. {
  1598. ServiceCarStatus.carState = 2;
  1599. ServiceCarStatus.amilat=station_nearest.station_location.gps_lat;
  1600. ServiceCarStatus.amilng=station_nearest.station_location.gps_lng;
  1601. busMode=true;
  1602. }else
  1603. {
  1604. ServiceCarStatus.carState = 1;
  1605. busMode=false;
  1606. ServiceCarStatus.station_control_door=0;
  1607. ServiceCarStatus.station_control_door_option=false;
  1608. }
  1609. }
  1610. if(ServiceCarStatus.stationCmd.has_carMode)
  1611. {
  1612. if(ServiceCarStatus.stationCmd.carMode==0x00)
  1613. {
  1614. ServiceCarStatus.stationCmd.mode_manual_drive=true;
  1615. }else
  1616. {
  1617. ServiceCarStatus.stationCmd.mode_manual_drive=false;
  1618. }
  1619. }
  1620. ServiceCarStatus.stationCmd.received=false;
  1621. }
  1622. //carState == 0,紧急停车
  1623. if ((ServiceCarStatus.emergencyStop==1)) //||(adjuseultra()==true))
  1624. {
  1625. minDecelerate=-1.0;
  1626. }
  1627. if (ServiceCarStatus.carState == 3 && busMode)
  1628. {
  1629. if(realspeed<0.1){
  1630. ServiceCarStatus.carState=0;
  1631. minDecelerate=-1.0;
  1632. }else{
  1633. nearStation=true;
  1634. dSpeed=0;
  1635. }
  1636. }
  1637. //carState==2,站点停车
  1638. if ((ServiceCarStatus.carState==2)&&busMode)
  1639. {
  1640. aim_gps_ins.gps_lat=ServiceCarStatus.amilat;
  1641. aim_gps_ins.gps_lng=ServiceCarStatus.amilng;
  1642. GaussProjCal( aim_gps_ins.gps_lng, aim_gps_ins.gps_lat, &aim_gps_ins.gps_x, &aim_gps_ins.gps_y);
  1643. double dis = GetDistance(aim_gps_ins, now_gps_ins);
  1644. Point2D pt = Coordinate_Transfer((aim_gps_ins).gps_x, (aim_gps_ins).gps_y, now_gps_ins);
  1645. if (dis<20 && pt.y<5 && abs(pt.x)<3)
  1646. {
  1647. dSpeed = 0;
  1648. nearStation=true;
  1649. //is_arrivaled = true;
  1650. //ServiceCarStatus.status[0] = true;
  1651. ServiceCarStatus.istostation=1;
  1652. minDecelerate=-1.0;
  1653. }
  1654. else if (dis<20 && pt.y<15 && abs(pt.x)<3)
  1655. {
  1656. nearStation=true;
  1657. dSpeed = min(8.0, dSpeed);
  1658. }
  1659. else if (dis<30 && pt.y<20 && abs(pt.x)<3)
  1660. {
  1661. dSpeed = min(15.0, dSpeed);
  1662. }
  1663. else if (dis<50 && abs(pt.x)<3)
  1664. {
  1665. dSpeed = min(20.0, dSpeed);
  1666. }
  1667. if((pt.y<5)&&(abs(realspeed)<0.1)&&(ServiceCarStatus.station_control_door==0))
  1668. {
  1669. ServiceCarStatus.station_control_door=1; //open door
  1670. }
  1671. //站点停车log
  1672. givlog->debug("brain_v2x","aim_gps_ins.gps_lat: %.7f, aim_gps_ins.gps_lng: %.7f, dis: %.2f, dSpeed: %.1f",
  1673. aim_gps_ins.gps_lat, aim_gps_ins.gps_lng,
  1674. dis,dSpeed);
  1675. }
  1676. dSecSpeed = dSpeed / 3.6;
  1677. gps_decition->speed = dSpeed;
  1678. if (gpsMapLine[PathPoint]->runMode == 2)
  1679. {
  1680. obsDistance = -1;
  1681. }
  1682. std::cout<<"juecesudu0="<<dSpeed<<std::endl;
  1683. //-------------------------------traffic light----------------------------------------------------------------------------------------
  1684. if(traffic_light_gps.gps_lat!=0 && traffic_light_gps.gps_lng!=0){
  1685. traffic_light_pathpoint = iv::decition::Compute00().getNoAngleNearestPointIndex(traffic_light_gps, gpsMapLine);
  1686. // traffic_light_pathpoint=130;
  1687. float traffic_speed=ComputeTrafficLightSpeed(ServiceCarStatus.iTrafficeLightColor,ServiceCarStatus.iTrafficeLightTime,gpsMapLine,
  1688. traffic_light_pathpoint ,PathPoint,secSpeed,dSpeed);
  1689. dSpeed = min((double)traffic_speed,dSpeed);
  1690. if(traffic_speed==0){
  1691. minDecelerate=-2.0;
  1692. }
  1693. }
  1694. //-------------------------------traffic light end-----------------------------------------------------------------------------------------------
  1695. //-------------------------------v2x traffic light-----------------------------------------------------------------------------------------
  1696. double v2xTrafficSpeed= ComputeV2XTrafficLightSpeed( trafficLight, gpsMapLine, v2xTrafficVector,
  1697. PathPoint, secSpeed, dSpeed, circleMode);
  1698. dSpeed = min(v2xTrafficSpeed,dSpeed);
  1699. //------------------------------v2x traffic light end--------------------------------------------------------------------------------------
  1700. transferGpsMode2(gpsMapLine);
  1701. if((ServiceCarStatus.msysparam.mvehtype=="hapo")&&(abs(realspeed)<18)){
  1702. if(obsDistance>0 && obsDistance<6){
  1703. dSpeed=0;
  1704. }
  1705. }else if(obsDistance>0 && obsDistance<10){
  1706. dSpeed=0;
  1707. }
  1708. // obsDistance=-1; //1227
  1709. if(ServiceCarStatus.group_control){
  1710. dSpeed = ServiceCarStatus.group_comm_speed;
  1711. }
  1712. if(dSpeed==0){
  1713. minDecelerate=min(-1.0f,minDecelerate);
  1714. }
  1715. std::cout<<"dSpeed= "<<dSpeed<<std::endl;
  1716. // givlog->debug("SPEED","dSpeed is %f",dSpeed);
  1717. gps_decition->wheel_angle = 0.0 - controlAng;
  1718. phaseSpeedDecition(gps_decition, secSpeed, obsDistance, obsSpeed,now_gps_ins);
  1719. lastAngle=gps_decition->wheel_angle;
  1720. // qDebug("decide1 time is %d",xTime.elapsed());
  1721. for(int i=0;i<ServiceCarStatus.obsTraceLeft.size();i++){
  1722. givlog->debug("obs_distance","obsTraceLeftX: %f, obsTraceLeftY: %f",
  1723. ServiceCarStatus.obsTraceLeft.at(i).x, ServiceCarStatus.obsTraceLeft.at(i).y);
  1724. }
  1725. return gps_decition;
  1726. }
  1727. iv::Station ivdecision_brain::getNearestStation(iv::GPS_INS now_gps_ins,std::vector<Station> station_n,std::vector<GPSData> gpsMap){
  1728. int now_index=0,front_index=0;
  1729. int station_size=station_n.size();
  1730. for(int i=0;i<station_size;i++)
  1731. {
  1732. int minDistance=10;
  1733. for (int j = 0; j < gpsMap.size(); j++)
  1734. {
  1735. double tmpdis = GetDistance(station_n[i].station_location, (*gpsMap[j]));
  1736. if (tmpdis < minDistance )
  1737. {
  1738. minDistance = tmpdis;
  1739. station_n[i].map_index=j;
  1740. }
  1741. }
  1742. givlog->debug("brain_v2x","stationi: %d, map_index: %d",
  1743. i,station_n[i].map_index);
  1744. }
  1745. int minDistance=10;
  1746. for (int j = 0; j < gpsMap.size(); j++)
  1747. {
  1748. double tmpdis = GetDistance(now_gps_ins, (*gpsMap[j]));
  1749. if (tmpdis < minDistance )
  1750. {
  1751. minDistance = tmpdis;
  1752. now_index=j;
  1753. }
  1754. }
  1755. givlog->debug("brain_v2x","now_index: %d",
  1756. now_index);
  1757. int min_index=gpsMap.size()-1;
  1758. int station_index=0;
  1759. for(int i=0;i<station_size;i++)
  1760. {
  1761. if(station_n[i].map_index>now_index)
  1762. {
  1763. front_index=station_n[i].map_index;
  1764. if(front_index<min_index)
  1765. {
  1766. min_index=front_index;
  1767. station_index=i;
  1768. }
  1769. }
  1770. }
  1771. qDebug("station_index:%d",station_index);
  1772. return station_n[station_index];
  1773. }
  1774. void ivdecision_brain::initMethods(){
  1775. pid_Controller= new PIDController();
  1776. ge3_Adapter = new Ge3Adapter();
  1777. qingyuan_Adapter = new QingYuanAdapter();
  1778. vv7_Adapter = new VV7Adapter();
  1779. zhongche_Adapter = new ZhongcheAdapter();
  1780. bus_Adapter = new BusAdapter();
  1781. hapo_Adapter = new HapoAdapter();
  1782. yuhesen_Adapter = new YuHeSenAdapter();
  1783. mpid_Controller.reset(pid_Controller);
  1784. mbus_Adapter.reset(bus_Adapter);
  1785. mhapo_Adapter.reset(hapo_Adapter);
  1786. myuhesen_Adapter.reset(yuhesen_Adapter);
  1787. frenetPlanner = new FrenetPlanner();
  1788. // laneChangePlanner = new LaneChangePlanner();
  1789. mfrenetPlanner.reset(frenetPlanner);
  1790. // mlaneChangePlanner.reset(laneChangePlanner);
  1791. }
  1792. void ivdecision_brain::phaseSpeedDecition(iv::decition::Decition decition, double secSpeed, double obsDis, double obsSpeed, GPS_INS gpsIns ) {
  1793. pid_Controller->getControlDecition( gpsIns, gpsTraceNow, dSpeed, obsDis, obsSpeed, false, true, &decition);
  1794. if(ServiceCarStatus.msysparam.mvehtype=="ge3"){
  1795. ge3_Adapter->getAdapterDeciton(gpsIns, gpsTraceNow, dSpeed, obsDis,obsSpeed, decition->accelerator,ServiceCarStatus.mfCalAcc ,changingDangWei, &decition);
  1796. }else if( ServiceCarStatus.msysparam.mvehtype=="qingyuan"){
  1797. qingyuan_Adapter->getAdapterDeciton(gpsIns, gpsTraceNow, dSpeed, obsDis,obsSpeed, decition->accelerator,ServiceCarStatus.mfCalAcc ,changingDangWei, &decition);
  1798. }else if( ServiceCarStatus.msysparam.mvehtype=="vv7"){
  1799. vv7_Adapter->getAdapterDeciton(gpsIns, gpsTraceNow, dSpeed, obsDis,obsSpeed, decition->accelerator,ServiceCarStatus.mfCalAcc ,changingDangWei, &decition);
  1800. }else if( ServiceCarStatus.msysparam.mvehtype=="zhongche"){
  1801. zhongche_Adapter->getAdapterDeciton(gpsIns, gpsTraceNow, dSpeed, obsDis,obsSpeed, decition->accelerator,ServiceCarStatus.mfCalAcc ,changingDangWei, &decition);
  1802. }else if(ServiceCarStatus.msysparam.mvehtype=="bus"){
  1803. bus_Adapter->getAdapterDeciton(gpsIns, gpsTraceNow, dSpeed, obsDis,obsSpeed, decition->accelerator,ServiceCarStatus.mfCalAcc ,changingDangWei, &decition);
  1804. }else if(ServiceCarStatus.msysparam.mvehtype=="hapo"){
  1805. hapo_Adapter->getAdapterDeciton(gpsIns, gpsTraceNow, dSpeed, obsDis,obsSpeed, decition->accelerator,ServiceCarStatus.mfCalAcc ,changingDangWei, &decition);
  1806. }
  1807. else if(ServiceCarStatus.msysparam.mvehtype=="yuhesen"){
  1808. yuhesen_Adapter->getAdapterDeciton(gpsIns, gpsTraceNow, dSpeed, obsDis,obsSpeed, decition->accelerator,ServiceCarStatus.mfCalAcc ,changingDangWei, &decition);
  1809. }
  1810. }
  1811. std::vector<iv::Point2D> ivdecision_brain::getGpsTrace(iv::GPS_INS now_gps_ins, const std::vector<GPSData> gpsMapLine, int lastIndex, bool circleMode) {
  1812. vector<iv::Point2D> trace;
  1813. // int PathPoint = iv::decition::Compute00().getNearestPointIndex(now_gps_ins, gpsMapLine, lastGpsIndex, minDis, maxAngle);
  1814. /*if (PathPoint != -1)
  1815. lastGpsIndex = PathPoint;*/
  1816. if (gpsMapLine.size() > 600 && PathPoint >= 0) {
  1817. int aimIndex;
  1818. if(circleMode){
  1819. aimIndex=PathPoint+600;
  1820. }else{
  1821. aimIndex=min((PathPoint+600),(int)gpsMapLine.size());
  1822. }
  1823. for (int i = PathPoint; i < aimIndex; i++)
  1824. {
  1825. int index = i % gpsMapLine.size();
  1826. Point2D pt = Coordinate_Transfer((*gpsMapLine[index]).gps_x, (*gpsMapLine[index]).gps_y, now_gps_ins);
  1827. pt.x += offset_real * 0.032;
  1828. pt.v1 = (*gpsMapLine[index]).speed_mode;
  1829. pt.v2 = (*gpsMapLine[index]).mode2;
  1830. pt.roadMode=(*gpsMapLine[index]).roadMode;
  1831. if (gpsMapLine[index]->roadMode==3 && !hasZhuched)
  1832. {
  1833. readyZhucheMode = true;
  1834. zhuchePointNum = index;
  1835. }
  1836. if (gpsMapLine[index]->roadMode==3 && !hasZhuched)
  1837. {
  1838. readyZhucheMode = true;
  1839. zhuchePointNum = index;
  1840. }
  1841. //csvv7
  1842. if (gpsMapLine[index]->speed_mode==22 || gpsMapLine[index]->speed_mode==23)
  1843. {
  1844. readyParkMode = true;
  1845. finishPointNum = index;
  1846. }
  1847. // if (pt.v1 == 22 || pt.v1 == 23)
  1848. // {
  1849. // readyParkMode = true;
  1850. // finishPointNum = i;
  1851. // }
  1852. switch (pt.v1)
  1853. {
  1854. case 0:
  1855. pt.speed = 80;
  1856. break;
  1857. case 1:
  1858. pt.speed = 25;
  1859. break;
  1860. case 2:
  1861. pt.speed =25;
  1862. break;
  1863. case 3:
  1864. pt.speed = 20;
  1865. break;
  1866. case 4:
  1867. pt.speed =18;
  1868. break;
  1869. case 5:
  1870. pt.speed = 18;
  1871. break;
  1872. case 7:
  1873. pt.speed = 10;
  1874. break;
  1875. case 22:
  1876. pt.speed = 5;
  1877. break;
  1878. case 23:
  1879. pt.speed = 5;
  1880. break;
  1881. default:
  1882. break;
  1883. }
  1884. trace.push_back(pt);
  1885. }
  1886. }
  1887. return trace;
  1888. }
  1889. std::vector<iv::Point2D> ivdecision_brain::getGpsTraceOffset(std::vector<Point2D> gpsTrace, double offset) {
  1890. if (offset==0)
  1891. {
  1892. return gpsTrace;
  1893. }
  1894. std::vector<iv::Point2D> trace;
  1895. for (int j = 0; j < gpsTrace.size(); j++)
  1896. {
  1897. double sumx1 = 0, sumy1 = 0, count1 = 0;
  1898. double sumx2 = 0, sumy2 = 0, count2 = 0;
  1899. for (int k = max(0, j - 4); k <= j; k++)
  1900. {
  1901. count1 = count1 + 1;
  1902. sumx1 += gpsTrace[k].x;
  1903. sumy1 += gpsTrace[k].y;
  1904. }
  1905. for (int k = j; k <= min(gpsTrace.size() - 1, (size_t)(j + 4)); k++)
  1906. {
  1907. count2 = count2 + 1;
  1908. sumx2 += gpsTrace[k].x;
  1909. sumy2 += gpsTrace[k].y;
  1910. }
  1911. sumx1 /= count1; sumy1 /= count1;
  1912. sumx2 /= count2; sumy2 /= count2;
  1913. double anglevalue = atan2(sumy2 - sumy1, sumx2 - sumx1);
  1914. double carFrontx = gpsTrace[j].x;// -Form1.CarRear * Math.Cos(anglevalue);
  1915. double carFronty = gpsTrace[j].y;// -Form1.CarRear * Math.Sin(anglevalue);
  1916. double avoidLenth = abs(offset);
  1917. if (offset<0)
  1918. {
  1919. Point2D ptLeft(carFrontx + avoidLenth * cos(anglevalue + M_PI / 2),
  1920. carFronty + avoidLenth * sin(anglevalue + M_PI / 2));
  1921. ptLeft.speed = gpsTrace[j].speed;
  1922. ptLeft.v1 = gpsTrace[j].v1;
  1923. ptLeft.v2 = gpsTrace[j].v2;
  1924. trace.push_back(ptLeft);
  1925. }
  1926. else
  1927. {
  1928. Point2D ptRight(carFrontx + avoidLenth * cos(anglevalue - M_PI / 2),
  1929. carFronty + avoidLenth * sin(anglevalue - M_PI / 2));
  1930. ptRight.speed = gpsTrace[j].speed;
  1931. ptRight.v1 = gpsTrace[j].v1;
  1932. ptRight.v2 = gpsTrace[j].v2;
  1933. trace.push_back(ptRight);
  1934. }
  1935. }
  1936. return trace;
  1937. }
  1938. double ivdecision_brain::getAngle(std::vector<Point2D> gpsTrace,GPS_INS gpsIns,iv::decition::Decition decition) {
  1939. double angle=0;
  1940. if ( abs(minDis) < 20 && abs(maxAngle) < 100)
  1941. {
  1942. // angle = iv::decition::iv::decition::Compute00().getDecideAngle(gpsTrace, realspeed);
  1943. pid_Controller->getControlDecition(gpsIns, gpsTrace, -1, -1, -1, true, false, &decition);
  1944. angle= decition->wheel_angle;
  1945. }
  1946. return angle;
  1947. }
  1948. double ivdecision_brain::getSpeed(std::vector<Point2D> gpsTrace) {
  1949. double speed=0;
  1950. int speedPoint = iv::decition::Compute00().getSpeedPointIndex(gpsTrace, max(10.0, realspeed));
  1951. speed = gpsTrace[speedPoint].speed;
  1952. for (int i = 0; i < speedPoint; i++) {
  1953. speed = min(speed, gpsTrace[i].speed);
  1954. }
  1955. return speed;
  1956. }
  1957. //void ivdecision_brain::getEsrObs(std::vector<iv::ObstacleBasic> obsRadars) {
  1958. //
  1959. // if (!obsRadars.empty())
  1960. // {
  1961. // esrIndex = iv::decition::iv::decition::Compute00().getEsrIndex(gpsTrace, obsRadars);
  1962. //
  1963. // if (esrIndex != -1)
  1964. // {
  1965. // esrDistance = obsRadars[esrIndex].nomal_y;
  1966. //
  1967. //
  1968. //
  1969. // obsSpeed = obsRadars[esrIndex].speed_y;
  1970. //
  1971. // }
  1972. // else {
  1973. // esrDistance = -1;
  1974. // }
  1975. //
  1976. // }
  1977. // else
  1978. // {
  1979. // esrIndex = -1;
  1980. // esrDistance = -1;
  1981. // }
  1982. // if (esrDistance < 0) {
  1983. // ODS("\n------------------>ESR障碍物距离:%f\n", esrDistance);
  1984. // }
  1985. // else {
  1986. // ODS("\n------------------>ESR障碍物距离:%f ( %.05f , %.05f )\n", esrDistance, obsRadars[esrIndex].nomal_x, obsRadars[esrIndex].nomal_y);
  1987. // }
  1988. //
  1989. // ODS("\n------------------>ESR障碍物速度:%f\n", obsSpeed);
  1990. //}
  1991. void ivdecision_brain::getEsrObsDistance(std::vector<Point2D> gpsTrace, int roadNum) {
  1992. int esrPathpoint;
  1993. esrIndex = iv::decition::Compute00().getEsrIndex(gpsTrace, roadNum, &esrPathpoint,xiuzhengCs);
  1994. if (esrIndex != -1)
  1995. {
  1996. //优化
  1997. // double distance = 0.0;
  1998. // for(int i=0; i<esrPathpoint; ++i){
  1999. // distance+=DirectDistance(gpsTrace[i].x,gpsTrace[i].y,gpsTrace[i+1].x,gpsTrace[i+1].y);
  2000. // }
  2001. // esrDistance = distance - Esr_Y_Offset;
  2002. // if(esrDistance<=0){
  2003. // esrDistance=1;
  2004. // }
  2005. esrDistance = ServiceCarStatus.obs_radar[esrIndex].nomal_y;
  2006. obsSpeed = ServiceCarStatus.obs_radar[esrIndex].speed_y;
  2007. }
  2008. else {
  2009. esrDistance = -1;
  2010. }
  2011. }
  2012. void ivdecision_brain::getEsrObsDistanceAvoid() {
  2013. esrIndexAvoid = iv::decition::Compute00().getEsrIndexAvoid(gpsTraceAvoid);
  2014. if (esrIndexAvoid != -1)
  2015. {
  2016. esrDistanceAvoid = ServiceCarStatus.obs_radar[esrIndexAvoid].nomal_y;
  2017. obsSpeedAvoid = ServiceCarStatus.obs_radar[esrIndexAvoid].speed_y;
  2018. }
  2019. else {
  2020. esrDistanceAvoid = -1;
  2021. }
  2022. if (esrDistanceAvoid < 0) {
  2023. std::cout << "\nESR障碍物距离Avoid:%f\n" << esrDistanceAvoid << std::endl;
  2024. }
  2025. else {
  2026. std::cout << "\nESR障碍物距离Avoid:%f %d:( %.05f , %.05f ,%.05f )\n" << esrDistanceAvoid << esrIndexAvoid << ServiceCarStatus.obs_radar[esrIndexAvoid].nomal_x << ServiceCarStatus.obs_radar[esrIndexAvoid].nomal_y << std::endl;
  2027. }
  2028. std::cout << "\nESR障碍物速度Avoid:%f\n" << obsSpeedAvoid <<std::endl;
  2029. }
  2030. double ivdecision_brain::limitAngle(double speed, double angle) {
  2031. double preAngle = angle;
  2032. if (speed > 15)
  2033. {
  2034. if (preAngle > 350)
  2035. {
  2036. preAngle = 350;
  2037. }
  2038. if (preAngle < -350)
  2039. {
  2040. preAngle = -350;
  2041. }
  2042. }
  2043. if (speed > 22)
  2044. {
  2045. if (preAngle > 200)
  2046. {
  2047. preAngle = 200;
  2048. }
  2049. if (preAngle < -200)
  2050. {
  2051. preAngle = -200;
  2052. }
  2053. }
  2054. if (speed > 25)
  2055. {
  2056. if (preAngle > 150)
  2057. {
  2058. preAngle = 150;
  2059. }
  2060. if (preAngle < -150)
  2061. {
  2062. preAngle = -150;
  2063. }
  2064. }
  2065. if (speed > 30)
  2066. {
  2067. if (preAngle > 70)
  2068. {
  2069. preAngle = 70;
  2070. }
  2071. if (preAngle < -70)
  2072. {
  2073. preAngle = -70;
  2074. }
  2075. }
  2076. if (speed > 45) //20
  2077. {
  2078. if (preAngle > 15)
  2079. {
  2080. preAngle = 15;
  2081. }
  2082. if (preAngle < -15)
  2083. {
  2084. preAngle = -15;
  2085. }
  2086. }
  2087. return preAngle;
  2088. }
  2089. double ivdecision_brain::limitSpeed(double angle, double speed) {
  2090. if (abs(angle) > 500 && speed > 8) speed = 8;
  2091. else if (abs(angle) > 350 && speed > 14) speed = 14;
  2092. else if (abs(angle) > 200 && speed > 21) speed = 21;
  2093. else if (abs(angle) > 150 && speed > 24) speed = 24;
  2094. else if (abs(angle) > 60 && speed > 29) speed = 29;
  2095. else if (abs(angle) > 20 && speed > 34) speed = 34;
  2096. return max(0.0, speed);
  2097. }
  2098. bool ivdecision_brain::checkAvoidEnable(double avoidX, iv::LidarGridPtr lidarGridPtr,int roadNum) {
  2099. if ((obsDisVector[roadNum]>0 && obsDisVector[roadNum]<obsDisVector[roadNow]+ServiceCarStatus.msysparam.vehLenth)||
  2100. (obsDisVector[roadNum]>0 && obsDisVector[roadNum]<15))
  2101. {
  2102. return false;
  2103. }
  2104. if (roadNum-roadNow>1)
  2105. {
  2106. for (int i = roadNow+1; i < roadNum; i++)
  2107. {
  2108. if (obsDisVector[i] < 8 + (i-roadNow) * 2 && obsDisVector[i]>0) {
  2109. return false;
  2110. }
  2111. }
  2112. }
  2113. else if (roadNow-roadNum>1)
  2114. {
  2115. for (int i = roadNow-1; i >roadNum; i--)
  2116. {
  2117. if (obsDisVector[i] < 8 + (roadNow-i) * 2 && obsDisVector[i]>0) {
  2118. return false;
  2119. }
  2120. }
  2121. }
  2122. return true;
  2123. }
  2124. bool ivdecision_brain::checkReturnEnable(double avoidX, iv::LidarGridPtr lidarGridPtr, int roadNum) {
  2125. //lsn
  2126. if (obsDisVector[roadNum]>0 && obsDisVector[roadNum]<20)
  2127. {
  2128. return false;
  2129. }
  2130. if ((obsDisVector[roadNum]>0 && obsDisVector[roadNum]<50 && obsDisVector[roadNum]< obsDisVector[roadNow]) ||
  2131. (obsDisVector[roadNum]>0 && obsDisVector[roadNum]<50 && obsDisVector[roadNow]<0))
  2132. {
  2133. return false;
  2134. }
  2135. if (roadNum - roadNow>1)
  2136. {
  2137. for (int i = roadNow + 1; i < roadNum; i++)
  2138. {
  2139. if (obsDisVector[i] < 8 + (i-roadNow) * 2 && obsDisVector[i]>0) {
  2140. return false;
  2141. }
  2142. }
  2143. }
  2144. else if (roadNow - roadNum>1)
  2145. {
  2146. for (int i = roadNow - 1; i >roadNum; i--)
  2147. {
  2148. if (obsDisVector[i] < 8 + (roadNow-i) * 2 && obsDisVector[i]>0) {
  2149. return false;
  2150. }
  2151. }
  2152. }
  2153. return true;
  2154. }
  2155. void ivdecision_brain::getObsAvoid(iv::LidarGridPtr lidarGridPtr) {
  2156. if (lidarGridPtr == NULL)
  2157. {
  2158. lidarDistanceAvoid = lastLidarDisAvoid;
  2159. }
  2160. else {
  2161. obsPointAvoid = iv::decition::Compute00().getLidarObsPointAvoid(gpsTraceAvoid, lidarGridPtr,lidarDistanceAvoid);
  2162. lastLidarDisAvoid = lidarDistanceAvoid;
  2163. }
  2164. std::cout << "\nLidarAvoid距离:%f\n" << lidarDistanceAvoid << std::endl;
  2165. getEsrObsDistanceAvoid();
  2166. //lidarDistanceAvoid = -1; //20200103 apollo_fu
  2167. if (esrDistanceAvoid>0 && lidarDistanceAvoid > 0)
  2168. {
  2169. if (lidarDistanceAvoid >= esrDistanceAvoid)
  2170. {
  2171. obsDistanceAvoid = esrDistanceAvoid;
  2172. obsSpeedAvoid = ServiceCarStatus.obs_radar[esrIndexAvoid].speed_y;
  2173. }
  2174. else if (!ServiceCarStatus.obs_radar.empty())
  2175. {
  2176. obsDistanceAvoid = lidarDistanceAvoid;
  2177. obsSpeedAvoid = iv::decition::Compute00().getObsSpeed(obsPointAvoid, secSpeed);
  2178. std::cout << "\n计算obsSpeed:%f\n" << obsSpeedAvoid << std::endl;
  2179. }
  2180. else
  2181. {
  2182. obsDistanceAvoid = lidarDistanceAvoid;
  2183. obsSpeedAvoid = obsSpeedAvoid = 0 - secSpeed;;
  2184. std::cout << "\n毫米波无数据,计算obsSpeed:%f\n" << obsSpeedAvoid << std::endl;
  2185. }
  2186. }
  2187. else if (esrDistanceAvoid>0)
  2188. {
  2189. obsDistanceAvoid = esrDistanceAvoid;
  2190. obsSpeedAvoid = ServiceCarStatus.obs_radar[esrIndexAvoid].speed_y;
  2191. }
  2192. else if (lidarDistanceAvoid > 0)
  2193. {
  2194. obsDistanceAvoid = lidarDistanceAvoid;
  2195. obsSpeedAvoid = iv::decition::Compute00().getObsSpeed(obsPointAvoid, secSpeed);
  2196. std::cout << "\n计算obsSpeed:%f\n" << obsSpeedAvoid << std::endl;
  2197. }
  2198. else {
  2199. obsDistanceAvoid = esrDistanceAvoid;
  2200. obsSpeedAvoid = 0 - secSpeed;
  2201. }
  2202. std::cout << "\n最终得出的obsDistanceAvoid:%f\n" << obsDistanceAvoid << std::endl;
  2203. if (obsDistanceAvoid <0 && obsLostTimeAvoid<4)
  2204. {
  2205. obsDistanceAvoid = lastDistanceAvoid;
  2206. obsLostTimeAvoid++;
  2207. }
  2208. else
  2209. {
  2210. obsLostTimeAvoid = 0;
  2211. lastDistanceAvoid = -1;
  2212. }
  2213. if (obsDistanceAvoid>0)
  2214. {
  2215. lastDistanceAvoid = obsDistanceAvoid;
  2216. }
  2217. std::cout << "\nODSAvoid距离:%f\n" << obsDistanceAvoid << std::endl;
  2218. }
  2219. void ivdecision_brain::init() {
  2220. for (int i = 0; i < roadSum; i++)
  2221. {
  2222. lastEsrIdVector.push_back(-1);
  2223. lastEsrCountVector.push_back(0);
  2224. GPS_INS gps_ins;
  2225. gps_ins.gps_x = 0;
  2226. gps_ins.gps_y = 0;
  2227. startAvoidGpsInsVector.push_back(gps_ins);
  2228. avoidMinDistanceVector.push_back(0);
  2229. }
  2230. }
  2231. #include <QTime>
  2232. void ivdecision_brain::computeObsOnRoad(iv::LidarGridPtr lidarGridPtr, std::vector<Point2D> gpsTrace, int roadNum,
  2233. const std::vector<GPSData> gpsMapLine, std::vector<iv::Perception::PerceptionOutput> lidar_per) {
  2234. // QTime xTime;
  2235. // xTime.start();
  2236. // qDebug("time 0 is %d ",xTime.elapsed());
  2237. double obs,obsSd;
  2238. if (lidarGridPtr == NULL)
  2239. {
  2240. lidarDistance = lastLidarDis;
  2241. // lidarDistance = lastlidarDistance;
  2242. }
  2243. else {
  2244. obsPoint = iv::decition::Compute00().getLidarObsPoint(gpsTrace, lidarGridPtr);
  2245. float lidarXiuZheng=0;
  2246. if(!ServiceCarStatus.useMobileEye){
  2247. lidarXiuZheng=0-ServiceCarStatus.msysparam.frontGpsXiuzheng;
  2248. }
  2249. lidarDistance = obsPoint.y + lidarXiuZheng; //激光距离推到车头 gjw20191110 lidar
  2250. // lidarDistance=-1;
  2251. if (lidarDistance<0)
  2252. {
  2253. lidarDistance = -1;
  2254. }
  2255. lastLidarDis = lidarDistance;
  2256. }
  2257. // obsPredict start
  2258. if(ServiceCarStatus.useObsPredict){
  2259. float preObsDis=200;
  2260. if(!lidar_per.empty()){
  2261. preObsDis=PredictObsDistance( secSpeed, gpsTrace, lidar_per);
  2262. lastPreObsDistance=preObsDis;
  2263. }else{
  2264. preObsDis=lastPreObsDistance;
  2265. }
  2266. if(preObsDis<lidarDistance || lidarDistance==-1){
  2267. lidarDistance=preObsDis;
  2268. }
  2269. }
  2270. // obsPredict end
  2271. // qDebug("time 1 is %d ",xTime.elapsed());
  2272. // if(gpsMapLine[PathPoint]->roadMode==14||gpsMapLine[PathPoint]->roadMode==15){
  2273. // lidarDistance=-1;
  2274. // }
  2275. getEsrObsDistance(gpsTrace, roadNum);
  2276. double mobieye_ttc,mobieye_obsid,mobieye_speed,mobieye_distance;
  2277. double fveh_width = 2.0;
  2278. #ifdef USE_MOBIEYE_OBS
  2279. MobieyeInst.GetObsFromMobieye(&gpsTrace,mobieye_distance,mobieye_speed,mobieye_ttc,mobieye_obsid,fveh_width);
  2280. #endif
  2281. // qDebug("time 2 is %d ",xTime.elapsed());
  2282. // esrDistance=-1;
  2283. // if(PathPoint>2992 && PathPoint<4134){
  2284. // lidarDistance=-1;
  2285. // }
  2286. // if(PathPoint>10193 && PathPoint<10929){
  2287. // esrDistance=-1;
  2288. // }
  2289. if(lidarDistance<0){
  2290. lidarDistance=500;
  2291. }
  2292. #ifdef USE_MOBIEYE_OBS
  2293. esrDistance = mobieye_distance;
  2294. if(esrDistance>150){
  2295. esrDistance=500;
  2296. }
  2297. #else
  2298. if(esrDistance>30){
  2299. esrDistance=500;
  2300. }
  2301. #endif
  2302. if(esrDistance<0){
  2303. esrDistance=500;
  2304. }
  2305. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "激光雷达距离:" << lidarDistance << std::endl;
  2306. // if(esrDistance>30){
  2307. // esrDistance=-1;
  2308. // }
  2309. // if(esrDistance>=15 && esrDistance<=50&& ServiceCarStatus.mLidarS>0&&ServiceCarStatus.mLidarPer>0 ){
  2310. // if(abs(lidarDistance-esrDistance)>5){
  2311. // esrDistance=-1;
  2312. // }
  2313. // }
  2314. // if(esrDistance>=1&& esrDistance<=50&& ServiceCarStatus.mLidarS>0&&ServiceCarStatus.mLidarPer>0
  2315. // && gpsMapLine[PathPoint]->runMode == 1 ){
  2316. // if(abs(lidarDistance-esrDistance)>5){
  2317. // esrDistance=-1;
  2318. // }
  2319. // }
  2320. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "毫米波距离:" << esrDistance << std::endl;
  2321. myesrDistance = esrDistance;
  2322. if(lidarDistance==500){
  2323. lidarDistance=-1;
  2324. }
  2325. if(esrDistance==500){
  2326. esrDistance=-1;
  2327. }
  2328. ServiceCarStatus.mRadarObs = esrDistance;
  2329. ServiceCarStatus.mLidarObs = lidarDistance;
  2330. //zhuanwan pingbi haomibo
  2331. if(gpsTraceNow[0].v1==4||gpsTraceNow[0].v1==5){
  2332. esrDistance=-1;
  2333. }
  2334. if (esrDistance>0 && lidarDistance > 0)
  2335. {
  2336. if (lidarDistance >= esrDistance)
  2337. {
  2338. #ifdef USE_MOBIEYE_OBS
  2339. obs = esrDistance;
  2340. obsSd = mobieye_speed;
  2341. #else
  2342. // obsDistance = esrDistance;
  2343. obs = esrDistance;
  2344. // obsSpeed = ServiceCarStatus.obs_radar[esrIndex].speed_y;
  2345. obsSd=ServiceCarStatus.obs_radar[esrIndex].speed_y;
  2346. #endif
  2347. }
  2348. else if (!ServiceCarStatus.obs_radar.empty())
  2349. {
  2350. // obsDistance = lidarDistance;
  2351. obs = lidarDistance;
  2352. // obsSpeed = iv::decition::Compute00().getObsSpeed(obsPoint, secSpeed);
  2353. obsSd = iv::decition::Compute00().getObsSpeed(obsPoint, secSpeed);
  2354. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "计算obsSpeed:" << obsSpeed << std::endl;
  2355. }
  2356. else
  2357. {
  2358. // obsDistance = lidarDistance;
  2359. obs=lidarDistance;
  2360. // obsSpeed = 0 - secSpeed;
  2361. obsSd = 0 -secSpeed;
  2362. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "毫米波无数据,计算obsSpeed:" << obsSpeed << std::endl;
  2363. }
  2364. }
  2365. else if (esrDistance>0)
  2366. {
  2367. // obsDistance = esrDistance;
  2368. // obsSpeed = ServiceCarStatus.obs_radar[esrIndex].speed_y;
  2369. #ifdef USE_MOBIEYE_OBS
  2370. obs = esrDistance;
  2371. obsSd = mobieye_speed;
  2372. #else
  2373. obs = esrDistance;
  2374. obsSd = ServiceCarStatus.obs_radar[esrIndex].speed_y;
  2375. #endif
  2376. }
  2377. else if (lidarDistance > 0)
  2378. {
  2379. // obsDistance = lidarDistance;
  2380. // obsSpeed = iv::decition::Compute00().getObsSpeed(obsPoint, secSpeed);
  2381. obs = lidarDistance;
  2382. obsSd = iv::decition::Compute00().getObsSpeed(obsPoint, secSpeed);
  2383. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "计算obsSpeed:" << obsSpeed << std::endl;
  2384. }
  2385. else {
  2386. // obsDistance = esrDistance;
  2387. // obsSpeed = 0 - secSpeed;
  2388. obs = esrDistance;
  2389. obsSd = 0 - secSpeed;
  2390. }
  2391. if(roadNum==roadNow){
  2392. obsDistance=obs;
  2393. obsSpeed=obsSd;
  2394. }
  2395. // if (obsDistance <0 && obsLostTime<4)
  2396. // {
  2397. // obsDistance = lastDistance;
  2398. // obsLostTime++;
  2399. // }
  2400. // else
  2401. // {
  2402. // obsLostTime = 0;
  2403. // lastDistance = -1;
  2404. // }
  2405. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "最终得出的obsDistance:" << obsDistance << std::endl;
  2406. ServiceCarStatus.mObs = obsDistance;
  2407. if(ServiceCarStatus.mObs>100){
  2408. ServiceCarStatus.mObs =-1;
  2409. }
  2410. if (obsDistance>0)
  2411. {
  2412. lastDistance = obsDistance;
  2413. }
  2414. //lsn
  2415. if(obs<0){
  2416. obsDisVector[roadNum]=500;
  2417. }else{
  2418. obsDisVector[roadNum]=obs;
  2419. }
  2420. givlog->debug("obs_distance","obs: %f, lidar_obs: %f, Radar_obs: %f, lidar_obs_x: %f, lidar_obs_y: %f",
  2421. ServiceCarStatus.mObs, ServiceCarStatus.mLidarObs,
  2422. ServiceCarStatus.mRadarObs,obsPoint.x,lidarDistance);
  2423. // qDebug("time 3 is %d ",xTime.elapsed());
  2424. }
  2425. //1220
  2426. void ivdecision_brain::computeRearObsOnRoad(iv::LidarGridPtr lidarGridPtr, std::vector<Point2D> gpsTrace, int roadNum,
  2427. const std::vector<GPSData> gpsMapLine) {
  2428. double obs,obsSd;
  2429. if(!ServiceCarStatus.obs_rear_radar.empty()){
  2430. getRearEsrObsDistance(gpsTrace, roadNum);
  2431. }
  2432. if (lidarGridPtr == NULL)
  2433. {
  2434. lidarDistance = lastLidarDis;
  2435. // lidarDistance = lastlidarDistance;
  2436. }
  2437. else {
  2438. obsPoint = iv::decition::Compute00().getLidarRearObsPoint(gpsTrace, lidarGridPtr);
  2439. float lidarXiuZheng=0;
  2440. if(!ServiceCarStatus.useMobileEye){
  2441. lidarXiuZheng = ServiceCarStatus.msysparam.rearGpsXiuzheng;
  2442. }
  2443. if(abs(obsPoint.y)>lidarXiuZheng)
  2444. lidarDistance = abs(obsPoint.y)-lidarXiuZheng; //激光距离推到车头 1220
  2445. // lidarDistance=-1;
  2446. if (lidarDistance<0)
  2447. {
  2448. lidarDistance = -1;
  2449. }
  2450. lastLidarDis = lidarDistance;
  2451. }
  2452. // if(gpsMapLine[PathPoint]->roadMode==14||gpsMapLine[PathPoint]->roadMode==15){
  2453. // lidarDistance=-1;
  2454. // }
  2455. // getEsrObsDistance(gpsTrace, roadNum);
  2456. esrDistance=-1;
  2457. // if(PathPoint>2992 && PathPoint<4134){
  2458. // lidarDistance=-1;
  2459. // }
  2460. // if(PathPoint>10193 && PathPoint<10929){
  2461. // esrDistance=-1;
  2462. // }
  2463. if(lidarDistance<0){
  2464. lidarDistance=500;
  2465. }
  2466. if(esrDistance<0){
  2467. esrDistance=500;
  2468. }
  2469. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "激光雷达距离:" << lidarDistance << std::endl;
  2470. // if(esrDistance>30){
  2471. // esrDistance=-1;
  2472. // }
  2473. // if(esrDistance>=15 && esrDistance<=50&& ServiceCarStatus.mLidarS>0&&ServiceCarStatus.mLidarPer>0 ){
  2474. // if(abs(lidarDistance-esrDistance)>5){
  2475. // esrDistance=-1;
  2476. // }
  2477. // }
  2478. // if(esrDistance>=1&& esrDistance<=50&& ServiceCarStatus.mLidarS>0&&ServiceCarStatus.mLidarPer>0
  2479. // && gpsMapLine[PathPoint]->runMode == 1 ){
  2480. // if(abs(lidarDistance-esrDistance)>5){
  2481. // esrDistance=-1;
  2482. // }
  2483. // }
  2484. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "毫米波距离:" << esrDistance << std::endl;
  2485. myesrDistance = esrDistance;
  2486. if(lidarDistance==500){
  2487. lidarDistance=-1;
  2488. }
  2489. if(esrDistance==500){
  2490. esrDistance=-1;
  2491. }
  2492. ServiceCarStatus.mRadarObs = esrDistance;
  2493. ServiceCarStatus.mLidarObs = lidarDistance;
  2494. //zhuanwan pingbi haomibo
  2495. if(gpsTraceNow[0].v1==4||gpsTraceNow[0].v1==5){
  2496. esrDistance=-1;
  2497. }
  2498. if (esrDistance>0 && lidarDistance > 0)
  2499. {
  2500. if (lidarDistance >= esrDistance)
  2501. {
  2502. // obsDistance = esrDistance;
  2503. obs = esrDistance;
  2504. // obsSpeed = ServiceCarStatus.obs_radar[esrIndex].speed_y;
  2505. obsSd=ServiceCarStatus.obs_radar[esrIndex].speed_y;
  2506. }
  2507. else if (!ServiceCarStatus.obs_radar.empty())
  2508. {
  2509. // obsDistance = lidarDistance;
  2510. obs = lidarDistance;
  2511. // obsSpeed = iv::decition::Compute00().getObsSpeed(obsPoint, secSpeed);
  2512. obsSd = iv::decition::Compute00().getObsSpeed(obsPoint, secSpeed);
  2513. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "计算obsSpeed:" << obsSpeed << std::endl;
  2514. }
  2515. else
  2516. {
  2517. // obsDistance = lidarDistance;
  2518. obs=lidarDistance;
  2519. // obsSpeed = 0 - secSpeed;
  2520. obsSd = 0 -secSpeed;
  2521. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "毫米波无数据,计算obsSpeed:" << obsSpeed << std::endl;
  2522. }
  2523. }
  2524. else if (esrDistance>0)
  2525. {
  2526. // obsDistance = esrDistance;
  2527. // obsSpeed = ServiceCarStatus.obs_radar[esrIndex].speed_y;
  2528. obs = esrDistance;
  2529. obsSd = ServiceCarStatus.obs_radar[esrIndex].speed_y;
  2530. }
  2531. else if (lidarDistance > 0)
  2532. {
  2533. // obsDistance = lidarDistance;
  2534. // obsSpeed = iv::decition::Compute00().getObsSpeed(obsPoint, secSpeed);
  2535. obs = lidarDistance;
  2536. obsSd = iv::decition::Compute00().getObsSpeed(obsPoint, secSpeed);
  2537. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "计算obsSpeed:" << obsSpeed << std::endl;
  2538. }
  2539. else {
  2540. // obsDistance = esrDistance;
  2541. // obsSpeed = 0 - secSpeed;
  2542. obs = esrDistance;
  2543. obsSd = 0 - secSpeed;
  2544. }
  2545. if(roadNum==roadNow){
  2546. obsDistance=obs;
  2547. obsSpeed=obsSd;
  2548. }
  2549. if (obsDistance <0 && obsLostTime<4)
  2550. {
  2551. obsDistance = lastDistance;
  2552. obsLostTime++;
  2553. }
  2554. else
  2555. {
  2556. obsLostTime = 0;
  2557. lastDistance = -1;
  2558. }
  2559. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "最终得出的obsDistance:" << obsDistance << std::endl;
  2560. ServiceCarStatus.mObs = obsDistance;
  2561. if(ServiceCarStatus.mObs>100){
  2562. ServiceCarStatus.mObs =-1;
  2563. }
  2564. if (obsDistance>0)
  2565. {
  2566. lastDistance = obsDistance;
  2567. }
  2568. //lsn
  2569. if(obs<0){
  2570. obsDisVector[roadNum]=500;
  2571. }else{
  2572. obsDisVector[roadNum]=obs;
  2573. }
  2574. }
  2575. void ivdecision_brain::predictObsOnRoad(std::vector<iv::Perception::PerceptionOutput> lidar_per,std::vector<Point2D> gpsTrace,double realSpeed){
  2576. double preObsDis;
  2577. if(!lidar_per.empty()){
  2578. preObsDis=PredictObsDistance( realSpeed, gpsTrace, lidar_per);
  2579. lastPreObsDistance=preObsDis;
  2580. }else{
  2581. preObsDis=lastPreObsDistance;
  2582. }
  2583. if(preObsDis<obsDistance){
  2584. obsDistance=preObsDis;
  2585. lastDistance=obsDistance;
  2586. }
  2587. }
  2588. int ivdecision_brain::chooseAvoidRoad(iv::LidarGridPtr lidarGridPtr, GPS_INS now_gps_ins, const std::vector<GPSData> gpsMapLine,std::vector<iv::Perception::PerceptionOutput> lidar_per) {
  2589. roadPre = -1;
  2590. // if (roadNow<roadOri)
  2591. // {
  2592. // for (int i = 0; i < roadNow; i++)
  2593. // {
  2594. // gpsTraceAvoid.clear();
  2595. // // gpsTraceAvoid = getGpsTrace(now_gps_ins, gmapsR[int(abs(roadWidth * 2)*(roadOri-i))], lastGpsIndex);
  2596. // avoidX = (roadWidth)*(roadOri - i);
  2597. // gpsTraceAvoid = getGpsTraceOffset(gpsTraceOri, avoidX);
  2598. // // computeObsOnRoad(lidarGridPtr, gpsTraceAvoid, roadNow + i);
  2599. // computeObsOnRoad(lidarGridPtr, gpsTraceAvoid, i,gpsMapLine,lidar_per);
  2600. // }
  2601. // for (int i = roadOri+1; i < roadSum; i++)
  2602. // {
  2603. // gpsTraceAvoid.clear();
  2604. // // gpsTraceAvoid = getGpsTrace(now_gps_ins, gmapsL[int(abs(roadWidth * 2)*(i - roadOri))], lastGpsIndex);
  2605. // avoidX = (roadWidth)*(roadOri - i);
  2606. // gpsTraceAvoid = getGpsTraceOffset(gpsTraceOri, avoidX);
  2607. // // bsOnRoad(lidarGridPtr, gpsTraceAvoid, roadNow + i);
  2608. // computeObsOnRoad(lidarGridPtr, gpsTraceAvoid, i,gpsMapLine,lidar_per);
  2609. // }
  2610. // }
  2611. // else if (roadNow>roadOri)
  2612. // {
  2613. // for (int i = 0; i < roadOri; i++)
  2614. // {
  2615. // gpsTraceAvoid.clear();
  2616. // // gpsTraceAvoid = getGpsTrace(now_gps_ins, gmapsR[int(abs(roadWidth * 2)*(roadOri - i))], lastGpsIndex);
  2617. // avoidX = (roadWidth)*(roadOri - i);
  2618. // gpsTraceAvoid = getGpsTraceOffset(gpsTraceOri, avoidX);
  2619. // // computeObsOnRoad(lidarGridPtr, gpsTraceAvoid, roadNow + i);
  2620. // computeObsOnRoad(lidarGridPtr, gpsTraceAvoid, i,gpsMapLine,lidar_per);
  2621. // }
  2622. // for (int i = roadNow + 1; i < roadSum; i++)
  2623. // {
  2624. // gpsTraceAvoid.clear();
  2625. // // gpsTraceAvoid = getGpsTrace(now_gps_ins, gmapsL[int(abs(roadWidth * 2)*(i - roadOri))], lastGpsIndex);
  2626. // avoidX = (roadWidth)*(roadOri - i);
  2627. // gpsTraceAvoid = getGpsTraceOffset(gpsTraceOri, avoidX);
  2628. // // computeObsOnRoad(lidarGridPtr, gpsTraceAvoid, roadNow + i);
  2629. // computeObsOnRoad(lidarGridPtr, gpsTraceAvoid, i,gpsMapLine,lidar_per);
  2630. // }
  2631. // }
  2632. // else
  2633. // {
  2634. // for (int i = 0; i < roadOri; i++)
  2635. // {
  2636. // gpsTraceAvoid.clear();
  2637. // // gpsTraceAvoid = getGpsTrace(now_gps_ins, gmapsR[int(abs(roadWidth * 2)*(roadOri - i))], lastGpsIndex);
  2638. // avoidX = (roadWidth)*(roadOri - i);
  2639. // gpsTraceAvoid = getGpsTraceOffset(gpsTraceOri, avoidX);
  2640. // // computeObsOnRoad(lidarGridPtr, gpsTraceAvoid, roadNow + i);
  2641. // computeObsOnRoad(lidarGridPtr, gpsTraceNow, roadNow,gpsMapLine,lidar_per);
  2642. // }
  2643. // for (int i = roadOri + 1; i < roadSum; i++)
  2644. // {
  2645. // gpsTraceAvoid.clear();
  2646. // // gpsTraceAvoid = getGpsTrace(now_gps_ins, gmapsL[int(abs(roadWidth * 2)*(i - roadOri))], lastGpsIndex);
  2647. // avoidX = (roadWidth)*(roadOri - i);
  2648. // gpsTraceAvoid = getGpsTraceOffset(gpsTraceOri, avoidX);
  2649. // // computeObsOnRoad(lidarGridPtr, gpsTraceAvoid, roadNow + i);
  2650. // computeObsOnRoad(lidarGridPtr, gpsTraceNow, roadNow,gpsMapLine,lidar_per);
  2651. // }
  2652. // }
  2653. for (int i = 0; i < roadSum; i++)
  2654. {
  2655. gpsTraceAvoid.clear();
  2656. // gpsTraceAvoid = getGpsTrace(now_gps_ins, gmapsL[int(abs(roadWidth * 2)*(i - roadOri))], lastGpsIndex);
  2657. // avoidX = (roadWidth)*(roadOri - i);
  2658. avoidX=computeAvoidX(i,roadOri,gpsMapLine[PathPoint],ServiceCarStatus.msysparam.vehWidth);
  2659. gpsTraceAvoid = getGpsTraceOffset(gpsTraceOri, avoidX);
  2660. // computeObsOnRoad(lidarGridPtr, gpsTraceAvoid, roadNow + i);
  2661. computeObsOnRoad(lidarGridPtr, gpsTraceAvoid, i,gpsMapLine,lidar_per);
  2662. }
  2663. if (lidarGridPtr!=NULL)
  2664. {
  2665. hasCheckedAvoidLidar = true;
  2666. }
  2667. for(int i=0; i<roadSum;i++){
  2668. std::cout<<"\odsjuli====================:\n"<<i<<"chedaojuli:"<<obsDisVector[i]<<endl;
  2669. }
  2670. checkAvoidObsTimes++;
  2671. if (checkAvoidObsTimes<4 || hasCheckedAvoidLidar==false)
  2672. {
  2673. return - 1;
  2674. }
  2675. for (int i = 1; i < roadSum; i++)
  2676. {
  2677. if (roadNow + i < roadSum) {
  2678. // avoidX = (roadOri-roadNow-i)*roadWidth;
  2679. avoidX=computeAvoidX(roadNow+i,roadOri,gpsMapLine[PathPoint],ServiceCarStatus.msysparam.vehWidth);
  2680. if (checkAvoidEnable(avoidX, lidarGridPtr, roadNow+i))
  2681. {
  2682. /*if (roadNow==roadOri)
  2683. {
  2684. avoidRunDistance = obsDisVector[roadNow] + ServiceCarStatus.msysparam.vehLenth;
  2685. startAvoid_gps_ins = now_gps_ins;
  2686. } */
  2687. avoidMinDistanceVector[roadNow]= obsDisVector[roadNow] + ServiceCarStatus.msysparam.vehLenth;
  2688. startAvoidGpsInsVector[roadNow] = now_gps_ins;
  2689. roadPre = roadNow + i;
  2690. return roadPre;
  2691. }
  2692. }
  2693. if (roadNow - i >= 0)
  2694. {
  2695. // avoidX = (roadOri - roadNow+i)*roadWidth;
  2696. avoidX=computeAvoidX(roadNow-i,roadOri,gpsMapLine[PathPoint],ServiceCarStatus.msysparam.vehWidth);
  2697. if (checkAvoidEnable(avoidX, lidarGridPtr, roadNow - i))
  2698. {
  2699. /*if (roadNow == roadOri)
  2700. {
  2701. avoidRunDistance = obsDisVector[roadNow] + ServiceCarStatus.msysparam.vehLenth;
  2702. startAvoid_gps_ins = now_gps_ins;
  2703. }*/
  2704. avoidMinDistanceVector[roadNow] = obsDisVector[roadNow] + ServiceCarStatus.msysparam.vehLenth;
  2705. startAvoidGpsInsVector[roadNow] = now_gps_ins;
  2706. roadPre = roadNow - i;
  2707. return roadPre;
  2708. }
  2709. }
  2710. }
  2711. return roadPre;
  2712. }
  2713. int ivdecision_brain::chooseBackRoad(iv::LidarGridPtr lidarGridPtr, GPS_INS now_gps_ins, std::vector<GPSData> gpsMapLine,std::vector<iv::Perception::PerceptionOutput> lidar_per) {
  2714. roadPre = -1;
  2715. // computeObsOnRoad(lidarGridPtr, gpsTraceNow, roadNow,gpsMapLine,lidar_per);
  2716. // if (roadNow>=roadOri+1)
  2717. // {
  2718. // for (int i = roadOri+1; i < roadNow; i++)
  2719. // {
  2720. // gpsTraceBack.clear();
  2721. // // gpsTraceBack = getGpsTrace(now_gps_ins, gmapsL[int(abs(roadWidth * 2)*(i-roadOri))], lastGpsIndex);
  2722. // avoidX = (roadWidth)*(roadOri - i);
  2723. // gpsTraceBack = getGpsTraceOffset(gpsTraceOri, avoidX);
  2724. // computeObsOnRoad(lidarGridPtr, gpsTraceNow, roadNow,gpsMapLine,lidar_per);
  2725. // }
  2726. // }
  2727. // else if (roadNow <= roadOri - 1) {
  2728. // for (int i = roadOri - 1; i > roadNow; i--)
  2729. // {
  2730. // gpsTraceBack.clear();
  2731. // // gpsTraceBack = getGpsTrace(now_gps_ins, gmapsR[int(abs(roadWidth * 2)*(roadOri-i))], lastGpsIndex);
  2732. // avoidX = (roadWidth)*(roadOri - i);
  2733. // gpsTraceBack = getGpsTraceOffset(gpsTraceOri, avoidX);
  2734. // computeObsOnRoad(lidarGridPtr, gpsTraceNow, roadNow,gpsMapLine,lidar_per);
  2735. // }
  2736. // }
  2737. for (int i = 0; i <roadSum; i++)
  2738. {
  2739. gpsTraceBack.clear();
  2740. // gpsTraceBack = getGpsTrace(now_gps_ins, gmapsR[int(abs(roadWidth * 2)*(roadOri-i))], lastGpsIndex);
  2741. // avoidX = (roadWidth)*(roadOri - i);
  2742. avoidX=computeAvoidX(i,roadOri,gpsMapLine[PathPoint],ServiceCarStatus.msysparam.vehWidth);
  2743. gpsTraceBack = getGpsTraceOffset(gpsTraceOri, avoidX);
  2744. computeObsOnRoad(lidarGridPtr, gpsTraceBack, i,gpsMapLine,lidar_per);
  2745. }
  2746. if (lidarGridPtr != NULL)
  2747. {
  2748. hasCheckedBackLidar = true;
  2749. }
  2750. checkBackObsTimes++;
  2751. if (checkBackObsTimes<4 || hasCheckedBackLidar == false)
  2752. {
  2753. return -1;
  2754. }
  2755. //if ((GetDistance(now_gps_ins, startAvoid_gps_ins)>avoidRunDistance)&&
  2756. //(checkReturnEnable(avoidX, lidarGridPtr,roadOri)))
  2757. if ((GetDistance(now_gps_ins, startAvoidGpsInsVector[roadOri])>max(avoidMinDistanceVector[roadOri],30.0)) &&
  2758. (checkReturnEnable(avoidX, lidarGridPtr, roadOri)))
  2759. {
  2760. roadPre = roadOri;
  2761. return roadPre;
  2762. }
  2763. if (roadNow-roadOri>1)
  2764. {
  2765. for (int i = roadOri + 1;i < roadNow;i++) {
  2766. if (checkReturnEnable(avoidX, lidarGridPtr, i)&&
  2767. (GetDistance(now_gps_ins, startAvoidGpsInsVector[i])> avoidMinDistanceVector[i])&&
  2768. (GetDistance(now_gps_ins, startAvoidGpsInsVector[i])> 30.0))
  2769. {
  2770. roadPre = i;
  2771. return roadPre;
  2772. }
  2773. }
  2774. }
  2775. else if (roadNow <roadOri-1)
  2776. {
  2777. for (int i = roadOri - 1;i > roadNow;i--) {
  2778. if (checkReturnEnable(avoidX, lidarGridPtr, i)&&
  2779. (GetDistance(now_gps_ins, startAvoidGpsInsVector[i])>avoidMinDistanceVector[i])&&
  2780. (GetDistance(now_gps_ins, startAvoidGpsInsVector[i])> 30.0))
  2781. {
  2782. roadPre = i;
  2783. return roadPre;
  2784. }
  2785. }
  2786. }
  2787. return roadPre;
  2788. }
  2789. double ivdecision_brain::trumpet() {
  2790. if (trumpetFirstCount)
  2791. {
  2792. trumpetFirstCount = false;
  2793. trumpetLastTime= GetTickCount();
  2794. trumpetTimeSpan = 0.0;
  2795. }
  2796. else
  2797. {
  2798. trumpetStartTime= GetTickCount();
  2799. trumpetTimeSpan += trumpetStartTime - trumpetLastTime;
  2800. trumpetLastTime = trumpetStartTime;
  2801. }
  2802. return trumpetTimeSpan;
  2803. }
  2804. double ivdecision_brain::transferP() {
  2805. if (transferFirstCount)
  2806. {
  2807. transferFirstCount = false;
  2808. transferLastTime= GetTickCount();
  2809. transferTimeSpan = 0.0;
  2810. }
  2811. else
  2812. {
  2813. transferStartTime= GetTickCount();
  2814. transferTimeSpan += transferStartTime - transferLastTime;
  2815. transferLastTime = transferStartTime;
  2816. }
  2817. return transferTimeSpan;
  2818. }
  2819. void ivdecision_brain::handBrakePark(iv::decition::Decition decition, long duringTime, GPS_INS now_gps_ins) {
  2820. if (abs(now_gps_ins.speed)>0.1)
  2821. {
  2822. decition->accelerator = 0;
  2823. decition->brake = 20;
  2824. decition->wheel_angle = 0;
  2825. }
  2826. else
  2827. {
  2828. decition->accelerator = 0;
  2829. decition->brake = 20;
  2830. decition->wheel_angle = 0;
  2831. handPark = true;
  2832. handParkTime = duringTime;
  2833. }
  2834. }
  2835. void ivdecision_brain::getMapBeside(std::vector<iv::GPSData> navigation_data, iv::GPS_INS now_gps_ins) {
  2836. gmapsL.clear();
  2837. gmapsR.clear();
  2838. for (int i = 0; i < 31; i++)
  2839. {
  2840. std::vector<iv::GPSData> gpsMapLineBeside;
  2841. // gpsMapLineBeside = iv::decition::ComputeUnit().getBesideGpsMapLine(*ServiceCarStatus.location, navigation_data, -0.5*i);
  2842. gpsMapLineBeside = iv::decition::Compute00().getBesideGpsMapLine(now_gps_ins, navigation_data, -0.5*i);
  2843. gmapsL.push_back(gpsMapLineBeside);
  2844. }
  2845. for (int i = 0; i < 31; i++)
  2846. {
  2847. std::vector<iv::GPSData> gpsMapLineBeside;
  2848. // gpsMapLineBeside = iv::decition::ComputeUnit().getBesideGpsMapLine(*ServiceCarStatus.location, navigation_data, 0.5*i);
  2849. gpsMapLineBeside = iv::decition::Compute00().getBesideGpsMapLine(now_gps_ins, navigation_data, 0.5*i);
  2850. gmapsR.push_back(gpsMapLineBeside);
  2851. }
  2852. }
  2853. bool ivdecision_brain::checkChaoCheBack(iv::LidarGridPtr lidarGridPtr) {
  2854. if (lidarGridPtr == NULL)
  2855. {
  2856. return false;
  2857. // lidarDistance = lastlidarDistance;
  2858. }
  2859. else {
  2860. obsPoint = iv::decition::Compute00().getLidarObsPoint(gpsTraceOri, lidarGridPtr);
  2861. double lidarDistance = obsPoint.y - 2.5; //激光距离推到车头
  2862. // ODS("\n超车雷达距离:%f\n", lidarDistance);
  2863. if (lidarDistance >-20 && lidarDistance<35)
  2864. {
  2865. checkChaoCheBackCounts = 0;
  2866. return false;
  2867. }
  2868. else {
  2869. checkChaoCheBackCounts++;
  2870. }
  2871. if (checkChaoCheBackCounts>2) {
  2872. checkChaoCheBackCounts = 0;
  2873. return true;
  2874. }
  2875. }
  2876. return false;
  2877. }
  2878. void ivdecision_brain::updateGroupDate(GPS_INS now_gps_ins,float realspeed,float theta,float s){
  2879. Point2D pt = Coordinate_Transfer( now_gps_ins.gps_x, now_gps_ins.gps_y, group_ori_gps);
  2880. ServiceCarStatus.group_x_local=pt.x;
  2881. // ServiceCarStatus.group_y_local=pt.y;
  2882. ServiceCarStatus.group_y_local=s;
  2883. if(realspeed<0.36){
  2884. ServiceCarStatus.group_velx_local=0;
  2885. ServiceCarStatus.group_vely_local=0;
  2886. }else{
  2887. ServiceCarStatus.group_velx_local=realspeed*sin(theta)/3.6;
  2888. ServiceCarStatus.group_vely_local=realspeed*cos(theta)/3.6;
  2889. }
  2890. ServiceCarStatus.group_pathpoint=PathPoint;
  2891. }
  2892. float ivdecision_brain::ComputeTrafficLightSpeed(int traffic_light_color, int traffic_light_time, const std::vector<GPSData> gpsMapLine,int traffic_light_pathpoint,
  2893. int pathpoint,float secSpeed,float dSpeed){
  2894. float traffic_speed=200;
  2895. float traffic_dis=0;
  2896. float passTime;
  2897. float passSpeed;
  2898. bool passEnable=false;
  2899. if(abs(secSpeed)<0.1){
  2900. secSpeed=0;
  2901. }
  2902. if(pathpoint <= traffic_light_pathpoint){
  2903. for(int i=pathpoint;i<traffic_light_pathpoint;i++){
  2904. traffic_dis +=GetDistance(*gpsMapLine[i],*gpsMapLine[i+1]);
  2905. }
  2906. }else{
  2907. for(int i=pathpoint;i<gpsMapLine.size()-1;i++){
  2908. traffic_dis +=GetDistance(*gpsMapLine[i],*gpsMapLine[i+1]);
  2909. }
  2910. for(int i=0;i<traffic_light_pathpoint;i++){
  2911. traffic_dis+=GetDistance(*gpsMapLine[i],*gpsMapLine[i+1]);
  2912. }
  2913. }
  2914. // if(traffic_light_color != 0)
  2915. // {
  2916. // int a = 3;
  2917. // }
  2918. if(traffic_light_color==0 && traffic_dis<10){
  2919. traffic_speed=0;
  2920. }
  2921. // else //20200108
  2922. // {
  2923. // traffic_speed=10;
  2924. // }
  2925. return traffic_speed;
  2926. passSpeed = min((float)(dSpeed/3.6),secSpeed);
  2927. passTime = traffic_dis/(dSpeed/3.6);
  2928. switch(traffic_light_color){
  2929. case 0:
  2930. if(passTime>traffic_light_time+1 && traffic_dis>10){
  2931. passEnable=true;
  2932. }else{
  2933. passEnable=false;
  2934. }
  2935. break;
  2936. case 1:
  2937. if(passTime<traffic_light_time-1 && traffic_dis<10){
  2938. passEnable=true;
  2939. }else{
  2940. passEnable = false;
  2941. }
  2942. break;
  2943. case 2:
  2944. if(passTime<traffic_light_time){
  2945. passEnable= true;
  2946. }else{
  2947. passEnable=false;
  2948. }
  2949. break;
  2950. default:
  2951. break;
  2952. }
  2953. if(!passEnable){
  2954. if(traffic_dis<5){
  2955. traffic_speed=0;
  2956. }else if(traffic_dis<10){
  2957. traffic_speed=5;
  2958. }else if(traffic_dis<20){
  2959. traffic_speed=15;
  2960. }else if(traffic_dis<30){
  2961. traffic_speed=25;
  2962. }else if(traffic_dis<50){
  2963. traffic_speed=30;
  2964. }
  2965. }
  2966. return traffic_speed;
  2967. }
  2968. void ivdecision_brain::computeObsOnRoadByFrenet(iv::LidarGridPtr lidarGridPtr, const std::vector<Point2D>& gpsTrace, double & obs, const std::vector<iv::GPSData>& gpsMap,int pathpoint,GPS_INS nowGps)
  2969. {
  2970. // Point2D obsCombinePoint = Point2D(-1,-1);
  2971. iv::decition::FrenetPoint car_now_frenet_point = iv::decition::FrenetPlanner::getFrenetfromXY(0,0,gpsTrace,gpsMap,pathpoint,nowGps);
  2972. double obsSd;
  2973. if (lidarGridPtr == NULL)
  2974. {
  2975. lidarDistance = lastLidarDis;
  2976. // lidarDistance = lastlidarDistance;
  2977. }
  2978. else {
  2979. obsPoint = iv::decition::Compute00().getLidarObsPoint(gpsTrace, lidarGridPtr);
  2980. // lidarDistance = obsPoint.y-2.5; //激光距离推到车头
  2981. iv::decition::FrenetPoint lidarFPointTmp = iv::decition::FrenetPlanner::getFrenetfromXY(this->obsPoint.x,this->obsPoint.y,gpsTrace,gpsMap,pathpoint,nowGps);
  2982. lidarDistance = lidarFPointTmp.s - car_now_frenet_point.s - 2.5;
  2983. // lidarDistance=-1;
  2984. if (lidarDistance<0)
  2985. {
  2986. lidarDistance = -1;
  2987. }
  2988. lastLidarDis = lidarDistance;
  2989. }
  2990. FrenetPoint esr_obs_frenet_point;
  2991. getEsrObsDistanceByFrenet(gpsTrace, car_now_frenet_point,esr_obs_frenet_point,gpsMap,pathpoint,nowGps);
  2992. if(lidarDistance<0){
  2993. lidarDistance=500;
  2994. }
  2995. if(esrDistance<0){
  2996. esrDistance=500;
  2997. }
  2998. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "激光雷达距离:" << lidarDistance << std::endl;
  2999. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "毫米波距离:" << esrDistance << std::endl;
  3000. myesrDistance = esrDistance;
  3001. if(lidarDistance==500){
  3002. lidarDistance=-1;
  3003. }
  3004. if(esrDistance==500){
  3005. esrDistance=-1;
  3006. }
  3007. ServiceCarStatus.mRadarObs = esrDistance;
  3008. ServiceCarStatus.mLidarObs = lidarDistance;
  3009. // //zhuanwan pingbi haomibo
  3010. // if(gpsTraceNow[0].v1==4||gpsTraceNow[0].v1==5){
  3011. // esrDistance=-1;
  3012. // }
  3013. if (esrDistance>0 && lidarDistance > 0)
  3014. {
  3015. if (lidarDistance >= esrDistance)
  3016. {
  3017. obs = esrDistance;
  3018. // obsSd=ServiceCarStatus.obs_radar[esrIndex].speed_y;
  3019. obsSd = obsSpeed;
  3020. //障碍物信息使用毫米波采集的。其位置坐标加上偏移量,转换成相对于惯导的位置,即转换成车辆坐标系下的位置坐标。
  3021. // obsCombinePoint = Point2D(ServiceCarStatus.obs_radar[esrIndex].nomal_x+Esr_Offset,ServiceCarStatus.obs_radar[esrIndex].nomal_y+Esr_Y_Offset);
  3022. }
  3023. else if (!ServiceCarStatus.obs_radar.empty())
  3024. {
  3025. obs = lidarDistance;
  3026. // obsCombinePoint = obsPoint;
  3027. // obsSd = iv::decition::Compute00().getObsSpeedByFrenet(obsPoint, secSpeed,gpsTrace);
  3028. obsSd = iv::decition::Compute00().getObsSpeedByFrenet(obsPoint, secSpeed,gpsTrace,gpsMap,pathpoint,nowGps);
  3029. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "计算obsSpeed:" << obsSpeed << std::endl;
  3030. }
  3031. else
  3032. {
  3033. obs=lidarDistance;
  3034. // obsCombinePoint = obsPoint;
  3035. obsSd = 0 -secSpeed*cos(car_now_frenet_point.tangent_Ang-M_PI/2);
  3036. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "毫米波无数据,计算obsSpeed:" << obsSpeed << std::endl;
  3037. }
  3038. }
  3039. else if (esrDistance>0)
  3040. {
  3041. obs = esrDistance;
  3042. // obsSd = ServiceCarStatus.obs_radar[esrIndex].speed_y;
  3043. obsSd = obsSpeed;
  3044. //障碍物信息使用毫米波采集的。其位置坐标加上偏移量,转换成相对于惯导的位置,即转换成车辆坐标系下的位置坐标。
  3045. // obsCombinePoint = Point2D(ServiceCarStatus.obs_radar[esrIndex].nomal_x+Esr_Offset,ServiceCarStatus.obs_radar[esrIndex].nomal_y+Esr_Y_Offset);
  3046. }
  3047. else if (lidarDistance > 0)
  3048. {
  3049. obs = lidarDistance;
  3050. // obsCombinePoint = obsPoint;
  3051. obsSd = iv::decition::Compute00().getObsSpeedByFrenet(obsPoint, secSpeed,gpsTrace,gpsMap,pathpoint,nowGps);
  3052. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "计算obsSpeed:" << obsSpeed << std::endl;
  3053. }
  3054. else {
  3055. obs = esrDistance;
  3056. // obsCombinePoint = Point2D(ServiceCarStatus.obs_radar[esrIndex].nomal_x+Esr_Offset,ServiceCarStatus.obs_radar[esrIndex].nomal_y+Esr_Y_Offset);
  3057. obsSd = 0 - secSpeed*cos(car_now_frenet_point.tangent_Ang-M_PI/2);
  3058. }
  3059. obsDistance=obs;
  3060. obsSpeed=obsSd;
  3061. std::cout <<ServiceCarStatus.mRunTime.elapsed()<<"ms:"<< "最终得出的obsDistance:" << obsDistance << std::endl;
  3062. ServiceCarStatus.mObs = obsDistance;
  3063. if(ServiceCarStatus.mObs>100){
  3064. ServiceCarStatus.mObs =-1;
  3065. }
  3066. if (obsDistance>0)
  3067. {
  3068. lastDistance = obsDistance;
  3069. }
  3070. if(obs<0){
  3071. obsDistance=500;
  3072. }else{
  3073. obsDistance=obs;
  3074. }
  3075. }
  3076. void ivdecision_brain::getRearEsrObsDistance(std::vector<Point2D> gpsTrace, int roadNum) {
  3077. esrIndex = iv::decition::Compute00().getRearEsrIndex(gpsTrace, roadNum,xiuzhengCs);
  3078. if (esrIndex != -1)
  3079. {
  3080. esrDistance = ServiceCarStatus.obs_rear_radar[esrIndex].nomal_y;
  3081. obsSpeed = ServiceCarStatus.obs_rear_radar[esrIndex].speed_y;
  3082. }
  3083. else {
  3084. esrDistance = -1;
  3085. }
  3086. }
  3087. void ivdecision_brain::getEsrObsDistanceByFrenet(const std::vector<Point2D>& gpsTrace, const FrenetPoint car_now_frenet_point, FrenetPoint &esrObs_F_Point, const std::vector<iv::GPSData>& gpsMap,int pathpoint,GPS_INS nowGps) {
  3088. esrIndex = iv::decition::Compute00().getEsrIndexByFrenet(gpsTrace,esrObs_F_Point,gpsMap,pathpoint,nowGps,xiuzhengCs);
  3089. if (esrIndex != -1)
  3090. {
  3091. //障碍物的距离,是障碍物和车辆沿道路上的距离,即s。并不直接是它的x坐标或y坐标或两点直线坐标。
  3092. //严格来说应是 esrDistance=障碍物的s - 车辆的s - Esr_Y_Offset,但这是根据车辆位置实时搜索路径,故车辆的s极其小。
  3093. esrDistance = esrObs_F_Point.s - car_now_frenet_point.s - Esr_Y_Offset; //-Esr_Y_Offset是把距离推到车头,换算frenet坐标时,把它加上了的。故需减去。
  3094. double speedx=ServiceCarStatus.obs_radar[esrIndex].speed_x; //障碍物相对于车辆x轴的速度
  3095. double speedy=ServiceCarStatus.obs_radar[esrIndex].speed_y; //障碍物相对于车辆y轴的速度
  3096. double speed_combine = sqrt(speedx*speedx+speedy*speedy); //将x、y轴两个方向的速度求矢量和
  3097. //障碍物的速度方向与道路方向的夹角。用于将速度分解到s方向和d方向。
  3098. //所谓道路方向是指,道路上离障碍物的最近的点沿道路弧线的切线方向。
  3099. double Etheta = esrObs_F_Point.tangent_Ang - atan2(speedy,speedx);
  3100. obsSpeed = speed_combine*cos(Etheta); //由speed_combine分解的s轴方向上的速度
  3101. }
  3102. else {
  3103. esrDistance = -1;
  3104. }
  3105. }
  3106. void ivdecision_brain::getV2XTrafficPositionVector(const std::vector<GPSData> gpsMapLine){
  3107. v2xTrafficVector.clear();
  3108. for (int var = 0; var < gpsMapLine.size(); var++) {
  3109. if(gpsMapLine[var]->roadMode==6 || gpsMapLine[var]->mode2==1000001){
  3110. v2xTrafficVector.push_back(var);
  3111. }
  3112. }
  3113. }
  3114. float ivdecision_brain::ComputeV2XTrafficLightSpeed(iv::TrafficLight trafficLight, const std::vector<GPSData> gpsMapLine,std::vector<int> v2xTrafficVector,
  3115. int pathpoint,float secSpeed,float dSpeed, bool circleMode){
  3116. float trafficSpeed=200;
  3117. int nearTraffixPoint=-1;
  3118. float nearTrafficDis=0;
  3119. int traffic_color=0;
  3120. int traffic_time=0;
  3121. bool passThrough=false;
  3122. float dSecSpeed=dSpeed/3.6;
  3123. if(v2xTrafficVector.empty()){
  3124. return trafficSpeed;
  3125. }
  3126. if(!circleMode){
  3127. if(pathpoint>v2xTrafficVector.back()){
  3128. return trafficSpeed;
  3129. }else {
  3130. for(int i=0; i< v2xTrafficVector.size();i++){
  3131. if (pathpoint<= v2xTrafficVector[i]){
  3132. nearTraffixPoint=v2xTrafficVector[i];
  3133. break;
  3134. }
  3135. }
  3136. }
  3137. }else if(circleMode){
  3138. if(pathpoint>v2xTrafficVector.back()){
  3139. nearTraffixPoint=v2xTrafficVector[0];
  3140. }else {
  3141. for(int i=0; i< v2xTrafficVector.size();i++){
  3142. if (pathpoint<= v2xTrafficVector[i]){
  3143. nearTraffixPoint=v2xTrafficVector[i];
  3144. break;
  3145. }
  3146. }
  3147. }
  3148. }
  3149. if(nearTraffixPoint!=-1){
  3150. for(int i=pathpoint;i<nearTraffixPoint;i++){
  3151. nearTrafficDis +=GetDistance(*gpsMapLine[i],*gpsMapLine[i+1]);
  3152. }
  3153. }
  3154. if(nearTrafficDis>50){
  3155. return trafficSpeed;
  3156. }
  3157. int roadMode = gpsMapLine[pathpoint]->roadMode;
  3158. if(roadMode==14 || roadMode==16){
  3159. traffic_color=trafficLight.leftColor;
  3160. traffic_time=trafficLight.leftTime;
  3161. }else if(roadMode==15 ||roadMode==17){
  3162. traffic_color=trafficLight.rightColor;
  3163. traffic_time=trafficLight.rightTime;
  3164. }else {
  3165. traffic_color=trafficLight.straightColor;
  3166. traffic_time=trafficLight.straightTime;
  3167. }
  3168. passThrough=computeTrafficPass(nearTrafficDis,traffic_color,traffic_time,secSpeed,dSecSpeed);
  3169. if(passThrough){
  3170. return trafficSpeed;
  3171. }else{
  3172. trafficSpeed=computeTrafficSpeedLimt(nearTrafficDis);
  3173. if(nearTrafficDis<6){
  3174. float decelerate =0-( secSpeed*secSpeed*0.5/nearTrafficDis);
  3175. minDecelerate=min(minDecelerate,decelerate);
  3176. }
  3177. return trafficSpeed;
  3178. }
  3179. return trafficSpeed;
  3180. }
  3181. bool ivdecision_brain::computeTrafficPass(float trafficDis,int trafficColor,float trafficTime,float realSecSpeed,float dSecSpeed){
  3182. float passTime=0;
  3183. if (trafficColor==2 || trafficColor==3){
  3184. return false;
  3185. }else if(trafficColor==0){
  3186. return true;
  3187. }else{
  3188. passTime=trafficDis/dSecSpeed;
  3189. if(passTime+1< trafficTime){
  3190. return true;
  3191. }else{
  3192. return false;
  3193. }
  3194. }
  3195. }
  3196. float ivdecision_brain::computeTrafficSpeedLimt(float trafficDis){
  3197. float limit=200;
  3198. if(trafficDis<10){
  3199. limit = 0;
  3200. }else if(trafficDis<15){
  3201. limit = 5;
  3202. }else if(trafficDis<20){
  3203. limit=10;
  3204. }else if(trafficDis<30){
  3205. limit=15;
  3206. }
  3207. return limit;
  3208. }
  3209. bool ivdecision_brain::adjuseultra(){
  3210. bool front=false,back=false,left=false,right=false;
  3211. for(int i=1;i<=13;i++)
  3212. {
  3213. if((i==2)||(i==3)||(i==4)||(i==5)) //front
  3214. {
  3215. if(ServiceCarStatus.ultraDistance[i]<100)
  3216. {
  3217. front=true;
  3218. }
  3219. }else if((i==1)||(i==12)||(i==6)||(i==7)) //left,right
  3220. {
  3221. if(ServiceCarStatus.ultraDistance[i]<30)
  3222. {
  3223. left=true;
  3224. }
  3225. }else if((i==8)||(i==9)||(i==10)||(i==11)) //back
  3226. {
  3227. if(ServiceCarStatus.ultraDistance[i]<10)
  3228. {
  3229. back=true;
  3230. }
  3231. }
  3232. }
  3233. if(front||left||back)
  3234. return true;
  3235. else
  3236. return false;
  3237. }
  3238. void ivdecision_brain::transferGpsMode2( const std::vector<GPSData> gpsMapLine){
  3239. if( gpsMapLine[PathPoint]->mode2==3000){
  3240. if(obsDistance>5){
  3241. obsDistance=200;
  3242. }
  3243. dSpeed=min(dSpeed,5.0);
  3244. }
  3245. }
  3246. float ivdecision_brain::computeAvoidX(int roadAim,int roadOri,GPSData gps,float vehWidth){
  3247. if(roadAim==roadOri){
  3248. return 0;
  3249. }
  3250. float x=0;
  3251. float veh_to_roadSide=(gps->mfRoadWidth- ServiceCarStatus.msysparam.vehWidth)*0.5;
  3252. float roadSide_to_roadSide=ServiceCarStatus.msysparam.vehWidth;
  3253. if(!ServiceCarStatus.inRoadAvoid){
  3254. x= (roadOri-roadAim)*gps->mfRoadWidth;
  3255. }else{
  3256. int num=roadOri-roadAim;
  3257. switch (abs(num%3)) {
  3258. case 0:
  3259. x=(num/3)*gps->mfRoadWidth;
  3260. break;
  3261. case 1:
  3262. if(num>0){
  3263. x=(num/3)*gps->mfRoadWidth +veh_to_roadSide;
  3264. }else{
  3265. x=(num/3)*gps->mfRoadWidth -veh_to_roadSide;
  3266. }
  3267. break;
  3268. case 2:
  3269. if(num>0){
  3270. x=(num/3)*gps->mfRoadWidth +veh_to_roadSide+roadSide_to_roadSide;
  3271. }else{
  3272. x=(num/3)*gps->mfRoadWidth -veh_to_roadSide-roadSide_to_roadSide;
  3273. }
  3274. break;
  3275. default:
  3276. break;
  3277. }
  3278. }
  3279. return x;
  3280. }
  3281. }