ivdecision_brain.cpp 129 KB

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