12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102 |
- #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;
- 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;
- }
- 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)
- {
- 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;
|