compute_00.cpp 66 KB

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