123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355 |
- #include <adc_tools/compute_00.h>
- //#include <decision/decide_gps_00.h>
- #include <adc_tools/gps_distance.h>
- #include <decition_type.h>
- #include <adc_tools/transfer.h>
- #include <constants.h>
- #include <math.h>
- #include <iostream>
- #include <fstream>
- //#include <control/can.h>
- #include "common/car_status.h"
- #include "adc_planner/frenet_planner.h"
- using namespace std;
- extern bool handPark;
- extern long handParkTime;
- extern bool rapidStop;
- extern int gpsMissCount;
- extern bool changeRoad;
- extern double avoidX;
- extern bool parkBesideRoad;
- extern double steerSpeed;
- extern bool transferPieriod;
- extern bool transferPieriod2;
- extern double traceDevi;
- #define PI (3.1415926535897932384626433832795)
- iv::decition::Compute00::Compute00() {
- }
- iv::decition::Compute00::~Compute00() {
- }
- double iv::decition::Compute00::angleLimit = 700;
- double iv::decition::Compute00::lastEA = 0;
- double iv::decition::Compute00::lastEP = 0;
- double iv::decition::Compute00::decision_Angle = 0;
- double iv::decition::Compute00::lastAng = 0;
- int iv::decition::Compute00::lastEsrID = -1;
- int iv::decition::Compute00::lastEsrCount = 0;
- int iv::decition::Compute00::lastEsrIDAvoid = -1;
- int iv::decition::Compute00::lastEsrCountAvoid = 0;
- iv::GPS_INS iv::decition::Compute00::nearTpoint;
- iv::GPS_INS iv::decition::Compute00::farTpoint;
- double iv::decition::Compute00::bocheAngle;
- iv::GPS_INS iv::decition::Compute00::dTpoint0;
- iv::GPS_INS iv::decition::Compute00::dTpoint1;
- iv::GPS_INS iv::decition::Compute00::dTpoint2;
- iv::GPS_INS iv::decition::Compute00::dTpoint3;
- double iv::decition::Compute00::dBocheAngle;
- int iv::decition::Compute00::nParkType;
- std::vector<int> lastEsrIdVector;
- std::vector<int> lastEsrCountVector;
- int iv::decition::Compute00::getDesiredSpeed(std::vector<GPSData> gpsMap)
- {
- int startIndex = 0; // startIndex = 0 则每一次都是遍历整条地图路线
- int endIndex = gpsMap.size() - 1;
- static double FrontTotalFive=0,FrontAveFive=0,BackAveFive=0,BackTotalFive=0;
- static int FrontCount=0,BackCount=0;
- static int CurrentIndex=0,MarkingIndex=0,MarkingCount=0;
- int MarkedIndex=0,CurveContinue=0;
- for (int j = startIndex; j < endIndex; j++)
- {
- int i = (j + gpsMap.size()) % gpsMap.size();
- if((*gpsMap[i]).roadMode!=6)
- (*gpsMap[i]).roadMode=5;
- }
- for (int j = startIndex; j < (endIndex-40); j+=40)
- {
- int i = (j + gpsMap.size()) % gpsMap.size();
- for(int front_k=i;front_k<i+20;front_k++)
- {
- if(fabs(((*gpsMap[front_k]).ins_heading_angle)-((*gpsMap[i]).ins_heading_angle))<10)
- {
- FrontTotalFive+=(*gpsMap[front_k]).ins_heading_angle;
- FrontCount++;
- }
- }
- i+=20;
- FrontAveFive=FrontTotalFive/FrontCount;
- FrontTotalFive=0;
- FrontCount=0;
- for(int back_k=i;back_k<i+20;back_k++)
- {
- if(fabs((*gpsMap[back_k]).ins_heading_angle-(*gpsMap[i]).ins_heading_angle)<10)
- {
- BackTotalFive+=(*gpsMap[back_k]).ins_heading_angle;
- BackCount++;
- }
- }
- i+=20;
- CurrentIndex=i-1;
- BackAveFive=BackTotalFive/BackCount;
- BackTotalFive=0;
- BackCount=0;
- if(fabs(FrontAveFive-BackAveFive)<50)
- {
- if(fabs(FrontAveFive-BackAveFive)>4)
- {
- CurveContinue+=1;
- if(CurveContinue>=1)
- {
- MarkingCount=0;
- for(MarkingIndex=CurrentIndex;MarkingIndex>=MarkedIndex;MarkingIndex--)
- {
- if((*gpsMap[MarkingIndex]).roadMode!=6)
- {
- if(MarkingCount<150)
- {
- if((BackAveFive-FrontAveFive)<=3.5)
- {
- (*gpsMap[MarkingIndex]).roadMode=14; //弯道,2米,14
- }
- else if((BackAveFive-FrontAveFive)>3.5)
- {
- (*gpsMap[MarkingIndex]).roadMode=15;
- }
- } //else if((MarkingCount>=100)&&(MarkingCount<150)){(*gpsMap[MarkingIndex]).roadMode=18; //超低速,10米,1}
- else if((MarkingCount>=150)&&(MarkingCount<320))
- {
- (*gpsMap[MarkingIndex]).roadMode=5; //低速,20米,5
- }
- else if((MarkingCount>=320)&&(MarkingCount<620))
- {
- (*gpsMap[MarkingIndex]).roadMode=0; //常速,60米
- }
- else if(MarkingCount>=620)
- {
- (*gpsMap[MarkingIndex]).roadMode=11; //高速/疯狂加速,大于60米
- }
- }
- MarkingCount++;
- }
- MarkedIndex=CurrentIndex;
- }
- }
- else if(fabs(FrontAveFive-BackAveFive)<=4)
- {
- CurveContinue=0;
- }
- }
- FrontAveFive=0;
- BackAveFive=0;
- }
- if(MarkedIndex<endIndex)
- {
- MarkingCount=0;
- for(MarkingIndex=endIndex;MarkingIndex>=MarkedIndex;MarkingIndex--)
- {
- if((*gpsMap[MarkingIndex]).roadMode!=6)
- {
- if(MarkingCount<100)
- {
- if((BackAveFive-FrontAveFive)<3)
- {
- (*gpsMap[MarkingIndex]).roadMode=14; //弯道,2米,14
- }
- else if((BackAveFive-FrontAveFive)>3)
- {
- (*gpsMap[MarkingIndex]).roadMode=15;
- }
- }
- else if((MarkingCount>=100)&&(MarkingCount<150))
- {
- (*gpsMap[MarkingIndex]).roadMode=18; //超低速,10米
- }
- else if((MarkingCount>=150)&&(MarkingCount<320))
- {
- (*gpsMap[MarkingIndex]).roadMode=5; //低速,30米
- }
- else if((MarkingCount>=320)&&(MarkingCount<620))
- {
- (*gpsMap[MarkingIndex]).roadMode=0; //常速,60米
- }
- else if(MarkingCount>=620)
- {
- (*gpsMap[MarkingIndex]).roadMode=11; //高速/疯狂加速,大于60米
- }
- }
- MarkingCount++;
- }
- }
- return 1;
- }
- //首次找点
- int iv::decition::Compute00::getFirstNearestPointIndex(GPS_INS rp, std::vector<GPSData> gpsMap, int lastIndex, double mindis, double maxAngle)
- {
- int index = -1;
- // DecideGps00().minDis = iv::MaxValue;
- float minDis = 10;
- double maxAng = iv::MaxValue;
- int startIndex = 0; // startIndex = 0 则每一次都是遍历整条地图路线
- int endIndex = gpsMap.size() - 1;
- for (int j = startIndex; j < endIndex; j++)
- {
- int i = (j + gpsMap.size()) % gpsMap.size();
- double tmpdis = GetDistance(rp, (*gpsMap[i]));
- if (tmpdis < minDis && (abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle) < 80
- || abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle - 360) < 80
- || abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle + 360) < 80)
- )
- {
- index = i;
- minDis = tmpdis;
- maxAng = min(abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle), abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle - 360));
- maxAng = min(maxAng, abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle + 360));
- }
- }
- // DecideGps00().maxAngle=maxAng;
- // DecideGps00().minDis=minDis;
- return index;
- }
- //search pathpoint
- int iv::decition::Compute00::getNearestPointIndex(GPS_INS rp, const std::vector<GPSData> gpsMap, int lastIndex, double mindis, double maxAngle)
- {
- int index = -1;
- float minDis = 10;
- double maxAng = iv::MaxValue;
- int map_size=gpsMap.size();
- int preDistance=max(100,(int)(rp.speed*10));
- preDistance=min(500,preDistance);
- int startIndex = max((int)(lastIndex - 100),(int)(lastIndex-map_size)); // startIndex = 0 则每一次都是遍历整条地图路线
- int endIndex = min((int)(lastIndex + preDistance ),(int)(lastIndex+map_size));
- for (int j = startIndex; j < endIndex; j++)
- {
- int i = (j + map_size) % map_size;
- double tmpdis = GetDistance(rp, (*gpsMap[i]));
- if (tmpdis < minDis && (abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle) < 80
- || abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle - 360) < 80
- || abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle + 360) < 80)
- )
- {
- index = i;
- minDis = tmpdis;
- maxAng = min(abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle), abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle - 360));
- maxAng = min(maxAngle, abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle + 360));
- }
- }
- // DecideGps00().maxAngle=maxAng;
- // DecideGps00().minDis=minDis;
- return index;
- }
- double iv::decition::Compute00::getAveDef(std::vector<Point2D> farTrace)
- {
- double sum_x = 0;
- double sum_y = 0;
- for (int i = 0; i < min(5, (int)farTrace.size()); i++)
- {
- sum_x += farTrace[i].x;
- sum_y += abs(farTrace[i].y);
- }
- double average_y = sum_y / min(5, (int)farTrace.size());
- double average_x = sum_x / min(5, (int)farTrace.size());
- return atan(average_x / average_y) / PI * 180;
- }
- double iv::decition::Compute00::getAvoidAveDef(std::vector<Point2D> farTrace, double avoidX)
- {
- double sum_x = 0;
- double sum_y = 0;
- for (int i = 0; i < min(5, (int)farTrace.size()); i++)
- {
- sum_x += farTrace[i].x;
- sum_y += abs(farTrace[i].y);
- }
- double average_y = sum_y / min(5, (int)farTrace.size());
- double average_x = sum_x / min(5, (int)farTrace.size());
- return atan(average_x + avoidX / average_y) / PI * 180;
- }
- double iv::decition::Compute00::getDecideAngle(std::vector<Point2D> gpsTrace, double realSpeed) {
- double ang = 0;
- double EPos = 0, EAng = 0;
- // double KEang = 14, KEPos = 10, DEang = 3, DEPos = 1; // double KEang = 14, KEPos = 10, DEang = 10, DEPos = 10;
- double KEang = 14, KEPos = 10, DEang = 0, DEPos = 0;
- if(transferPieriod&& !transferPieriod2){
- DEang = 200;
- DEPos = 150;
- }
- // double PreviewDistance = max(6.0, realSpeed / 3.6 * 1.8);//预瞄距离
- double PreviewDistance;//预瞄距离
- realSpeed > 40 ? PreviewDistance = max(6.0, realSpeed *0.6) : PreviewDistance = max(6.0, realSpeed *0.5);
- if(changeRoad ||transferPieriod){
- PreviewDistance=PreviewDistance+avoidX;
- }
- if(realSpeed <15){
- PreviewDistance = max(4.0, realSpeed *0.4) ;
- }
- if (gpsTrace[0].v1 == 1)
- {
- KEang = 14; KEPos = 10;
- }
- else if (gpsTrace[0].v1 == 2 || gpsTrace[0].v1 == 3)
- {
- KEang = 14; KEPos = 10;
- }
- else if (gpsTrace[0].v1 == 4 || gpsTrace[0].v1 == 5)
- {
- KEang = 14; KEPos = 10;
- }
- else if (gpsTrace[0].v1 == 7 && (gpsTrace[0].v2 == 23 || gpsTrace[0].v2 == 24))
- {
- KEang = 18; KEPos = 50; PreviewDistance = 3;
- }
- else if (gpsTrace[0].v1 == 7)
- {
- KEang = 20; KEPos = 50; PreviewDistance = 4;
- }
- if (realSpeed > 40) KEang = 10; KEPos = 8;
- if (realSpeed > 50) KEang = 5;
- double sumdis = 0;
- int gpsIndex = 0;
- std::vector<Point2D> farTrace;
- for (int i = 1; i < gpsTrace.size() - 1; i++)
- {
- sumdis += GetDistance(gpsTrace[i - 1], gpsTrace[i]);
- if (sumdis > PreviewDistance)
- {
- gpsIndex = i;
- break;
- }
- }
- EPos = gpsTrace[gpsIndex].x;
- for (unsigned int i = max(0, gpsIndex - 3); i < min((size_t)(gpsIndex + 3), gpsTrace.size()); i++) {
- farTrace.push_back(gpsTrace[gpsIndex]);
- }
- if (farTrace.size() == 0) {
- EAng = 0;
- }
- else {
- EAng = getAveDef(farTrace);
- }
- ang = KEang * EAng + KEPos * EPos + DEang * (EAng - lastEA) + DEPos * (EPos - lastEP);
- lastEA = EAng;
- lastEP = EPos;
- if (ang > angleLimit) {
- ang = angleLimit;
- }
- else if (ang < -angleLimit) {
- ang = -angleLimit;
- }
- if (lastAng != iv::MaxValue) {
- ang = 0.2 * lastAng + 0.8 * ang;
- //ODS("lastAng:%d\n", lastAng);
- }
- lastAng = ang;
- return ang;
- }
- int iv::decition::Compute00::getSpeedPointIndex(std::vector<Point2D> gpsTrace, double realSpeed)
- {
- int index = 1;
- double sumdis = 0;
- while (index < gpsTrace.size() && sumdis < realSpeed)
- sumdis += GetDistance(gpsTrace[index - 1], gpsTrace[index++]);
- if (index == gpsTrace.size())
- return index - 1;
- if (abs(sumdis - realSpeed) > abs(sumdis - GetDistance(gpsTrace[index - 1], gpsTrace[index]) - realSpeed))
- index--;
- return index;
- }
- iv::Point2D iv::decition::Compute00::getLidarObsPoint(std::vector<Point2D> gpsTrace, iv::LidarGridPtr lidarGridPtr) {
- iv::Point2D obsPoint(-1, -1);
- vector<Point2D> gpsTraceLeft;
- vector<Point2D> gpsTraceRight;
- float xiuzheng=0;
- if(!ServiceCarStatus.useMobileEye){
- xiuzheng=0-ServiceCarStatus.msysparam.lidarGpsXiuzheng;
- }
- ServiceCarStatus.obsTraceLeft.clear();
- ServiceCarStatus.obsTraceRight.clear();
- for (int j = 0; j < gpsTrace.size(); j++)
- {
- double sumx1 = 0, sumy1 = 0, count1 = 0;
- double sumx2 = 0, sumy2 = 0, count2 = 0;
- for (int k = max(0, j - 4); k <= j; k++)
- {
- count1 = count1 + 1;
- sumx1 += gpsTrace[k].x;
- sumy1 += gpsTrace[k].y;
- }
- for (unsigned int k = j; k <= min(gpsTrace.size() - 1, (size_t)(j + 4)); k++)
- {
- count2 = count2 + 1;
- sumx2 += gpsTrace[k].x;
- sumy2 += gpsTrace[k].y;
- }
- sumx1 /= count1; sumy1 /= count1;
- sumx2 /= count2; sumy2 /= count2;
- double anglevalue = atan2(sumy2 - sumy1, sumx2 - sumx1);
- double carFrontx = gpsTrace[j].x;// -Form1.CarRear * Math.Cos(anglevalue);
- double carFronty = gpsTrace[j].y;// -Form1.CarRear * Math.Sin(anglevalue);
- Point2D ptLeft(carFrontx + ServiceCarStatus.msysparam.vehWidth / 2 * cos(anglevalue + PI / 2),
- carFronty + ServiceCarStatus.msysparam.vehWidth / 2 * sin(anglevalue + PI / 2));
- Point2D ptRight(carFrontx + ServiceCarStatus.msysparam.vehWidth / 2 * cos(anglevalue - PI / 2),
- carFronty + ServiceCarStatus.msysparam.vehWidth / 2 * sin(anglevalue - PI / 2));
- gpsTraceLeft.push_back(ptLeft);
- gpsTraceRight.push_back(ptRight);
- TracePoint obsptleft(ptLeft.x,ptLeft.y);
- ServiceCarStatus.obsTraceLeft.push_back(obsptleft);
- TracePoint obsptright(ptRight.x,ptRight.y);
- ServiceCarStatus.obsTraceLeft.push_back(obsptright);
- }
- bool isRemove = false;
- for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
- {
- if (!isRemove && gpsTrace[j].y>ServiceCarStatus.msysparam.lidarGpsXiuzheng)
- {
- int count = 0;
- for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
- // int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx; //+(ptx / abs(ptx))) / 2左右多出一半的车宽(1米)
- // int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
- int dx = (ptx + gridwide*(double)centerx)/gridwide;
- int dy = (pty + gridwide*(double)centery+xiuzheng)/gridwide;
- if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
- {
- // if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
- if (lidarGridPtr[dx * (iv::gry) + dy].ob != 0)
- {
- count++; obsPoint.x = ptx; obsPoint.y = pty;
- }
- }
- }
- j++;
- for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
- // int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx;
- // int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
- int dx = (ptx + gridwide*(double)centerx)/gridwide;
- int dy = (pty + gridwide*(double)centery+xiuzheng)/gridwide;
- if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
- {
- // if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
- if (lidarGridPtr[dx * (iv::gry) + dy].ob != 0)
- {
- count++; obsPoint.x = ptx; obsPoint.y = pty;
- }
- }
- }
- if (count >= 2)
- {
- obsPoint.x = gpsTrace[j].x;
- obsPoint.y = gpsTrace[j].y;
- isRemove = true;
- // DecideGps00().lidarDistance = obsPoint.y;
- return obsPoint;
- }
- }
- }
- // DecideGps00().lidarDistance = obsPoint.y;
- return obsPoint;
- }
- //1220
- iv::Point2D iv::decition::Compute00::getLidarRearObsPoint(std::vector<Point2D> gpsTrace, iv::LidarGridPtr lidarGridPtr) {
- iv::Point2D obsPoint(-1, -1);
- vector<Point2D> gpsTraceLeft;
- vector<Point2D> gpsTraceRight;
- float xiuzheng=0;
- if(!ServiceCarStatus.useMobileEye){
- xiuzheng=0-ServiceCarStatus.msysparam.rearLidarGpsXiuzheng;
- }
- for (int j = 0; j < gpsTrace.size(); j++)
- {
- double sumx1 = 0, sumy1 = 0, count1 = 0;
- double sumx2 = 0, sumy2 = 0, count2 = 0;
- for (int k = max(0, j - 4); k <= j; k++)
- {
- count1 = count1 + 1;
- sumx1 += gpsTrace[k].x;
- sumy1 += gpsTrace[k].y;
- }
- for (unsigned int k = j; k <= min(gpsTrace.size() - 1, (size_t)(j + 4)); k++)
- {
- count2 = count2 + 1;
- sumx2 += gpsTrace[k].x;
- sumy2 += gpsTrace[k].y;
- }
- sumx1 /= count1; sumy1 /= count1;
- sumx2 /= count2; sumy2 /= count2;
- double anglevalue = atan2(sumy2 - sumy1, sumx2 - sumx1);
- double carFrontx = gpsTrace[j].x;// -Form1.CarRear * Math.Cos(anglevalue);
- double carFronty = gpsTrace[j].y;// -Form1.CarRear * Math.Sin(anglevalue);
- Point2D ptLeft(carFrontx + (ServiceCarStatus.msysparam.vehWidth-0.3) / 2 * cos(anglevalue + PI / 2),
- carFronty + (ServiceCarStatus.msysparam.vehWidth-0.3) / 2 * sin(anglevalue + PI / 2));
- Point2D ptRight(carFrontx + (ServiceCarStatus.msysparam.vehWidth-0.3) / 2 * cos(anglevalue - PI / 2),
- carFronty + (ServiceCarStatus.msysparam.vehWidth-0.3) / 2 * sin(anglevalue - PI / 2));
- gpsTraceLeft.push_back(ptLeft);
- gpsTraceRight.push_back(ptRight);
- }
- bool isRemove = false;
- for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
- {
- if (!isRemove && gpsTrace[j].y<(0-ServiceCarStatus.msysparam.rearGpsXiuzheng) )
- {
- int count = 0;
- for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
- // int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx; //+(ptx / abs(ptx))) / 2左右多出一半的车宽(1米)
- // int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
- int dx = (ptx + gridwide*(double)centerx)/gridwide;
- dx=grx-dx;//1227
- int dy = (pty + gridwide*(double)centery+xiuzheng)/gridwide;
- if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
- {
- // if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
- if (lidarGridPtr[dx * (iv::gry) + dy].ob != 0)
- {
- count++; obsPoint.x = ptx; obsPoint.y = pty;
- }
- }
- }
- j++;
- for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
- // int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx;
- // int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
- int dx = (ptx + gridwide*(double)centerx)/gridwide;
- dx=grx-dx;//1227
- int dy = (pty + gridwide*(double)centery+xiuzheng)/gridwide;
- if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
- {
- // if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
- if (lidarGridPtr[dx * (iv::gry) + dy].ob != 0)
- {
- count++; obsPoint.x = ptx; obsPoint.y = pty;
- }
- }
- }
- if (count >= 2)
- {
- obsPoint.x = gpsTrace[j].x;
- obsPoint.y = gpsTrace[j].y;
- isRemove = true;
- // DecideGps00().lidarDistance = obsPoint.y;
- return obsPoint;
- }
- }
- }
- // DecideGps00().lidarDistance = obsPoint.y;
- return obsPoint;
- }
- iv::Point2D iv::decition::Compute00::getLidarObsPointAvoid(std::vector<Point2D> gpsTrace, iv::LidarGridPtr lidarGridPtr,double & lidarDistanceAvoid) {
- iv::Point2D obsPoint(-1, -1);
- vector<Point2D> gpsTraceLeft;
- vector<Point2D> gpsTraceRight;
- for (int j = 0; j < gpsTrace.size(); j++)
- {
- double sumx1 = 0, sumy1 = 0, count1 = 0;
- double sumx2 = 0, sumy2 = 0, count2 = 0;
- for (int k = max(0, j - 4); k <= j; k++)
- {
- count1 = count1 + 1;
- sumx1 += gpsTrace[k].x;
- sumy1 += gpsTrace[k].y;
- }
- for (unsigned int k = j; k <= min(gpsTrace.size() - 1, (size_t)(j + 4)); k++)
- {
- count2 = count2 + 1;
- sumx2 += gpsTrace[k].x;
- sumy2 += gpsTrace[k].y;
- }
- sumx1 /= count1; sumy1 /= count1;
- sumx2 /= count2; sumy2 /= count2;
- double anglevalue = atan2(sumy2 - sumy1, sumx2 - sumx1);
- double carFrontx = gpsTrace[j].x;// -Form1.CarRear * Math.Cos(anglevalue);
- double carFronty = gpsTrace[j].y;// -Form1.CarRear * Math.Sin(anglevalue);
- //1127 fanwei xiuzheng
- float buchang=0;
- Point2D ptLeft(carFrontx + (ServiceCarStatus.msysparam.vehWidth+(buchang)*2) / 2 * cos(anglevalue + PI / 2),
- carFronty + (ServiceCarStatus.msysparam.vehWidth+(buchang)*2) / 2 * sin(anglevalue + PI / 2));
- Point2D ptRight(carFrontx + (ServiceCarStatus.msysparam.vehWidth+(buchang)*2) / 2 * cos(anglevalue - PI / 2),
- carFronty + (ServiceCarStatus.msysparam.vehWidth+(buchang)*2) / 2 * sin(anglevalue - PI / 2));
- gpsTraceLeft.push_back(ptLeft);
- gpsTraceRight.push_back(ptRight);
- }
- bool isRemove = false;
- for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
- {
- if (!isRemove && gpsTrace[j].y>2.5 && gpsTraceLeft[j].y>2.5 && gpsTraceRight[j].y>2.5)
- {
- int count = 0;
- for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
- int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx; //*2左右多出一半的车宽(1米)
- int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
- if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
- {
- if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
- {
- count++; obsPoint.x = ptx; obsPoint.y = pty;
- }
- }
- }
- j++;
- for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
- int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx;
- int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
- if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
- {
- if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
- {
- count++; obsPoint.x = ptx; obsPoint.y = pty;
- }
- }
- }
- if (count >= 2)
- {
- obsPoint.x = gpsTrace[j].x;
- obsPoint.y = gpsTrace[j].y;
- isRemove = true;
- // DecideGps00().lidarDistanceAvoid = obsPoint.y;
- lidarDistanceAvoid = obsPoint.y;
- return obsPoint;
- }
- }
- }
- // DecideGps00().lidarDistanceAvoid = obsPoint.y;
- return obsPoint;
- }
- //int iv::decition::Compute00::getEsrIndex(std::vector<Point2D> gpsTrace, std::vector<ObstacleBasic> esrRadars) {
- // bool isRemove = false;
- //
- // for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
- // {
- //
- // for (int i = 0; i < esrRadars.size(); i++)
- // if ((esrRadars[i].nomal_y) != 0)
- // {
- // double xxx = esrRadars[i].nomal_x + Esr_Offset;
- // double yyy = esrRadars[i].nomal_y;
- //
- // if (abs(xxx - gpsTrace[j].x) <= 3.0*ServiceCarStatus.msysparam.vehWidth / 4.0 && abs(yyy - (gpsTrace[j].y)) <= 1)
- // {
- //
- // if (lastEsrID == (esrRadars[i]).esr_ID)
- // {
- // lastEsrCount++;
- // }
- // else
- // {
- // lastEsrCount = 0;
- // }
- //
- // if (lastEsrCount >= 3)
- // {
- // return i;
- // }
- //
- // lastEsrID = (esrRadars[i]).esr_ID;
- // }
- // }
- // }
- // return -1;
- //}
- int iv::decition::Compute00::getEsrIndex(std::vector<Point2D> gpsTrace,int roadNum,int *esrPathpoint,const double xiuzhengCs) {
- bool isRemove = false;
- float xiuzheng=0;
- if(!ServiceCarStatus.useMobileEye){
- xiuzheng=ServiceCarStatus.msysparam.radarGpsXiuzheng;
- }
- // float fxiuzhengCs = DecideGps00().xiuzhengCs;
- float fxiuzhengCs = xiuzhengCs;
- int nsize = gpsTrace.size();
- for (int j = 1; j < nsize - 1 && !isRemove; j++)
- {
- for (int i = 0; i < 64; i++)
- if ((ServiceCarStatus.obs_radar[i].nomal_y) != 0 && (ServiceCarStatus.obs_radar[i].valid))
- {
- double xxx = ServiceCarStatus.obs_radar[i].nomal_x + Esr_Offset;
- double yyy = ServiceCarStatus.obs_radar[i].nomal_y+ xiuzheng;
- /*ODS("\nESR毫米波检测物体X距离:%f\n", xxx);
- ODS("\nESR毫米波检测物体Y距离:%f\n", yyy);*/
- //优化
- // if(sqrt((xxx - gpsTrace[j].x)*(xxx - gpsTrace[j].x) + (yyy - gpsTrace[j].y)*(yyy - gpsTrace[j].y)) < (1.0*ServiceCarStatus.msysparam.vehWidth / 2.0+DecideGps00().xiuzhengCs)){
- // *esrPathpoint = j;
- // return i;
- // }
- if (abs(xxx - gpsTrace[j].x) <= (3.0*ServiceCarStatus.msysparam.vehWidth / 4.0+fxiuzhengCs) && abs(yyy - (gpsTrace[j].y)) <= 1)
- {
- return i;
- if (lastEsrID == i)
- {
- lastEsrCount++;
- }
- else
- {
- lastEsrCount = 0;
- }
- if(yyy>50 ){
- if (lastEsrCount >=200)
- {
- return i;
- }
- }
- else if (lastEsrCount >= 1)
- {
- return i;
- }
- lastEsrID = i;
- }
- }
- }
- return -1;
- }
- int iv::decition::Compute00::getRearEsrIndex(std::vector<Point2D> gpsTrace,int roadNum,const double xiuzhengCs) {
- bool isRemove = false;
- float xiuzheng = ServiceCarStatus.msysparam.rearRadarGpsXiuzheng;
- for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
- {
- for (int i = 0; i < 64; i++)
- if ((ServiceCarStatus.obs_rear_radar[i].nomal_y) != 0 && (ServiceCarStatus.obs_rear_radar[i].valid))
- {
- double xxx = 0-(ServiceCarStatus.obs_rear_radar[i].nomal_x + Esr_Offset);
- double yyy = 0-(ServiceCarStatus.obs_rear_radar[i].nomal_y+ xiuzheng);
- if(ServiceCarStatus.msysparam.mvehtype=="qingyuan"){
- xxx=0-xxx;
- }
- /*ODS("\nESR毫米波检测物体X距离:%f\n", xxx);
- ODS("\nESR毫米波检测物体Y距离:%f\n", yyy);*/
- // if (abs(xxx - gpsTrace[j].x) <= (3.0*ServiceCarStatus.msysparam.vehWidth / 4.0+DecideGps00().xiuzhengCs) && abs(yyy - (gpsTrace[j].y)) <= 1)
- if (abs(xxx - gpsTrace[j].x) <= (3.0*ServiceCarStatus.msysparam.vehWidth / 4.0+xiuzhengCs) && abs(yyy - (gpsTrace[j].y)) <= 1)
- {
- if (lastEsrID == i)
- {
- lastEsrCount++;
- }
- else
- {
- lastEsrCount = 0;
- }
- if(yyy>50 ){
- if (lastEsrCount >=200)
- {
- return i;
- }
- }
- else if (lastEsrCount >= 1)
- {
- return i;
- }
- lastEsrID = i;
- }
- }
- }
- return -1;
- }
- //int iv::decition::Compute00::getEsrIndex(std::vector<Point2D> gpsTrace,int roadNum) {
- // bool isRemove = false;
- // for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
- // {
- // for (int i = 0; i < 64; i++)
- // if ((examed_obs_radar[i].nomal_y) != 0 && (examed_obs_radar[i].valid))
- // {
- // double xxx = examed_obs_radar[i].nomal_x + Esr_Offset;
- // double yyy = examed_obs_radar[i].nomal_y+ Esr_Y_Offset;
- // /*ODS("\nESR毫米波检测物体X距离:%f\n", xxx);
- // ODS("\nESR毫米波检测物体Y距离:%f\n", yyy);*/
- // if (abs(xxx - gpsTrace[j].x) <= 3.0*ServiceCarStatus.msysparam.vehWidth / 4.0 && abs(yyy - (gpsTrace[j].y)) <= 1)
- // {
- // if (lastEsrID == i)
- // {
- // lastEsrCount++;
- // }
- // else
- // {
- // lastEsrCount = 0;
- // }
- // if(yyy>50 ){
- // if (lastEsrCount >=200)
- // {
- // return i;
- // }
- // }
- // else if (lastEsrCount >= 3)
- // {
- // return i;
- // }
- // lastEsrID = i;
- // }
- // }
- // }
- // return -1;
- //}
- int iv::decition::Compute00::getEsrIndexAvoid(std::vector<Point2D> gpsTrace) {
- bool isRemove = false;
- for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
- {
- for (int i = 0; i < 64; i++)
- if ((ServiceCarStatus.obs_radar[i].nomal_y) != 0 && (ServiceCarStatus.obs_radar[i].valid))
- {
- double xxx = ServiceCarStatus.obs_radar[i].nomal_x + Esr_Offset;
- double yyy = ServiceCarStatus.obs_radar[i].nomal_y;
- if (abs(xxx - gpsTrace[j].x) <= 3.0*ServiceCarStatus.msysparam.vehWidth / 4.0 && abs(yyy - (gpsTrace[j].y)) <= 1)
- {
- if (lastEsrIDAvoid == i)
- {
- lastEsrCountAvoid++;
- }
- else
- {
- lastEsrCountAvoid = 0;
- }
- if (lastEsrCountAvoid >= 6)
- {
- return i;
- }
- lastEsrIDAvoid = i;
- }
- }
- }
- return -1;
- }
- //double iv::decition::Compute00::getObsSpeed(Point2D obsPoint, std::vector<ObstacleBasic> esrRadars,double realSecSpeed) {
- // double obsSpeed = 0 - realSecSpeed;
- // double minDis = iv::MaxValue;
- // for (int i = 0; i < esrRadars.size(); i++)
- // if ((esrRadars[i].nomal_y) != 0)
- // {
- // double xxx = esrRadars[i].nomal_x + Esr_Offset;
- // double yyy = esrRadars[i].nomal_y;
- //
- // if (abs(xxx - obsPoint.x) < 4 && abs(yyy - obsPoint.y) < 2)
- // {
- // double tmpDis =sqrt((xxx - obsPoint.x) * (xxx - obsPoint.x) + (yyy - obsPoint.y) * (yyy - obsPoint.y));
- // if (tmpDis < minDis)
- // {
- // minDis = tmpDis;
- // obsSpeed = esrRadars[i].speed_y;
- // }
- // }
- // }
- //
- // return obsSpeed;
- //
- //
- //}
- double iv::decition::Compute00::getObsSpeed(Point2D obsPoint, double realSecSpeed) {
- double obsSpeed = 0 - realSecSpeed;
- double minDis = iv::MaxValue;
- for (int i = 0; i < 64; i++)
- if ((ServiceCarStatus.obs_radar[i].nomal_y) != 0 && ServiceCarStatus.obs_radar[i].valid)
- {
- double xxx = ServiceCarStatus.obs_radar[i].nomal_x + Esr_Offset;
- double yyy = ServiceCarStatus.obs_radar[i].nomal_y + Esr_Y_Offset;
- if (abs(xxx - obsPoint.x) < 4 && abs(yyy - obsPoint.y) < 2)
- {
- double tmpDis = sqrt((xxx - obsPoint.x) * (xxx - obsPoint.x) + (yyy - obsPoint.y) * (yyy - obsPoint.y));
- if (tmpDis < minDis)
- {
- minDis = tmpDis;
- obsSpeed = ServiceCarStatus.obs_radar[i].speed_y;
- }
- }
- }
- return obsSpeed;
- }
- double iv::decition::Compute00::getDecideAvoidAngle(std::vector<Point2D> gpsTrace, double realSpeed, float avoidX
- ,const bool readyParkMode,const int gpsLineParkIndex) {
- double ang = 0;
- double EPos = 0, EAng = 0;
- double KEang = 14, KEPos = 10, DEang = 0, DEPos = 0;
- double PreviewDistance = max(6.0, realSpeed / 3.6 * 1.8);//预瞄距离
- if (gpsTrace[0].v1 == 1)
- {
- KEang = 10; KEPos = 8;
- if (realSpeed > 60) KEang = 5;
- }
- else if (gpsTrace[0].v1 == 2 || gpsTrace[0].v1 == 3)
- {
- KEang = 14; KEPos = 10;
- }
- else if (gpsTrace[0].v1 == 4 || gpsTrace[0].v1 == 5)
- {
- KEang = 14; KEPos = 10;
- }
- else if (gpsTrace[0].v1 == 7 && (gpsTrace[0].v2 == 23 || gpsTrace[0].v2 == 24))
- {
- KEang = 18; KEPos = 50; PreviewDistance = 3;
- }
- else if (gpsTrace[0].v1 == 7)
- {
- KEang = 20; KEPos = 50; PreviewDistance = 4;
- }
- double sumdis = 0;
- int gpsIndex = 0;
- std::vector<Point2D> farTrace;
- for (int i = 1; i < gpsTrace.size() - 1; i++)
- {
- sumdis += GetDistance(gpsTrace[i - 1], gpsTrace[i]);
- if (sumdis > PreviewDistance)
- {
- gpsIndex = i;
- break;
- }
- }
- // if ((DecideGps00().readyParkMode) && (gpsIndex + 10>DecideGps00().gpsLineParkIndex))
- // {
- // gpsIndex = DecideGps00().gpsLineParkIndex;
- // }
- if ((readyParkMode) && (gpsIndex + 10>gpsLineParkIndex))
- {
- gpsIndex = gpsLineParkIndex;
- }
- EPos = gpsTrace[gpsIndex].x + avoidX;
- for (unsigned int i = max(0, gpsIndex - 3); i < min((size_t)(gpsIndex + 3), gpsTrace.size()); i++) {
- farTrace.push_back(gpsTrace[gpsIndex]);
- }
- if (farTrace.size() == 0) {
- EAng = 0;
- }
- else {
- EAng = getAvoidAveDef(farTrace, avoidX);
- }
- ang = KEang * EAng + KEPos * EPos + DEang * (EAng - lastEA) + DEPos * (EPos - lastEP);
- lastEA = EAng;
- lastEP = EPos;
- if (ang > angleLimit) {
- ang = angleLimit;
- }
- else if (ang < -angleLimit) {
- ang = -angleLimit;
- }
- if (lastAng != iv::MaxValue) {
- ang = 0.2 * lastAng + 0.8 * ang;
- //ODS("lastAng:%d\n", lastAng);
- }
- lastAng = ang;
- return ang;
- }
- std::vector<iv::GPSData> iv::decition::Compute00::getBesideGpsMapLine(iv::GPS_INS now_gps_ins, vector<iv::GPSData>gpsMapLine, float avoidX) {
- vector<vector<iv::GPSData>> maps;
- vector<iv::GPSData> gpsMapLineBeside;
- int sizeN = gpsMapLine.size();
- for (int i = 1; i < sizeN; i++)
- {
- iv::GPSData gpsData(new GPS_INS);
- double xx = gpsMapLine[i]->gps_x - now_gps_ins.gps_x;
- double yy = gpsMapLine[i]->gps_y - now_gps_ins.gps_y;
- double lng = ServiceCarStatus.location->ins_heading_angle;
- double x0 = xx * cos(lng * PI / 180) - yy * sin(lng * PI / 180);
- double y0 = xx * sin(lng * PI / 180) + yy * cos(lng * PI / 180);
- double k1 = sin((90 + (gpsMapLine[i]->ins_heading_angle - lng)) * PI / 180);
- double k2 = cos((90 + (gpsMapLine[i]->ins_heading_angle - lng)) * PI / 180);
- // memcpy(&gpsData, &gpsMapLine[i], sizeof(gpsData));
- gpsData->speed_mode = gpsMapLine[i]->speed_mode;
- gpsData->gps_x = x0 + k1 * avoidX;
- gpsData->gps_y = y0 + k2 * avoidX;
- gpsMapLineBeside.push_back(gpsData);
- }
- return gpsMapLineBeside;
- }
- //double iv::decition::Compute00::getDecideAngleByLane(double realSpeed) {
- // double ang = 0;
- // double EPos = 0, EAng = 0;
- // // double KEang = 14, KEpos = 10, DEang = 0, DEpos = 0;
- // double KEang = 5, KEPos = 30, DEang = 0, DEPos = 0;
- // // double PreviewDistance = max(6.0, realSpeed / 3.6 * 1.8);//预瞄距离
- // double PreviewDistance;//预瞄距离
- // realSpeed > 40 ? PreviewDistance = max(6.0, realSpeed *0.6) : PreviewDistance = max(6.0, realSpeed *0.5);
- //// if (realSpeed > 40) KEang = 10; KEpos = 8;
- //// if (realSpeed > 50) KEang = 5;
- //double c1 = ServiceCarStatus.aftermarketLane.dist_to_lane_l;
- //double c2 = ServiceCarStatus.aftermarketLane.dist_to_lane_r;
- //double a = ServiceCarStatus.Lane.curvature;
- //double b = ServiceCarStatus.Lane.heading;
- //double c = (c1+c2)*0.5;
- //double x= PreviewDistance;
- //double y;
- //y=a*x*x+b*x+c;
- // // EPos = y;
- //EPos=c;
- // // EAng=atan(2*a*x+b) / PI * 180;
- // EAng=ServiceCarStatus.Lane.yaw;
- // ang = KEang * EAng + KEPos * EPos + DEang * (EAng - lastEA) + DEPos * (EPos - lastEP);
- // lastEA = EAng;
- // lastEP = EPos;
- // std::cout << "\nEPos:%f\n" << EPos << std::endl;
- // std::cout << "\nEAng:%f\n" << EAng << std::endl;
- // if (ang > angleLimit) {
- // ang = angleLimit;
- // }
- // else if (ang < -angleLimit) {
- // ang = -angleLimit;
- // }
- // if (lastAng != iv::MaxValue) {
- // ang = 0.2 * lastAng + 0.8 * ang;
- // //ODS("lastAng:%d\n", lastAng);
- // }
- // lastAng = ang;
- // return ang;
- // }
- double IEPos = 0, IEang = 0;
- double iv::decition::Compute00::getDecideAngleByLanePID(double realSpeed) {
- double ang = 0;
- double EPos = 0, EAng = 0;
- double Curve=0;
- double KEang = 14, KEPos = 10, DEang = 0, DEPos = 0;
- double KCurve=120;
- double KIEPos = 0, KIEang = 0;
- // double PreviewDistance = max(6.0, realSpeed / 3.6 * 1.8);//预瞄距离
- double PreviewDistance;//预瞄距离
- int confL=ServiceCarStatus.aftermarketLane.lane_conf_left;
- int confR=ServiceCarStatus.aftermarketLane.lane_conf_right;
- int conf =min(confL,confR);
- realSpeed > 40 ? PreviewDistance = max(6.0, realSpeed *0.6) : PreviewDistance = max(6.0, realSpeed *0.5);
- if (realSpeed > 40) KEang = 10; KEPos = 8;
- if (realSpeed > 50) KEang = 5;
- KEPos = 20;
- KEang = 200;
- //KEang = 15;
- double c1 = ServiceCarStatus.aftermarketLane.dist_to_lane_l;
- double c2 = ServiceCarStatus.aftermarketLane.dist_to_lane_r;
- double a = ServiceCarStatus.Lane.curvature;
- double b = ServiceCarStatus.Lane.heading;
- double c = (c1+c2)*0.5;
- double yaw= ServiceCarStatus.Lane.yaw;
- double x= PreviewDistance;
- double y;
- y=c-(a*x*x+b*x);
- double difa=0-(atan(2*a*x+b) / PI * 180);
- Curve=0-a;
- //EAng=difa;
- //EPos=y;
- EAng= 0-b;
- EPos = c;
- DEang = 10;
- DEPos = 20;
- //DEang = 20;
- //DEPos = 10;
- IEang = EAng+0.7*IEang;
- IEPos = EPos+0.7*IEPos;
- KIEang = 0;
- //KIEang = 0.5;
- KIEPos =2;
- if(abs(confL)>=2&&abs(confR)>=2){
- //ang = KEang * EAng + KEPos * EPos + DEang * (EAng - lastEA) + DEPos * (EPos - lastEP)+ KIEang * IEang + KIEPos * IEPos;
- ang = KEang * EAng + KEPos * EPos +KCurve*Curve+ DEang * (EAng - lastEA) + DEPos * (EPos - lastEP)+ KIEang * IEang + KIEPos * IEPos;
- }else{
- ang=lastAng;
- }
- //if(lastAng!=0&&abs(ang-lastAng)>20)ang=lastAng;
- lastEA = EAng;
- lastEP = EPos;
- if (ang > angleLimit) {
- ang = angleLimit;
- }
- else if (ang < -angleLimit) {
- ang = -angleLimit;
- }
- if (lastAng != iv::MaxValue) {
- ang = 0.2 * lastAng + 0.8 * ang;
- //ODS("lastAng:%d\n", lastAng);
- }
- lastAng = ang;
- return ang;
- }
- int iv::decition::Compute00::bocheCompute(GPS_INS nowGps,GPS_INS aimGps,std::vector<GPS_INS> & xvectorPoint,double & dBocheAngle,double & fDirectRearDis,double l)
- {
- GaussProjCal(aimGps.gps_lng, aimGps.gps_lat, &aimGps.gps_x, &aimGps.gps_y);
- Point2D pt = Coordinate_Transfer(nowGps.gps_x, nowGps.gps_y, aimGps);
- double x_1 = pt.x;
- double y_1 = pt.y;
- double angle_1 = getQieXianAngle(nowGps,aimGps);
- double x_2 = 0.0, y_2 = 0.0;
- double steering_angle;
- double r =6;
- double x_o, y_o, x_o_1, y_o_1, x_o_2, y_o_2, x_3, y_3;
- double x_t_n, y_t_n, x_t_f, y_t_f;//近切点和远切点
- double x_t_1, y_t_1, x_t_2, y_t_2;//圆形1的切点
- double x_t_3, y_t_3, x_t_4, y_t_4;//圆形2的切点
- double g_1 = tan(angle_1);
- double car_pos[3] = { x_1,y_1,g_1 };
- double parking_pos[2] = { x_2,y_2 };
- double g_3;
- double t[4][2];
- double p[4];
- double s1, s2; //切点与车起始位置的距离
- double min;
- int min_i;
- //g_3 = 0 - 0.5775;
- g_3 = pingfenxian_xielv(x_1, y_1, x_2, y_2, angle_1);
- //交点
- x_3 = 0.0;//(y_1 - y_2 + g_2*x_2 - g_1*x_1) / (g_2 - g_1);
- y_3 = y_1 - g_1 * x_1;
- //圆心1
- x_o_1 = r;
- y_o_1 = g_3 * r + y_3;
- //圆形1的切点1
- x_t_1 = 0.0;
- y_t_1 = g_3 * r + y_3;
- //圆形1的切点2
- if (g_1 == 0)
- {
- x_t_2 = r;
- y_t_2 = y_1 - g_1 * x_1;
- }
- else
- {
- y_t_2 = (y_1 + g_1 * x_o_1 + y_o_1 * g_1*g_1 - g_1 * x_1) / (1 + g_1 * g_1);
- x_t_2 = (y_t_2 + g_1 * x_1 - y_1) / g_1;
- }
- //圆心2
- x_o_2 = 0 - r;
- y_o_2 = y_3 - g_3 * r;
- //圆形2的切点1
- x_t_3 = 0;
- y_t_3 = y_3 - g_3 * r;
- //圆形2的切点2
- if (g_1 == 0)
- {
- x_t_4 = 0 - r;
- y_t_4 = y_1 - g_1 * x_1;
- }
- else
- {
- y_t_4 = (y_1 + g_1 * x_o_2 + y_o_2 * g_1*g_1 - g_1 * x_1) / (1 + g_1 * g_1);
- x_t_4 = (y_t_4 + g_1 * x_1 - y_1) / g_1;
- }
- t[0][0] = x_t_1;
- t[0][1] = y_t_1;
- t[1][0] = x_t_2;
- t[1][1] = y_t_2;
- t[2][0] = x_t_3;
- t[2][1] = y_t_3;
- t[3][0] = x_t_4;
- t[3][1] = y_t_4;
- for (int i = 0; i < 4; i++)
- {
- p[i] = (t[i][0] - parking_pos[0])*(t[i][0] - parking_pos[0]) + (t[i][1] - parking_pos[1])*(t[i][1] - parking_pos[1]);
- }
- min = p[0];
- min_i = 0;
- for (int i = 1; i < 4; i++)
- {
- if (p[i] < min)
- {
- min = p[i]; min_i = i;
- }
- }
- if (min_i < 2)
- {
- x_o = x_o_1;
- y_o = y_o_1;
- s1 = (x_t_1 - x_1)*(x_t_1 - x_1) + (y_t_1 - y_1)*(y_t_1 - y_1);
- s2 = (x_t_2 - x_1)*(x_t_2 - x_1) + (y_t_2 - y_1)*(y_t_2 - y_1);
- if (s1 < s2)
- {
- x_t_n = x_t_1;
- y_t_n = y_t_1;
- x_t_f = x_t_2;
- y_t_f = y_t_2;
- }
- else
- {
- x_t_n = x_t_2;
- y_t_n = y_t_2;
- x_t_f = x_t_1;
- y_t_f = y_t_1;
- }
- }
- else
- {
- x_o = x_o_2;
- y_o = y_o_2;
- s1 = (x_t_3 - x_1)*(x_t_3 - x_1) + (y_t_3 - y_1)*(y_t_3 - y_1);
- s2 = (x_t_4 - x_1)*(x_t_4 - x_1) + (y_t_4 - y_1)*(y_t_4 - y_1);
- if (s1 < s2)
- {
- x_t_n = x_t_3;
- y_t_n = y_t_3;
- x_t_f = x_t_4;
- y_t_f = y_t_4;
- }
- else
- {
- x_t_n = x_t_4;
- y_t_n = y_t_4;
- x_t_f = x_t_3;
- y_t_f = y_t_3;
- }
- }
- steering_angle = atan2(l, r);
- if (x_t_n < 0)
- {
- steering_angle = 0 - steering_angle;
- }
- nearTpoint=Coordinate_UnTransfer(x_t_n, y_t_n, aimGps);
- farTpoint = Coordinate_UnTransfer(x_t_f, y_t_f, aimGps);
- bocheAngle = steering_angle*180/PI;
- // if (x_1 < 0 && y_1 > 0 && x_1 < x_t_n &&y_t_f > 0.1) {
- // return 1;
- // }
- Point2D ptN = Coordinate_Transfer(nearTpoint.gps_x, nearTpoint.gps_y, nowGps);
- double disA = GetDistance(aimGps,nowGps);
- if(y_t_n>0 && ptN.y<0 && y_t_f>0.1 && disA<40){
- dBocheAngle = bocheAngle;
- fDirectRearDis = sqrt(pow(pt.x - x_t_n,2)+ pow(pt.y - y_t_n,2));
- xvectorPoint.push_back(nearTpoint);
- xvectorPoint.push_back(farTpoint);
- cout << "近切点:x_t_n=" << x_t_n << endl;
- cout << "近切点:y_t_n=" << y_t_n << endl;
- cout << "远切点:x_t_f=" << x_t_f << endl;
- cout << "远切点:y_t_f=" << y_t_f << endl;
- cout << "航向角:" << steering_angle << endl;
- return 1;
- }
- return 0;
- }
- double iv::decition::Compute00::bocheCompute(GPS_INS nowGps, GPS_INS aimGps) {
- GaussProjCal(aimGps.gps_lng, aimGps.gps_lat, &aimGps.gps_x, &aimGps.gps_y);
- Point2D pt = Coordinate_Transfer(nowGps.gps_x, nowGps.gps_y, aimGps);
- double x_1 = pt.x;
- double y_1 = pt.y;
- double angle_1 = getQieXianAngle(nowGps,aimGps);
- double x_2 = 0.0, y_2 = 0.0;
- double steering_angle;
- double l = 2.950;
- double r =6;
- double x_o, y_o, x_o_1, y_o_1, x_o_2, y_o_2, x_3, y_3;
- double x_t_n, y_t_n, x_t_f, y_t_f;//近切点和远切点
- double x_t_1, y_t_1, x_t_2, y_t_2;//圆形1的切点
- double x_t_3, y_t_3, x_t_4, y_t_4;//圆形2的切点
- double g_1 = tan(angle_1);
- double car_pos[3] = { x_1,y_1,g_1 };
- double parking_pos[2] = { x_2,y_2 };
- double g_3;
- double t[4][2];
- double p[4];
- double s1, s2; //切点与车起始位置的距离
- double min;
- int min_i;
- //g_3 = 0 - 0.5775;
- g_3 = pingfenxian_xielv(x_1, y_1, x_2, y_2, angle_1);
- //交点
- x_3 = 0.0;//(y_1 - y_2 + g_2*x_2 - g_1*x_1) / (g_2 - g_1);
- y_3 = y_1 - g_1 * x_1;
- //圆心1
- x_o_1 = r;
- y_o_1 = g_3 * r + y_3;
- //圆形1的切点1
- x_t_1 = 0.0;
- y_t_1 = g_3 * r + y_3;
- //圆形1的切点2
- if (g_1 == 0)
- {
- x_t_2 = r;
- y_t_2 = y_1 - g_1 * x_1;
- }
- else
- {
- y_t_2 = (y_1 + g_1 * x_o_1 + y_o_1 * g_1*g_1 - g_1 * x_1) / (1 + g_1 * g_1);
- x_t_2 = (y_t_2 + g_1 * x_1 - y_1) / g_1;
- }
- //圆心2
- x_o_2 = 0 - r;
- y_o_2 = y_3 - g_3 * r;
- //圆形2的切点1
- x_t_3 = 0;
- y_t_3 = y_3 - g_3 * r;
- //圆形2的切点2
- if (g_1 == 0)
- {
- x_t_4 = 0 - r;
- y_t_4 = y_1 - g_1 * x_1;
- }
- else
- {
- y_t_4 = (y_1 + g_1 * x_o_2 + y_o_2 * g_1*g_1 - g_1 * x_1) / (1 + g_1 * g_1);
- x_t_4 = (y_t_4 + g_1 * x_1 - y_1) / g_1;
- }
- t[0][0] = x_t_1;
- t[0][1] = y_t_1;
- t[1][0] = x_t_2;
- t[1][1] = y_t_2;
- t[2][0] = x_t_3;
- t[2][1] = y_t_3;
- t[3][0] = x_t_4;
- t[3][1] = y_t_4;
- for (int i = 0; i < 4; i++)
- {
- p[i] = (t[i][0] - parking_pos[0])*(t[i][0] - parking_pos[0]) + (t[i][1] - parking_pos[1])*(t[i][1] - parking_pos[1]);
- }
- min = p[0];
- min_i = 0;
- for (int i = 1; i < 4; i++)
- {
- if (p[i] < min)
- {
- min = p[i]; min_i = i;
- }
- }
- if (min_i < 2)
- {
- x_o = x_o_1;
- y_o = y_o_1;
- s1 = (x_t_1 - x_1)*(x_t_1 - x_1) + (y_t_1 - y_1)*(y_t_1 - y_1);
- s2 = (x_t_2 - x_1)*(x_t_2 - x_1) + (y_t_2 - y_1)*(y_t_2 - y_1);
- if (s1 < s2)
- {
- x_t_n = x_t_1;
- y_t_n = y_t_1;
- x_t_f = x_t_2;
- y_t_f = y_t_2;
- }
- else
- {
- x_t_n = x_t_2;
- y_t_n = y_t_2;
- x_t_f = x_t_1;
- y_t_f = y_t_1;
- }
- }
- else
- {
- x_o = x_o_2;
- y_o = y_o_2;
- s1 = (x_t_3 - x_1)*(x_t_3 - x_1) + (y_t_3 - y_1)*(y_t_3 - y_1);
- s2 = (x_t_4 - x_1)*(x_t_4 - x_1) + (y_t_4 - y_1)*(y_t_4 - y_1);
- if (s1 < s2)
- {
- x_t_n = x_t_3;
- y_t_n = y_t_3;
- x_t_f = x_t_4;
- y_t_f = y_t_4;
- }
- else
- {
- x_t_n = x_t_4;
- y_t_n = y_t_4;
- x_t_f = x_t_3;
- y_t_f = y_t_3;
- }
- }
- steering_angle = atan2(l, r);
- if (x_t_n < 0)
- {
- steering_angle = 0 - steering_angle;
- }
- nearTpoint=Coordinate_UnTransfer(x_t_n, y_t_n, aimGps);
- farTpoint = Coordinate_UnTransfer(x_t_f, y_t_f, aimGps);
- bocheAngle = steering_angle*180/PI;
- cout << "近切点:x_t_n=" << x_t_n << endl;
- cout << "近切点:y_t_n=" << y_t_n << endl;
- cout << "远切点:x_t_f=" << x_t_f << endl;
- cout << "远切点:y_t_f=" << y_t_f << endl;
- cout << "航向角:" << steering_angle << endl;
- // if (x_1 < 0 && y_1 > 0 && x_1 < x_t_n &&y_t_f > 0.1) {
- // return 1;
- // }
- Point2D ptN = Coordinate_Transfer(nearTpoint.gps_x, nearTpoint.gps_y, nowGps);
- double disA = GetDistance(aimGps,nowGps);
- if(y_t_n>0 && ptN.y<0 && y_t_f>0.1 && disA<40){
- return 1;
- }
- return 0;
- }
- //返回垂直平分线的斜率
- double iv::decition::Compute00::pingfenxian_xielv(double x_1, double y_1, double x_2, double y_2, double angle_1) {
- double angl, x_3, angle_3;
- if (tan(angle_1 == 0))
- {
- if ((x_1 - x_2) > 0 && ((y_1 - y_2) > 0))
- {
- angle_3 = 0 - 1;
- }
- else
- {
- angle_3 = 1;
- }
- }
- else
- {
- x_3 = (tan(angle_1)*x_1 - y_1) / tan(angle_1);//车所在直线与x轴交点
- angl = tan(angle_1);//车所在直线的斜率
- if ((x_1 - x_2)>0 && ((y_1 - y_2)>0))//第一象限
- {
- if ((angl *x_3)<0)//车斜率与车直线的x轴交点异号
- {
- if (angl < 0)
- {
- angle_3 = tan(PI*0.5 + (PI*0.5 - atan(fabs(angl))) *0.5);//垂直平分线斜率
- }
- else
- {
- angle_3 = tan(PI*0.5 + (PI*0.5 + atan(fabs(angl))) *0.5);//垂直平分线斜率
- }
- }
- }
- else//第二象限
- {
- if ((angl*x_3)<0)//车斜率与车直线的x轴交点异号
- {
- if (angl < 0)
- {
- angle_3 = tan(PI*0.5 - (PI*0.5 + atan(fabs(angl))) *0.5);//垂直平分线斜率
- }
- else
- {
- angle_3 = tan(atan(fabs(angl)) + (PI*0.5 - atan(fabs(angl))) *0.5);//垂直平分线斜率
- }
- }
- }
- }
- return angle_3;
- }
- double iv::decition::Compute00::getQieXianAngle(GPS_INS nowGps, GPS_INS aimGps) {
- double heading = nowGps.ins_heading_angle *PI/180;
- double x1 = nowGps.gps_x;
- double y1 = nowGps.gps_y;
- if (heading<=PI*0.5)
- {
- heading = 0.5*PI - heading;
- }
- else if (heading>PI*0.5 && heading<=PI*1.5) {
- heading = 1.5*PI - heading;
- }
- else if (heading>PI*1.5) {
- heading = 2.5*PI - heading;
- }
- double k1 = tan(heading);
- double x = x1+10;
- double y = k1 * x + y1 - (k1 * x1);
- Point2D pt1 = Coordinate_Transfer(nowGps.gps_x, nowGps.gps_y, aimGps);
- Point2D pt2 = Coordinate_Transfer(x, y, aimGps);
- double xielv = (pt1.y - pt2.y) / (pt1.x - pt2.x);
- double angle = atan(abs(xielv));
- if (xielv<0)
- {
- angle = PI - angle;
- }
- return angle;
- }
- /*
- chuizhicheweiboche
- */
- int iv::decition::Compute00::bocheDirectCompute(GPS_INS nowGps,GPS_INS aimGps,std::vector<GPS_INS> & xvectorPoint,double & dBocheAngle,double & fDirectRearDis,double l)
- {
- double x_0 = 0, y_0 = 0.5;
- double x_1, y_1;//车起点坐标
- double ange1;//车航向角弧度
- double x_2, y_2;//另一条与车直线在angle2和R_M 固定情况下过坐标点,第二个近切点
- double real_rad;;//另一条直线的航向角弧度
- double angle_3;//垂直平分线弧度
- double x_3, y_3;//垂直平分线交点
- double x_4, y_4;//另一条直线的远切点坐标,第二个远切点,已知
- double x_o_1, y_o_1;//圆形1坐标
- double x_o_2, y_o_2;//圆形2坐标
- double x_t_n, y_t_n, x_t_f, y_t_f;//近切点和远切点
- double min_rad;
- double R_M; //后轴中点的转弯半径
- double steering_angle;
- xvectorPoint.clear();
- GaussProjCal(aimGps.gps_lng, aimGps.gps_lat, &aimGps.gps_x, &aimGps.gps_y);
- Point2D pt = Coordinate_Transfer(nowGps.gps_x, nowGps.gps_y, aimGps);
- x_1=pt.x;
- y_1=pt.y;
- ange1=getQieXianAngle(nowGps,aimGps);
- min_rad_zhuanxiang(&R_M , &min_rad);
- qiedian_n(x_1,y_1,R_M,min_rad,&x_2 , &y_2, &real_rad);//计算另一条与车直线在angle2和R_M 固定情况下近切点:x_2, y_2
- liangzhixian_jiaodian( x_1, y_1, x_2, y_2,ange1,real_rad,&x_3 , &y_3);
- chuizhipingfenxian_xielv( x_1, y_1, ange1, real_rad, min_rad,&angle_3);
- yuanxin( x_2, y_2, x_3, y_3, real_rad, angle_3, R_M,&x_o_1,&y_o_1,&x_o_2,&y_o_2);
- yuanxin_qiedian( ange1, x_o_1, y_o_1, x_o_2, y_o_2,
- x_1, y_1, x_2, y_2, x_3, y_3, real_rad, angle_3, R_M,&x_t_n,&y_t_n,&x_t_f, &y_t_f);
- steering_angle = atan2(l, R_M);
- x_4 = 0.5;
- y_4 = 0;
- //for (int i = 0; i < 4; i++)
- //{
- //for (int j = 0; j < 2; j++)
- //{
- // cout << t[i][j] << endl;
- //}
- //}
- //cout << "min_rad:" << min_rad<< endl;
- //cout << "jiaodian:x=" << x_3 << endl;
- //cout << "jiaodian:y=" << y_3 << endl;
- // cout << "R-M:" << R_M << endl;
- dTpoint0=Coordinate_UnTransfer(x_t_n, y_t_n, aimGps);
- dTpoint1 = Coordinate_UnTransfer(x_t_f, y_t_f, aimGps);
- dTpoint2 = Coordinate_UnTransfer(x_2, y_2, aimGps);
- dTpoint3 = Coordinate_UnTransfer(x_0, y_0, aimGps);
- dBocheAngle = steering_angle*180/PI;
- double disA = GetDistance(aimGps,nowGps);
- if(pt.y>y_t_n && x_t_f<x_2 && y_t_f>y_2&&disA<40){
- cout << "x_0:" << x_0 << endl;
- cout << "y_0:" << y_0 << endl;
- cout << "x_2:" << x_2 << endl;
- cout << "y_2:" << y_2 << endl;
- cout << "近切点:x_t_n="<< x_t_n << endl;
- cout << "近切点:y_t_n=" << y_t_n << endl;
- cout << "远切点:x_t_f=" << x_t_f << endl;
- cout << "远切点:y_t_f=" << y_t_f << endl;
- xvectorPoint.push_back(dTpoint0);xvectorPoint.push_back(dTpoint1);xvectorPoint.push_back(dTpoint2);xvectorPoint.push_back(dTpoint3);
- fDirectRearDis = sqrt(pow(pt.x - x_t_n,2) + pow(pt.y - y_t_n,2));
- return 1;
- }
- return 0;
- }
- int iv::decition::Compute00::bocheDirectCompute(GPS_INS nowGps, GPS_INS aimGps)
- {
- double l=2.95;//轴距
- double x_0 = 0, y_0 = 0.5;
- double x_1, y_1;//车起点坐标
- double ange1;//车航向角弧度
- double x_2, y_2;//另一条与车直线在angle2和R_M 固定情况下过坐标点,第二个近切点
- double real_rad;;//另一条直线的航向角弧度
- double angle_3;//垂直平分线弧度
- double x_3, y_3;//垂直平分线交点
- double x_4, y_4;//另一条直线的远切点坐标,第二个远切点,已知
- double x_o_1, y_o_1;//圆形1坐标
- double x_o_2, y_o_2;//圆形2坐标
- double x_t_n, y_t_n, x_t_f, y_t_f;//近切点和远切点
- double min_rad;
- double R_M; //后轴中点的转弯半径
- double steering_angle;
- GaussProjCal(aimGps.gps_lng, aimGps.gps_lat, &aimGps.gps_x, &aimGps.gps_y);
- Point2D pt = Coordinate_Transfer(nowGps.gps_x, nowGps.gps_y, aimGps);
- x_1=pt.x;
- y_1=pt.y;
- ange1=getQieXianAngle(nowGps,aimGps);
- min_rad_zhuanxiang(&R_M , &min_rad);
- qiedian_n(x_1,y_1,R_M,min_rad,&x_2 , &y_2, &real_rad);//计算另一条与车直线在angle2和R_M 固定情况下近切点:x_2, y_2
- liangzhixian_jiaodian( x_1, y_1, x_2, y_2,ange1,real_rad,&x_3 , &y_3);
- chuizhipingfenxian_xielv( x_1, y_1, ange1, real_rad, min_rad,&angle_3);
- yuanxin( x_2, y_2, x_3, y_3, real_rad, angle_3, R_M,&x_o_1,&y_o_1,&x_o_2,&y_o_2);
- yuanxin_qiedian( ange1, x_o_1, y_o_1, x_o_2, y_o_2,
- x_1, y_1, x_2, y_2, x_3, y_3, real_rad, angle_3, R_M,&x_t_n,&y_t_n,&x_t_f, &y_t_f);
- steering_angle = atan2(l, R_M);
- x_4 = 0.5;
- y_4 = 0;
- //for (int i = 0; i < 4; i++)
- //{
- //for (int j = 0; j < 2; j++)
- //{
- // cout << t[i][j] << endl;
- //}
- //}
- //cout << "min_rad:" << min_rad<< endl;
- //cout << "jiaodian:x=" << x_3 << endl;
- //cout << "jiaodian:y=" << y_3 << endl;
- // cout << "R-M:" << R_M << endl;
- cout << "x_0:" << x_0 << endl;
- cout << "y_0:" << y_0 << endl;
- cout << "x_2:" << x_2 << endl;
- cout << "y_2:" << y_2 << endl;
- cout << "近切点:x_t_n="<< x_t_n << endl;
- cout << "近切点:y_t_n=" << y_t_n << endl;
- cout << "远切点:x_t_f=" << x_t_f << endl;
- cout << "远切点:y_t_f=" << y_t_f << endl;
- //cout << "航向角:" << steering_angle << endl;
- //cout << "圆心1横坐标=" << x_o_1 << endl;
- //cout << "圆心1纵坐标=" << y_o_1 << endl;
- //cout << "圆心2横坐标=" << x_o_2 << endl;
- //cout << "圆心2纵坐标=" << y_o_2 << endl;
- //cout << "平分线弧度=" << angle_3 << endl;
- //cout << " min_rad=" << min_rad << endl;
- //cout << " real_rad=" << real_rad << endl;
- // system("PAUSE");
- dTpoint0=Coordinate_UnTransfer(x_t_n, y_t_n, aimGps);
- dTpoint1 = Coordinate_UnTransfer(x_t_f, y_t_f, aimGps);
- dTpoint2 = Coordinate_UnTransfer(x_2, y_2, aimGps);
- dTpoint3 = Coordinate_UnTransfer(x_0, y_0, aimGps);
- dBocheAngle = steering_angle*180/PI;
- double disA = GetDistance(aimGps,nowGps);
- if(pt.y>y_t_n && x_t_f<x_2 && y_t_f>y_2&&disA<40){
- return 1;
- }
- return 0;
- }
- double iv::decition::Compute00::min_rad_zhuanxiang(double *R_M, double *min_rad) {
- double L_c = 4.749;//车长
- double rad_1;
- double rad_2;
- double L_k = 1.931;//车宽
- double L = 2.95;//轴距
- double L_f =1.2 ;//前悬
- double L_r =0.7 ;//后悬
- double R_min =6.5 ;//最小转弯半径
- *R_M = fabs(sqrt(R_min*R_min - (L + L_f)*(L + L_f))) - L_k*0.5;//double R_M ;//后轴中点的转弯半径
- //rad_1 = atan2(sqrt(R_min*R_min - (R_M - L_k*0.5)*(R_M - L_k*0.5)), R_M - L_k*0.5);
- //rad_2 = atan2(L + L_f, R_M + L_k*0.5);
- *min_rad = 45 * PI / 180;// rad_1 - rad_2;
- return 0;
- }
- double iv::decition::Compute00::qiedian_n(double x_1, double y_1, double R_M,double min_rad, double *x_2, double *y_2, double *real_rad ) {
- if (x_1 > 0 && y_1 > 0)
- {
- *real_rad = PI*0.5 - min_rad;
- *x_2 = R_M - R_M*cos(min_rad);
- *y_2 = R_M*sin(min_rad) + 0.5;
- }
- else
- {
- *real_rad = PI*0.5 + min_rad;
- *x_2 = R_M*cos(min_rad) - R_M;
- *y_2 = R_M*sin(min_rad) + 0.5;
- }
- return 0;
- }
- double iv::decition::Compute00::liangzhixian_jiaodian(double x_1,double y_1,double x_2,double y_2,double ange1,double real_rad,double *x_3,double *y_3) {
- double b1, b2;
- double k1, k2;
- if (ange1!=(PI*0.5))
- {
- k1 = tan(ange1);
- b1 = y_1 - k1*x_1;
- k2 = tan(real_rad);
- b2 = y_2 - k2*x_2;
- *x_3 = (b2 - b1) / (k1 - k2);
- *y_3 = k2*(*x_3) + b2;
- }
- else
- {
- k2 = tan(real_rad);
- b2 = y_2 - k2*x_2;
- *x_3 = x_1;
- *y_3 = k2*(*x_3) + b2;
- }
- return 0;
- }
- double iv::decition::Compute00::chuizhipingfenxian_xielv(double x_1,double y_1,double ange1,double real_rad,double min_rad,double *angle_3) {
- double k1, k2;
- double angle_j;
- k2 = tan(real_rad);
- if (ange1 != (PI*0.5))
- {
- k1 = tan(ange1);
- angle_j = atan(fabs((k2 - k1) / (1 + k2*k1)));//两直线夹角
- if (x_1 > 0 && y_1 > 0)
- {
- *angle_3 = angle_j*0.5 - min_rad + PI;
- }
- else
- {
- *angle_3 = min_rad - angle_j*0.5;
- }
- }
- else
- {
- angle_j = min_rad;//两直线夹角
- if (x_1 > 0 && y_1 > 0)
- {
- *angle_3 = angle_j*0.5 - min_rad + PI;
- }
- else
- {
- *angle_3 = min_rad - angle_j*0.5;
- }
- }
- return 0;
- }
- double iv::decition::Compute00::yuanxin(double x_2,double y_2,double x_3,double y_3,double real_rad,double angle_3,double R_M,
- double *x_o_1,double *y_o_1,double *x_o_2,double *y_o_2) {
- double b2, b3, k2, k3;
- b2 = y_2 - tan(real_rad)*x_2;
- b3 = y_3 - tan(angle_3)*x_3;
- k2 = tan(real_rad);
- k3 = tan(angle_3);
- *x_o_1 = (sqrt(k2*k2 + 1)*R_M + b3 - b2) / (k2 - k3);
- *y_o_1 = k3*(*x_o_1) + b3;
- *x_o_2 = (b3 - b2 - (sqrt(k2*k2 + 1)*R_M)) / (k2 - k3);
- *y_o_2 = k3*(*x_o_2) + b3;
- return 0;
- }
- double iv::decition::Compute00::yuanxin_qiedian(double ange1,double x_o_1,double y_o_1, double x_o_2,double y_o_2,
- double x_1,double y_1,double x_2,double y_2,double x_3,double y_3,double real_rad,double angle_3,double R_M,
- double *x_t_n, double *y_t_n, double *x_t_f, double *y_t_f)
- {
- double x_o, y_o;
- double b2, b3, k1, k2, k3;
- //double car_pos[3] = { x_1,y_1,k1 };
- double parking_pos[2] = { x_2,y_2 };
- //double t[4][2];
- double p[4];
- double s1, s2; //切点与车起始位置的距离
- double min;
- int min_i;
- double x_t_1, y_t_1, x_t_2, y_t_2;//圆形1的切点
- double x_t_3, y_t_3, x_t_4, y_t_4;//圆形2的切点
- double t[4][2];
- k1 = tan(ange1);
- b2 = y_2 - tan(real_rad)*x_2;
- b3 = y_3 - tan(real_rad)*x_3;
- k2 = tan(real_rad);//另一条直线斜率
- k3 = tan(angle_3);//垂直平分线斜率
- //圆心1和2切点*********************************************
- if (x_1 > 0 && y_1 > 0)//第一象限
- {
- if (ange1 == (PI*0.5))
- {
- x_t_1 = x_1;
- y_t_1 = y_o_1;
- y_t_2 = (y_2 + k2 *x_o_1 + y_o_1*k2*k2 - k2*x_2) / (1 + k2*k2);
- x_t_2 = (y_t_2 + k2*x_2 - y_2) / k2;
- x_t_3 = x_1;
- y_t_3 = y_o_2;
- y_t_4 = (y_2 + k2 *x_o_2 + y_o_2*k2*k2 - k2*x_2) / (1 + k2*k2);
- x_t_4 = (y_t_4 + k2*x_2 - y_2) / k2;
- }
- else
- {
- y_t_1 = (y_1 + k1 *x_o_1 + y_o_1*k1*k1 - k1*x_1) / (1 + k1*k1);
- x_t_1 = (y_t_1 + k1*x_1 - y_1) / k1;
- y_t_2 = (y_2 + k2 *x_o_1 + y_o_1*k2*k2 - k2*x_2) / (1 + k2*k2);
- x_t_2 = (y_t_2 + k2*x_2 - y_2) / k2;
- y_t_3 = (y_1 + k1 *x_o_2 + y_o_2*k1*k1 - k1*x_1) / (1 + k1*k1);
- x_t_3 = (y_t_3 + k1*x_1 - y_1) / k1;
- y_t_4 = (y_2 + k2 *x_o_2 + y_o_2*k2*k2 - k2*x_2) / (1 + k2*k2);
- x_t_4 = (y_t_4 + k2*x_2 - y_2) / k2;
- }
- }
- else
- {
- if (ange1 == 0)
- {
- x_t_1 = 0 - x_1;
- y_t_1 = y_o_1;
- y_t_2 = (y_2 + k2 *x_o_1 + y_o_1*k2*k2 - k2*x_2) / (1 + k2*k2);
- x_t_2 = (y_t_2 + k2*x_2 - y_2) / k2;
- x_t_3 = 0 - x_1;
- y_t_3 = y_o_2;
- y_t_4 = (y_2 + k2 *x_o_2 + y_o_2*k2*k2 - k2*x_2) / (1 + k2*k2);
- x_t_4 = (y_t_4 + k2*x_2 - y_2) / k2;
- }
- else
- {
- y_t_1 = (y_1 + k1 *x_o_1 + y_o_1*k1*k1 - k1*x_1) / (1 + k1*k1);
- x_t_1 = (y_t_1 + k1*x_1 - y_1) / k1;
- y_t_2 = (y_2 + k2 *x_o_1 + y_o_1*k2*k2 - k2*x_2) / (1 + k2*k2);
- x_t_2 = (y_t_2 + k2*x_2 - y_2) / k2;
- y_t_3 = (y_1 + k1 *x_o_2 + y_o_2*k1*k1 - k1*x_1) / (1 + k1*k1);
- x_t_3 = (y_t_3 + k1*x_1 - y_1) / k1;
- y_t_4 = (y_2 + k2 *x_o_2 + y_o_2*k2*k2 - k2*x_2) / (1 + k2*k2);
- x_t_4 = (y_t_4 + k2*x_2 - y_2) / k2;
- }
- }
- //圆心1和2切点*********************************************
- t[0][0] = x_t_1;
- t[0][1] = y_t_1;
- t[1][0] = x_t_2;
- t[1][1] = y_t_2;
- t[2][0] = x_t_3;
- t[2][1] = y_t_3;
- t[3][0] = x_t_4;
- t[3][1] = y_t_4;
- for (int i = 0; i < 4; i++)
- {
- p[i] = (t[i][0] - parking_pos[0])*(t[i][0] - parking_pos[0]) + (t[i][1] - parking_pos[1])*(t[i][1] - parking_pos[1]);
- }
- min = p[0];
- min_i = 0;
- for (int i = 1; i < 4; i++)
- {
- if (p[i] < min)
- {
- min = p[i]; min_i = i;
- }
- }
- if (min_i < 2)
- {
- x_o = x_o_1;
- y_o = y_o_1;
- s1 = (x_t_1 - x_1)*(x_t_1 - x_1) + (y_t_1 - y_1)*(y_t_1 - y_1);
- s2 = (x_t_2 - x_1)*(x_t_2 - x_1) + (y_t_2 - y_1)*(y_t_2 - y_1);
- if (s1 < s2)
- {
- *x_t_n = x_t_1;
- *y_t_n = y_t_1;
- *x_t_f = x_t_2;
- *y_t_f = y_t_2;
- }
- else
- {
- *x_t_n = x_t_2;
- *y_t_n = y_t_2;
- *x_t_f = x_t_1;
- *y_t_f = y_t_1;
- }
- }
- else
- {
- x_o = x_o_2;
- y_o = y_o_2;
- s1 = (x_t_3 - x_1)*(x_t_3 - x_1) + (y_t_3 - y_1)*(y_t_3 - y_1);
- s2 = (x_t_4 - x_1)*(x_t_4 - x_1) + (y_t_4 - y_1)*(y_t_4 - y_1);
- if (s1 < s2)
- {
- *x_t_n = x_t_3;
- *y_t_n = y_t_3;
- *x_t_f = x_t_4;
- *y_t_f = y_t_4;
- }
- else
- {
- *x_t_n = x_t_4;
- *y_t_n = y_t_4;
- *x_t_f = x_t_3;
- *y_t_f = y_t_3;
- }
- }
- return 0;
- }
- int iv::decition::Compute00::getNoAngleNearestPointIndex(GPS_INS rp, const std::vector<GPSData> gpsMap)
- {
- int index = -1;
- int startIndex = 0; // startIndex = 0 则每一次都是遍历整条地图路线
- int endIndex = gpsMap.size() - 1;
- float minDis=20;
- for (int j = startIndex; j < endIndex; j++)
- {
- int i = (j + gpsMap.size()) % gpsMap.size();
- double tmpdis = GetDistance(rp, (*gpsMap[i]));
- if (tmpdis < minDis)
- {
- index = i;
- minDis=tmpdis;
- }
- }
- return index;
- }
- double iv::decition::Compute00::getObsSpeedByFrenet(Point2D obsPoint, double realSecSpeed,const vector<Point2D> gpsTrace, std::vector<iv::GPSData> gpsMap,int pathpoint,GPS_INS nowGps) {
- double obsSpeed = 0 - realSecSpeed;
- double minDis = iv::MaxValue;
- FrenetPoint esr_obs_F_point;
- for (int i = 0; i < 64; i++)
- if ((ServiceCarStatus.obs_radar[i].nomal_y) != 0 && ServiceCarStatus.obs_radar[i].valid)
- {
- double xxx = ServiceCarStatus.obs_radar[i].nomal_x + Esr_Offset;
- double yyy = ServiceCarStatus.obs_radar[i].nomal_y + Esr_Y_Offset;
- if (abs(xxx - obsPoint.x) < 4 && abs(yyy - obsPoint.y) < 2)
- {
- double tmpDis = sqrt((xxx - obsPoint.x) * (xxx - obsPoint.x) + (yyy - obsPoint.y) * (yyy - obsPoint.y));
- if (tmpDis < minDis)
- {
- minDis = tmpDis;
- // esr_obs_F_point = iv::decition::FrenetPlanner::XY2Frenet(xxx, yyy, gpsTrace);
- esr_obs_F_point = iv::decition::FrenetPlanner::getFrenetfromXY(xxx, yyy, gpsTrace,gpsMap,pathpoint,nowGps);
- // obsSpeed = ServiceCarStatus.obs_radar[i].speed_y;
- double speedx=ServiceCarStatus.obs_radar[i].speed_x; //障碍物相对于车辆x轴的速度
- double speedy=ServiceCarStatus.obs_radar[i].speed_y; //障碍物相对于车辆y轴的速度
- double speed_combine = sqrt(speedx*speedx+speedy*speedy); //将x、y轴两个方向的速度求矢量和
- //障碍物的速度方向与道路方向的夹角。用于将速度分解到s方向和d方向。
- //所谓道路方向是指,道路上离障碍物的最近的点沿道路弧线的切线方向。
- double Etheta = esr_obs_F_point.tangent_Ang - atan2(speedy,speedx);
- obsSpeed = speed_combine*cos(Etheta); //由speed_combine分解的s轴方向上的速度
- }
- }
- }
- return obsSpeed;
- }
- int iv::decition::Compute00::getEsrIndexByFrenet(std::vector<Point2D> gpsTrace, FrenetPoint &esrObsPoint, std::vector<iv::GPSData> gpsMap,int pathpoint,GPS_INS nowGps
- ,const double xiuzhengCs){
- double minDistance = numeric_limits<double>::max();
- int minDis_index=-1;
- for(int i=0; i<64; ++i){
- if ((ServiceCarStatus.obs_radar[i].nomal_y) != 0 && (ServiceCarStatus.obs_radar[i].valid)){
- //毫米波在车头,故要加上毫米波与惯导的相对距离。(xxx,yyy)才是障碍物在 车辆坐标系下的坐标。
- double xxx = ServiceCarStatus.obs_radar[i].nomal_x + Esr_Offset;
- double yyy = ServiceCarStatus.obs_radar[i].nomal_y+ Esr_Y_Offset;
- //将毫米波障碍物位置转换到frenet坐标系下
- // esrObsPoint = iv::decition::FrenetPlanner::XY2Frenet(xxx,yyy,gpsTrace);
- esrObsPoint = iv::decition::FrenetPlanner::getFrenetfromXY(xxx,yyy,gpsTrace,gpsMap,pathpoint,nowGps);
- //如果障碍物与道路的横向距离d<=3.0*ServiceCarStatus.msysparam.vehWidth / 4.0,则认为道路上有障碍物。
- //s则可理解为障碍物距离。为障碍物与车辆沿着道路方向的距离,而不是空间上的x或y坐标或者直线距离。
- //minDistance、minDis_index用来统计最近的障碍物信息。
- // if(abs(esrObsPoint.d)<=(3.0*ServiceCarStatus.msysparam.vehWidth / 4.0+DecideGps00().xiuzhengCs)){
- if(abs(esrObsPoint.d)<=(3.0*ServiceCarStatus.msysparam.vehWidth / 4.0+xiuzhengCs)){
- if(esrObsPoint.s<minDistance){
- minDistance = esrObsPoint.s;
- minDis_index = i;
- }
- }
- }
- }
- return minDis_index;
- }
- std::vector<std::vector<iv::GPSData>> gmapsL;
- std::vector<std::vector<iv::GPSData>> gmapsR;
|