| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843 |
- #include <decition/compute_00.h>
- #include <decition/decide_gps_00.h>
- #include <decition/gps_distance.h>
- #include <decition/decition_type.h>
- #include <decition/transfer.h>
- #include <common/constants.h>
- #include <math.h>
- #include <iostream>
- #include <fstream>
- //#include <control/radar_exam.h>
- #include <control/can.h>
- using namespace std;
- #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::getNearestPointIndex(GPS_INS rp, const std::vector<GPSData> gpsMap, int lastIndex, double mindis, double maxAngle)
- {
- int index = -1;
- // DecideGps00().minDis = iv::MaxValue;
- DecideGps00().minDis = 20;
- DecideGps00().maxAngle = iv::MaxValue;
- int startIndex = max((lastIndex - 500), 0); // startIndex = 0 则每一次都是遍历整条地图路线
- int endIndex = min((gpsMap.size() - 1), (size_t)(lastIndex + 2000 + 100 * (gpsMissCount + 1)));
- for (int j = startIndex; j < endIndex; j++)
- {
- int i = (j + gpsMap.size()) % gpsMap.size();
- double tmpdis = GetDistance(rp, (*gpsMap[i]));
- if (tmpdis < DecideGps00().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;
- DecideGps00().minDis = tmpdis;
- DecideGps00().maxAngle = min(abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle), abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle - 360));
- DecideGps00().maxAngle = min(DecideGps00().maxAngle, abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle + 360));
- }
- }
- /*if (index == -1) {
- index = 0;
- }*/
- return index;
- }
- //首次找点
- int iv::decition::Compute00::getFirstNearestPointIndex(GPS_INS rp, const std::vector<GPSData> gpsMap, int lastIndex, double mindis, double maxAngle)
- {
- int index = -1;
- // DecideGps00().minDis = iv::MaxValue;
- DecideGps00().minDis = 40;
- DecideGps00().maxAngle = 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 < DecideGps00().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;
- DecideGps00().minDis = tmpdis;
- DecideGps00().maxAngle = min(abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle), abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle - 360));
- DecideGps00().maxAngle = min(DecideGps00().maxAngle, abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle + 360));
- }
- }
- /*if (index == -1) {
- index = 0;
- }*/
- 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;
- 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 + Veh_Width / 2 * cos(anglevalue + PI / 2),
- carFronty + Veh_Width / 2 * sin(anglevalue + PI / 2));
- Point2D ptRight(carFrontx + Veh_Width / 2 * cos(anglevalue - PI / 2),
- carFronty + Veh_Width / 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 )
- {
- int count = 0;
- for (double length = 0; length <= Veh_Width; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / Veh_Width * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / Veh_Width * 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)/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 <= Veh_Width; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / Veh_Width * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / Veh_Width * 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)/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;
- 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 + (Veh_Width-0.3) / 2 * cos(anglevalue + PI / 2),
- carFronty + (Veh_Width-0.3) / 2 * sin(anglevalue + PI / 2));
- Point2D ptRight(carFrontx + (Veh_Width-0.3) / 2 * cos(anglevalue - PI / 2),
- carFronty + (Veh_Width-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<-1.0 )
- {
- int count = 0;
- for (double length = 0; length <= Veh_Width; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / Veh_Width * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / Veh_Width * 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)/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 <= Veh_Width; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / Veh_Width * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / Veh_Width * 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)/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) {
- 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 + (Veh_Width+(buchang)*2) / 2 * cos(anglevalue + PI / 2),
- carFronty + (Veh_Width+(buchang)*2) / 2 * sin(anglevalue + PI / 2));
- Point2D ptRight(carFrontx + (Veh_Width+(buchang)*2) / 2 * cos(anglevalue - PI / 2),
- carFronty + (Veh_Width+(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 <= Veh_Width; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / Veh_Width * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / Veh_Width * 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 <= Veh_Width; length += 0.4)
- {
- double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / Veh_Width * length;
- double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / Veh_Width * 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;
- 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*Veh_Width / 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) {
- 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+ Esr_Y_Offset;
- /*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*Veh_Width / 2.0+DecideGps00().xiuzhengCs)){
- // *esrPathpoint = j;
- // return i;
- // }
- if (abs(xxx - gpsTrace[j].x) <= (3.0*Veh_Width / 4.0+DecideGps00().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*Veh_Width / 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*Veh_Width / 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) {
- 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;
- }
- 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, const 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(const std::vector<Point2D>& gpsTrace, FrenetPoint &esrObsPoint, const std::vector<iv::GPSData>& gpsMap,int pathpoint,GPS_INS nowGps){
- 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*Veh_Width / 4.0,则认为道路上有障碍物。
- //s则可理解为障碍物距离。为障碍物与车辆沿着道路方向的距离,而不是空间上的x或y坐标或者直线距离。
- //minDistance、minDis_index用来统计最近的障碍物信息。
- if(abs(esrObsPoint.d)<=(3.0*Veh_Width / 4.0+DecideGps00().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;
|