compute_00.cpp 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355
  1. #include <adc_tools/compute_00.h>
  2. //#include <decision/decide_gps_00.h>
  3. #include <adc_tools/gps_distance.h>
  4. #include <decition_type.h>
  5. #include <adc_tools/transfer.h>
  6. #include <constants.h>
  7. #include <math.h>
  8. #include <iostream>
  9. #include <fstream>
  10. //#include <control/can.h>
  11. #include "common/car_status.h"
  12. #include "adc_planner/frenet_planner.h"
  13. using namespace std;
  14. extern bool handPark;
  15. extern long handParkTime;
  16. extern bool rapidStop;
  17. extern int gpsMissCount;
  18. extern bool changeRoad;
  19. extern double avoidX;
  20. extern bool parkBesideRoad;
  21. extern double steerSpeed;
  22. extern bool transferPieriod;
  23. extern bool transferPieriod2;
  24. extern double traceDevi;
  25. #define PI (3.1415926535897932384626433832795)
  26. iv::decition::Compute00::Compute00() {
  27. }
  28. iv::decition::Compute00::~Compute00() {
  29. }
  30. double iv::decition::Compute00::angleLimit = 700;
  31. double iv::decition::Compute00::lastEA = 0;
  32. double iv::decition::Compute00::lastEP = 0;
  33. double iv::decition::Compute00::decision_Angle = 0;
  34. double iv::decition::Compute00::lastAng = 0;
  35. int iv::decition::Compute00::lastEsrID = -1;
  36. int iv::decition::Compute00::lastEsrCount = 0;
  37. int iv::decition::Compute00::lastEsrIDAvoid = -1;
  38. int iv::decition::Compute00::lastEsrCountAvoid = 0;
  39. iv::GPS_INS iv::decition::Compute00::nearTpoint;
  40. iv::GPS_INS iv::decition::Compute00::farTpoint;
  41. double iv::decition::Compute00::bocheAngle;
  42. iv::GPS_INS iv::decition::Compute00::dTpoint0;
  43. iv::GPS_INS iv::decition::Compute00::dTpoint1;
  44. iv::GPS_INS iv::decition::Compute00::dTpoint2;
  45. iv::GPS_INS iv::decition::Compute00::dTpoint3;
  46. double iv::decition::Compute00::dBocheAngle;
  47. int iv::decition::Compute00::nParkType;
  48. std::vector<int> lastEsrIdVector;
  49. std::vector<int> lastEsrCountVector;
  50. int iv::decition::Compute00::getDesiredSpeed(std::vector<GPSData> gpsMap)
  51. {
  52. int startIndex = 0; // startIndex = 0 则每一次都是遍历整条地图路线
  53. int endIndex = gpsMap.size() - 1;
  54. static double FrontTotalFive=0,FrontAveFive=0,BackAveFive=0,BackTotalFive=0;
  55. static int FrontCount=0,BackCount=0;
  56. static int CurrentIndex=0,MarkingIndex=0,MarkingCount=0;
  57. int MarkedIndex=0,CurveContinue=0;
  58. for (int j = startIndex; j < endIndex; j++)
  59. {
  60. int i = (j + gpsMap.size()) % gpsMap.size();
  61. if((*gpsMap[i]).roadMode!=6)
  62. (*gpsMap[i]).roadMode=5;
  63. }
  64. for (int j = startIndex; j < (endIndex-40); j+=40)
  65. {
  66. int i = (j + gpsMap.size()) % gpsMap.size();
  67. for(int front_k=i;front_k<i+20;front_k++)
  68. {
  69. if(fabs(((*gpsMap[front_k]).ins_heading_angle)-((*gpsMap[i]).ins_heading_angle))<10)
  70. {
  71. FrontTotalFive+=(*gpsMap[front_k]).ins_heading_angle;
  72. FrontCount++;
  73. }
  74. }
  75. i+=20;
  76. FrontAveFive=FrontTotalFive/FrontCount;
  77. FrontTotalFive=0;
  78. FrontCount=0;
  79. for(int back_k=i;back_k<i+20;back_k++)
  80. {
  81. if(fabs((*gpsMap[back_k]).ins_heading_angle-(*gpsMap[i]).ins_heading_angle)<10)
  82. {
  83. BackTotalFive+=(*gpsMap[back_k]).ins_heading_angle;
  84. BackCount++;
  85. }
  86. }
  87. i+=20;
  88. CurrentIndex=i-1;
  89. BackAveFive=BackTotalFive/BackCount;
  90. BackTotalFive=0;
  91. BackCount=0;
  92. if(fabs(FrontAveFive-BackAveFive)<50)
  93. {
  94. if(fabs(FrontAveFive-BackAveFive)>4)
  95. {
  96. CurveContinue+=1;
  97. if(CurveContinue>=1)
  98. {
  99. MarkingCount=0;
  100. for(MarkingIndex=CurrentIndex;MarkingIndex>=MarkedIndex;MarkingIndex--)
  101. {
  102. if((*gpsMap[MarkingIndex]).roadMode!=6)
  103. {
  104. if(MarkingCount<150)
  105. {
  106. if((BackAveFive-FrontAveFive)<=3.5)
  107. {
  108. (*gpsMap[MarkingIndex]).roadMode=14; //弯道,2米,14
  109. }
  110. else if((BackAveFive-FrontAveFive)>3.5)
  111. {
  112. (*gpsMap[MarkingIndex]).roadMode=15;
  113. }
  114. } //else if((MarkingCount>=100)&&(MarkingCount<150)){(*gpsMap[MarkingIndex]).roadMode=18; //超低速,10米,1}
  115. else if((MarkingCount>=150)&&(MarkingCount<320))
  116. {
  117. (*gpsMap[MarkingIndex]).roadMode=5; //低速,20米,5
  118. }
  119. else if((MarkingCount>=320)&&(MarkingCount<620))
  120. {
  121. (*gpsMap[MarkingIndex]).roadMode=0; //常速,60米
  122. }
  123. else if(MarkingCount>=620)
  124. {
  125. (*gpsMap[MarkingIndex]).roadMode=11; //高速/疯狂加速,大于60米
  126. }
  127. }
  128. MarkingCount++;
  129. }
  130. MarkedIndex=CurrentIndex;
  131. }
  132. }
  133. else if(fabs(FrontAveFive-BackAveFive)<=4)
  134. {
  135. CurveContinue=0;
  136. }
  137. }
  138. FrontAveFive=0;
  139. BackAveFive=0;
  140. }
  141. if(MarkedIndex<endIndex)
  142. {
  143. MarkingCount=0;
  144. for(MarkingIndex=endIndex;MarkingIndex>=MarkedIndex;MarkingIndex--)
  145. {
  146. if((*gpsMap[MarkingIndex]).roadMode!=6)
  147. {
  148. if(MarkingCount<100)
  149. {
  150. if((BackAveFive-FrontAveFive)<3)
  151. {
  152. (*gpsMap[MarkingIndex]).roadMode=14; //弯道,2米,14
  153. }
  154. else if((BackAveFive-FrontAveFive)>3)
  155. {
  156. (*gpsMap[MarkingIndex]).roadMode=15;
  157. }
  158. }
  159. else if((MarkingCount>=100)&&(MarkingCount<150))
  160. {
  161. (*gpsMap[MarkingIndex]).roadMode=18; //超低速,10米
  162. }
  163. else if((MarkingCount>=150)&&(MarkingCount<320))
  164. {
  165. (*gpsMap[MarkingIndex]).roadMode=5; //低速,30米
  166. }
  167. else if((MarkingCount>=320)&&(MarkingCount<620))
  168. {
  169. (*gpsMap[MarkingIndex]).roadMode=0; //常速,60米
  170. }
  171. else if(MarkingCount>=620)
  172. {
  173. (*gpsMap[MarkingIndex]).roadMode=11; //高速/疯狂加速,大于60米
  174. }
  175. }
  176. MarkingCount++;
  177. }
  178. }
  179. return 1;
  180. }
  181. //首次找点
  182. int iv::decition::Compute00::getFirstNearestPointIndex(GPS_INS rp, std::vector<GPSData> gpsMap, int lastIndex, double mindis, double maxAngle)
  183. {
  184. int index = -1;
  185. // DecideGps00().minDis = iv::MaxValue;
  186. float minDis = 10;
  187. double maxAng = iv::MaxValue;
  188. int startIndex = 0; // startIndex = 0 则每一次都是遍历整条地图路线
  189. int endIndex = gpsMap.size() - 1;
  190. for (int j = startIndex; j < endIndex; j++)
  191. {
  192. int i = (j + gpsMap.size()) % gpsMap.size();
  193. double tmpdis = GetDistance(rp, (*gpsMap[i]));
  194. if (tmpdis < minDis && (abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle) < 80
  195. || abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle - 360) < 80
  196. || abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle + 360) < 80)
  197. )
  198. {
  199. index = i;
  200. minDis = tmpdis;
  201. maxAng = min(abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle), abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle - 360));
  202. maxAng = min(maxAng, abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle + 360));
  203. }
  204. }
  205. // DecideGps00().maxAngle=maxAng;
  206. // DecideGps00().minDis=minDis;
  207. return index;
  208. }
  209. //search pathpoint
  210. int iv::decition::Compute00::getNearestPointIndex(GPS_INS rp, const std::vector<GPSData> gpsMap, int lastIndex, double mindis, double maxAngle)
  211. {
  212. int index = -1;
  213. float minDis = 10;
  214. double maxAng = iv::MaxValue;
  215. int map_size=gpsMap.size();
  216. int preDistance=max(100,(int)(rp.speed*10));
  217. preDistance=min(500,preDistance);
  218. int startIndex = max((int)(lastIndex - 100),(int)(lastIndex-map_size)); // startIndex = 0 则每一次都是遍历整条地图路线
  219. int endIndex = min((int)(lastIndex + preDistance ),(int)(lastIndex+map_size));
  220. for (int j = startIndex; j < endIndex; j++)
  221. {
  222. int i = (j + map_size) % map_size;
  223. double tmpdis = GetDistance(rp, (*gpsMap[i]));
  224. if (tmpdis < minDis && (abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle) < 80
  225. || abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle - 360) < 80
  226. || abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle + 360) < 80)
  227. )
  228. {
  229. index = i;
  230. minDis = tmpdis;
  231. maxAng = min(abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle), abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle - 360));
  232. maxAng = min(maxAngle, abs(rp.ins_heading_angle - (*gpsMap[i]).ins_heading_angle + 360));
  233. }
  234. }
  235. // DecideGps00().maxAngle=maxAng;
  236. // DecideGps00().minDis=minDis;
  237. return index;
  238. }
  239. double iv::decition::Compute00::getAveDef(std::vector<Point2D> farTrace)
  240. {
  241. double sum_x = 0;
  242. double sum_y = 0;
  243. for (int i = 0; i < min(5, (int)farTrace.size()); i++)
  244. {
  245. sum_x += farTrace[i].x;
  246. sum_y += abs(farTrace[i].y);
  247. }
  248. double average_y = sum_y / min(5, (int)farTrace.size());
  249. double average_x = sum_x / min(5, (int)farTrace.size());
  250. return atan(average_x / average_y) / PI * 180;
  251. }
  252. double iv::decition::Compute00::getAvoidAveDef(std::vector<Point2D> farTrace, double avoidX)
  253. {
  254. double sum_x = 0;
  255. double sum_y = 0;
  256. for (int i = 0; i < min(5, (int)farTrace.size()); i++)
  257. {
  258. sum_x += farTrace[i].x;
  259. sum_y += abs(farTrace[i].y);
  260. }
  261. double average_y = sum_y / min(5, (int)farTrace.size());
  262. double average_x = sum_x / min(5, (int)farTrace.size());
  263. return atan(average_x + avoidX / average_y) / PI * 180;
  264. }
  265. double iv::decition::Compute00::getDecideAngle(std::vector<Point2D> gpsTrace, double realSpeed) {
  266. double ang = 0;
  267. double EPos = 0, EAng = 0;
  268. // double KEang = 14, KEPos = 10, DEang = 3, DEPos = 1; // double KEang = 14, KEPos = 10, DEang = 10, DEPos = 10;
  269. double KEang = 14, KEPos = 10, DEang = 0, DEPos = 0;
  270. if(transferPieriod&& !transferPieriod2){
  271. DEang = 200;
  272. DEPos = 150;
  273. }
  274. // double PreviewDistance = max(6.0, realSpeed / 3.6 * 1.8);//预瞄距离
  275. double PreviewDistance;//预瞄距离
  276. realSpeed > 40 ? PreviewDistance = max(6.0, realSpeed *0.6) : PreviewDistance = max(6.0, realSpeed *0.5);
  277. if(changeRoad ||transferPieriod){
  278. PreviewDistance=PreviewDistance+avoidX;
  279. }
  280. if(realSpeed <15){
  281. PreviewDistance = max(4.0, realSpeed *0.4) ;
  282. }
  283. if (gpsTrace[0].v1 == 1)
  284. {
  285. KEang = 14; KEPos = 10;
  286. }
  287. else if (gpsTrace[0].v1 == 2 || gpsTrace[0].v1 == 3)
  288. {
  289. KEang = 14; KEPos = 10;
  290. }
  291. else if (gpsTrace[0].v1 == 4 || gpsTrace[0].v1 == 5)
  292. {
  293. KEang = 14; KEPos = 10;
  294. }
  295. else if (gpsTrace[0].v1 == 7 && (gpsTrace[0].v2 == 23 || gpsTrace[0].v2 == 24))
  296. {
  297. KEang = 18; KEPos = 50; PreviewDistance = 3;
  298. }
  299. else if (gpsTrace[0].v1 == 7)
  300. {
  301. KEang = 20; KEPos = 50; PreviewDistance = 4;
  302. }
  303. if (realSpeed > 40) KEang = 10; KEPos = 8;
  304. if (realSpeed > 50) KEang = 5;
  305. double sumdis = 0;
  306. int gpsIndex = 0;
  307. std::vector<Point2D> farTrace;
  308. for (int i = 1; i < gpsTrace.size() - 1; i++)
  309. {
  310. sumdis += GetDistance(gpsTrace[i - 1], gpsTrace[i]);
  311. if (sumdis > PreviewDistance)
  312. {
  313. gpsIndex = i;
  314. break;
  315. }
  316. }
  317. EPos = gpsTrace[gpsIndex].x;
  318. for (unsigned int i = max(0, gpsIndex - 3); i < min((size_t)(gpsIndex + 3), gpsTrace.size()); i++) {
  319. farTrace.push_back(gpsTrace[gpsIndex]);
  320. }
  321. if (farTrace.size() == 0) {
  322. EAng = 0;
  323. }
  324. else {
  325. EAng = getAveDef(farTrace);
  326. }
  327. ang = KEang * EAng + KEPos * EPos + DEang * (EAng - lastEA) + DEPos * (EPos - lastEP);
  328. lastEA = EAng;
  329. lastEP = EPos;
  330. if (ang > angleLimit) {
  331. ang = angleLimit;
  332. }
  333. else if (ang < -angleLimit) {
  334. ang = -angleLimit;
  335. }
  336. if (lastAng != iv::MaxValue) {
  337. ang = 0.2 * lastAng + 0.8 * ang;
  338. //ODS("lastAng:%d\n", lastAng);
  339. }
  340. lastAng = ang;
  341. return ang;
  342. }
  343. int iv::decition::Compute00::getSpeedPointIndex(std::vector<Point2D> gpsTrace, double realSpeed)
  344. {
  345. int index = 1;
  346. double sumdis = 0;
  347. while (index < gpsTrace.size() && sumdis < realSpeed)
  348. sumdis += GetDistance(gpsTrace[index - 1], gpsTrace[index++]);
  349. if (index == gpsTrace.size())
  350. return index - 1;
  351. if (abs(sumdis - realSpeed) > abs(sumdis - GetDistance(gpsTrace[index - 1], gpsTrace[index]) - realSpeed))
  352. index--;
  353. return index;
  354. }
  355. iv::Point2D iv::decition::Compute00::getLidarObsPoint(std::vector<Point2D> gpsTrace, iv::LidarGridPtr lidarGridPtr) {
  356. iv::Point2D obsPoint(-1, -1);
  357. vector<Point2D> gpsTraceLeft;
  358. vector<Point2D> gpsTraceRight;
  359. float xiuzheng=0;
  360. if(!ServiceCarStatus.useMobileEye){
  361. xiuzheng=0-ServiceCarStatus.msysparam.lidarGpsXiuzheng;
  362. }
  363. ServiceCarStatus.obsTraceLeft.clear();
  364. ServiceCarStatus.obsTraceRight.clear();
  365. for (int j = 0; j < gpsTrace.size(); j++)
  366. {
  367. double sumx1 = 0, sumy1 = 0, count1 = 0;
  368. double sumx2 = 0, sumy2 = 0, count2 = 0;
  369. for (int k = max(0, j - 4); k <= j; k++)
  370. {
  371. count1 = count1 + 1;
  372. sumx1 += gpsTrace[k].x;
  373. sumy1 += gpsTrace[k].y;
  374. }
  375. for (unsigned int k = j; k <= min(gpsTrace.size() - 1, (size_t)(j + 4)); k++)
  376. {
  377. count2 = count2 + 1;
  378. sumx2 += gpsTrace[k].x;
  379. sumy2 += gpsTrace[k].y;
  380. }
  381. sumx1 /= count1; sumy1 /= count1;
  382. sumx2 /= count2; sumy2 /= count2;
  383. double anglevalue = atan2(sumy2 - sumy1, sumx2 - sumx1);
  384. double carFrontx = gpsTrace[j].x;// -Form1.CarRear * Math.Cos(anglevalue);
  385. double carFronty = gpsTrace[j].y;// -Form1.CarRear * Math.Sin(anglevalue);
  386. Point2D ptLeft(carFrontx + ServiceCarStatus.msysparam.vehWidth / 2 * cos(anglevalue + PI / 2),
  387. carFronty + ServiceCarStatus.msysparam.vehWidth / 2 * sin(anglevalue + PI / 2));
  388. Point2D ptRight(carFrontx + ServiceCarStatus.msysparam.vehWidth / 2 * cos(anglevalue - PI / 2),
  389. carFronty + ServiceCarStatus.msysparam.vehWidth / 2 * sin(anglevalue - PI / 2));
  390. gpsTraceLeft.push_back(ptLeft);
  391. gpsTraceRight.push_back(ptRight);
  392. TracePoint obsptleft(ptLeft.x,ptLeft.y);
  393. ServiceCarStatus.obsTraceLeft.push_back(obsptleft);
  394. TracePoint obsptright(ptRight.x,ptRight.y);
  395. ServiceCarStatus.obsTraceLeft.push_back(obsptright);
  396. }
  397. bool isRemove = false;
  398. for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
  399. {
  400. if (!isRemove && gpsTrace[j].y>ServiceCarStatus.msysparam.lidarGpsXiuzheng)
  401. {
  402. int count = 0;
  403. for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
  404. {
  405. double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
  406. double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
  407. // int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx; //+(ptx / abs(ptx))) / 2左右多出一半的车宽(1米)
  408. // int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
  409. int dx = (ptx + gridwide*(double)centerx)/gridwide;
  410. int dy = (pty + gridwide*(double)centery+xiuzheng)/gridwide;
  411. if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
  412. {
  413. // if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
  414. if (lidarGridPtr[dx * (iv::gry) + dy].ob != 0)
  415. {
  416. count++; obsPoint.x = ptx; obsPoint.y = pty;
  417. }
  418. }
  419. }
  420. j++;
  421. for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
  422. {
  423. double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
  424. double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
  425. // int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx;
  426. // int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
  427. int dx = (ptx + gridwide*(double)centerx)/gridwide;
  428. int dy = (pty + gridwide*(double)centery+xiuzheng)/gridwide;
  429. if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
  430. {
  431. // if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
  432. if (lidarGridPtr[dx * (iv::gry) + dy].ob != 0)
  433. {
  434. count++; obsPoint.x = ptx; obsPoint.y = pty;
  435. }
  436. }
  437. }
  438. if (count >= 2)
  439. {
  440. obsPoint.x = gpsTrace[j].x;
  441. obsPoint.y = gpsTrace[j].y;
  442. isRemove = true;
  443. // DecideGps00().lidarDistance = obsPoint.y;
  444. return obsPoint;
  445. }
  446. }
  447. }
  448. // DecideGps00().lidarDistance = obsPoint.y;
  449. return obsPoint;
  450. }
  451. //1220
  452. iv::Point2D iv::decition::Compute00::getLidarRearObsPoint(std::vector<Point2D> gpsTrace, iv::LidarGridPtr lidarGridPtr) {
  453. iv::Point2D obsPoint(-1, -1);
  454. vector<Point2D> gpsTraceLeft;
  455. vector<Point2D> gpsTraceRight;
  456. float xiuzheng=0;
  457. if(!ServiceCarStatus.useMobileEye){
  458. xiuzheng=0-ServiceCarStatus.msysparam.rearLidarGpsXiuzheng;
  459. }
  460. for (int j = 0; j < gpsTrace.size(); j++)
  461. {
  462. double sumx1 = 0, sumy1 = 0, count1 = 0;
  463. double sumx2 = 0, sumy2 = 0, count2 = 0;
  464. for (int k = max(0, j - 4); k <= j; k++)
  465. {
  466. count1 = count1 + 1;
  467. sumx1 += gpsTrace[k].x;
  468. sumy1 += gpsTrace[k].y;
  469. }
  470. for (unsigned int k = j; k <= min(gpsTrace.size() - 1, (size_t)(j + 4)); k++)
  471. {
  472. count2 = count2 + 1;
  473. sumx2 += gpsTrace[k].x;
  474. sumy2 += gpsTrace[k].y;
  475. }
  476. sumx1 /= count1; sumy1 /= count1;
  477. sumx2 /= count2; sumy2 /= count2;
  478. double anglevalue = atan2(sumy2 - sumy1, sumx2 - sumx1);
  479. double carFrontx = gpsTrace[j].x;// -Form1.CarRear * Math.Cos(anglevalue);
  480. double carFronty = gpsTrace[j].y;// -Form1.CarRear * Math.Sin(anglevalue);
  481. Point2D ptLeft(carFrontx + (ServiceCarStatus.msysparam.vehWidth-0.3) / 2 * cos(anglevalue + PI / 2),
  482. carFronty + (ServiceCarStatus.msysparam.vehWidth-0.3) / 2 * sin(anglevalue + PI / 2));
  483. Point2D ptRight(carFrontx + (ServiceCarStatus.msysparam.vehWidth-0.3) / 2 * cos(anglevalue - PI / 2),
  484. carFronty + (ServiceCarStatus.msysparam.vehWidth-0.3) / 2 * sin(anglevalue - PI / 2));
  485. gpsTraceLeft.push_back(ptLeft);
  486. gpsTraceRight.push_back(ptRight);
  487. }
  488. bool isRemove = false;
  489. for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
  490. {
  491. if (!isRemove && gpsTrace[j].y<(0-ServiceCarStatus.msysparam.rearGpsXiuzheng) )
  492. {
  493. int count = 0;
  494. for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
  495. {
  496. double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
  497. double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
  498. // int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx; //+(ptx / abs(ptx))) / 2左右多出一半的车宽(1米)
  499. // int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
  500. int dx = (ptx + gridwide*(double)centerx)/gridwide;
  501. dx=grx-dx;//1227
  502. int dy = (pty + gridwide*(double)centery+xiuzheng)/gridwide;
  503. if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
  504. {
  505. // if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
  506. if (lidarGridPtr[dx * (iv::gry) + dy].ob != 0)
  507. {
  508. count++; obsPoint.x = ptx; obsPoint.y = pty;
  509. }
  510. }
  511. }
  512. j++;
  513. for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
  514. {
  515. double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
  516. double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
  517. // int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx;
  518. // int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
  519. int dx = (ptx + gridwide*(double)centerx)/gridwide;
  520. dx=grx-dx;//1227
  521. int dy = (pty + gridwide*(double)centery+xiuzheng)/gridwide;
  522. if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
  523. {
  524. // if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
  525. if (lidarGridPtr[dx * (iv::gry) + dy].ob != 0)
  526. {
  527. count++; obsPoint.x = ptx; obsPoint.y = pty;
  528. }
  529. }
  530. }
  531. if (count >= 2)
  532. {
  533. obsPoint.x = gpsTrace[j].x;
  534. obsPoint.y = gpsTrace[j].y;
  535. isRemove = true;
  536. // DecideGps00().lidarDistance = obsPoint.y;
  537. return obsPoint;
  538. }
  539. }
  540. }
  541. // DecideGps00().lidarDistance = obsPoint.y;
  542. return obsPoint;
  543. }
  544. iv::Point2D iv::decition::Compute00::getLidarObsPointAvoid(std::vector<Point2D> gpsTrace, iv::LidarGridPtr lidarGridPtr,double & lidarDistanceAvoid) {
  545. iv::Point2D obsPoint(-1, -1);
  546. vector<Point2D> gpsTraceLeft;
  547. vector<Point2D> gpsTraceRight;
  548. for (int j = 0; j < gpsTrace.size(); j++)
  549. {
  550. double sumx1 = 0, sumy1 = 0, count1 = 0;
  551. double sumx2 = 0, sumy2 = 0, count2 = 0;
  552. for (int k = max(0, j - 4); k <= j; k++)
  553. {
  554. count1 = count1 + 1;
  555. sumx1 += gpsTrace[k].x;
  556. sumy1 += gpsTrace[k].y;
  557. }
  558. for (unsigned int k = j; k <= min(gpsTrace.size() - 1, (size_t)(j + 4)); k++)
  559. {
  560. count2 = count2 + 1;
  561. sumx2 += gpsTrace[k].x;
  562. sumy2 += gpsTrace[k].y;
  563. }
  564. sumx1 /= count1; sumy1 /= count1;
  565. sumx2 /= count2; sumy2 /= count2;
  566. double anglevalue = atan2(sumy2 - sumy1, sumx2 - sumx1);
  567. double carFrontx = gpsTrace[j].x;// -Form1.CarRear * Math.Cos(anglevalue);
  568. double carFronty = gpsTrace[j].y;// -Form1.CarRear * Math.Sin(anglevalue);
  569. //1127 fanwei xiuzheng
  570. float buchang=0;
  571. Point2D ptLeft(carFrontx + (ServiceCarStatus.msysparam.vehWidth+(buchang)*2) / 2 * cos(anglevalue + PI / 2),
  572. carFronty + (ServiceCarStatus.msysparam.vehWidth+(buchang)*2) / 2 * sin(anglevalue + PI / 2));
  573. Point2D ptRight(carFrontx + (ServiceCarStatus.msysparam.vehWidth+(buchang)*2) / 2 * cos(anglevalue - PI / 2),
  574. carFronty + (ServiceCarStatus.msysparam.vehWidth+(buchang)*2) / 2 * sin(anglevalue - PI / 2));
  575. gpsTraceLeft.push_back(ptLeft);
  576. gpsTraceRight.push_back(ptRight);
  577. }
  578. bool isRemove = false;
  579. for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
  580. {
  581. if (!isRemove && gpsTrace[j].y>2.5 && gpsTraceLeft[j].y>2.5 && gpsTraceRight[j].y>2.5)
  582. {
  583. int count = 0;
  584. for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
  585. {
  586. double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
  587. double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
  588. int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx; //*2左右多出一半的车宽(1米)
  589. int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
  590. if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
  591. {
  592. if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
  593. {
  594. count++; obsPoint.x = ptx; obsPoint.y = pty;
  595. }
  596. }
  597. }
  598. j++;
  599. for (double length = 0; length <= ServiceCarStatus.msysparam.vehWidth; length += 0.4)
  600. {
  601. double ptx = gpsTraceLeft[j].x + (gpsTraceRight[j].x - gpsTraceLeft[j].x) / ServiceCarStatus.msysparam.vehWidth * length;
  602. double pty = gpsTraceLeft[j].y + (gpsTraceRight[j].y - gpsTraceLeft[j].y) / ServiceCarStatus.msysparam.vehWidth * length;
  603. int dx = (int)(ptx / gridwide * 2 + (ptx / abs(ptx))) / 2 + centerx;
  604. int dy = (int)(pty / gridwide * 2 + (pty / abs(pty))) / 2 + centery;
  605. if (dx >= 0 && dx <grx && dy >= 0 && dy < gry)
  606. {
  607. if (lidarGridPtr[dx * (iv::gry + 1) + dy].ob != 0)
  608. {
  609. count++; obsPoint.x = ptx; obsPoint.y = pty;
  610. }
  611. }
  612. }
  613. if (count >= 2)
  614. {
  615. obsPoint.x = gpsTrace[j].x;
  616. obsPoint.y = gpsTrace[j].y;
  617. isRemove = true;
  618. // DecideGps00().lidarDistanceAvoid = obsPoint.y;
  619. lidarDistanceAvoid = obsPoint.y;
  620. return obsPoint;
  621. }
  622. }
  623. }
  624. // DecideGps00().lidarDistanceAvoid = obsPoint.y;
  625. return obsPoint;
  626. }
  627. //int iv::decition::Compute00::getEsrIndex(std::vector<Point2D> gpsTrace, std::vector<ObstacleBasic> esrRadars) {
  628. // bool isRemove = false;
  629. //
  630. // for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
  631. // {
  632. //
  633. // for (int i = 0; i < esrRadars.size(); i++)
  634. // if ((esrRadars[i].nomal_y) != 0)
  635. // {
  636. // double xxx = esrRadars[i].nomal_x + Esr_Offset;
  637. // double yyy = esrRadars[i].nomal_y;
  638. //
  639. // if (abs(xxx - gpsTrace[j].x) <= 3.0*ServiceCarStatus.msysparam.vehWidth / 4.0 && abs(yyy - (gpsTrace[j].y)) <= 1)
  640. // {
  641. //
  642. // if (lastEsrID == (esrRadars[i]).esr_ID)
  643. // {
  644. // lastEsrCount++;
  645. // }
  646. // else
  647. // {
  648. // lastEsrCount = 0;
  649. // }
  650. //
  651. // if (lastEsrCount >= 3)
  652. // {
  653. // return i;
  654. // }
  655. //
  656. // lastEsrID = (esrRadars[i]).esr_ID;
  657. // }
  658. // }
  659. // }
  660. // return -1;
  661. //}
  662. int iv::decition::Compute00::getEsrIndex(std::vector<Point2D> gpsTrace,int roadNum,int *esrPathpoint,const double xiuzhengCs) {
  663. bool isRemove = false;
  664. float xiuzheng=0;
  665. if(!ServiceCarStatus.useMobileEye){
  666. xiuzheng=ServiceCarStatus.msysparam.radarGpsXiuzheng;
  667. }
  668. // float fxiuzhengCs = DecideGps00().xiuzhengCs;
  669. float fxiuzhengCs = xiuzhengCs;
  670. int nsize = gpsTrace.size();
  671. for (int j = 1; j < nsize - 1 && !isRemove; j++)
  672. {
  673. for (int i = 0; i < 64; i++)
  674. if ((ServiceCarStatus.obs_radar[i].nomal_y) != 0 && (ServiceCarStatus.obs_radar[i].valid))
  675. {
  676. double xxx = ServiceCarStatus.obs_radar[i].nomal_x + Esr_Offset;
  677. double yyy = ServiceCarStatus.obs_radar[i].nomal_y+ xiuzheng;
  678. /*ODS("\nESR毫米波检测物体X距离:%f\n", xxx);
  679. ODS("\nESR毫米波检测物体Y距离:%f\n", yyy);*/
  680. //优化
  681. // 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)){
  682. // *esrPathpoint = j;
  683. // return i;
  684. // }
  685. if (abs(xxx - gpsTrace[j].x) <= (3.0*ServiceCarStatus.msysparam.vehWidth / 4.0+fxiuzhengCs) && abs(yyy - (gpsTrace[j].y)) <= 1)
  686. {
  687. return i;
  688. if (lastEsrID == i)
  689. {
  690. lastEsrCount++;
  691. }
  692. else
  693. {
  694. lastEsrCount = 0;
  695. }
  696. if(yyy>50 ){
  697. if (lastEsrCount >=200)
  698. {
  699. return i;
  700. }
  701. }
  702. else if (lastEsrCount >= 1)
  703. {
  704. return i;
  705. }
  706. lastEsrID = i;
  707. }
  708. }
  709. }
  710. return -1;
  711. }
  712. int iv::decition::Compute00::getRearEsrIndex(std::vector<Point2D> gpsTrace,int roadNum,const double xiuzhengCs) {
  713. bool isRemove = false;
  714. float xiuzheng = ServiceCarStatus.msysparam.rearRadarGpsXiuzheng;
  715. for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
  716. {
  717. for (int i = 0; i < 64; i++)
  718. if ((ServiceCarStatus.obs_rear_radar[i].nomal_y) != 0 && (ServiceCarStatus.obs_rear_radar[i].valid))
  719. {
  720. double xxx = 0-(ServiceCarStatus.obs_rear_radar[i].nomal_x + Esr_Offset);
  721. double yyy = 0-(ServiceCarStatus.obs_rear_radar[i].nomal_y+ xiuzheng);
  722. if(ServiceCarStatus.msysparam.mvehtype=="qingyuan"){
  723. xxx=0-xxx;
  724. }
  725. /*ODS("\nESR毫米波检测物体X距离:%f\n", xxx);
  726. ODS("\nESR毫米波检测物体Y距离:%f\n", yyy);*/
  727. // if (abs(xxx - gpsTrace[j].x) <= (3.0*ServiceCarStatus.msysparam.vehWidth / 4.0+DecideGps00().xiuzhengCs) && abs(yyy - (gpsTrace[j].y)) <= 1)
  728. if (abs(xxx - gpsTrace[j].x) <= (3.0*ServiceCarStatus.msysparam.vehWidth / 4.0+xiuzhengCs) && abs(yyy - (gpsTrace[j].y)) <= 1)
  729. {
  730. if (lastEsrID == i)
  731. {
  732. lastEsrCount++;
  733. }
  734. else
  735. {
  736. lastEsrCount = 0;
  737. }
  738. if(yyy>50 ){
  739. if (lastEsrCount >=200)
  740. {
  741. return i;
  742. }
  743. }
  744. else if (lastEsrCount >= 1)
  745. {
  746. return i;
  747. }
  748. lastEsrID = i;
  749. }
  750. }
  751. }
  752. return -1;
  753. }
  754. //int iv::decition::Compute00::getEsrIndex(std::vector<Point2D> gpsTrace,int roadNum) {
  755. // bool isRemove = false;
  756. // for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
  757. // {
  758. // for (int i = 0; i < 64; i++)
  759. // if ((examed_obs_radar[i].nomal_y) != 0 && (examed_obs_radar[i].valid))
  760. // {
  761. // double xxx = examed_obs_radar[i].nomal_x + Esr_Offset;
  762. // double yyy = examed_obs_radar[i].nomal_y+ Esr_Y_Offset;
  763. // /*ODS("\nESR毫米波检测物体X距离:%f\n", xxx);
  764. // ODS("\nESR毫米波检测物体Y距离:%f\n", yyy);*/
  765. // if (abs(xxx - gpsTrace[j].x) <= 3.0*ServiceCarStatus.msysparam.vehWidth / 4.0 && abs(yyy - (gpsTrace[j].y)) <= 1)
  766. // {
  767. // if (lastEsrID == i)
  768. // {
  769. // lastEsrCount++;
  770. // }
  771. // else
  772. // {
  773. // lastEsrCount = 0;
  774. // }
  775. // if(yyy>50 ){
  776. // if (lastEsrCount >=200)
  777. // {
  778. // return i;
  779. // }
  780. // }
  781. // else if (lastEsrCount >= 3)
  782. // {
  783. // return i;
  784. // }
  785. // lastEsrID = i;
  786. // }
  787. // }
  788. // }
  789. // return -1;
  790. //}
  791. int iv::decition::Compute00::getEsrIndexAvoid(std::vector<Point2D> gpsTrace) {
  792. bool isRemove = false;
  793. for (int j = 1; j < gpsTrace.size() - 1 && !isRemove; j++)
  794. {
  795. for (int i = 0; i < 64; i++)
  796. if ((ServiceCarStatus.obs_radar[i].nomal_y) != 0 && (ServiceCarStatus.obs_radar[i].valid))
  797. {
  798. double xxx = ServiceCarStatus.obs_radar[i].nomal_x + Esr_Offset;
  799. double yyy = ServiceCarStatus.obs_radar[i].nomal_y;
  800. if (abs(xxx - gpsTrace[j].x) <= 3.0*ServiceCarStatus.msysparam.vehWidth / 4.0 && abs(yyy - (gpsTrace[j].y)) <= 1)
  801. {
  802. if (lastEsrIDAvoid == i)
  803. {
  804. lastEsrCountAvoid++;
  805. }
  806. else
  807. {
  808. lastEsrCountAvoid = 0;
  809. }
  810. if (lastEsrCountAvoid >= 6)
  811. {
  812. return i;
  813. }
  814. lastEsrIDAvoid = i;
  815. }
  816. }
  817. }
  818. return -1;
  819. }
  820. //double iv::decition::Compute00::getObsSpeed(Point2D obsPoint, std::vector<ObstacleBasic> esrRadars,double realSecSpeed) {
  821. // double obsSpeed = 0 - realSecSpeed;
  822. // double minDis = iv::MaxValue;
  823. // for (int i = 0; i < esrRadars.size(); i++)
  824. // if ((esrRadars[i].nomal_y) != 0)
  825. // {
  826. // double xxx = esrRadars[i].nomal_x + Esr_Offset;
  827. // double yyy = esrRadars[i].nomal_y;
  828. //
  829. // if (abs(xxx - obsPoint.x) < 4 && abs(yyy - obsPoint.y) < 2)
  830. // {
  831. // double tmpDis =sqrt((xxx - obsPoint.x) * (xxx - obsPoint.x) + (yyy - obsPoint.y) * (yyy - obsPoint.y));
  832. // if (tmpDis < minDis)
  833. // {
  834. // minDis = tmpDis;
  835. // obsSpeed = esrRadars[i].speed_y;
  836. // }
  837. // }
  838. // }
  839. //
  840. // return obsSpeed;
  841. //
  842. //
  843. //}
  844. double iv::decition::Compute00::getObsSpeed(Point2D obsPoint, double realSecSpeed) {
  845. double obsSpeed = 0 - realSecSpeed;
  846. double minDis = iv::MaxValue;
  847. for (int i = 0; i < 64; i++)
  848. if ((ServiceCarStatus.obs_radar[i].nomal_y) != 0 && ServiceCarStatus.obs_radar[i].valid)
  849. {
  850. double xxx = ServiceCarStatus.obs_radar[i].nomal_x + Esr_Offset;
  851. double yyy = ServiceCarStatus.obs_radar[i].nomal_y + Esr_Y_Offset;
  852. if (abs(xxx - obsPoint.x) < 4 && abs(yyy - obsPoint.y) < 2)
  853. {
  854. double tmpDis = sqrt((xxx - obsPoint.x) * (xxx - obsPoint.x) + (yyy - obsPoint.y) * (yyy - obsPoint.y));
  855. if (tmpDis < minDis)
  856. {
  857. minDis = tmpDis;
  858. obsSpeed = ServiceCarStatus.obs_radar[i].speed_y;
  859. }
  860. }
  861. }
  862. return obsSpeed;
  863. }
  864. double iv::decition::Compute00::getDecideAvoidAngle(std::vector<Point2D> gpsTrace, double realSpeed, float avoidX
  865. ,const bool readyParkMode,const int gpsLineParkIndex) {
  866. double ang = 0;
  867. double EPos = 0, EAng = 0;
  868. double KEang = 14, KEPos = 10, DEang = 0, DEPos = 0;
  869. double PreviewDistance = max(6.0, realSpeed / 3.6 * 1.8);//预瞄距离
  870. if (gpsTrace[0].v1 == 1)
  871. {
  872. KEang = 10; KEPos = 8;
  873. if (realSpeed > 60) KEang = 5;
  874. }
  875. else if (gpsTrace[0].v1 == 2 || gpsTrace[0].v1 == 3)
  876. {
  877. KEang = 14; KEPos = 10;
  878. }
  879. else if (gpsTrace[0].v1 == 4 || gpsTrace[0].v1 == 5)
  880. {
  881. KEang = 14; KEPos = 10;
  882. }
  883. else if (gpsTrace[0].v1 == 7 && (gpsTrace[0].v2 == 23 || gpsTrace[0].v2 == 24))
  884. {
  885. KEang = 18; KEPos = 50; PreviewDistance = 3;
  886. }
  887. else if (gpsTrace[0].v1 == 7)
  888. {
  889. KEang = 20; KEPos = 50; PreviewDistance = 4;
  890. }
  891. double sumdis = 0;
  892. int gpsIndex = 0;
  893. std::vector<Point2D> farTrace;
  894. for (int i = 1; i < gpsTrace.size() - 1; i++)
  895. {
  896. sumdis += GetDistance(gpsTrace[i - 1], gpsTrace[i]);
  897. if (sumdis > PreviewDistance)
  898. {
  899. gpsIndex = i;
  900. break;
  901. }
  902. }
  903. // if ((DecideGps00().readyParkMode) && (gpsIndex + 10>DecideGps00().gpsLineParkIndex))
  904. // {
  905. // gpsIndex = DecideGps00().gpsLineParkIndex;
  906. // }
  907. if ((readyParkMode) && (gpsIndex + 10>gpsLineParkIndex))
  908. {
  909. gpsIndex = gpsLineParkIndex;
  910. }
  911. EPos = gpsTrace[gpsIndex].x + avoidX;
  912. for (unsigned int i = max(0, gpsIndex - 3); i < min((size_t)(gpsIndex + 3), gpsTrace.size()); i++) {
  913. farTrace.push_back(gpsTrace[gpsIndex]);
  914. }
  915. if (farTrace.size() == 0) {
  916. EAng = 0;
  917. }
  918. else {
  919. EAng = getAvoidAveDef(farTrace, avoidX);
  920. }
  921. ang = KEang * EAng + KEPos * EPos + DEang * (EAng - lastEA) + DEPos * (EPos - lastEP);
  922. lastEA = EAng;
  923. lastEP = EPos;
  924. if (ang > angleLimit) {
  925. ang = angleLimit;
  926. }
  927. else if (ang < -angleLimit) {
  928. ang = -angleLimit;
  929. }
  930. if (lastAng != iv::MaxValue) {
  931. ang = 0.2 * lastAng + 0.8 * ang;
  932. //ODS("lastAng:%d\n", lastAng);
  933. }
  934. lastAng = ang;
  935. return ang;
  936. }
  937. std::vector<iv::GPSData> iv::decition::Compute00::getBesideGpsMapLine(iv::GPS_INS now_gps_ins, vector<iv::GPSData>gpsMapLine, float avoidX) {
  938. vector<vector<iv::GPSData>> maps;
  939. vector<iv::GPSData> gpsMapLineBeside;
  940. int sizeN = gpsMapLine.size();
  941. for (int i = 1; i < sizeN; i++)
  942. {
  943. iv::GPSData gpsData(new GPS_INS);
  944. double xx = gpsMapLine[i]->gps_x - now_gps_ins.gps_x;
  945. double yy = gpsMapLine[i]->gps_y - now_gps_ins.gps_y;
  946. double lng = ServiceCarStatus.location->ins_heading_angle;
  947. double x0 = xx * cos(lng * PI / 180) - yy * sin(lng * PI / 180);
  948. double y0 = xx * sin(lng * PI / 180) + yy * cos(lng * PI / 180);
  949. double k1 = sin((90 + (gpsMapLine[i]->ins_heading_angle - lng)) * PI / 180);
  950. double k2 = cos((90 + (gpsMapLine[i]->ins_heading_angle - lng)) * PI / 180);
  951. // memcpy(&gpsData, &gpsMapLine[i], sizeof(gpsData));
  952. gpsData->speed_mode = gpsMapLine[i]->speed_mode;
  953. gpsData->gps_x = x0 + k1 * avoidX;
  954. gpsData->gps_y = y0 + k2 * avoidX;
  955. gpsMapLineBeside.push_back(gpsData);
  956. }
  957. return gpsMapLineBeside;
  958. }
  959. //double iv::decition::Compute00::getDecideAngleByLane(double realSpeed) {
  960. // double ang = 0;
  961. // double EPos = 0, EAng = 0;
  962. // // double KEang = 14, KEpos = 10, DEang = 0, DEpos = 0;
  963. // double KEang = 5, KEPos = 30, DEang = 0, DEPos = 0;
  964. // // double PreviewDistance = max(6.0, realSpeed / 3.6 * 1.8);//预瞄距离
  965. // double PreviewDistance;//预瞄距离
  966. // realSpeed > 40 ? PreviewDistance = max(6.0, realSpeed *0.6) : PreviewDistance = max(6.0, realSpeed *0.5);
  967. //// if (realSpeed > 40) KEang = 10; KEpos = 8;
  968. //// if (realSpeed > 50) KEang = 5;
  969. //double c1 = ServiceCarStatus.aftermarketLane.dist_to_lane_l;
  970. //double c2 = ServiceCarStatus.aftermarketLane.dist_to_lane_r;
  971. //double a = ServiceCarStatus.Lane.curvature;
  972. //double b = ServiceCarStatus.Lane.heading;
  973. //double c = (c1+c2)*0.5;
  974. //double x= PreviewDistance;
  975. //double y;
  976. //y=a*x*x+b*x+c;
  977. // // EPos = y;
  978. //EPos=c;
  979. // // EAng=atan(2*a*x+b) / PI * 180;
  980. // EAng=ServiceCarStatus.Lane.yaw;
  981. // ang = KEang * EAng + KEPos * EPos + DEang * (EAng - lastEA) + DEPos * (EPos - lastEP);
  982. // lastEA = EAng;
  983. // lastEP = EPos;
  984. // std::cout << "\nEPos:%f\n" << EPos << std::endl;
  985. // std::cout << "\nEAng:%f\n" << EAng << std::endl;
  986. // if (ang > angleLimit) {
  987. // ang = angleLimit;
  988. // }
  989. // else if (ang < -angleLimit) {
  990. // ang = -angleLimit;
  991. // }
  992. // if (lastAng != iv::MaxValue) {
  993. // ang = 0.2 * lastAng + 0.8 * ang;
  994. // //ODS("lastAng:%d\n", lastAng);
  995. // }
  996. // lastAng = ang;
  997. // return ang;
  998. // }
  999. double IEPos = 0, IEang = 0;
  1000. double iv::decition::Compute00::getDecideAngleByLanePID(double realSpeed) {
  1001. double ang = 0;
  1002. double EPos = 0, EAng = 0;
  1003. double Curve=0;
  1004. double KEang = 14, KEPos = 10, DEang = 0, DEPos = 0;
  1005. double KCurve=120;
  1006. double KIEPos = 0, KIEang = 0;
  1007. // double PreviewDistance = max(6.0, realSpeed / 3.6 * 1.8);//预瞄距离
  1008. double PreviewDistance;//预瞄距离
  1009. int confL=ServiceCarStatus.aftermarketLane.lane_conf_left;
  1010. int confR=ServiceCarStatus.aftermarketLane.lane_conf_right;
  1011. int conf =min(confL,confR);
  1012. realSpeed > 40 ? PreviewDistance = max(6.0, realSpeed *0.6) : PreviewDistance = max(6.0, realSpeed *0.5);
  1013. if (realSpeed > 40) KEang = 10; KEPos = 8;
  1014. if (realSpeed > 50) KEang = 5;
  1015. KEPos = 20;
  1016. KEang = 200;
  1017. //KEang = 15;
  1018. double c1 = ServiceCarStatus.aftermarketLane.dist_to_lane_l;
  1019. double c2 = ServiceCarStatus.aftermarketLane.dist_to_lane_r;
  1020. double a = ServiceCarStatus.Lane.curvature;
  1021. double b = ServiceCarStatus.Lane.heading;
  1022. double c = (c1+c2)*0.5;
  1023. double yaw= ServiceCarStatus.Lane.yaw;
  1024. double x= PreviewDistance;
  1025. double y;
  1026. y=c-(a*x*x+b*x);
  1027. double difa=0-(atan(2*a*x+b) / PI * 180);
  1028. Curve=0-a;
  1029. //EAng=difa;
  1030. //EPos=y;
  1031. EAng= 0-b;
  1032. EPos = c;
  1033. DEang = 10;
  1034. DEPos = 20;
  1035. //DEang = 20;
  1036. //DEPos = 10;
  1037. IEang = EAng+0.7*IEang;
  1038. IEPos = EPos+0.7*IEPos;
  1039. KIEang = 0;
  1040. //KIEang = 0.5;
  1041. KIEPos =2;
  1042. if(abs(confL)>=2&&abs(confR)>=2){
  1043. //ang = KEang * EAng + KEPos * EPos + DEang * (EAng - lastEA) + DEPos * (EPos - lastEP)+ KIEang * IEang + KIEPos * IEPos;
  1044. ang = KEang * EAng + KEPos * EPos +KCurve*Curve+ DEang * (EAng - lastEA) + DEPos * (EPos - lastEP)+ KIEang * IEang + KIEPos * IEPos;
  1045. }else{
  1046. ang=lastAng;
  1047. }
  1048. //if(lastAng!=0&&abs(ang-lastAng)>20)ang=lastAng;
  1049. lastEA = EAng;
  1050. lastEP = EPos;
  1051. if (ang > angleLimit) {
  1052. ang = angleLimit;
  1053. }
  1054. else if (ang < -angleLimit) {
  1055. ang = -angleLimit;
  1056. }
  1057. if (lastAng != iv::MaxValue) {
  1058. ang = 0.2 * lastAng + 0.8 * ang;
  1059. //ODS("lastAng:%d\n", lastAng);
  1060. }
  1061. lastAng = ang;
  1062. return ang;
  1063. }
  1064. int iv::decition::Compute00::bocheCompute(GPS_INS nowGps,GPS_INS aimGps,std::vector<GPS_INS> & xvectorPoint,double & dBocheAngle,double & fDirectRearDis,double l)
  1065. {
  1066. GaussProjCal(aimGps.gps_lng, aimGps.gps_lat, &aimGps.gps_x, &aimGps.gps_y);
  1067. Point2D pt = Coordinate_Transfer(nowGps.gps_x, nowGps.gps_y, aimGps);
  1068. double x_1 = pt.x;
  1069. double y_1 = pt.y;
  1070. double angle_1 = getQieXianAngle(nowGps,aimGps);
  1071. double x_2 = 0.0, y_2 = 0.0;
  1072. double steering_angle;
  1073. double r =6;
  1074. double x_o, y_o, x_o_1, y_o_1, x_o_2, y_o_2, x_3, y_3;
  1075. double x_t_n, y_t_n, x_t_f, y_t_f;//近切点和远切点
  1076. double x_t_1, y_t_1, x_t_2, y_t_2;//圆形1的切点
  1077. double x_t_3, y_t_3, x_t_4, y_t_4;//圆形2的切点
  1078. double g_1 = tan(angle_1);
  1079. double car_pos[3] = { x_1,y_1,g_1 };
  1080. double parking_pos[2] = { x_2,y_2 };
  1081. double g_3;
  1082. double t[4][2];
  1083. double p[4];
  1084. double s1, s2; //切点与车起始位置的距离
  1085. double min;
  1086. int min_i;
  1087. //g_3 = 0 - 0.5775;
  1088. g_3 = pingfenxian_xielv(x_1, y_1, x_2, y_2, angle_1);
  1089. //交点
  1090. x_3 = 0.0;//(y_1 - y_2 + g_2*x_2 - g_1*x_1) / (g_2 - g_1);
  1091. y_3 = y_1 - g_1 * x_1;
  1092. //圆心1
  1093. x_o_1 = r;
  1094. y_o_1 = g_3 * r + y_3;
  1095. //圆形1的切点1
  1096. x_t_1 = 0.0;
  1097. y_t_1 = g_3 * r + y_3;
  1098. //圆形1的切点2
  1099. if (g_1 == 0)
  1100. {
  1101. x_t_2 = r;
  1102. y_t_2 = y_1 - g_1 * x_1;
  1103. }
  1104. else
  1105. {
  1106. 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);
  1107. x_t_2 = (y_t_2 + g_1 * x_1 - y_1) / g_1;
  1108. }
  1109. //圆心2
  1110. x_o_2 = 0 - r;
  1111. y_o_2 = y_3 - g_3 * r;
  1112. //圆形2的切点1
  1113. x_t_3 = 0;
  1114. y_t_3 = y_3 - g_3 * r;
  1115. //圆形2的切点2
  1116. if (g_1 == 0)
  1117. {
  1118. x_t_4 = 0 - r;
  1119. y_t_4 = y_1 - g_1 * x_1;
  1120. }
  1121. else
  1122. {
  1123. 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);
  1124. x_t_4 = (y_t_4 + g_1 * x_1 - y_1) / g_1;
  1125. }
  1126. t[0][0] = x_t_1;
  1127. t[0][1] = y_t_1;
  1128. t[1][0] = x_t_2;
  1129. t[1][1] = y_t_2;
  1130. t[2][0] = x_t_3;
  1131. t[2][1] = y_t_3;
  1132. t[3][0] = x_t_4;
  1133. t[3][1] = y_t_4;
  1134. for (int i = 0; i < 4; i++)
  1135. {
  1136. 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]);
  1137. }
  1138. min = p[0];
  1139. min_i = 0;
  1140. for (int i = 1; i < 4; i++)
  1141. {
  1142. if (p[i] < min)
  1143. {
  1144. min = p[i]; min_i = i;
  1145. }
  1146. }
  1147. if (min_i < 2)
  1148. {
  1149. x_o = x_o_1;
  1150. y_o = y_o_1;
  1151. s1 = (x_t_1 - x_1)*(x_t_1 - x_1) + (y_t_1 - y_1)*(y_t_1 - y_1);
  1152. s2 = (x_t_2 - x_1)*(x_t_2 - x_1) + (y_t_2 - y_1)*(y_t_2 - y_1);
  1153. if (s1 < s2)
  1154. {
  1155. x_t_n = x_t_1;
  1156. y_t_n = y_t_1;
  1157. x_t_f = x_t_2;
  1158. y_t_f = y_t_2;
  1159. }
  1160. else
  1161. {
  1162. x_t_n = x_t_2;
  1163. y_t_n = y_t_2;
  1164. x_t_f = x_t_1;
  1165. y_t_f = y_t_1;
  1166. }
  1167. }
  1168. else
  1169. {
  1170. x_o = x_o_2;
  1171. y_o = y_o_2;
  1172. s1 = (x_t_3 - x_1)*(x_t_3 - x_1) + (y_t_3 - y_1)*(y_t_3 - y_1);
  1173. s2 = (x_t_4 - x_1)*(x_t_4 - x_1) + (y_t_4 - y_1)*(y_t_4 - y_1);
  1174. if (s1 < s2)
  1175. {
  1176. x_t_n = x_t_3;
  1177. y_t_n = y_t_3;
  1178. x_t_f = x_t_4;
  1179. y_t_f = y_t_4;
  1180. }
  1181. else
  1182. {
  1183. x_t_n = x_t_4;
  1184. y_t_n = y_t_4;
  1185. x_t_f = x_t_3;
  1186. y_t_f = y_t_3;
  1187. }
  1188. }
  1189. steering_angle = atan2(l, r);
  1190. if (x_t_n < 0)
  1191. {
  1192. steering_angle = 0 - steering_angle;
  1193. }
  1194. nearTpoint=Coordinate_UnTransfer(x_t_n, y_t_n, aimGps);
  1195. farTpoint = Coordinate_UnTransfer(x_t_f, y_t_f, aimGps);
  1196. bocheAngle = steering_angle*180/PI;
  1197. // if (x_1 < 0 && y_1 > 0 && x_1 < x_t_n &&y_t_f > 0.1) {
  1198. // return 1;
  1199. // }
  1200. Point2D ptN = Coordinate_Transfer(nearTpoint.gps_x, nearTpoint.gps_y, nowGps);
  1201. double disA = GetDistance(aimGps,nowGps);
  1202. if(y_t_n>0 && ptN.y<0 && y_t_f>0.1 && disA<40){
  1203. dBocheAngle = bocheAngle;
  1204. fDirectRearDis = sqrt(pow(pt.x - x_t_n,2)+ pow(pt.y - y_t_n,2));
  1205. xvectorPoint.push_back(nearTpoint);
  1206. xvectorPoint.push_back(farTpoint);
  1207. cout << "近切点:x_t_n=" << x_t_n << endl;
  1208. cout << "近切点:y_t_n=" << y_t_n << endl;
  1209. cout << "远切点:x_t_f=" << x_t_f << endl;
  1210. cout << "远切点:y_t_f=" << y_t_f << endl;
  1211. cout << "航向角:" << steering_angle << endl;
  1212. return 1;
  1213. }
  1214. return 0;
  1215. }
  1216. double iv::decition::Compute00::bocheCompute(GPS_INS nowGps, GPS_INS aimGps) {
  1217. GaussProjCal(aimGps.gps_lng, aimGps.gps_lat, &aimGps.gps_x, &aimGps.gps_y);
  1218. Point2D pt = Coordinate_Transfer(nowGps.gps_x, nowGps.gps_y, aimGps);
  1219. double x_1 = pt.x;
  1220. double y_1 = pt.y;
  1221. double angle_1 = getQieXianAngle(nowGps,aimGps);
  1222. double x_2 = 0.0, y_2 = 0.0;
  1223. double steering_angle;
  1224. double l = 2.950;
  1225. double r =6;
  1226. double x_o, y_o, x_o_1, y_o_1, x_o_2, y_o_2, x_3, y_3;
  1227. double x_t_n, y_t_n, x_t_f, y_t_f;//近切点和远切点
  1228. double x_t_1, y_t_1, x_t_2, y_t_2;//圆形1的切点
  1229. double x_t_3, y_t_3, x_t_4, y_t_4;//圆形2的切点
  1230. double g_1 = tan(angle_1);
  1231. double car_pos[3] = { x_1,y_1,g_1 };
  1232. double parking_pos[2] = { x_2,y_2 };
  1233. double g_3;
  1234. double t[4][2];
  1235. double p[4];
  1236. double s1, s2; //切点与车起始位置的距离
  1237. double min;
  1238. int min_i;
  1239. //g_3 = 0 - 0.5775;
  1240. g_3 = pingfenxian_xielv(x_1, y_1, x_2, y_2, angle_1);
  1241. //交点
  1242. x_3 = 0.0;//(y_1 - y_2 + g_2*x_2 - g_1*x_1) / (g_2 - g_1);
  1243. y_3 = y_1 - g_1 * x_1;
  1244. //圆心1
  1245. x_o_1 = r;
  1246. y_o_1 = g_3 * r + y_3;
  1247. //圆形1的切点1
  1248. x_t_1 = 0.0;
  1249. y_t_1 = g_3 * r + y_3;
  1250. //圆形1的切点2
  1251. if (g_1 == 0)
  1252. {
  1253. x_t_2 = r;
  1254. y_t_2 = y_1 - g_1 * x_1;
  1255. }
  1256. else
  1257. {
  1258. 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);
  1259. x_t_2 = (y_t_2 + g_1 * x_1 - y_1) / g_1;
  1260. }
  1261. //圆心2
  1262. x_o_2 = 0 - r;
  1263. y_o_2 = y_3 - g_3 * r;
  1264. //圆形2的切点1
  1265. x_t_3 = 0;
  1266. y_t_3 = y_3 - g_3 * r;
  1267. //圆形2的切点2
  1268. if (g_1 == 0)
  1269. {
  1270. x_t_4 = 0 - r;
  1271. y_t_4 = y_1 - g_1 * x_1;
  1272. }
  1273. else
  1274. {
  1275. 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);
  1276. x_t_4 = (y_t_4 + g_1 * x_1 - y_1) / g_1;
  1277. }
  1278. t[0][0] = x_t_1;
  1279. t[0][1] = y_t_1;
  1280. t[1][0] = x_t_2;
  1281. t[1][1] = y_t_2;
  1282. t[2][0] = x_t_3;
  1283. t[2][1] = y_t_3;
  1284. t[3][0] = x_t_4;
  1285. t[3][1] = y_t_4;
  1286. for (int i = 0; i < 4; i++)
  1287. {
  1288. 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]);
  1289. }
  1290. min = p[0];
  1291. min_i = 0;
  1292. for (int i = 1; i < 4; i++)
  1293. {
  1294. if (p[i] < min)
  1295. {
  1296. min = p[i]; min_i = i;
  1297. }
  1298. }
  1299. if (min_i < 2)
  1300. {
  1301. x_o = x_o_1;
  1302. y_o = y_o_1;
  1303. s1 = (x_t_1 - x_1)*(x_t_1 - x_1) + (y_t_1 - y_1)*(y_t_1 - y_1);
  1304. s2 = (x_t_2 - x_1)*(x_t_2 - x_1) + (y_t_2 - y_1)*(y_t_2 - y_1);
  1305. if (s1 < s2)
  1306. {
  1307. x_t_n = x_t_1;
  1308. y_t_n = y_t_1;
  1309. x_t_f = x_t_2;
  1310. y_t_f = y_t_2;
  1311. }
  1312. else
  1313. {
  1314. x_t_n = x_t_2;
  1315. y_t_n = y_t_2;
  1316. x_t_f = x_t_1;
  1317. y_t_f = y_t_1;
  1318. }
  1319. }
  1320. else
  1321. {
  1322. x_o = x_o_2;
  1323. y_o = y_o_2;
  1324. s1 = (x_t_3 - x_1)*(x_t_3 - x_1) + (y_t_3 - y_1)*(y_t_3 - y_1);
  1325. s2 = (x_t_4 - x_1)*(x_t_4 - x_1) + (y_t_4 - y_1)*(y_t_4 - y_1);
  1326. if (s1 < s2)
  1327. {
  1328. x_t_n = x_t_3;
  1329. y_t_n = y_t_3;
  1330. x_t_f = x_t_4;
  1331. y_t_f = y_t_4;
  1332. }
  1333. else
  1334. {
  1335. x_t_n = x_t_4;
  1336. y_t_n = y_t_4;
  1337. x_t_f = x_t_3;
  1338. y_t_f = y_t_3;
  1339. }
  1340. }
  1341. steering_angle = atan2(l, r);
  1342. if (x_t_n < 0)
  1343. {
  1344. steering_angle = 0 - steering_angle;
  1345. }
  1346. nearTpoint=Coordinate_UnTransfer(x_t_n, y_t_n, aimGps);
  1347. farTpoint = Coordinate_UnTransfer(x_t_f, y_t_f, aimGps);
  1348. bocheAngle = steering_angle*180/PI;
  1349. cout << "近切点:x_t_n=" << x_t_n << endl;
  1350. cout << "近切点:y_t_n=" << y_t_n << endl;
  1351. cout << "远切点:x_t_f=" << x_t_f << endl;
  1352. cout << "远切点:y_t_f=" << y_t_f << endl;
  1353. cout << "航向角:" << steering_angle << endl;
  1354. // if (x_1 < 0 && y_1 > 0 && x_1 < x_t_n &&y_t_f > 0.1) {
  1355. // return 1;
  1356. // }
  1357. Point2D ptN = Coordinate_Transfer(nearTpoint.gps_x, nearTpoint.gps_y, nowGps);
  1358. double disA = GetDistance(aimGps,nowGps);
  1359. if(y_t_n>0 && ptN.y<0 && y_t_f>0.1 && disA<40){
  1360. return 1;
  1361. }
  1362. return 0;
  1363. }
  1364. //返回垂直平分线的斜率
  1365. double iv::decition::Compute00::pingfenxian_xielv(double x_1, double y_1, double x_2, double y_2, double angle_1) {
  1366. double angl, x_3, angle_3;
  1367. if (tan(angle_1 == 0))
  1368. {
  1369. if ((x_1 - x_2) > 0 && ((y_1 - y_2) > 0))
  1370. {
  1371. angle_3 = 0 - 1;
  1372. }
  1373. else
  1374. {
  1375. angle_3 = 1;
  1376. }
  1377. }
  1378. else
  1379. {
  1380. x_3 = (tan(angle_1)*x_1 - y_1) / tan(angle_1);//车所在直线与x轴交点
  1381. angl = tan(angle_1);//车所在直线的斜率
  1382. if ((x_1 - x_2)>0 && ((y_1 - y_2)>0))//第一象限
  1383. {
  1384. if ((angl *x_3)<0)//车斜率与车直线的x轴交点异号
  1385. {
  1386. if (angl < 0)
  1387. {
  1388. angle_3 = tan(PI*0.5 + (PI*0.5 - atan(fabs(angl))) *0.5);//垂直平分线斜率
  1389. }
  1390. else
  1391. {
  1392. angle_3 = tan(PI*0.5 + (PI*0.5 + atan(fabs(angl))) *0.5);//垂直平分线斜率
  1393. }
  1394. }
  1395. }
  1396. else//第二象限
  1397. {
  1398. if ((angl*x_3)<0)//车斜率与车直线的x轴交点异号
  1399. {
  1400. if (angl < 0)
  1401. {
  1402. angle_3 = tan(PI*0.5 - (PI*0.5 + atan(fabs(angl))) *0.5);//垂直平分线斜率
  1403. }
  1404. else
  1405. {
  1406. angle_3 = tan(atan(fabs(angl)) + (PI*0.5 - atan(fabs(angl))) *0.5);//垂直平分线斜率
  1407. }
  1408. }
  1409. }
  1410. }
  1411. return angle_3;
  1412. }
  1413. double iv::decition::Compute00::getQieXianAngle(GPS_INS nowGps, GPS_INS aimGps) {
  1414. double heading = nowGps.ins_heading_angle *PI/180;
  1415. double x1 = nowGps.gps_x;
  1416. double y1 = nowGps.gps_y;
  1417. if (heading<=PI*0.5)
  1418. {
  1419. heading = 0.5*PI - heading;
  1420. }
  1421. else if (heading>PI*0.5 && heading<=PI*1.5) {
  1422. heading = 1.5*PI - heading;
  1423. }
  1424. else if (heading>PI*1.5) {
  1425. heading = 2.5*PI - heading;
  1426. }
  1427. double k1 = tan(heading);
  1428. double x = x1+10;
  1429. double y = k1 * x + y1 - (k1 * x1);
  1430. Point2D pt1 = Coordinate_Transfer(nowGps.gps_x, nowGps.gps_y, aimGps);
  1431. Point2D pt2 = Coordinate_Transfer(x, y, aimGps);
  1432. double xielv = (pt1.y - pt2.y) / (pt1.x - pt2.x);
  1433. double angle = atan(abs(xielv));
  1434. if (xielv<0)
  1435. {
  1436. angle = PI - angle;
  1437. }
  1438. return angle;
  1439. }
  1440. /*
  1441. chuizhicheweiboche
  1442. */
  1443. int iv::decition::Compute00::bocheDirectCompute(GPS_INS nowGps,GPS_INS aimGps,std::vector<GPS_INS> & xvectorPoint,double & dBocheAngle,double & fDirectRearDis,double l)
  1444. {
  1445. double x_0 = 0, y_0 = 0.5;
  1446. double x_1, y_1;//车起点坐标
  1447. double ange1;//车航向角弧度
  1448. double x_2, y_2;//另一条与车直线在angle2和R_M 固定情况下过坐标点,第二个近切点
  1449. double real_rad;;//另一条直线的航向角弧度
  1450. double angle_3;//垂直平分线弧度
  1451. double x_3, y_3;//垂直平分线交点
  1452. double x_4, y_4;//另一条直线的远切点坐标,第二个远切点,已知
  1453. double x_o_1, y_o_1;//圆形1坐标
  1454. double x_o_2, y_o_2;//圆形2坐标
  1455. double x_t_n, y_t_n, x_t_f, y_t_f;//近切点和远切点
  1456. double min_rad;
  1457. double R_M; //后轴中点的转弯半径
  1458. double steering_angle;
  1459. xvectorPoint.clear();
  1460. GaussProjCal(aimGps.gps_lng, aimGps.gps_lat, &aimGps.gps_x, &aimGps.gps_y);
  1461. Point2D pt = Coordinate_Transfer(nowGps.gps_x, nowGps.gps_y, aimGps);
  1462. x_1=pt.x;
  1463. y_1=pt.y;
  1464. ange1=getQieXianAngle(nowGps,aimGps);
  1465. min_rad_zhuanxiang(&R_M , &min_rad);
  1466. qiedian_n(x_1,y_1,R_M,min_rad,&x_2 , &y_2, &real_rad);//计算另一条与车直线在angle2和R_M 固定情况下近切点:x_2, y_2
  1467. liangzhixian_jiaodian( x_1, y_1, x_2, y_2,ange1,real_rad,&x_3 , &y_3);
  1468. chuizhipingfenxian_xielv( x_1, y_1, ange1, real_rad, min_rad,&angle_3);
  1469. 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);
  1470. yuanxin_qiedian( ange1, x_o_1, y_o_1, x_o_2, y_o_2,
  1471. 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);
  1472. steering_angle = atan2(l, R_M);
  1473. x_4 = 0.5;
  1474. y_4 = 0;
  1475. //for (int i = 0; i < 4; i++)
  1476. //{
  1477. //for (int j = 0; j < 2; j++)
  1478. //{
  1479. // cout << t[i][j] << endl;
  1480. //}
  1481. //}
  1482. //cout << "min_rad:" << min_rad<< endl;
  1483. //cout << "jiaodian:x=" << x_3 << endl;
  1484. //cout << "jiaodian:y=" << y_3 << endl;
  1485. // cout << "R-M:" << R_M << endl;
  1486. dTpoint0=Coordinate_UnTransfer(x_t_n, y_t_n, aimGps);
  1487. dTpoint1 = Coordinate_UnTransfer(x_t_f, y_t_f, aimGps);
  1488. dTpoint2 = Coordinate_UnTransfer(x_2, y_2, aimGps);
  1489. dTpoint3 = Coordinate_UnTransfer(x_0, y_0, aimGps);
  1490. dBocheAngle = steering_angle*180/PI;
  1491. double disA = GetDistance(aimGps,nowGps);
  1492. if(pt.y>y_t_n && x_t_f<x_2 && y_t_f>y_2&&disA<40){
  1493. cout << "x_0:" << x_0 << endl;
  1494. cout << "y_0:" << y_0 << endl;
  1495. cout << "x_2:" << x_2 << endl;
  1496. cout << "y_2:" << y_2 << endl;
  1497. cout << "近切点:x_t_n="<< x_t_n << endl;
  1498. cout << "近切点:y_t_n=" << y_t_n << endl;
  1499. cout << "远切点:x_t_f=" << x_t_f << endl;
  1500. cout << "远切点:y_t_f=" << y_t_f << endl;
  1501. xvectorPoint.push_back(dTpoint0);xvectorPoint.push_back(dTpoint1);xvectorPoint.push_back(dTpoint2);xvectorPoint.push_back(dTpoint3);
  1502. fDirectRearDis = sqrt(pow(pt.x - x_t_n,2) + pow(pt.y - y_t_n,2));
  1503. return 1;
  1504. }
  1505. return 0;
  1506. }
  1507. int iv::decition::Compute00::bocheDirectCompute(GPS_INS nowGps, GPS_INS aimGps)
  1508. {
  1509. double l=2.95;//轴距
  1510. double x_0 = 0, y_0 = 0.5;
  1511. double x_1, y_1;//车起点坐标
  1512. double ange1;//车航向角弧度
  1513. double x_2, y_2;//另一条与车直线在angle2和R_M 固定情况下过坐标点,第二个近切点
  1514. double real_rad;;//另一条直线的航向角弧度
  1515. double angle_3;//垂直平分线弧度
  1516. double x_3, y_3;//垂直平分线交点
  1517. double x_4, y_4;//另一条直线的远切点坐标,第二个远切点,已知
  1518. double x_o_1, y_o_1;//圆形1坐标
  1519. double x_o_2, y_o_2;//圆形2坐标
  1520. double x_t_n, y_t_n, x_t_f, y_t_f;//近切点和远切点
  1521. double min_rad;
  1522. double R_M; //后轴中点的转弯半径
  1523. double steering_angle;
  1524. GaussProjCal(aimGps.gps_lng, aimGps.gps_lat, &aimGps.gps_x, &aimGps.gps_y);
  1525. Point2D pt = Coordinate_Transfer(nowGps.gps_x, nowGps.gps_y, aimGps);
  1526. x_1=pt.x;
  1527. y_1=pt.y;
  1528. ange1=getQieXianAngle(nowGps,aimGps);
  1529. min_rad_zhuanxiang(&R_M , &min_rad);
  1530. qiedian_n(x_1,y_1,R_M,min_rad,&x_2 , &y_2, &real_rad);//计算另一条与车直线在angle2和R_M 固定情况下近切点:x_2, y_2
  1531. liangzhixian_jiaodian( x_1, y_1, x_2, y_2,ange1,real_rad,&x_3 , &y_3);
  1532. chuizhipingfenxian_xielv( x_1, y_1, ange1, real_rad, min_rad,&angle_3);
  1533. 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);
  1534. yuanxin_qiedian( ange1, x_o_1, y_o_1, x_o_2, y_o_2,
  1535. 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);
  1536. steering_angle = atan2(l, R_M);
  1537. x_4 = 0.5;
  1538. y_4 = 0;
  1539. //for (int i = 0; i < 4; i++)
  1540. //{
  1541. //for (int j = 0; j < 2; j++)
  1542. //{
  1543. // cout << t[i][j] << endl;
  1544. //}
  1545. //}
  1546. //cout << "min_rad:" << min_rad<< endl;
  1547. //cout << "jiaodian:x=" << x_3 << endl;
  1548. //cout << "jiaodian:y=" << y_3 << endl;
  1549. // cout << "R-M:" << R_M << endl;
  1550. cout << "x_0:" << x_0 << endl;
  1551. cout << "y_0:" << y_0 << endl;
  1552. cout << "x_2:" << x_2 << endl;
  1553. cout << "y_2:" << y_2 << endl;
  1554. cout << "近切点:x_t_n="<< x_t_n << endl;
  1555. cout << "近切点:y_t_n=" << y_t_n << endl;
  1556. cout << "远切点:x_t_f=" << x_t_f << endl;
  1557. cout << "远切点:y_t_f=" << y_t_f << endl;
  1558. //cout << "航向角:" << steering_angle << endl;
  1559. //cout << "圆心1横坐标=" << x_o_1 << endl;
  1560. //cout << "圆心1纵坐标=" << y_o_1 << endl;
  1561. //cout << "圆心2横坐标=" << x_o_2 << endl;
  1562. //cout << "圆心2纵坐标=" << y_o_2 << endl;
  1563. //cout << "平分线弧度=" << angle_3 << endl;
  1564. //cout << " min_rad=" << min_rad << endl;
  1565. //cout << " real_rad=" << real_rad << endl;
  1566. // system("PAUSE");
  1567. dTpoint0=Coordinate_UnTransfer(x_t_n, y_t_n, aimGps);
  1568. dTpoint1 = Coordinate_UnTransfer(x_t_f, y_t_f, aimGps);
  1569. dTpoint2 = Coordinate_UnTransfer(x_2, y_2, aimGps);
  1570. dTpoint3 = Coordinate_UnTransfer(x_0, y_0, aimGps);
  1571. dBocheAngle = steering_angle*180/PI;
  1572. double disA = GetDistance(aimGps,nowGps);
  1573. if(pt.y>y_t_n && x_t_f<x_2 && y_t_f>y_2&&disA<40){
  1574. return 1;
  1575. }
  1576. return 0;
  1577. }
  1578. double iv::decition::Compute00::min_rad_zhuanxiang(double *R_M, double *min_rad) {
  1579. double L_c = 4.749;//车长
  1580. double rad_1;
  1581. double rad_2;
  1582. double L_k = 1.931;//车宽
  1583. double L = 2.95;//轴距
  1584. double L_f =1.2 ;//前悬
  1585. double L_r =0.7 ;//后悬
  1586. double R_min =6.5 ;//最小转弯半径
  1587. *R_M = fabs(sqrt(R_min*R_min - (L + L_f)*(L + L_f))) - L_k*0.5;//double R_M ;//后轴中点的转弯半径
  1588. //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);
  1589. //rad_2 = atan2(L + L_f, R_M + L_k*0.5);
  1590. *min_rad = 45 * PI / 180;// rad_1 - rad_2;
  1591. return 0;
  1592. }
  1593. 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 ) {
  1594. if (x_1 > 0 && y_1 > 0)
  1595. {
  1596. *real_rad = PI*0.5 - min_rad;
  1597. *x_2 = R_M - R_M*cos(min_rad);
  1598. *y_2 = R_M*sin(min_rad) + 0.5;
  1599. }
  1600. else
  1601. {
  1602. *real_rad = PI*0.5 + min_rad;
  1603. *x_2 = R_M*cos(min_rad) - R_M;
  1604. *y_2 = R_M*sin(min_rad) + 0.5;
  1605. }
  1606. return 0;
  1607. }
  1608. 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) {
  1609. double b1, b2;
  1610. double k1, k2;
  1611. if (ange1!=(PI*0.5))
  1612. {
  1613. k1 = tan(ange1);
  1614. b1 = y_1 - k1*x_1;
  1615. k2 = tan(real_rad);
  1616. b2 = y_2 - k2*x_2;
  1617. *x_3 = (b2 - b1) / (k1 - k2);
  1618. *y_3 = k2*(*x_3) + b2;
  1619. }
  1620. else
  1621. {
  1622. k2 = tan(real_rad);
  1623. b2 = y_2 - k2*x_2;
  1624. *x_3 = x_1;
  1625. *y_3 = k2*(*x_3) + b2;
  1626. }
  1627. return 0;
  1628. }
  1629. double iv::decition::Compute00::chuizhipingfenxian_xielv(double x_1,double y_1,double ange1,double real_rad,double min_rad,double *angle_3) {
  1630. double k1, k2;
  1631. double angle_j;
  1632. k2 = tan(real_rad);
  1633. if (ange1 != (PI*0.5))
  1634. {
  1635. k1 = tan(ange1);
  1636. angle_j = atan(fabs((k2 - k1) / (1 + k2*k1)));//两直线夹角
  1637. if (x_1 > 0 && y_1 > 0)
  1638. {
  1639. *angle_3 = angle_j*0.5 - min_rad + PI;
  1640. }
  1641. else
  1642. {
  1643. *angle_3 = min_rad - angle_j*0.5;
  1644. }
  1645. }
  1646. else
  1647. {
  1648. angle_j = min_rad;//两直线夹角
  1649. if (x_1 > 0 && y_1 > 0)
  1650. {
  1651. *angle_3 = angle_j*0.5 - min_rad + PI;
  1652. }
  1653. else
  1654. {
  1655. *angle_3 = min_rad - angle_j*0.5;
  1656. }
  1657. }
  1658. return 0;
  1659. }
  1660. 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,
  1661. double *x_o_1,double *y_o_1,double *x_o_2,double *y_o_2) {
  1662. double b2, b3, k2, k3;
  1663. b2 = y_2 - tan(real_rad)*x_2;
  1664. b3 = y_3 - tan(angle_3)*x_3;
  1665. k2 = tan(real_rad);
  1666. k3 = tan(angle_3);
  1667. *x_o_1 = (sqrt(k2*k2 + 1)*R_M + b3 - b2) / (k2 - k3);
  1668. *y_o_1 = k3*(*x_o_1) + b3;
  1669. *x_o_2 = (b3 - b2 - (sqrt(k2*k2 + 1)*R_M)) / (k2 - k3);
  1670. *y_o_2 = k3*(*x_o_2) + b3;
  1671. return 0;
  1672. }
  1673. double iv::decition::Compute00::yuanxin_qiedian(double ange1,double x_o_1,double y_o_1, double x_o_2,double y_o_2,
  1674. 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,
  1675. double *x_t_n, double *y_t_n, double *x_t_f, double *y_t_f)
  1676. {
  1677. double x_o, y_o;
  1678. double b2, b3, k1, k2, k3;
  1679. //double car_pos[3] = { x_1,y_1,k1 };
  1680. double parking_pos[2] = { x_2,y_2 };
  1681. //double t[4][2];
  1682. double p[4];
  1683. double s1, s2; //切点与车起始位置的距离
  1684. double min;
  1685. int min_i;
  1686. double x_t_1, y_t_1, x_t_2, y_t_2;//圆形1的切点
  1687. double x_t_3, y_t_3, x_t_4, y_t_4;//圆形2的切点
  1688. double t[4][2];
  1689. k1 = tan(ange1);
  1690. b2 = y_2 - tan(real_rad)*x_2;
  1691. b3 = y_3 - tan(real_rad)*x_3;
  1692. k2 = tan(real_rad);//另一条直线斜率
  1693. k3 = tan(angle_3);//垂直平分线斜率
  1694. //圆心1和2切点*********************************************
  1695. if (x_1 > 0 && y_1 > 0)//第一象限
  1696. {
  1697. if (ange1 == (PI*0.5))
  1698. {
  1699. x_t_1 = x_1;
  1700. y_t_1 = y_o_1;
  1701. y_t_2 = (y_2 + k2 *x_o_1 + y_o_1*k2*k2 - k2*x_2) / (1 + k2*k2);
  1702. x_t_2 = (y_t_2 + k2*x_2 - y_2) / k2;
  1703. x_t_3 = x_1;
  1704. y_t_3 = y_o_2;
  1705. y_t_4 = (y_2 + k2 *x_o_2 + y_o_2*k2*k2 - k2*x_2) / (1 + k2*k2);
  1706. x_t_4 = (y_t_4 + k2*x_2 - y_2) / k2;
  1707. }
  1708. else
  1709. {
  1710. y_t_1 = (y_1 + k1 *x_o_1 + y_o_1*k1*k1 - k1*x_1) / (1 + k1*k1);
  1711. x_t_1 = (y_t_1 + k1*x_1 - y_1) / k1;
  1712. y_t_2 = (y_2 + k2 *x_o_1 + y_o_1*k2*k2 - k2*x_2) / (1 + k2*k2);
  1713. x_t_2 = (y_t_2 + k2*x_2 - y_2) / k2;
  1714. y_t_3 = (y_1 + k1 *x_o_2 + y_o_2*k1*k1 - k1*x_1) / (1 + k1*k1);
  1715. x_t_3 = (y_t_3 + k1*x_1 - y_1) / k1;
  1716. y_t_4 = (y_2 + k2 *x_o_2 + y_o_2*k2*k2 - k2*x_2) / (1 + k2*k2);
  1717. x_t_4 = (y_t_4 + k2*x_2 - y_2) / k2;
  1718. }
  1719. }
  1720. else
  1721. {
  1722. if (ange1 == 0)
  1723. {
  1724. x_t_1 = 0 - x_1;
  1725. y_t_1 = y_o_1;
  1726. y_t_2 = (y_2 + k2 *x_o_1 + y_o_1*k2*k2 - k2*x_2) / (1 + k2*k2);
  1727. x_t_2 = (y_t_2 + k2*x_2 - y_2) / k2;
  1728. x_t_3 = 0 - x_1;
  1729. y_t_3 = y_o_2;
  1730. y_t_4 = (y_2 + k2 *x_o_2 + y_o_2*k2*k2 - k2*x_2) / (1 + k2*k2);
  1731. x_t_4 = (y_t_4 + k2*x_2 - y_2) / k2;
  1732. }
  1733. else
  1734. {
  1735. y_t_1 = (y_1 + k1 *x_o_1 + y_o_1*k1*k1 - k1*x_1) / (1 + k1*k1);
  1736. x_t_1 = (y_t_1 + k1*x_1 - y_1) / k1;
  1737. y_t_2 = (y_2 + k2 *x_o_1 + y_o_1*k2*k2 - k2*x_2) / (1 + k2*k2);
  1738. x_t_2 = (y_t_2 + k2*x_2 - y_2) / k2;
  1739. y_t_3 = (y_1 + k1 *x_o_2 + y_o_2*k1*k1 - k1*x_1) / (1 + k1*k1);
  1740. x_t_3 = (y_t_3 + k1*x_1 - y_1) / k1;
  1741. y_t_4 = (y_2 + k2 *x_o_2 + y_o_2*k2*k2 - k2*x_2) / (1 + k2*k2);
  1742. x_t_4 = (y_t_4 + k2*x_2 - y_2) / k2;
  1743. }
  1744. }
  1745. //圆心1和2切点*********************************************
  1746. t[0][0] = x_t_1;
  1747. t[0][1] = y_t_1;
  1748. t[1][0] = x_t_2;
  1749. t[1][1] = y_t_2;
  1750. t[2][0] = x_t_3;
  1751. t[2][1] = y_t_3;
  1752. t[3][0] = x_t_4;
  1753. t[3][1] = y_t_4;
  1754. for (int i = 0; i < 4; i++)
  1755. {
  1756. 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]);
  1757. }
  1758. min = p[0];
  1759. min_i = 0;
  1760. for (int i = 1; i < 4; i++)
  1761. {
  1762. if (p[i] < min)
  1763. {
  1764. min = p[i]; min_i = i;
  1765. }
  1766. }
  1767. if (min_i < 2)
  1768. {
  1769. x_o = x_o_1;
  1770. y_o = y_o_1;
  1771. s1 = (x_t_1 - x_1)*(x_t_1 - x_1) + (y_t_1 - y_1)*(y_t_1 - y_1);
  1772. s2 = (x_t_2 - x_1)*(x_t_2 - x_1) + (y_t_2 - y_1)*(y_t_2 - y_1);
  1773. if (s1 < s2)
  1774. {
  1775. *x_t_n = x_t_1;
  1776. *y_t_n = y_t_1;
  1777. *x_t_f = x_t_2;
  1778. *y_t_f = y_t_2;
  1779. }
  1780. else
  1781. {
  1782. *x_t_n = x_t_2;
  1783. *y_t_n = y_t_2;
  1784. *x_t_f = x_t_1;
  1785. *y_t_f = y_t_1;
  1786. }
  1787. }
  1788. else
  1789. {
  1790. x_o = x_o_2;
  1791. y_o = y_o_2;
  1792. s1 = (x_t_3 - x_1)*(x_t_3 - x_1) + (y_t_3 - y_1)*(y_t_3 - y_1);
  1793. s2 = (x_t_4 - x_1)*(x_t_4 - x_1) + (y_t_4 - y_1)*(y_t_4 - y_1);
  1794. if (s1 < s2)
  1795. {
  1796. *x_t_n = x_t_3;
  1797. *y_t_n = y_t_3;
  1798. *x_t_f = x_t_4;
  1799. *y_t_f = y_t_4;
  1800. }
  1801. else
  1802. {
  1803. *x_t_n = x_t_4;
  1804. *y_t_n = y_t_4;
  1805. *x_t_f = x_t_3;
  1806. *y_t_f = y_t_3;
  1807. }
  1808. }
  1809. return 0;
  1810. }
  1811. int iv::decition::Compute00::getNoAngleNearestPointIndex(GPS_INS rp, const std::vector<GPSData> gpsMap)
  1812. {
  1813. int index = -1;
  1814. int startIndex = 0; // startIndex = 0 则每一次都是遍历整条地图路线
  1815. int endIndex = gpsMap.size() - 1;
  1816. float minDis=20;
  1817. for (int j = startIndex; j < endIndex; j++)
  1818. {
  1819. int i = (j + gpsMap.size()) % gpsMap.size();
  1820. double tmpdis = GetDistance(rp, (*gpsMap[i]));
  1821. if (tmpdis < minDis)
  1822. {
  1823. index = i;
  1824. minDis=tmpdis;
  1825. }
  1826. }
  1827. return index;
  1828. }
  1829. double iv::decition::Compute00::getObsSpeedByFrenet(Point2D obsPoint, double realSecSpeed,const vector<Point2D> gpsTrace, std::vector<iv::GPSData> gpsMap,int pathpoint,GPS_INS nowGps) {
  1830. double obsSpeed = 0 - realSecSpeed;
  1831. double minDis = iv::MaxValue;
  1832. FrenetPoint esr_obs_F_point;
  1833. for (int i = 0; i < 64; i++)
  1834. if ((ServiceCarStatus.obs_radar[i].nomal_y) != 0 && ServiceCarStatus.obs_radar[i].valid)
  1835. {
  1836. double xxx = ServiceCarStatus.obs_radar[i].nomal_x + Esr_Offset;
  1837. double yyy = ServiceCarStatus.obs_radar[i].nomal_y + Esr_Y_Offset;
  1838. if (abs(xxx - obsPoint.x) < 4 && abs(yyy - obsPoint.y) < 2)
  1839. {
  1840. double tmpDis = sqrt((xxx - obsPoint.x) * (xxx - obsPoint.x) + (yyy - obsPoint.y) * (yyy - obsPoint.y));
  1841. if (tmpDis < minDis)
  1842. {
  1843. minDis = tmpDis;
  1844. // esr_obs_F_point = iv::decition::FrenetPlanner::XY2Frenet(xxx, yyy, gpsTrace);
  1845. esr_obs_F_point = iv::decition::FrenetPlanner::getFrenetfromXY(xxx, yyy, gpsTrace,gpsMap,pathpoint,nowGps);
  1846. // obsSpeed = ServiceCarStatus.obs_radar[i].speed_y;
  1847. double speedx=ServiceCarStatus.obs_radar[i].speed_x; //障碍物相对于车辆x轴的速度
  1848. double speedy=ServiceCarStatus.obs_radar[i].speed_y; //障碍物相对于车辆y轴的速度
  1849. double speed_combine = sqrt(speedx*speedx+speedy*speedy); //将x、y轴两个方向的速度求矢量和
  1850. //障碍物的速度方向与道路方向的夹角。用于将速度分解到s方向和d方向。
  1851. //所谓道路方向是指,道路上离障碍物的最近的点沿道路弧线的切线方向。
  1852. double Etheta = esr_obs_F_point.tangent_Ang - atan2(speedy,speedx);
  1853. obsSpeed = speed_combine*cos(Etheta); //由speed_combine分解的s轴方向上的速度
  1854. }
  1855. }
  1856. }
  1857. return obsSpeed;
  1858. }
  1859. int iv::decition::Compute00::getEsrIndexByFrenet(std::vector<Point2D> gpsTrace, FrenetPoint &esrObsPoint, std::vector<iv::GPSData> gpsMap,int pathpoint,GPS_INS nowGps
  1860. ,const double xiuzhengCs){
  1861. double minDistance = numeric_limits<double>::max();
  1862. int minDis_index=-1;
  1863. for(int i=0; i<64; ++i){
  1864. if ((ServiceCarStatus.obs_radar[i].nomal_y) != 0 && (ServiceCarStatus.obs_radar[i].valid)){
  1865. //毫米波在车头,故要加上毫米波与惯导的相对距离。(xxx,yyy)才是障碍物在 车辆坐标系下的坐标。
  1866. double xxx = ServiceCarStatus.obs_radar[i].nomal_x + Esr_Offset;
  1867. double yyy = ServiceCarStatus.obs_radar[i].nomal_y+ Esr_Y_Offset;
  1868. //将毫米波障碍物位置转换到frenet坐标系下
  1869. // esrObsPoint = iv::decition::FrenetPlanner::XY2Frenet(xxx,yyy,gpsTrace);
  1870. esrObsPoint = iv::decition::FrenetPlanner::getFrenetfromXY(xxx,yyy,gpsTrace,gpsMap,pathpoint,nowGps);
  1871. //如果障碍物与道路的横向距离d<=3.0*ServiceCarStatus.msysparam.vehWidth / 4.0,则认为道路上有障碍物。
  1872. //s则可理解为障碍物距离。为障碍物与车辆沿着道路方向的距离,而不是空间上的x或y坐标或者直线距离。
  1873. //minDistance、minDis_index用来统计最近的障碍物信息。
  1874. // if(abs(esrObsPoint.d)<=(3.0*ServiceCarStatus.msysparam.vehWidth / 4.0+DecideGps00().xiuzhengCs)){
  1875. if(abs(esrObsPoint.d)<=(3.0*ServiceCarStatus.msysparam.vehWidth / 4.0+xiuzhengCs)){
  1876. if(esrObsPoint.s<minDistance){
  1877. minDistance = esrObsPoint.s;
  1878. minDis_index = i;
  1879. }
  1880. }
  1881. }
  1882. }
  1883. return minDis_index;
  1884. }
  1885. std::vector<std::vector<iv::GPSData>> gmapsL;
  1886. std::vector<std::vector<iv::GPSData>> gmapsR;