globalplan.cpp 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965
  1. #include "globalplan.h"
  2. #include "limits"
  3. #include <iostream>
  4. #include <Eigen/Dense>
  5. #include <Eigen/Cholesky>
  6. #include <Eigen/LU>
  7. #include <Eigen/QR>
  8. #include <Eigen/SVD>
  9. #include <QDebug>
  10. #include <QPointF>
  11. using namespace Eigen;
  12. extern "C"
  13. {
  14. #include "dubins.h"
  15. }
  16. static void AddSignalMark(Road * pRoad, int nlane,std::vector<PlanPoint> & xvectorPP);
  17. /**
  18. * @brief GetLineDis 获得点到直线Geometry的距离。
  19. * @param pline
  20. * @param x
  21. * @param y
  22. * @param nearx
  23. * @param neary
  24. * @param nearhead
  25. * @return
  26. */
  27. static double GetLineDis(GeometryLine * pline,const double x,const double y,double & nearx,
  28. double & neary,double & nearhead)
  29. {
  30. double fRtn = 1000.0;
  31. double a1,a2,a3,a4,b1,b2;
  32. double ratio = pline->GetHdg();
  33. while(ratio >= 2.0* M_PI)ratio = ratio-2.0*M_PI;
  34. while(ratio<0)ratio = ratio+2.0*M_PI;
  35. double dis1,dis2,dis3;
  36. double x1,x2,x3,y1,y2,y3;
  37. x1 = pline->GetX();y1=pline->GetY();
  38. if((ratio == 0)||(ratio == M_PI))
  39. {
  40. a1 = 0;a4=0;
  41. a2 = 1;b1= pline->GetY();
  42. a3 = 1;b2= x;
  43. }
  44. else
  45. {
  46. if((ratio == 0.5*M_PI)||(ratio == 1.5*M_PI))
  47. {
  48. a2=0;a3=0;
  49. a1=1,b1=pline->GetX();
  50. a4 = 1;b2 = y;
  51. }
  52. else
  53. {
  54. a1 = tan(ratio) *(-1.0);
  55. a2 = 1;
  56. a3 = tan(ratio+M_PI/2.0)*(-1.0);
  57. a4 = 1;
  58. b1 = a1*pline->GetX() + a2 * pline->GetY();
  59. b2 = a3*x+a4*y;
  60. }
  61. }
  62. y2 = y1 + pline->GetLength() * sin(ratio);
  63. x2 = x1 + pline->GetLength() * cos(ratio);
  64. Eigen::Matrix2d A;
  65. A<<a1,a2,
  66. a3,a4;
  67. Eigen::Vector2d B(b1,b2);
  68. Eigen::Vector2d opoint = A.lu().solve(B);
  69. // std::cout<<opoint<<std::endl;
  70. x3 = opoint(0);
  71. y3 = opoint(1);
  72. dis1 = sqrt(pow(x1-x,2)+pow(y1-y,2));
  73. dis2 = sqrt(pow(x2-x,2)+pow(y2-y,2));
  74. dis3 = sqrt(pow(x3-x,2)+pow(y3-y,2));
  75. // std::cout<<" dis 1 is "<<dis1<<std::endl;
  76. // std::cout<<" dis 2 is "<<dis2<<std::endl;
  77. // std::cout<<" dis 3 is "<<dis3<<std::endl;
  78. if((dis1>pline->GetLength())||(dis2>pline->GetLength())) //Outoff line
  79. {
  80. // std::cout<<" out line"<<std::endl;
  81. if(dis1<dis2)
  82. {
  83. fRtn = dis1;
  84. nearx = x1;neary=y1;nearhead = pline->GetHdg();
  85. }
  86. else
  87. {
  88. fRtn = dis2;
  89. nearx = x2;neary=y2;nearhead = pline->GetHdg();
  90. }
  91. }
  92. else
  93. {
  94. fRtn = dis3;
  95. nearx = x3;neary=y3;nearhead = pline->GetHdg();
  96. }
  97. // std::cout<<"dis is "<<fRtn<<" x is "<<nearx<<" y is "<<neary<<" head is "<<nearhead<<std::endl;
  98. return fRtn;
  99. }
  100. static int getcirclecrosspoint(QPointF startPos, QPointF endPos, QPointF agvPos, double R,QPointF & point1,QPointF & point2 )
  101. {
  102. double m=0;
  103. double k;
  104. double b;
  105. //计算分子
  106. m=startPos.x()-endPos.x();
  107. //求直线的方程
  108. if(0==m)
  109. {
  110. k=100000;
  111. b=startPos.y()-k*startPos.x();
  112. }
  113. else
  114. {
  115. k=(endPos.y()-startPos.y())/(endPos.x()-startPos.x());
  116. b=startPos.y()-k*startPos.x();
  117. }
  118. // qDebug()<<k<<b;
  119. double temp = fabs(k*agvPos.x()-agvPos.y()+b)/sqrt(k*k+b*b);
  120. //求直线与圆的交点 前提是圆需要与直线有交点
  121. if(fabs(k*agvPos.x()-agvPos.y()+b)/sqrt(k*k+b*b)<R)
  122. {
  123. point1.setX((2*agvPos.x()-2*k*(b-agvPos.y())+sqrt(pow((2*k*(b-agvPos.y())-2*agvPos.x()),2)-4*(k*k+1)*((b-agvPos.y())*(b-agvPos.y())+agvPos.x()*agvPos.x()-R*R)))/(2*k*k+2));
  124. point2.setX((2*agvPos.x()-2*k*(b-agvPos.y())-sqrt(pow((2*k*(b-agvPos.y())-2*agvPos.x()),2)-4*(k*k+1)*((b-agvPos.y())*(b-agvPos.y())+agvPos.x()*agvPos.x()-R*R)))/(2*k*k+2));
  125. point1.setY(k*point1.x()+b);
  126. point2.setY(k*point2.x()+b);
  127. return 0;
  128. }
  129. return -1;
  130. }
  131. /**
  132. * @brief CalcHdg
  133. * 计算点0到点1的航向
  134. * @param p0 Point 0
  135. * @param p1 Point 1
  136. **/
  137. static double CalcHdg(QPointF p0, QPointF p1)
  138. {
  139. double x0,y0,x1,y1;
  140. x0 = p0.x();
  141. y0 = p0.y();
  142. x1 = p1.x();
  143. y1 = p1.y();
  144. if(x0 == x1)
  145. {
  146. if(y0 < y1)
  147. {
  148. return M_PI/2.0;
  149. }
  150. else
  151. return M_PI*3.0/2.0;
  152. }
  153. double ratio = (y1-y0)/(x1-x0);
  154. double hdg = atan(ratio);
  155. if(ratio > 0)
  156. {
  157. if(y1 > y0)
  158. {
  159. }
  160. else
  161. {
  162. hdg = hdg + M_PI;
  163. }
  164. }
  165. else
  166. {
  167. if(y1 > y0)
  168. {
  169. hdg = hdg + M_PI;
  170. }
  171. else
  172. {
  173. hdg = hdg + 2.0*M_PI;
  174. }
  175. }
  176. return hdg;
  177. }
  178. static bool pointinarc(GeometryArc * parc,QPointF poingarc,QPointF point1)
  179. {
  180. double hdg = CalcHdg(poingarc,point1);
  181. if(parc->GetCurvature() >0)hdg = hdg + M_PI/2.0;
  182. else hdg = hdg - M_PI/2.0;
  183. if(hdg >= 2.0*M_PI)hdg = hdg - 2.0*M_PI;
  184. if(hdg < 0)hdg = hdg + 2.0*M_PI;
  185. double hdgrange = parc->GetLength()/(1.0/parc->GetCurvature());
  186. double hdgdiff = hdg - parc->GetHdg();
  187. if(hdgrange >= 0 )
  188. {
  189. if(hdgdiff < 0)hdgdiff = hdgdiff + M_PI*2.0;
  190. }
  191. else
  192. {
  193. if(hdgdiff > 0)hdgdiff = hdgdiff - M_PI*2.0;
  194. }
  195. if(fabs(hdgdiff ) < fabs(hdgrange))return true;
  196. return false;
  197. }
  198. static inline double calcpointdis(QPointF p1,QPointF p2)
  199. {
  200. return sqrt(pow(p1.x()-p2.x(),2)+pow(p1.y()-p2.y(),2));
  201. }
  202. /**
  203. * @brief GetArcDis
  204. * 计算点到圆弧的最短距离,首先用点和圆弧中心点的直线与圆的交点,计算点到交点的距离,如果交点在圆弧上,则最短距离是交点之一,否则计算点到圆弧两个端点的距离。
  205. * @param parc pointer to a arc geomery
  206. * @param x current x
  207. * @param y current y
  208. * @param nearx near x
  209. * @param neary near y
  210. * @param nearhead nearhead
  211. **/
  212. static double GetArcDis(GeometryArc * parc,double x,double y,double & nearx,
  213. double & neary,double & nearhead)
  214. {
  215. // double fRtn = 1000.0;
  216. if(parc->GetCurvature() == 0.0)return 1000.0;
  217. double R = fabs(1.0/parc->GetCurvature());
  218. // if(parc->GetX() == 4.8213842690322309e+01)
  219. // {
  220. // int a = 1;
  221. // a = 3;
  222. // }
  223. // if(parc->GetCurvature() == -0.0000110203)
  224. // {
  225. // int a = 1;
  226. // a = 3;
  227. // }
  228. //calculate arc center
  229. double x_center,y_center;
  230. if(parc->GetCurvature() > 0)
  231. {
  232. x_center = parc->GetX() + R * cos(parc->GetHdg() + M_PI/2.0);
  233. y_center = parc->GetY() + R * sin(parc->GetHdg()+ M_PI/2.0);
  234. }
  235. else
  236. {
  237. x_center = parc->GetX() + R * cos(parc->GetHdg() - M_PI/2.0);
  238. y_center = parc->GetY() + R * sin(parc->GetHdg() - M_PI/2.0);
  239. }
  240. double hdgltoa = CalcHdg(QPointF(x,y),QPointF(x_center,y_center));
  241. QPointF arcpoint;
  242. arcpoint.setX(x_center);arcpoint.setY(y_center);
  243. QPointF pointnow;
  244. pointnow.setX(x);pointnow.setY(y);
  245. QPointF point1,point2;
  246. point1.setX(x_center + (R * cos(hdgltoa)));
  247. point1.setY(y_center + (R * sin(hdgltoa)));
  248. point2.setX(x_center + (R * cos(hdgltoa + M_PI)));
  249. point2.setY(y_center + (R * sin(hdgltoa + M_PI)));
  250. //calculat dis
  251. bool bp1inarc,bp2inarc;
  252. bp1inarc =pointinarc(parc,arcpoint,point1);
  253. bp2inarc =pointinarc(parc,arcpoint,point2);
  254. double fdis[4];
  255. fdis[0] = calcpointdis(pointnow,point1);
  256. fdis[1] = calcpointdis(pointnow,point2);
  257. fdis[2] = calcpointdis(pointnow,QPointF(parc->GetX(),parc->GetY()));
  258. QPointF pointend;
  259. double hdgrange = parc->GetLength()*parc->GetCurvature();
  260. double hdgend = parc->GetHdg() + hdgrange;
  261. while(hdgend <0.0)hdgend = hdgend + 2.0 *M_PI;
  262. while(hdgend >= 2.0*M_PI) hdgend = hdgend -2.0*M_PI;
  263. if(parc->GetCurvature() >0)
  264. {
  265. pointend.setX(arcpoint.x() + R*cos(hdgend -M_PI/2.0 ));
  266. pointend.setY(arcpoint.y() + R*sin(hdgend -M_PI/2.0) );
  267. }
  268. else
  269. {
  270. pointend.setX(arcpoint.x() + R*cos(hdgend +M_PI/2.0 ));
  271. pointend.setY(arcpoint.y() + R*sin(hdgend +M_PI/2.0) );
  272. }
  273. fdis[3] = calcpointdis(pointnow,pointend);
  274. int indexmin = -1;
  275. double fdismin = 1000000.0;
  276. if(bp1inarc)
  277. {
  278. indexmin = 0;fdismin = fdis[0];
  279. }
  280. if(bp2inarc)
  281. {
  282. if(indexmin == -1)
  283. {
  284. indexmin = 1;fdismin = fdis[1];
  285. }
  286. else
  287. {
  288. if(fdis[1]<fdismin)
  289. {
  290. indexmin = 1;fdismin = fdis[1];
  291. }
  292. }
  293. }
  294. if(indexmin == -1)
  295. {
  296. indexmin = 2;fdismin = fdis[2];
  297. }
  298. else
  299. {
  300. if(fdis[2]<fdismin)
  301. {
  302. indexmin = 2;fdismin = fdis[2];
  303. }
  304. }
  305. if(fdis[3]<fdismin)
  306. {
  307. indexmin = 3;fdismin = fdis[3];
  308. }
  309. switch (indexmin) {
  310. case 0:
  311. nearx = point1.x();
  312. neary = point1.y();
  313. if(parc->GetCurvature()<0)
  314. {
  315. nearhead = CalcHdg(arcpoint,point1) - M_PI/2.0;
  316. }
  317. else
  318. {
  319. nearhead = CalcHdg(arcpoint,point1) + M_PI/2.0;
  320. }
  321. break;
  322. case 1:
  323. nearx = point2.x();
  324. neary = point2.y();
  325. if(parc->GetCurvature()<0)
  326. {
  327. nearhead = CalcHdg(arcpoint,point2) - M_PI/2.0;
  328. }
  329. else
  330. {
  331. nearhead = CalcHdg(arcpoint,point2) + M_PI/2.0;
  332. }
  333. break;
  334. case 2:
  335. nearx = parc->GetX();
  336. neary = parc->GetY();
  337. nearhead = parc->GetHdg();
  338. break;
  339. case 3:
  340. nearx = pointend.x();
  341. neary = pointend.y();
  342. nearhead = hdgend;
  343. break;
  344. default:
  345. std::cout<<"error in arcdis "<<std::endl;
  346. break;
  347. }
  348. while(nearhead>2.0*M_PI)nearhead = nearhead -2.0*M_PI;
  349. while(nearhead<0)nearhead = nearhead + 2.0*M_PI;
  350. return fdismin;
  351. }
  352. static double GetSpiralDis(GeometrySpiral * pspiral,double xnow,double ynow,double & nearx,
  353. double & neary,double & nearhead)
  354. {
  355. double x,y,hdg;
  356. double s = 0.0;
  357. double fdismin = 100000.0;
  358. double s0 = pspiral->GetS();
  359. while(s<pspiral->GetLength())
  360. {
  361. pspiral->GetCoords(s0+s,x,y,hdg);
  362. s = s+0.1;
  363. double fdis = calcpointdis(QPointF(x,y),QPointF(xnow,ynow));
  364. if(fdis<fdismin)
  365. {
  366. fdismin = fdis;
  367. nearhead = hdg;
  368. nearx = x;
  369. neary = y;
  370. }
  371. }
  372. return fdismin;
  373. }
  374. /**
  375. * @brief GetParamPoly3Dis 获得点到贝塞尔曲线的距离。
  376. * @param parc
  377. * @param xnow
  378. * @param ynow
  379. * @param nearx
  380. * @param neary
  381. * @param nearhead
  382. * @return
  383. */
  384. static double GetParamPoly3Dis(GeometryParamPoly3 * parc,double xnow,double ynow,double & nearx,
  385. double & neary,double & nearhead)
  386. {
  387. double s = 0.1;
  388. double fdismin = 100000.0;
  389. double xold,yold;
  390. xold = parc->GetX();
  391. yold = parc->GetY();
  392. double fdis = calcpointdis(QPointF(parc->GetX(),parc->GetY()),QPointF(xnow,ynow));
  393. if(fdis<fdismin)
  394. {
  395. fdismin = fdis;
  396. nearhead = parc->GetHdg();
  397. nearx = parc->GetX();
  398. neary = parc->GetY();
  399. }
  400. while(s < parc->GetLength())
  401. {
  402. double x, y,xtem,ytem;
  403. xtem = parc->GetuA() + parc->GetuB() * s + parc->GetuC() * s*s + parc->GetuD() * s*s*s;
  404. ytem = parc->GetvA() + parc->GetvB() * s + parc->GetvC() * s*s + parc->GetvD() * s*s*s;
  405. x = xtem*cos(parc->GetHdg()) - ytem * sin(parc->GetHdg()) + parc->GetX();
  406. y = xtem*sin(parc->GetHdg()) + ytem * cos(parc->GetHdg()) + parc->GetY();
  407. double hdg = CalcHdg(QPointF(xold,yold),QPointF(x,y));
  408. double fdis = calcpointdis(QPointF(x,y),QPointF(xnow,ynow));
  409. if(fdis<fdismin)
  410. {
  411. fdismin = fdis;
  412. nearhead = hdg;
  413. nearx = x;
  414. neary = y;
  415. }
  416. xold = x;
  417. yold = y;
  418. s = s+ 0.1;
  419. }
  420. return fdismin;
  421. }
  422. static double GetPoly3Dis(GeometryPoly3 * ppoly,double xnow,double ynow,double & nearx,
  423. double & neary,double & nearhead)
  424. {
  425. double x,y,hdg;
  426. // double s = 0.0;
  427. double fdismin = 100000.0;
  428. // double s0 = ppoly->GetS();
  429. x = ppoly->GetX();
  430. y = ppoly->GetY();
  431. double A,B,C,D;
  432. A = ppoly->GetA();
  433. B = ppoly->GetB();
  434. C = ppoly->GetC();
  435. D = ppoly->GetD();
  436. const double steplim = 0.3;
  437. double du = steplim;
  438. double u = 0;
  439. double v = 0;
  440. double oldx,oldy;
  441. oldx = x;
  442. oldy = y;
  443. double xstart,ystart;
  444. xstart = x;
  445. ystart = y;
  446. double hdgstart = ppoly->GetHdg();
  447. double flen = 0;
  448. u = u+du;
  449. while(flen < ppoly->GetLength())
  450. {
  451. double fdis = 0;
  452. v = A + B*u + C*u*u + D*u*u*u;
  453. x = xstart + u*cos(hdgstart) - v*sin(hdgstart);
  454. y = ystart + u*sin(hdgstart) + v*cos(hdgstart);
  455. fdis = sqrt(pow(x- oldx,2)+pow(y-oldy,2));
  456. if(fdis>(steplim*2.0))du = du/2.0;
  457. flen = flen + fdis;
  458. u = u + du;
  459. hdg = CalcHdg(QPointF(oldx,oldy),QPointF(x,y));
  460. double fdisnow = calcpointdis(QPointF(x,y),QPointF(xnow,ynow));
  461. if(fdisnow<fdismin)
  462. {
  463. fdismin = fdisnow;
  464. nearhead = hdg;
  465. nearx = x;
  466. neary = y;
  467. }
  468. oldx = x;
  469. oldy = y;
  470. }
  471. return fdismin;
  472. }
  473. /**
  474. * @brief GetNearPoint
  475. * 计算点到圆弧的最短距离,首先用点和圆弧中心点的直线与圆的交点,计算点到交点的距离,如果交点在圆弧上,则最短距离是交点之一,否则计算点到圆弧两个端点的距离。
  476. * @param x current x
  477. * @param y current y
  478. * @param pxodr OpenDrive
  479. * @param pObjRoad Road
  480. * @param pgeo Geometry of road
  481. * @param nearx near x
  482. * @param neary near y
  483. * @param nearhead nearhead
  484. * @param nearthresh near threshhold
  485. * @retval if == 0 successfull <0 fail.
  486. **/
  487. int GetNearPoint(const double x,const double y,OpenDrive * pxodr,Road ** pObjRoad,GeometryBlock ** pgeo, double & s,double & nearx,
  488. double & neary,double & nearhead,const double nearthresh)
  489. {
  490. double dismin = std::numeric_limits<double>::infinity();
  491. s = dismin;
  492. int i;
  493. for(i=0;i<pxodr->GetRoadCount();i++)
  494. {
  495. int j;
  496. Road * proad = pxodr->GetRoad(i);
  497. double nx,ny,nh;
  498. for(j=0;j<proad->GetGeometryBlockCount();j++)
  499. {
  500. GeometryBlock * pgb = proad->GetGeometryBlock(j);
  501. double dis;
  502. RoadGeometry * pg;
  503. pg = pgb->GetGeometryAt(0);
  504. switch (pg->GetGeomType()) {
  505. case 0: //line
  506. dis = GetLineDis((GeometryLine *) pg,x,y,nx,ny,nh);
  507. break;
  508. case 1:
  509. dis = GetSpiralDis((GeometrySpiral *)pg,x,y,nx,ny,nh);
  510. break;
  511. case 2: //arc
  512. dis = GetArcDis((GeometryArc *)pg,x,y,nx,ny,nh);
  513. break;
  514. case 3:
  515. dis = GetPoly3Dis((GeometryPoly3 *)pg,x,y,nx,ny,nh);
  516. break;
  517. case 4:
  518. dis = GetParamPoly3Dis((GeometryParamPoly3 *)pg,x,y,nx,ny,nh);
  519. break;
  520. default:
  521. dis = 100000.0;
  522. break;
  523. }
  524. if(dis < dismin)
  525. {
  526. dismin = dis;
  527. nearx = nx;
  528. neary = ny;
  529. nearhead = nh;
  530. s = dis;
  531. *pObjRoad = proad;
  532. *pgeo = pgb;
  533. }
  534. // if(pgb->CheckIfLine())
  535. // {
  536. // GeometryLine * pline = (GeometryLine *)pgb->GetGeometryAt(0);
  537. // double dis = GetLineDis(pline,x,y,nx,ny,nh);
  538. // if(dis < dismin)
  539. // {
  540. // dismin = dis;
  541. // nearx = nx;
  542. // neary = ny;
  543. // nearhead = nh;
  544. // s = dis;
  545. // *pObjRoad = proad;
  546. // *pgeo = pgb;
  547. // }
  548. // }
  549. // else
  550. // {
  551. // GeometryLine * pline1 = (GeometryLine *)pgb->GetGeometryAt(0);
  552. // double dis = GetLineDis(pline1,x,y,nx,ny,nh);
  553. // if(dis < dismin)
  554. // {
  555. // dismin = dis;
  556. // nearx = nx;
  557. // neary = ny;
  558. // nearhead = nh;
  559. // s = dis;
  560. // *pObjRoad = proad;
  561. // *pgeo = pgb;
  562. // }
  563. // GeometryArc * parc = (GeometryArc *)pgb->GetGeometryAt(1);
  564. // dis = GetArcDis(parc,x,y,nx,ny,nh);
  565. // if(dis < dismin)
  566. // {
  567. // dismin = dis;
  568. // nearx = nx;
  569. // neary = ny;
  570. // nearhead = nh;
  571. // s = dis;
  572. // *pObjRoad = proad;
  573. // *pgeo = pgb;
  574. // }
  575. // pline1 = (GeometryLine *)pgb->GetGeometryAt(2);
  576. // dis = GetLineDis(pline1,x,y,nx,ny,nh);
  577. // if(dis < dismin)
  578. // {
  579. // dismin = dis;
  580. // nearx = nx;
  581. // neary = ny;
  582. // nearhead = nh;
  583. // s = dis;
  584. // *pObjRoad = proad;
  585. // *pgeo = pgb;
  586. // }
  587. // }
  588. }
  589. }
  590. if(s > nearthresh)return -1;
  591. return 0;
  592. }
  593. int GetNearPointWithHead(const double x,const double y,const double hdg,OpenDrive * pxodr,Road ** pObjRoad,GeometryBlock ** pgeo, double & s,double & nearx,
  594. double & neary,double & nearhead,const double nearthresh)
  595. {
  596. double dismin = std::numeric_limits<double>::infinity();
  597. s = dismin;
  598. int i;
  599. std::vector<Road * > xvectorroad;
  600. std::vector<double > xvectordismin;
  601. std::vector<double > xvecotrnearx;
  602. std::vector<double > xvectorneary;
  603. std::vector<double > xvectornearhead;
  604. std::vector<double > xvectors;
  605. std::vector<GeometryBlock *> xvectorgeob;
  606. double VECTORTHRESH = 5;
  607. for(i=0;i<pxodr->GetRoadCount();i++)
  608. {
  609. int j;
  610. Road * proad = pxodr->GetRoad(i);
  611. double nx,ny,nh;
  612. bool bchange = false;
  613. double localdismin = std::numeric_limits<double>::infinity();
  614. double localnearx = 0;
  615. double localneary = 0;
  616. double localnearhead = 0;
  617. double locals = 0;
  618. GeometryBlock * pgeolocal;
  619. for(j=0;j<proad->GetGeometryBlockCount();j++)
  620. {
  621. GeometryBlock * pgb = proad->GetGeometryBlock(j);
  622. double dis;
  623. RoadGeometry * pg;
  624. pg = pgb->GetGeometryAt(0);
  625. switch (pg->GetGeomType()) {
  626. case 0: //line
  627. dis = GetLineDis((GeometryLine *) pg,x,y,nx,ny,nh);
  628. break;
  629. case 1:
  630. dis = GetSpiralDis((GeometrySpiral *)pg,x,y,nx,ny,nh);
  631. break;
  632. case 2: //arc
  633. dis = GetArcDis((GeometryArc *)pg,x,y,nx,ny,nh);
  634. break;
  635. case 3:
  636. dis = 100000.0;
  637. break;
  638. case 4:
  639. dis = GetParamPoly3Dis((GeometryParamPoly3 *)pg,x,y,nx,ny,nh);
  640. break;
  641. default:
  642. dis = 100000.0;
  643. break;
  644. }
  645. if(dis < dismin)
  646. {
  647. dismin = dis;
  648. nearx = nx;
  649. neary = ny;
  650. nearhead = nh;
  651. s = dis;
  652. *pObjRoad = proad;
  653. *pgeo = pgb;
  654. }
  655. if((dis<VECTORTHRESH) &&(dis<localdismin))
  656. {
  657. localdismin = dis;
  658. localnearx = nx;
  659. localneary = ny;
  660. localnearhead = nh;
  661. locals = dis;
  662. pgeolocal = pgb;
  663. bchange = true;
  664. }
  665. }
  666. if(bchange)
  667. {
  668. xvectorroad.push_back(proad);
  669. xvecotrnearx.push_back(localnearx);
  670. xvectorneary.push_back(localneary);
  671. xvectordismin.push_back(localdismin);
  672. xvectors.push_back(locals);
  673. xvectorgeob.push_back(pgeolocal);
  674. xvectornearhead.push_back(localnearhead);
  675. }
  676. }
  677. if(s > nearthresh)return -1;
  678. if((*pObjRoad)->GetLaneSectionCount()>0)
  679. {
  680. LaneSection * pLS = (*pObjRoad)->GetLaneSection(0);
  681. if((*pObjRoad)->GetLaneSection(0)->GetLeftLaneCount()&&(*pObjRoad)->GetLaneSection(0)->GetRightLaneCount()>0)
  682. {
  683. return 0;
  684. }
  685. else
  686. {
  687. double headdiff = hdg - nearhead;
  688. while(headdiff < 2.0*M_PI) headdiff = headdiff + 2.0*M_PI;
  689. while(headdiff >= 2.0*M_PI)headdiff = headdiff - 2.0*M_PI;
  690. if(((headdiff <M_PI/2.0)||(headdiff > M_PI*3.0/2.0))&&(pLS->GetRightLaneCount()>0))
  691. {
  692. return 0;
  693. }
  694. else
  695. {
  696. if((headdiff >=M_PI/2.0)&&(headdiff <= M_PI*3.0/2.0)&&(pLS->GetLeftLaneCount()>0))
  697. {
  698. return 0;
  699. }
  700. else
  701. {
  702. bool bHaveSame = false;
  703. for(i=0;i<xvectorroad.size();i++)
  704. {
  705. if(xvectorroad[i]->GetLaneSectionCount()<1)continue;
  706. bool bNeedFind = false;
  707. if(bHaveSame == false)bNeedFind = true;
  708. else
  709. {
  710. if(xvectordismin[i]<dismin)bNeedFind = true;
  711. }
  712. if(bNeedFind)
  713. {
  714. double fdiff = hdg - xvectornearhead[i];
  715. while(fdiff < 2.0*M_PI) fdiff = fdiff + 2.0*M_PI;
  716. while(fdiff >= 2.0*M_PI)fdiff = fdiff - 2.0*M_PI;
  717. bool bUse = false;
  718. LaneSection * pLS = xvectorroad[i]->GetLaneSection(0);
  719. if(((fdiff <M_PI/2.0)||(fdiff > M_PI*3.0/2.0))&&(pLS->GetRightLaneCount()>0))
  720. {
  721. bUse = true;
  722. }
  723. if(((fdiff >=M_PI/2.0)&&(fdiff <= M_PI*3.0/2.0))&&(pLS->GetLeftLaneCount()>0))
  724. {
  725. bUse = true;
  726. }
  727. if(bUse)
  728. {
  729. dismin = xvectordismin[i];
  730. nearx = xvecotrnearx[i];
  731. neary = xvectorneary[i];
  732. nearhead = xvectornearhead[i];
  733. s = xvectors[i];
  734. *pObjRoad = xvectorroad[i];
  735. *pgeo = xvectorgeob[i];
  736. bHaveSame = true;
  737. std::cout<<"change road. "<<std::endl;
  738. }
  739. }
  740. }
  741. }
  742. }
  743. }
  744. }
  745. return 0;
  746. }
  747. /**
  748. * @brief SelectRoadLeftRight
  749. * 选择左侧道路或右侧道路
  750. * 1.选择角度差小于90度的道路一侧,即同侧道路
  751. * 2.单行路,选择存在的那一侧道路。
  752. * @param pRoad 道路
  753. * @param head1 车的航向或目标点的航向
  754. * @param head_road 目标点的航向
  755. * @retval 1 left 2 right
  756. **/
  757. static int SelectRoadLeftRight(Road * pRoad,const double head1,const double head_road)
  758. {
  759. int nrtn = 2;
  760. double headdiff = head1 - head_road;
  761. while(headdiff < 2.0*M_PI) headdiff = headdiff + 2.0*M_PI;
  762. while(headdiff >= 2.0*M_PI)headdiff = headdiff - 2.0*M_PI;
  763. bool bSel = false;
  764. if((headdiff >=M_PI/2.0)&&(headdiff <= M_PI*3.0/2.0)) //if diff is
  765. {
  766. if(pRoad->GetLaneSection(0)->GetLeftLaneCount()>0)
  767. {
  768. nrtn = 1;
  769. bSel = true;
  770. }
  771. }
  772. else
  773. {
  774. if(pRoad->GetLaneSection(0)->GetRightLaneCount()>0)
  775. {
  776. nrtn = 2;
  777. bSel = true;
  778. }
  779. }
  780. if(bSel == false)
  781. {
  782. if(pRoad->GetLaneSection(0)->GetLeftLaneCount() >0)
  783. {
  784. nrtn = 1;
  785. }
  786. else
  787. {
  788. nrtn = 2;
  789. }
  790. }
  791. return nrtn;
  792. }
  793. //static double getlinereldis(GeometryLine * pline,double x,double y)
  794. //{
  795. // double x0,y0;
  796. // x0 = pline->GetX();
  797. // y0 = pline->GetY();
  798. // double dis = sqrt(pow(x-x0,2) + pow(y-y0,2));
  799. // if(dis > pline->GetS())
  800. // {
  801. // std::cout<<"getlinereldis exceed s S is "<<pline->GetS()<<" dis is "<<dis<<std::endl;
  802. // return dis;
  803. // }
  804. // return dis;
  805. //}
  806. //static double getarcreldis(GeometryArc * parc,double x,double y)
  807. //{
  808. // double x0,y0;
  809. // x0 = parc->GetX();
  810. // y0 = parc->GetY();
  811. // double dis = sqrt(pow(x-x0,2) + pow(y-y0,2));
  812. // double R = fabs(1.0/parc->GetCurvature());
  813. // double ang = 2.0* asin(dis/(2.0*R));
  814. // double frtn = ang * R;
  815. // return frtn;
  816. //}
  817. //static double getparampoly3reldis(GeometryParamPoly3 *parc, double xnow, double ynow)
  818. //{
  819. // double s = 0.1;
  820. // double xold,yold;
  821. // xold = parc->GetX();
  822. // yold = parc->GetY();
  823. // while(s < parc->GetLength())
  824. // {
  825. // double x, y,xtem,ytem;
  826. // xtem = parc->GetuA() + parc->GetuB() * s + parc->GetuC() * s*s + parc->GetuD() * s*s*s;
  827. // ytem = parc->GetvA() + parc->GetvB() * s + parc->GetvC() * s*s + parc->GetvD() * s*s*s;
  828. // x = xtem*cos(parc->GetHdg()) - ytem * sin(parc->GetHdg()) + parc->GetX();
  829. // y = xtem*sin(parc->GetHdg()) + ytem * cos(parc->GetHdg()) + parc->GetY();
  830. // if(sqrt(pow(xnow - x,2) + pow(ynow -y,2))<0.3)
  831. // {
  832. // break;
  833. // }
  834. // xold = x;
  835. // yold = y;
  836. // s = s+ 0.1;
  837. // }
  838. // return s;
  839. //}
  840. //static double getreldis(RoadGeometry * prg,double x,double y)
  841. //{
  842. // int ngeotype = prg->GetGeomType();
  843. // double frtn = 0;
  844. // switch (ngeotype) {
  845. // case 0:
  846. // frtn = getlinereldis((GeometryLine *)prg,x,y);
  847. // break;
  848. // case 1:
  849. // break;
  850. // case 2:
  851. // frtn = getarcreldis((GeometryArc *)prg,x,y);
  852. // break;
  853. // case 3:
  854. // break;
  855. // case 4:
  856. // frtn = getparampoly3reldis((GeometryParamPoly3 *)prg,x,y);
  857. // break;
  858. // default:
  859. // break;
  860. // }
  861. // return frtn;
  862. //}
  863. //static double getposinroad(Road * pRoad,GeometryBlock * pgeob,double x,double y)
  864. //{
  865. // RoadGeometry* prg = pgeob->GetGeometryAt(0);
  866. // double s1 = prg->GetS();
  867. // double srtn = s1;
  868. // return s1 + getreldis(prg,x,y);
  869. //}
  870. static std::vector<PlanPoint> getlinepoint(GeometryLine * pline)
  871. {
  872. std::vector<PlanPoint> xvectorPP;
  873. int i;
  874. double s = pline->GetLength();
  875. int nsize = s/0.1;
  876. for(i=0;i<nsize;i++)
  877. {
  878. double x,y;
  879. x = pline->GetX() + i *0.1 * cos(pline->GetHdg());
  880. y = pline->GetY() + i *0.1 * sin(pline->GetHdg());
  881. PlanPoint pp;
  882. pp.x = x;
  883. pp.y = y;
  884. pp.dis = i*0.1;
  885. pp.hdg = pline->GetHdg();
  886. pp.mS = pline->GetS() + i*0.1;
  887. xvectorPP.push_back(pp);
  888. }
  889. return xvectorPP;
  890. }
  891. static std::vector<PlanPoint> getarcpoint(GeometryArc * parc)
  892. {
  893. std::vector<PlanPoint> xvectorPP;
  894. // double fRtn = 1000.0;
  895. if(parc->GetCurvature() == 0.0)return xvectorPP;
  896. double R = fabs(1.0/parc->GetCurvature());
  897. //calculate arc center
  898. double x_center = parc->GetX() + (1.0/parc->GetCurvature()) * cos(parc->GetHdg() + M_PI/2.0);
  899. double y_center = parc->GetY() + (1.0/parc->GetCurvature()) * sin(parc->GetHdg()+ M_PI/2.0);
  900. double arcdiff = 0.1/R;
  901. int nsize = parc->GetLength()/0.1;
  902. int i;
  903. for(i=0;i<nsize;i++)
  904. {
  905. double x,y;
  906. PlanPoint pp;
  907. if(parc->GetCurvature() > 0)
  908. {
  909. x = x_center + R * cos(parc->GetHdg() + i*arcdiff - M_PI/2.0);
  910. y = y_center + R * sin(parc->GetHdg() + i*arcdiff - M_PI/2.0);
  911. pp.hdg = parc->GetHdg() + i*arcdiff;
  912. }
  913. else
  914. {
  915. x = x_center + R * cos(parc->GetHdg() -i*arcdiff + M_PI/2.0);
  916. y = y_center + R * sin(parc->GetHdg() -i*arcdiff + M_PI/2.0);
  917. pp.hdg = parc->GetHdg() - i*arcdiff;
  918. }
  919. pp.x = x;
  920. pp.y = y;
  921. pp.dis = i*0.1;
  922. pp.mS = parc->GetS() + i*0.1;
  923. xvectorPP.push_back(pp);
  924. }
  925. return xvectorPP;
  926. }
  927. static std::vector<PlanPoint> getspiralpoint(GeometrySpiral * pspiral)
  928. {
  929. double x,y,hdg;
  930. double s = 0.0;
  931. double s0 = pspiral->GetS();
  932. std::vector<PlanPoint> xvectorPP;
  933. PlanPoint pp;
  934. while(s<pspiral->GetLength())
  935. {
  936. pspiral->GetCoords(s0+s,x,y,hdg);
  937. pp.x = x;
  938. pp.y = y;
  939. pp.hdg = hdg;
  940. pp.dis = s;
  941. pp.mS = pspiral->GetS() + s;
  942. xvectorPP.push_back(pp);
  943. s = s+0.1;
  944. }
  945. return xvectorPP;
  946. }
  947. static std::vector<PlanPoint> getpoly3dpoint(GeometryPoly3 * ppoly)
  948. {
  949. double x,y;
  950. x = ppoly->GetX();
  951. y = ppoly->GetY();
  952. double A,B,C,D;
  953. A = ppoly->GetA();
  954. B = ppoly->GetB();
  955. C = ppoly->GetC();
  956. D = ppoly->GetD();
  957. const double steplim = 0.1;
  958. double du = steplim;
  959. double u = 0;
  960. double v = 0;
  961. double oldx,oldy;
  962. oldx = x;
  963. oldy = y;
  964. double xstart,ystart;
  965. xstart = x;
  966. ystart = y;
  967. double hdgstart = ppoly->GetHdg();
  968. double flen = 0;
  969. std::vector<PlanPoint> xvectorPP;
  970. PlanPoint pp;
  971. pp.x = xstart;
  972. pp.y = ystart;
  973. pp.hdg = hdgstart;
  974. pp.dis = 0;
  975. pp.mS = ppoly->GetS();
  976. xvectorPP.push_back(pp);
  977. while(flen < ppoly->GetLength())
  978. {
  979. double fdis = 0;
  980. v = A + B*u + C*u*u + D*u*u*u;
  981. x = xstart + u*cos(hdgstart) - v*sin(hdgstart);
  982. y = ystart + u*sin(hdgstart) + v*cos(hdgstart);
  983. fdis = sqrt(pow(x- oldx,2)+pow(y-oldy,2));
  984. double hdg = CalcHdg(QPointF(oldx,oldy),QPointF(x,y));
  985. oldx = x;
  986. oldy = y;
  987. if(fdis>(steplim*2.0))du = du/2.0;
  988. flen = flen + fdis;
  989. u = u + du;
  990. pp.x = x;
  991. pp.y = y;
  992. pp.hdg = hdg;
  993. // s = s+ dt;
  994. pp.dis = flen;;
  995. pp.mS = ppoly->GetS() + flen;
  996. xvectorPP.push_back(pp);
  997. }
  998. return xvectorPP;
  999. }
  1000. static std::vector<PlanPoint> getparampoly3dpoint(GeometryParamPoly3 * parc)
  1001. {
  1002. double s = 0.1;
  1003. std::vector<PlanPoint> xvectorPP;
  1004. PlanPoint pp;
  1005. double xold,yold;
  1006. xold = parc->GetX();
  1007. yold = parc->GetY();
  1008. double hdg0 = parc->GetHdg();
  1009. pp.x = xold;
  1010. pp.y = yold;
  1011. pp.hdg = hdg0;
  1012. pp.dis = 0;
  1013. xvectorPP.push_back(pp);
  1014. double dt = 1.0;
  1015. double tcount = parc->GetLength()/0.1;
  1016. if(tcount > 0)
  1017. {
  1018. dt = 1.0/tcount;
  1019. }
  1020. double t;
  1021. s = dt;
  1022. s = 0.1;
  1023. double ua,ub,uc,ud,va,vb,vc,vd;
  1024. ua = parc->GetuA();ub= parc->GetuB();uc= parc->GetuC();ud = parc->GetuD();
  1025. va = parc->GetvA();vb= parc->GetvB();vc= parc->GetvC();vd = parc->GetvD();
  1026. double a = parc->GetS();
  1027. while(s < parc->GetLength())
  1028. // while(s<1.0)
  1029. {
  1030. double len = parc->GetLength();
  1031. double x, y,xtem,ytem;
  1032. // xtem = parc->GetuA() + parc->GetuB() * s * len + parc->GetuC() * s*s *pow(len,2) + parc->GetuD() * s*s*s *pow(len,3);
  1033. // ytem = parc->GetvA() + parc->GetvB() * s* len + parc->GetvC() * s*s *pow(len,2) + parc->GetvD() * s*s*s *pow(len,3);
  1034. xtem = ua + ub * s + uc * s*s + ud * s*s*s ;
  1035. ytem = va + vb * s + vc * s*s + vd * s*s*s ;
  1036. x = xtem*cos(hdg0) - ytem * sin(hdg0) + parc->GetX();
  1037. y = xtem*sin(hdg0) + ytem * cos(hdg0) + parc->GetY();
  1038. // x= xtem + parc->GetX();
  1039. // y = ytem + parc->GetY();
  1040. // x = xtem*cos(parc->GetHdg()) + ytem * sin(parc->GetHdg()) + parc->GetX();
  1041. // y = -xtem*sin(parc->GetHdg()) + ytem * cos(parc->GetHdg()) + parc->GetY();
  1042. double hdg = CalcHdg(QPointF(xold,yold),QPointF(x,y));
  1043. pp.x = x;
  1044. pp.y = y;
  1045. pp.hdg = hdg;
  1046. double disx = sqrt(pow(x-xold,2)+ pow(y-yold,2));
  1047. /* if(disx > 0.1)s = s+ disx;
  1048. else s = s+ 0.5*/;
  1049. s = s+ 0.1;
  1050. // s = s+ sqrt(pow(x-xold,2)+ pow(y-yold,2));
  1051. xold = x;
  1052. yold = y;
  1053. // s = s+ dt;
  1054. pp.dis = pp.dis + disx;;
  1055. pp.mS = parc->GetS() + s;
  1056. xvectorPP.push_back(pp);
  1057. // std::cout<<" s is "<<s<<std::endl;
  1058. }
  1059. return xvectorPP;
  1060. }
  1061. std::vector<PlanPoint> GetPoint(Road * pRoad)
  1062. {
  1063. std::vector<PlanPoint> xvectorPPS;
  1064. double s = 0;
  1065. int i;
  1066. for(i=0;i<pRoad->GetGeometryBlockCount();i++)
  1067. {
  1068. GeometryBlock * pgb = pRoad->GetGeometryBlock(i);
  1069. RoadGeometry * prg = pgb->GetGeometryAt(0);
  1070. std::vector<PlanPoint> xvectorPP;
  1071. double s1 = prg->GetLength();
  1072. switch (prg->GetGeomType()) {
  1073. case 0:
  1074. xvectorPP = getlinepoint((GeometryLine *)prg);
  1075. break;
  1076. case 1:
  1077. xvectorPP = getspiralpoint((GeometrySpiral *)prg);
  1078. break;
  1079. case 2:
  1080. xvectorPP = getarcpoint((GeometryArc *)prg);
  1081. break;
  1082. case 3:
  1083. xvectorPP = getpoly3dpoint((GeometryPoly3 *)prg);
  1084. break;
  1085. case 4:
  1086. xvectorPP = getparampoly3dpoint((GeometryParamPoly3 *)prg);
  1087. break;
  1088. default:
  1089. break;
  1090. }
  1091. int j;
  1092. for(j=0;j<xvectorPP.size();j++)
  1093. {
  1094. PlanPoint pp = xvectorPP.at(j);
  1095. pp.dis = s + pp.dis;
  1096. pp.nRoadID = atoi(pRoad->GetRoadId().data());
  1097. xvectorPPS.push_back(pp);
  1098. }
  1099. s = s+ s1;
  1100. }
  1101. return xvectorPPS;
  1102. }
  1103. int indexinroadpoint(std::vector<PlanPoint> xvectorPP,double x,double y)
  1104. {
  1105. int nrtn = 0;
  1106. int i;
  1107. int dismin = 1000;
  1108. for(i=0;i<xvectorPP.size();i++)
  1109. {
  1110. double dis = sqrt(pow(xvectorPP.at(i).x - x,2) + pow(xvectorPP.at(i).y -y,2));
  1111. if(dis <dismin)
  1112. {
  1113. dismin = dis;
  1114. nrtn = i;
  1115. }
  1116. }
  1117. if(dismin > 10.0)
  1118. {
  1119. std::cout<<"indexinroadpoint near point is error. dis is "<<dismin<<std::endl;
  1120. }
  1121. return nrtn;
  1122. }
  1123. double getwidth(Road * pRoad, int nlane)
  1124. {
  1125. double frtn = 0;
  1126. int i;
  1127. int nlanecount = pRoad->GetLaneSection(0)->GetLaneCount();
  1128. for(i=0;i<nlanecount;i++)
  1129. {
  1130. if(nlane == pRoad->GetLaneSection(0)->GetLane(i)->GetId())
  1131. {
  1132. LaneWidth* pLW = pRoad->GetLaneSection(0)->GetLane(i)->GetLaneWidth(0);
  1133. if(pLW != 0)
  1134. {
  1135. frtn = pRoad->GetLaneSection(0)->GetLane(i)->GetLaneWidth(0)->GetA();
  1136. break;
  1137. }
  1138. }
  1139. }
  1140. return frtn;
  1141. }
  1142. double getoff(Road * pRoad,int nlane)
  1143. {
  1144. double off = getwidth(pRoad,nlane)/2.0;
  1145. if(nlane < 0)off = off * (-1.0);
  1146. // int nlanecount = pRoad->GetLaneSection(0)->GetLaneCount();
  1147. int i;
  1148. if(nlane > 0)
  1149. off = off + getwidth(pRoad,0)/2.0;
  1150. else
  1151. off = off - getwidth(pRoad,0)/2.0;
  1152. if(nlane > 0)
  1153. {
  1154. for(i=1;i<nlane;i++)
  1155. {
  1156. off = off + getwidth(pRoad,i);
  1157. }
  1158. }
  1159. else
  1160. {
  1161. for(i=-1;i>nlane;i--)
  1162. {
  1163. off = off - getwidth(pRoad,i);
  1164. }
  1165. }
  1166. // return 0;
  1167. return off;
  1168. }
  1169. namespace iv {
  1170. struct lanewidthabcd
  1171. {
  1172. int nlane;
  1173. double A;
  1174. double B;
  1175. double C;
  1176. double D;
  1177. };
  1178. }
  1179. double getwidth(Road * pRoad, int nlane,std::vector<iv::lanewidthabcd> xvectorlwa,double s)
  1180. {
  1181. double frtn = 0;
  1182. int i;
  1183. int nlanecount = xvectorlwa.size();
  1184. for(i=0;i<nlanecount;i++)
  1185. {
  1186. if(nlane == xvectorlwa.at(i).nlane)
  1187. {
  1188. iv::lanewidthabcd * plwa = &xvectorlwa.at(i);
  1189. frtn = plwa->A + plwa->B*s + plwa->C *s*s + plwa->D *s*s*s;
  1190. break;
  1191. }
  1192. }
  1193. return frtn;
  1194. }
  1195. std::vector<iv::lanewidthabcd> GetLaneWidthABCD(Road * pRoad)
  1196. {
  1197. std::vector<iv::lanewidthabcd> xvectorlwa;
  1198. if(pRoad->GetLaneSectionCount()<1)return xvectorlwa;
  1199. int i;
  1200. LaneSection * pLS = pRoad->GetLaneSection(0);
  1201. // if(pRoad->GetLaneSectionCount() > 1)
  1202. // {
  1203. // for(i=0;i<(pRoad->GetLaneSectionCount()-1);i++)
  1204. // {
  1205. // if(s>pRoad->GetLaneSection(i+1)->GetS())
  1206. // {
  1207. // pLS = pRoad->GetLaneSection(i+1);
  1208. // }
  1209. // else
  1210. // {
  1211. // break;
  1212. // }
  1213. // }
  1214. // }
  1215. int nlanecount = pLS->GetLaneCount();
  1216. for(i=0;i<nlanecount;i++)
  1217. {
  1218. iv::lanewidthabcd xlwa;
  1219. LaneWidth* pLW = pLS->GetLane(i)->GetLaneWidth(0);
  1220. xlwa.nlane = pLS->GetLane(i)->GetId();
  1221. if(pLW != 0)
  1222. {
  1223. xlwa.A = pLW->GetA();
  1224. xlwa.B = pLW->GetB();
  1225. xlwa.C = pLW->GetC();
  1226. xlwa.D = pLW->GetD();
  1227. }
  1228. else
  1229. {
  1230. xlwa.A = 0;
  1231. xlwa.B = 0;
  1232. xlwa.C = 0;
  1233. xlwa.D = 0;
  1234. }
  1235. // if(strncmp(pLS->GetLane(i)->GetType().data(),"driving",256) == 0)
  1236. xvectorlwa.push_back(xlwa); //Calculate Road Width, not driving need add in.
  1237. }
  1238. return xvectorlwa;
  1239. }
  1240. inline double getoff(int nlane,double s,std::vector<iv::lanewidthabcd> xvectorLWA,std::vector<int> xvectorIndex)
  1241. {
  1242. int i;
  1243. double off = 0;
  1244. double a,b,c,d;
  1245. if(xvectorIndex.size() == 0)return off;
  1246. for(i=0;i<(xvectorIndex.size()-1);i++)
  1247. {
  1248. a = xvectorLWA[xvectorIndex[i]].A;
  1249. b = xvectorLWA[xvectorIndex[i]].B;
  1250. c = xvectorLWA[xvectorIndex[i]].C;
  1251. d = xvectorLWA[xvectorIndex[i]].D;
  1252. if(xvectorLWA[xvectorIndex[i]].nlane != 0)
  1253. {
  1254. off = off + a + b*s + c*s*s + d*s*s*s;
  1255. }
  1256. else
  1257. {
  1258. off = off + (a + b*s + c*s*s + d*s*s*s)/2.0;
  1259. }
  1260. }
  1261. i = xvectorIndex.size()-1;
  1262. a = xvectorLWA[xvectorIndex[i]].A;
  1263. b = xvectorLWA[xvectorIndex[i]].B;
  1264. c = xvectorLWA[xvectorIndex[i]].C;
  1265. d = xvectorLWA[xvectorIndex[i]].D;
  1266. off = off + (a + b*s + c*s*s + d*s*s*s)/2.0;
  1267. if(nlane < 0) off = off*(-1.0);
  1268. std::cout<<"s is "<<s<<std::endl;
  1269. std::cout<<" off is "<<off<<std::endl;
  1270. return off;
  1271. }
  1272. double GetRoadWidth(std::vector<iv::lanewidthabcd> xvectorLWA,int nlane,double s)
  1273. {
  1274. double fwidth = 0;
  1275. int i;
  1276. double a,b,c,d;
  1277. int nsize = xvectorLWA.size();
  1278. for(i=0;i<nsize;i++)
  1279. {
  1280. if(nlane*(xvectorLWA[i].nlane)>0)
  1281. {
  1282. a = xvectorLWA[i].A;
  1283. b = xvectorLWA[i].B;
  1284. c = xvectorLWA[i].C;
  1285. d = xvectorLWA[i].D;
  1286. fwidth = fwidth + a + b*s +c*s*s + d*s*s*s;
  1287. }
  1288. }
  1289. return fwidth;
  1290. }
  1291. int GetLaneOriTotal(Road * pRoad, int nlane,double s,int & nori, int & ntotal,double & fSpeed)
  1292. {
  1293. if(pRoad->GetLaneSectionCount() < 1)return -1;
  1294. LaneSection * pLS = pRoad->GetLaneSection(0);
  1295. int i;
  1296. if(pRoad->GetLaneSectionCount() > 1)
  1297. {
  1298. for(i=0;i<(pRoad->GetLaneSectionCount()-1);i++)
  1299. {
  1300. if(s>pRoad->GetLaneSection(i+1)->GetS())
  1301. {
  1302. pLS = pRoad->GetLaneSection(i+1);
  1303. }
  1304. else
  1305. {
  1306. break;
  1307. }
  1308. }
  1309. }
  1310. nori = 0;
  1311. ntotal = 0;
  1312. fSpeed = -1; //if -1 no speedlimit for map
  1313. int nlanecount = pLS->GetLaneCount();
  1314. for(i=0;i<nlanecount;i++)
  1315. {
  1316. int nlaneid = pLS->GetLane(i)->GetId();
  1317. if(nlaneid == nlane)
  1318. {
  1319. Lane * pLane = pLS->GetLane(i);
  1320. if(pLane->GetLaneSpeedCount() > 0)
  1321. {
  1322. LaneSpeed * pLSpeed = pLane->GetLaneSpeed(0);
  1323. int j;
  1324. int nspeedcount = pLane->GetLaneSpeedCount();
  1325. for(j=0;j<(nspeedcount -1);j++)
  1326. {
  1327. if((s-pLS->GetS())>=pLane->GetLaneSpeed(j+1)->GetS())
  1328. {
  1329. pLSpeed = pLane->GetLaneSpeed(j+1);
  1330. }
  1331. else
  1332. {
  1333. break;
  1334. }
  1335. }
  1336. if(pLSpeed->GetS()<=(s-pLS->GetS()))fSpeed = pLSpeed->GetMax();
  1337. }
  1338. }
  1339. if(nlane<0)
  1340. {
  1341. if(nlaneid < 0)
  1342. {
  1343. if(strncmp(pLS->GetLane(i)->GetType().data(),"driving",256) == 0)
  1344. {
  1345. ntotal++;
  1346. if(nlaneid<nlane)nori++;
  1347. }
  1348. }
  1349. }
  1350. else
  1351. {
  1352. if(nlaneid > 0)
  1353. {
  1354. if(strncmp(pLS->GetLane(i)->GetType().data(),"driving",256) == 0)
  1355. {
  1356. ntotal++;
  1357. if(nlaneid > nlane)nori++;
  1358. }
  1359. }
  1360. }
  1361. }
  1362. return 0;
  1363. }
  1364. std::vector<int> GetLWIndex(std::vector<iv::lanewidthabcd> xvectorLWA,int nlane)
  1365. {
  1366. std::vector<int> xvectorindex;
  1367. int i;
  1368. if(nlane >= 0)
  1369. {
  1370. for(i=0;i<=nlane;i++)
  1371. {
  1372. int j;
  1373. int nsize = xvectorLWA.size();
  1374. for(j=0;j<nsize;j++)
  1375. {
  1376. if(i == xvectorLWA.at(j).nlane )
  1377. {
  1378. xvectorindex.push_back(j);
  1379. break;
  1380. }
  1381. }
  1382. }
  1383. }
  1384. else
  1385. {
  1386. for(i=0;i>=nlane;i--)
  1387. {
  1388. int j;
  1389. int nsize = xvectorLWA.size();
  1390. for(j=0;j<nsize;j++)
  1391. {
  1392. if(i == xvectorLWA.at(j).nlane )
  1393. {
  1394. xvectorindex.push_back(j);
  1395. break;
  1396. }
  1397. }
  1398. }
  1399. }
  1400. return xvectorindex;
  1401. }
  1402. void CalcInLaneAvoid(pathsection xps,std::vector<PlanPoint> & xvectorPP,const double fvehiclewidth,
  1403. const int nchang1,const int nchang2,const int nchangpoint)
  1404. {
  1405. if(xvectorPP.size()<2)return;
  1406. bool bInlaneavoid = false;
  1407. int i;
  1408. if((xps.mbStartToMainChange == false) && (xps.mbMainToEndChange == false))
  1409. {
  1410. if(xps.mpRoad->GetRoadLength()<30)
  1411. {
  1412. double hdgdiff = xvectorPP.at(xvectorPP.size()-1).hdg - xvectorPP.at(0).hdg;
  1413. if(hdgdiff<0)hdgdiff = hdgdiff + 2.0*M_PI;
  1414. if(hdgdiff>(M_PI/3.0)&&(hdgdiff<(5.0*M_PI/3.0)))
  1415. bInlaneavoid = false;
  1416. else
  1417. bInlaneavoid = true;
  1418. }
  1419. else
  1420. {
  1421. bInlaneavoid = true;
  1422. }
  1423. }
  1424. else
  1425. {
  1426. if(xps.mpRoad->GetRoadLength()>100)bInlaneavoid = true;
  1427. }
  1428. if(bInlaneavoid == false)
  1429. {
  1430. int nvpsize = xvectorPP.size();
  1431. for(i=0;i<nvpsize;i++)
  1432. {
  1433. xvectorPP.at(i).bInlaneAvoid = false;
  1434. xvectorPP.at(i).mx_left = xvectorPP.at(i).x;
  1435. xvectorPP.at(i).my_left = xvectorPP.at(i).y;
  1436. xvectorPP.at(i).mx_right = xvectorPP.at(i).x;
  1437. xvectorPP.at(i).my_right = xvectorPP.at(i).y;
  1438. }
  1439. }
  1440. else
  1441. {
  1442. int nvpsize = xvectorPP.size();
  1443. for(i=0;i<nvpsize;i++)xvectorPP.at(i).bInlaneAvoid = true;
  1444. if((xps.mbStartToMainChange == true)||(xps.mbMainToEndChange == true))
  1445. {
  1446. if(xps.mbStartToMainChange == true)
  1447. {
  1448. for(i=(nchang1 - nchangpoint/2);i<(nchang1 + nchangpoint/2);i++)
  1449. {
  1450. if((i>=0)&&(i<nvpsize))
  1451. xvectorPP.at(i).bInlaneAvoid = false;
  1452. }
  1453. }
  1454. if(xps.mbMainToEndChange)
  1455. {
  1456. for(i=(nchang2 - nchangpoint/2);i<(nchang2 + nchangpoint/2);i++)
  1457. {
  1458. if((i>=0)&&(i<nvpsize))
  1459. xvectorPP.at(i).bInlaneAvoid = false;
  1460. }
  1461. }
  1462. }
  1463. for(i=0;i<nvpsize;i++)
  1464. {
  1465. if(xvectorPP.at(i).bInlaneAvoid)
  1466. {
  1467. double foff = xvectorPP.at(i).mfDisToLaneLeft -0.3-fvehiclewidth*0.5; //30cm + 0.5vehcilewidth
  1468. if(foff < 0.3)
  1469. {
  1470. xvectorPP.at(i).bInlaneAvoid = false;
  1471. xvectorPP.at(i).mx_left = xvectorPP.at(i).x;
  1472. xvectorPP.at(i).my_left = xvectorPP.at(i).y;
  1473. xvectorPP.at(i).mx_right = xvectorPP.at(i).x;
  1474. xvectorPP.at(i).my_right = xvectorPP.at(i).y;
  1475. }
  1476. else
  1477. {
  1478. xvectorPP.at(i).mx_left = xvectorPP.at(i).x + foff * cos(xvectorPP.at(i).hdg + M_PI/2.0);
  1479. xvectorPP.at(i).my_left = xvectorPP.at(i).y + foff * sin(xvectorPP.at(i).hdg + M_PI/2.0);
  1480. xvectorPP.at(i).mx_right = xvectorPP.at(i).x + foff * cos(xvectorPP.at(i).hdg - M_PI/2.0);
  1481. xvectorPP.at(i).my_right = xvectorPP.at(i).y + foff * sin(xvectorPP.at(i).hdg - M_PI/2.0);
  1482. }
  1483. }
  1484. }
  1485. }
  1486. }
  1487. double getoff(Road * pRoad,int nlane,const double s)
  1488. {
  1489. int i;
  1490. int nLSCount = pRoad->GetLaneSectionCount();
  1491. double s_section = 0;
  1492. double foff = 0;
  1493. for(i=0;i<nLSCount;i++)
  1494. {
  1495. LaneSection * pLS = pRoad->GetLaneSection(i);
  1496. if(i<(nLSCount -1))
  1497. {
  1498. if(pRoad->GetLaneSection(i+1)->GetS()<s)
  1499. {
  1500. continue;
  1501. }
  1502. }
  1503. s_section = pLS->GetS();
  1504. int nlanecount = pLS->GetLaneCount();
  1505. int j;
  1506. for(j=0;j<nlanecount;j++)
  1507. {
  1508. Lane * pLane = pLS->GetLane(j);
  1509. int k;
  1510. double s_lane = s-s_section;
  1511. if(pLane->GetId() != 0)
  1512. {
  1513. for(k=0;k<pLane->GetLaneWidthCount();k++)
  1514. {
  1515. if(k<(pLane->GetLaneWidthCount()-1))
  1516. {
  1517. if((pLane->GetLaneWidth(k+1)->GetS()+s_section)<s)
  1518. {
  1519. continue;
  1520. }
  1521. }
  1522. s_lane = pLane->GetLaneWidth(k)->GetS();
  1523. break;
  1524. }
  1525. LaneWidth * pLW = pLane->GetLaneWidth(k);
  1526. if(pLW == 0)
  1527. {
  1528. std::cout<<"not find LaneWidth"<<std::endl;
  1529. break;
  1530. }
  1531. double fds = s - s_lane - s_section;
  1532. double fwidth= pLW->GetA() + pLW->GetB() * fds
  1533. +pLW->GetC() * pow(fds,2) + pLW->GetD() * pow(fds,3);
  1534. if(nlane == pLane->GetId())
  1535. {
  1536. foff = foff + fwidth/2.0;
  1537. }
  1538. if((nlane*(pLane->GetId())>0)&&(abs(nlane)>abs(pLane->GetId())))
  1539. {
  1540. foff = foff + fwidth;
  1541. }
  1542. }
  1543. }
  1544. break;
  1545. }
  1546. if(nlane<0)foff = foff*(-1);
  1547. return foff;
  1548. }
  1549. //暂不考虑多个LaneSection的情况,不考虑车道宽度变化
  1550. std::vector<PlanPoint> GetLanePoint(pathsection xps,std::vector<PlanPoint> xvPP,const double fvehiclewidth)
  1551. {
  1552. std::vector<PlanPoint> xvectorPP;
  1553. std::vector<iv::lanewidthabcd> xvectorLWA = GetLaneWidthABCD(xps.mpRoad);
  1554. std::vector<int> xvectorindex1,xvectorindex2,xvectorindex3;
  1555. int nchange1,nchange2;
  1556. int nlane1,nlane2,nlane3;
  1557. if(xps.mnStartLaneSel == xps.mnEndLaneSel)
  1558. {
  1559. xps.mainsel = xps.mnStartLaneSel;
  1560. xps.mbStartToMainChange = false;
  1561. xps.mbMainToEndChange = false;
  1562. }
  1563. else
  1564. {
  1565. if(xps.mpRoad->GetRoadLength() < 100)
  1566. {
  1567. xps.mainsel = xps.mnEndLaneSel;
  1568. xps.mbStartToMainChange = true;
  1569. xps.mbMainToEndChange = false;
  1570. }
  1571. }
  1572. double off1,off2,off3;
  1573. if(xps.mnStartLaneSel < 0)
  1574. {
  1575. off1 = getoff(xps.mpRoad,xps.mnStartLaneSel);
  1576. off2 = getoff(xps.mpRoad,xps.mainsel);
  1577. off3 = getoff(xps.mpRoad,xps.mnEndLaneSel);
  1578. xvectorindex1 = GetLWIndex(xvectorLWA,xps.mnStartLaneSel);
  1579. xvectorindex2 = GetLWIndex(xvectorLWA,xps.mainsel);
  1580. xvectorindex3 = GetLWIndex(xvectorLWA,xps.mnEndLaneSel);
  1581. nlane1 = xps.mnStartLaneSel;
  1582. nlane2 = xps.mainsel;
  1583. nlane3 = xps.mnEndLaneSel;
  1584. }
  1585. else
  1586. {
  1587. off3 = getoff(xps.mpRoad,xps.mnStartLaneSel);
  1588. off2 = getoff(xps.mpRoad,xps.mainsel);
  1589. off1 = getoff(xps.mpRoad,xps.mnEndLaneSel);
  1590. xvectorindex3 = GetLWIndex(xvectorLWA,xps.mnStartLaneSel);
  1591. xvectorindex2 = GetLWIndex(xvectorLWA,xps.mainsel);
  1592. xvectorindex1 = GetLWIndex(xvectorLWA,xps.mnEndLaneSel);
  1593. nlane3 = xps.mnStartLaneSel;
  1594. nlane2 = xps.mainsel;
  1595. nlane1 = xps.mnEndLaneSel;
  1596. }
  1597. int nchangepoint = 300;
  1598. if((nchangepoint * 3) > xvPP.size())
  1599. {
  1600. nchangepoint = xvPP.size()/3;
  1601. }
  1602. int nsize = xvPP.size();
  1603. nchange1 = nsize/3;
  1604. if(nchange1>500)nchange1 = 500;
  1605. nchange2 = nsize*2/3;
  1606. if( (nsize-nchange2)>500)nchange2 = nsize-500;
  1607. // if(nsize < 1000)
  1608. // {
  1609. // std::cout<<"GetLanePoint Error. road id is "<<xps.mpRoad->GetRoadId()<<std::endl;
  1610. // return xvectorPP;
  1611. // }
  1612. double x,y;
  1613. int i;
  1614. if(xps.mainsel < 0)
  1615. {
  1616. for(i=0;i<(nchange1- nchangepoint/2);i++)
  1617. {
  1618. PlanPoint pp = xvPP.at(i);
  1619. // off1 = getoff(nlane1,pp.mS,xvectorLWA,xvectorindex1);
  1620. off1 = getoff(xps.mpRoad,nlane1,pp.mS);
  1621. pp.x = pp.x + off1 *cos(pp.hdg + M_PI/2.0);
  1622. pp.y = pp.y + off1 *sin(pp.hdg + M_PI/2.0);
  1623. pp.mWidth = getwidth(xps.mpRoad,nlane1,xvectorLWA,pp.mS);
  1624. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  1625. pp.lanmp = 0;
  1626. pp.mfDisToRoadLeft = off1*(-1);
  1627. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane1,pp.mS);
  1628. GetLaneOriTotal(xps.mpRoad,nlane1,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1629. xvectorPP.push_back(pp);
  1630. }
  1631. for(i=(nchange1 - nchangepoint/2);i<(nchange1+nchangepoint/2);i++)
  1632. {
  1633. PlanPoint pp = xvPP.at(i);
  1634. // off1 = getoff(nlane1,pp.mS,xvectorLWA,xvectorindex1);
  1635. // off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
  1636. off1 = getoff(xps.mpRoad,nlane1,pp.mS);
  1637. off2 = getoff(xps.mpRoad,nlane2,pp.mS);
  1638. double offx = off1 + (off2 - off1) *(i-nchange1 + nchangepoint/2)/nchangepoint;
  1639. pp.x = pp.x + offx *cos(pp.hdg + M_PI/2.0);
  1640. pp.y = pp.y + offx *sin(pp.hdg + M_PI/2.0);
  1641. double flanewidth1 = getwidth(xps.mpRoad,nlane1,xvectorLWA,pp.mS);
  1642. pp.mfDisToRoadLeft = offx*(-1);
  1643. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane1,pp.mS);
  1644. if(nlane1 == nlane2)
  1645. {
  1646. pp.mWidth = flanewidth1;
  1647. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  1648. pp.lanmp = 0;
  1649. GetLaneOriTotal(xps.mpRoad,nlane1,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1650. }
  1651. else
  1652. {
  1653. if(nlane1 < nlane2)
  1654. {
  1655. pp.lanmp = 1;
  1656. }
  1657. else
  1658. {
  1659. pp.lanmp = -1;
  1660. }
  1661. if(i<nchange1)
  1662. {
  1663. pp.mWidth = getwidth(xps.mpRoad,nlane1,xvectorLWA,pp.mS);
  1664. double fmove = pp.mWidth * (i-(nchange1 - nchangepoint/2))/nchangepoint;
  1665. if(nlane1<nlane2)pp.mfDisToLaneLeft = pp.mWidth/2.0 - fmove;
  1666. else pp.mfDisToLaneLeft = pp.mWidth/2.0 + fmove;
  1667. GetLaneOriTotal(xps.mpRoad,nlane1,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1668. }
  1669. else
  1670. {
  1671. pp.mWidth = getwidth(xps.mpRoad,nlane2,xvectorLWA,pp.mS);
  1672. double fmove = pp.mWidth * (nchange1+nchangepoint/2 -i)/nchangepoint;
  1673. if(nlane1<nlane2)pp.mfDisToLaneLeft = pp.mWidth/2.0 + fmove;
  1674. else pp.mfDisToLaneLeft = pp.mWidth/2.0 - fmove;
  1675. GetLaneOriTotal(xps.mpRoad,nlane2,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1676. }
  1677. }
  1678. xvectorPP.push_back(pp);
  1679. }
  1680. for(i=(nchange1 + nchangepoint/2);i<(nchange2-nchangepoint/2);i++)
  1681. {
  1682. PlanPoint pp = xvPP.at(i);
  1683. // off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
  1684. off2 = getoff(xps.mpRoad,nlane2,pp.mS);
  1685. pp.x = pp.x + off2 *cos(pp.hdg + M_PI/2.0);
  1686. pp.y = pp.y + off2 *sin(pp.hdg + M_PI/2.0);
  1687. pp.mWidth = getwidth(xps.mpRoad,nlane2,xvectorLWA,pp.mS);
  1688. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  1689. pp.lanmp = 0;
  1690. pp.mfDisToRoadLeft = off2*(-1);
  1691. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane2,pp.mS);
  1692. GetLaneOriTotal(xps.mpRoad,nlane2,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1693. xvectorPP.push_back(pp);
  1694. }
  1695. for(i=(nchange2 - nchangepoint/2);i<(nchange2+nchangepoint/2);i++)
  1696. {
  1697. PlanPoint pp = xvPP.at(i);
  1698. // off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
  1699. // off3 = getoff(nlane3,pp.mS,xvectorLWA,xvectorindex3);
  1700. off2 = getoff(xps.mpRoad,nlane2,pp.mS);
  1701. off3 = getoff(xps.mpRoad,nlane3,pp.mS);
  1702. double offx = off2 + (off3 - off2) *(i-nchange2 + nchangepoint/2)/nchangepoint;
  1703. pp.x = pp.x + offx *cos(pp.hdg + M_PI/2.0);
  1704. pp.y = pp.y + offx *sin(pp.hdg + M_PI/2.0);
  1705. double flanewidth1 = getwidth(xps.mpRoad,nlane2,xvectorLWA,pp.mS);
  1706. pp.mfDisToRoadLeft = offx*(-1);
  1707. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane2,pp.mS);
  1708. if(nlane2 == nlane3)
  1709. {
  1710. pp.mWidth = flanewidth1;
  1711. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  1712. pp.lanmp = 0;
  1713. GetLaneOriTotal(xps.mpRoad,nlane2,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1714. }
  1715. else
  1716. {
  1717. if(nlane2 < nlane3)
  1718. {
  1719. pp.lanmp = 1;
  1720. }
  1721. else
  1722. {
  1723. pp.lanmp = -1;
  1724. }
  1725. if(i<nchange2)
  1726. {
  1727. pp.mWidth = getwidth(xps.mpRoad,nlane2,xvectorLWA,pp.mS);
  1728. double fmove = pp.mWidth * (i-(nchange2 - nchangepoint/2))/nchangepoint;
  1729. if(nlane2<nlane3)pp.mfDisToLaneLeft = pp.mWidth/2.0 - fmove;
  1730. else pp.mfDisToLaneLeft = pp.mWidth/2.0 + fmove;
  1731. GetLaneOriTotal(xps.mpRoad,nlane2,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1732. }
  1733. else
  1734. {
  1735. pp.mWidth = getwidth(xps.mpRoad,nlane3,xvectorLWA,pp.mS);
  1736. double fmove = pp.mWidth * (nchange2+nchangepoint/2 -i)/nchangepoint;
  1737. if(nlane2<nlane3)pp.mfDisToLaneLeft = pp.mWidth/2.0 + fmove;
  1738. else pp.mfDisToLaneLeft = pp.mWidth/2.0 - fmove;
  1739. GetLaneOriTotal(xps.mpRoad,nlane3,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1740. }
  1741. }
  1742. xvectorPP.push_back(pp);
  1743. }
  1744. for(i=(nchange2 + nchangepoint/2);i<nsize;i++)
  1745. {
  1746. PlanPoint pp = xvPP.at(i);
  1747. // off3 = getoff(nlane3,pp.mS,xvectorLWA,xvectorindex3);
  1748. off3 = getoff(xps.mpRoad,nlane3,pp.mS);
  1749. pp.x = pp.x + off3 *cos(pp.hdg + M_PI/2.0);
  1750. pp.y = pp.y + off3 *sin(pp.hdg + M_PI/2.0);
  1751. pp.mWidth = getwidth(xps.mpRoad,nlane3,xvectorLWA,pp.mS);
  1752. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  1753. pp.lanmp = 0;
  1754. pp.mfDisToRoadLeft = off3*(-1);
  1755. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane3,pp.mS);
  1756. GetLaneOriTotal(xps.mpRoad,nlane3,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1757. xvectorPP.push_back(pp);
  1758. }
  1759. }
  1760. else
  1761. {
  1762. for(i=0;i<(nchange1- nchangepoint/2);i++)
  1763. {
  1764. PlanPoint pp = xvPP.at(i);
  1765. off1 = getoff(nlane1,pp.mS,xvectorLWA,xvectorindex1);
  1766. pp.x = pp.x + off1 *cos(pp.hdg + M_PI/2.0);
  1767. pp.y = pp.y + off1 *sin(pp.hdg + M_PI/2.0);
  1768. pp.hdg = pp.hdg + M_PI;
  1769. pp.mWidth = getwidth(xps.mpRoad,nlane1,xvectorLWA,pp.mS);
  1770. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  1771. pp.lanmp = 0;
  1772. pp.mfDisToRoadLeft = off1;
  1773. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane1,pp.mS);
  1774. GetLaneOriTotal(xps.mpRoad,nlane1,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1775. xvectorPP.push_back(pp);
  1776. }
  1777. for(i=(nchange1 - nchangepoint/2);i<(nchange1+nchangepoint/2);i++)
  1778. {
  1779. PlanPoint pp = xvPP.at(i);
  1780. off1 = getoff(nlane1,pp.mS,xvectorLWA,xvectorindex1);
  1781. off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
  1782. double offx = off1 + (off2 - off1) *(i-nchange1 + nchangepoint/2)/nchangepoint;
  1783. pp.x = pp.x + offx *cos(pp.hdg + M_PI/2.0);
  1784. pp.y = pp.y + offx *sin(pp.hdg + M_PI/2.0);
  1785. pp.hdg = pp.hdg + M_PI;
  1786. double flanewidth1 = getwidth(xps.mpRoad,nlane1,xvectorLWA,pp.mS);
  1787. pp.mfDisToRoadLeft = offx;
  1788. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane1,pp.mS);
  1789. if(nlane1 == nlane2)
  1790. {
  1791. pp.mWidth = flanewidth1;
  1792. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  1793. pp.lanmp = 0;
  1794. GetLaneOriTotal(xps.mpRoad,nlane1,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1795. }
  1796. else
  1797. {
  1798. if(nlane1 < nlane2)
  1799. {
  1800. pp.lanmp = -1;
  1801. }
  1802. else
  1803. {
  1804. pp.lanmp = 1;
  1805. }
  1806. if(i<nchange1)
  1807. {
  1808. pp.mWidth = getwidth(xps.mpRoad,nlane1,xvectorLWA,pp.mS);
  1809. double fmove = pp.mWidth * (i-(nchange1 - nchangepoint/2))/nchangepoint;
  1810. if(nlane1<nlane2)pp.mfDisToLaneLeft = pp.mWidth/2.0 - fmove;
  1811. else pp.mfDisToLaneLeft = pp.mWidth/2.0 + fmove;
  1812. GetLaneOriTotal(xps.mpRoad,nlane1,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1813. }
  1814. else
  1815. {
  1816. pp.mWidth = getwidth(xps.mpRoad,nlane2,xvectorLWA,pp.mS);
  1817. double fmove = pp.mWidth * (nchange1+nchangepoint/2 -i)/nchangepoint;
  1818. if(nlane1<nlane2)pp.mfDisToLaneLeft = pp.mWidth/2.0 + fmove;
  1819. else pp.mfDisToLaneLeft = pp.mWidth/2.0 - fmove;
  1820. GetLaneOriTotal(xps.mpRoad,nlane2,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1821. }
  1822. }
  1823. xvectorPP.push_back(pp);
  1824. }
  1825. for(i=(nchange1 + nchangepoint/2);i<(nchange2-nchangepoint/2);i++)
  1826. {
  1827. PlanPoint pp = xvPP.at(i);
  1828. off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
  1829. pp.x = pp.x + off2 *cos(pp.hdg + M_PI/2.0);
  1830. pp.y = pp.y + off2 *sin(pp.hdg + M_PI/2.0);
  1831. pp.hdg = pp.hdg + M_PI;
  1832. pp.mWidth = getwidth(xps.mpRoad,nlane2,xvectorLWA,pp.mS);
  1833. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  1834. pp.lanmp = 0;
  1835. pp.mfDisToRoadLeft = off2;
  1836. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane2,pp.mS);
  1837. GetLaneOriTotal(xps.mpRoad,nlane2,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1838. xvectorPP.push_back(pp);
  1839. }
  1840. for(i=(nchange2 - nchangepoint/2);i<(nchange2+nchangepoint/2);i++)
  1841. {
  1842. PlanPoint pp = xvPP.at(i);
  1843. off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
  1844. off3 = getoff(nlane3,pp.mS,xvectorLWA,xvectorindex3);
  1845. double offx = off2 + (off3 - off2) *(i-nchange2 + nchangepoint/2)/nchangepoint;
  1846. pp.x = pp.x + offx *cos(pp.hdg + M_PI/2.0);
  1847. pp.y = pp.y + offx *sin(pp.hdg + M_PI/2.0);
  1848. pp.hdg = pp.hdg + M_PI;
  1849. double flanewidth1 = getwidth(xps.mpRoad,nlane2,xvectorLWA,pp.mS);
  1850. pp.mfDisToRoadLeft = offx;
  1851. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane2,pp.mS);
  1852. if(nlane2 == nlane3)
  1853. {
  1854. pp.mWidth = flanewidth1;
  1855. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  1856. pp.lanmp = 0;
  1857. GetLaneOriTotal(xps.mpRoad,nlane2,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1858. }
  1859. else
  1860. {
  1861. if(nlane2 < nlane3)
  1862. {
  1863. pp.lanmp = -1;
  1864. }
  1865. else
  1866. {
  1867. pp.lanmp = 1;
  1868. }
  1869. if(i<nchange2)
  1870. {
  1871. pp.mWidth = getwidth(xps.mpRoad,nlane2,xvectorLWA,pp.mS);
  1872. double fmove = pp.mWidth * (i-(nchange2 - nchangepoint/2))/nchangepoint;
  1873. if(nlane2<nlane3)pp.mfDisToLaneLeft = pp.mWidth/2.0 - fmove;
  1874. else pp.mfDisToLaneLeft = pp.mWidth/2.0 + fmove;
  1875. GetLaneOriTotal(xps.mpRoad,nlane2,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1876. }
  1877. else
  1878. {
  1879. pp.mWidth = getwidth(xps.mpRoad,nlane3,xvectorLWA,pp.mS);
  1880. double fmove = pp.mWidth * (nchange2+nchangepoint/2 -i)/nchangepoint;
  1881. if(nlane2<nlane3)pp.mfDisToLaneLeft = pp.mWidth/2.0 + fmove;
  1882. else pp.mfDisToLaneLeft = pp.mWidth/2.0 - fmove;
  1883. GetLaneOriTotal(xps.mpRoad,nlane3,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1884. }
  1885. }
  1886. xvectorPP.push_back(pp);
  1887. }
  1888. for(i=(nchange2+ nchangepoint/2);i<nsize;i++)
  1889. {
  1890. PlanPoint pp = xvPP.at(i);
  1891. off3 = getoff(nlane3,pp.mS,xvectorLWA,xvectorindex3);
  1892. pp.x = pp.x + off3 *cos(pp.hdg + M_PI/2.0);
  1893. pp.y = pp.y + off3 *sin(pp.hdg + M_PI/2.0);
  1894. pp.hdg = pp.hdg + M_PI;
  1895. pp.mWidth = getwidth(xps.mpRoad,nlane3,xvectorLWA,pp.mS);
  1896. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  1897. pp.lanmp = 0;
  1898. pp.mfDisToRoadLeft = off3;
  1899. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane3,pp.mS);
  1900. GetLaneOriTotal(xps.mpRoad,nlane3,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  1901. xvectorPP.push_back(pp);
  1902. }
  1903. }
  1904. CalcInLaneAvoid(xps,xvectorPP,fvehiclewidth,nchange1,nchange2,nchangepoint);
  1905. if(xps.mnStartLaneSel > 0)
  1906. {
  1907. std::vector<PlanPoint> xvvPP;
  1908. int nvsize = xvectorPP.size();
  1909. for(i=0;i<nvsize;i++)
  1910. {
  1911. xvvPP.push_back(xvectorPP.at(nvsize-1-i));
  1912. }
  1913. AddSignalMark(xps.mpRoad,xps.mainsel,xvvPP);
  1914. return xvvPP;
  1915. }
  1916. // pRoad->GetLaneSection(xps.msectionid)
  1917. AddSignalMark(xps.mpRoad,xps.mainsel,xvectorPP);
  1918. return xvectorPP;
  1919. }
  1920. static void AddSignalMark(Road * pRoad, int nlane,std::vector<PlanPoint> & xvectorPP)
  1921. {
  1922. if(pRoad->GetSignalCount() == 0)return;
  1923. int nsigcount = pRoad->GetSignalCount();
  1924. int i;
  1925. for(i=0;i<nsigcount;i++)
  1926. {
  1927. Signal * pSig = pRoad->GetSignal(i);
  1928. int nfromlane = -100;
  1929. int ntolane = 100;
  1930. signal_laneValidity * pSig_laneValidity = pSig->GetlaneValidity();
  1931. if(pSig_laneValidity != 0)
  1932. {
  1933. nfromlane = pSig_laneValidity->GetfromLane();
  1934. ntolane = pSig_laneValidity->GettoLane();
  1935. }
  1936. if((nlane < 0)&&(nfromlane >= 0))
  1937. {
  1938. continue;
  1939. }
  1940. if((nlane > 0)&&(ntolane<=0))
  1941. {
  1942. continue;
  1943. }
  1944. double s = pSig->Gets();
  1945. double fpos = s/pRoad->GetRoadLength();
  1946. if(nlane > 0)fpos = 1.0 -fpos;
  1947. int npos = fpos *xvectorPP.size();
  1948. if(npos <0)npos = 0;
  1949. if(npos>=xvectorPP.size())npos = xvectorPP.size()-1;
  1950. while(xvectorPP.at(npos).nSignal != -1)
  1951. {
  1952. if(npos > 0)npos--;
  1953. else break;
  1954. }
  1955. while(xvectorPP.at(npos).nSignal != -1)
  1956. {
  1957. if(npos < (xvectorPP.size()-1))npos++;
  1958. else break;
  1959. }
  1960. xvectorPP.at(npos).nSignal = atoi(pSig->Gettype().data());
  1961. }
  1962. }
  1963. static std::vector<PlanPoint> GetPlanPoint(std::vector<pathsection> xpathsection,Road * pRoad,GeometryBlock * pgeob,
  1964. Road * pRoad_obj,GeometryBlock * pgeob_obj,
  1965. const double x_now,const double y_now,const double head,
  1966. double nearx,double neary, double nearhead,
  1967. double nearx_obj,double neary_obj,const double fvehiclewidth)
  1968. {
  1969. std::vector<PlanPoint> xvectorPPs;
  1970. std::vector<PlanPoint> xvectorPP = GetPoint( xpathsection[0].mpRoad);
  1971. int indexstart = indexinroadpoint(xvectorPP,nearx,neary);
  1972. int i;
  1973. std::vector<PlanPoint> xvPP = GetLanePoint(xpathsection[0],xvectorPP,fvehiclewidth);
  1974. if(xpathsection[0].mainsel < 0)
  1975. {
  1976. for(i=indexstart;i<xvPP.size();i++)
  1977. {
  1978. xvectorPPs.push_back(xvPP.at(i));
  1979. }
  1980. }
  1981. else
  1982. {
  1983. for(i=(xvPP.size() -indexstart);i<xvPP.size();i++)
  1984. {
  1985. PlanPoint pp;
  1986. pp = xvPP.at(i);
  1987. // pp.hdg = pp.hdg +M_PI;
  1988. xvectorPPs.push_back(pp);
  1989. }
  1990. }
  1991. int npathlast = xpathsection.size() - 1;
  1992. // while(npathlast >= 0)
  1993. // {
  1994. // if(npathlast == 0)break;
  1995. // if(xpathsection[npathlast].mpRoad != xpathsection[npathlast - 1].mpRoad)break;
  1996. // }
  1997. for(i=1;i<(npathlast);i++)
  1998. {
  1999. if(xpathsection[i].mpRoad == xpathsection[i-1].mpRoad)
  2000. {
  2001. if(xpathsection[i].mainsel * xpathsection[i-1].mainsel >0)
  2002. {
  2003. continue;
  2004. }
  2005. }
  2006. if(xpathsection[i].mpRoad == xpathsection[npathlast].mpRoad)
  2007. {
  2008. if(xpathsection[i].mainsel * xpathsection[npathlast].mainsel > 0)
  2009. {
  2010. break;
  2011. }
  2012. }
  2013. xvectorPP = GetPoint( xpathsection[i].mpRoad);
  2014. xvPP = GetLanePoint(xpathsection[i],xvectorPP,fvehiclewidth);
  2015. // std::cout<<" road id is "<<xpathsection[i].mpRoad->GetRoadId().data()<<" size is "<<xvPP.size()<<std::endl;
  2016. int j;
  2017. for(j=0;j<xvPP.size();j++)
  2018. {
  2019. xvectorPPs.push_back(xvPP.at(j));
  2020. }
  2021. }
  2022. xvectorPP = GetPoint(xpathsection[npathlast].mpRoad);
  2023. int indexend = indexinroadpoint(xvectorPP,nearx_obj,neary_obj);
  2024. xvPP = GetLanePoint(xpathsection[npathlast],xvectorPP,fvehiclewidth);
  2025. int nlastsize;
  2026. if(xpathsection[npathlast].mainsel<0)
  2027. {
  2028. nlastsize = indexend;
  2029. }
  2030. else
  2031. {
  2032. if(indexend>0) nlastsize = xvPP.size() - indexend;
  2033. else nlastsize = xvPP.size();
  2034. }
  2035. for(i=0;i<nlastsize;i++)
  2036. {
  2037. xvectorPPs.push_back(xvPP.at(i));
  2038. }
  2039. //Find StartPoint
  2040. // if
  2041. // int a = 1;
  2042. return xvectorPPs;
  2043. }
  2044. std::vector<PlanPoint> gTempPP;
  2045. int getPoint(double q[3], double x, void* user_data) {
  2046. // printf("%f, %f, %f, %f\n", q[0], q[1], q[2], x);
  2047. PlanPoint pp;
  2048. pp.x = q[0];
  2049. pp.y = q[1];
  2050. pp.hdg = q[2];
  2051. pp.dis = x;
  2052. pp.speed = *((double *)user_data);
  2053. gTempPP.push_back(pp);
  2054. // std::cout<<pp.x<<" "<<" "<<pp.y<<" "<<pp.hdg<<std::endl;
  2055. return 0;
  2056. }
  2057. /**
  2058. * @brief getlanesel
  2059. * @param nSel
  2060. * @param pLaneSection
  2061. * @param nlr
  2062. * @return
  2063. */
  2064. int getlanesel(int nSel,LaneSection * pLaneSection,int nlr)
  2065. {
  2066. int nlane = nSel;
  2067. int mainselindex = 0;
  2068. if(nlr == 2)nlane = nlane*(-1);
  2069. int nlanecount = pLaneSection->GetLaneCount();
  2070. int i;
  2071. int nTrueSel = nSel;
  2072. if(nTrueSel <= 1)nTrueSel= 1;
  2073. int nCurSel = 1;
  2074. if(nlr == 2)nCurSel = nCurSel *(-1);
  2075. bool bOK = false;
  2076. int nxsel = 1;
  2077. int nlasttid = 0;
  2078. bool bfindlast = false;
  2079. while(bOK == false)
  2080. {
  2081. bool bHaveDriving = false;
  2082. int ncc = 0;
  2083. for(i=0;i<nlanecount;i++)
  2084. {
  2085. Lane * pLane = pLaneSection->GetLane(i);
  2086. if(strncmp(pLane->GetType().data(),"driving",255) == 0 )
  2087. {
  2088. if((nlr == 1)&&(pLane->GetId()>0))
  2089. {
  2090. ncc++;
  2091. }
  2092. if((nlr == 2)&&(pLane->GetId()<0))
  2093. {
  2094. ncc++;
  2095. }
  2096. if(ncc == nxsel)
  2097. {
  2098. bHaveDriving = true;
  2099. bfindlast = true;
  2100. nlasttid = pLane->GetId();
  2101. break;
  2102. }
  2103. }
  2104. }
  2105. if(bHaveDriving == true)
  2106. {
  2107. if(nxsel == nTrueSel)
  2108. {
  2109. return nlasttid;
  2110. }
  2111. else
  2112. {
  2113. nxsel++;
  2114. }
  2115. }
  2116. else
  2117. {
  2118. if(bfindlast)
  2119. {
  2120. return nlasttid;
  2121. }
  2122. else
  2123. {
  2124. std::cout<<"can't find lane."<<std::endl;
  2125. return 0;
  2126. }
  2127. //Use Last
  2128. }
  2129. }
  2130. return 0;
  2131. int k;
  2132. bool bFind = false;
  2133. while(bFind == false)
  2134. {
  2135. for(k=0;k<nlanecount;k++)
  2136. {
  2137. Lane * pLane = pLaneSection->GetLane(k);
  2138. if((nlane == pLane->GetId())&&(strncmp(pLane->GetType().data(),"driving",255) == 0))
  2139. {
  2140. bFind = true;
  2141. mainselindex = k;
  2142. break;
  2143. }
  2144. }
  2145. if(bFind)continue;
  2146. if(nlr == 1)nlane--;
  2147. else nlane++;
  2148. if(nlane == 0)
  2149. {
  2150. std::cout<<" Fail. can't find lane"<<std::endl;
  2151. break;
  2152. }
  2153. }
  2154. return nlane;
  2155. }
  2156. void checktrace(std::vector<PlanPoint> & xPlan)
  2157. {
  2158. int i;
  2159. int nsize = xPlan.size();
  2160. for(i=1;i<nsize;i++)
  2161. {
  2162. double dis = sqrt(pow(xPlan.at(i).x - xPlan.at(i-1).x,2) + pow(xPlan.at(i).y - xPlan.at(i-1).y,2));
  2163. if(dis > 0.3)
  2164. {
  2165. double hdg = CalcHdg(QPointF(xPlan.at(i-1).x,xPlan.at(i-1).y),QPointF(xPlan.at(i).x,xPlan.at(i).y));
  2166. int ncount = dis/0.1;
  2167. int j;
  2168. for(j=1;j<ncount;j++)
  2169. {
  2170. double x, y;
  2171. PlanPoint pp;
  2172. pp.x = xPlan.at(i-1).x + j*0.1 *cos(hdg);
  2173. pp.y = xPlan.at(i-1).y + j*0.1 *sin(hdg);
  2174. pp.hdg = hdg;
  2175. xPlan.insert(xPlan.begin()+i+j-1,pp);
  2176. }
  2177. qDebug("dis is %f",dis);
  2178. }
  2179. }
  2180. }
  2181. #include <QFile>
  2182. /**
  2183. * @brief MakePlan 全局路径规划
  2184. * @param pxd 有向图
  2185. * @param pxodr OpenDrive地图
  2186. * @param x_now 当前x坐标
  2187. * @param y_now 当前y坐标
  2188. * @param head 当前航向
  2189. * @param x_obj 目标点x坐标
  2190. * @param y_obj 目标点y坐标
  2191. * @param obj_dis 目标点到路径的距离
  2192. * @param srcnearthresh 当前点离最近路径的阈值,如果不在这个范围,寻找失败
  2193. * @param dstnearthresh 目标点离最近路径的阈值,如果不在这个范围,寻找失败
  2194. * @param nlanesel 车道偏好,1为内车道,数值越大越偏外,如果数值不满足,会选择最靠外的。
  2195. * @param xPlan 返回的轨迹点
  2196. * @return 0 成功 <0 失败
  2197. */
  2198. int MakePlan(xodrdijkstra * pxd,OpenDrive * pxodr,const double x_now,const double y_now,const double head,
  2199. const double x_obj,const double y_obj,const double & obj_dis,
  2200. const double srcnearthresh,const double dstnearthresh,
  2201. const int nlanesel,std::vector<PlanPoint> & xPlan,const double fvehiclewidth )
  2202. {
  2203. double s;double nearx;
  2204. double neary;double nearhead;
  2205. Road * pRoad;GeometryBlock * pgeob;
  2206. // int nfind = GetNearPoint(x_now,y_now,pxodr,&pRoad,&pgeob,s,nearx,neary,nearhead,srcnearthresh);
  2207. int nfind = GetNearPointWithHead(x_now,y_now,head,pxodr,&pRoad,&pgeob,s,nearx,neary,nearhead,srcnearthresh);
  2208. if(nfind < 0)return -1;
  2209. double s_obj;double nearx_obj;
  2210. double neary_obj;double nearhead_obj;
  2211. Road * pRoad_obj;GeometryBlock * pgeob_obj;
  2212. int nfind_obj = GetNearPoint(x_obj,y_obj,pxodr,&pRoad_obj,&pgeob_obj,s_obj,nearx_obj,neary_obj,
  2213. nearhead_obj,dstnearthresh);
  2214. if(nfind_obj < 0)return -2;
  2215. //计算终点在道路的左侧还是右侧
  2216. int lr_end = 2;
  2217. double hdg_end;
  2218. hdg_end = CalcHdg(QPointF(nearx_obj,neary_obj),QPointF(x_obj,y_obj));
  2219. double hdgdiff = nearhead_obj - hdg_end;
  2220. while(hdgdiff<0)hdgdiff= hdgdiff + 2.0*M_PI;
  2221. while(hdgdiff >= 2.0*M_PI)hdgdiff = hdgdiff- 2.0*M_PI;
  2222. if(hdgdiff<= M_PI)
  2223. {
  2224. lr_end = 2;
  2225. }
  2226. else
  2227. {
  2228. lr_end = 1;
  2229. }
  2230. if((pRoad_obj->GetLaneSection(0)->GetLeftLaneCount()<1)&&(lr_end == 1))
  2231. {
  2232. lr_end = 2;
  2233. }
  2234. if((pRoad_obj->GetLaneSection(0)->GetRightLaneCount()<1)&&(lr_end == 2))
  2235. {
  2236. lr_end = 2;
  2237. }
  2238. int lr_start = SelectRoadLeftRight(pRoad,head,nearhead);
  2239. bool bNeedDikstra = true;
  2240. if((atoi(pRoad->GetRoadId().data()) == atoi(pRoad_obj->GetRoadId().data()))&&(lr_start == lr_end))
  2241. {
  2242. std::vector<PlanPoint> xvPP = GetPoint(pRoad);
  2243. int nindexstart = indexinroadpoint(xvPP,nearx,neary);
  2244. int nindexend = indexinroadpoint(xvPP,nearx_obj,neary_obj);
  2245. int nlane = getlanesel(nlanesel,pRoad->GetLaneSection(0),lr_start);
  2246. AddSignalMark(pRoad,nlane,xvPP);
  2247. if((nindexend >nindexstart)&&(lr_start == 2))
  2248. {
  2249. bNeedDikstra = false;
  2250. }
  2251. if((nindexend <nindexstart)&&(lr_start == 1))
  2252. {
  2253. bNeedDikstra = false;
  2254. }
  2255. if(bNeedDikstra == false)
  2256. {
  2257. std::vector<iv::lanewidthabcd> xvectorLWA = GetLaneWidthABCD(pRoad);
  2258. std::vector<int> xvectorindex1;
  2259. xvectorindex1 = GetLWIndex(xvectorLWA,nlane);
  2260. double foff = getoff(pRoad,nlane);
  2261. foff = foff + 0.0;
  2262. std::vector<PlanPoint> xvectorPP;
  2263. int i = nindexstart;
  2264. while(i!=nindexend)
  2265. {
  2266. if(lr_start == 2)
  2267. {
  2268. PlanPoint pp = xvPP.at(i);
  2269. foff = getoff(nlane,pp.mS,xvectorLWA,xvectorindex1);
  2270. pp.x = pp.x + foff *cos(pp.hdg + M_PI/2.0);
  2271. pp.y = pp.y + foff *sin(pp.hdg + M_PI/2.0);
  2272. pp.mWidth = getwidth(pRoad,nlane,xvectorLWA,pp.mS);
  2273. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  2274. pp.lanmp = 0;
  2275. pp.mfDisToRoadLeft = foff *(-1.0);
  2276. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane,pp.mS);
  2277. GetLaneOriTotal(pRoad,nlane,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  2278. xvectorPP.push_back(pp);
  2279. i++;
  2280. }
  2281. else
  2282. {
  2283. PlanPoint pp = xvPP.at(i);
  2284. foff = getoff(nlane,pp.mS,xvectorLWA,xvectorindex1);
  2285. pp.x = pp.x + foff *cos(pp.hdg + M_PI/2.0);
  2286. pp.y = pp.y + foff *sin(pp.hdg + M_PI/2.0);
  2287. pp.hdg = pp.hdg + M_PI;
  2288. pp.mWidth = getwidth(pRoad,nlane,xvectorLWA,pp.mS);
  2289. pp.mfDisToLaneLeft = pp.mWidth/2.0;
  2290. pp.lanmp = 0;
  2291. pp.mfDisToRoadLeft = foff;
  2292. pp.mfRoadWidth = GetRoadWidth(xvectorLWA,nlane,pp.mS);
  2293. GetLaneOriTotal(pRoad,nlane,pp.mS,pp.mnLaneori,pp.mnLaneTotal,pp.speed);
  2294. xvectorPP.push_back(pp);
  2295. i--;
  2296. }
  2297. }
  2298. pathsection xps;
  2299. xps.mbStartToMainChange = false;
  2300. xps.mbMainToEndChange = false;
  2301. CalcInLaneAvoid(xps,xvectorPP,fvehiclewidth,0,0,0);
  2302. xPlan = xvectorPP;
  2303. }
  2304. }
  2305. if(bNeedDikstra)
  2306. {
  2307. std::vector<int> xpath = pxd->getpath(atoi(pRoad->GetRoadId().data()),lr_start,atoi(pRoad_obj->GetRoadId().data()),lr_end);
  2308. std::vector<pathsection> xpathsection = pxd->getgpspoint(atoi(pRoad->GetRoadId().data()),lr_start,atoi(pRoad_obj->GetRoadId().data()),lr_end,xpath,nlanesel);
  2309. std::vector<PlanPoint> xvectorPP = GetPlanPoint(xpathsection,pRoad,pgeob,pRoad_obj,pgeob_obj,x_now,y_now,
  2310. head,nearx,neary,nearhead,nearx_obj,neary_obj,fvehiclewidth);
  2311. xPlan = xvectorPP;
  2312. }
  2313. int i;
  2314. // QFile xFile;
  2315. // xFile.setFileName("/home/yuchuli/tempgps.txt");
  2316. // xFile.open(QIODevice::ReadWrite);
  2317. // for(i<0;i<xPlan.size();i++)
  2318. // {
  2319. // char strout[1000];
  2320. // snprintf(strout,1000,"%d %f %f %d %d %d %f \n",i,xPlan[i].mfDisToLaneLeft,
  2321. // xPlan[i].mfDisToRoadLeft,xPlan[i].mnLaneori,xPlan[i].mnLaneTotal,
  2322. // xPlan[i].lanmp,xPlan[i].mWidth);
  2323. // xFile.write(strout,strnlen(strout,1000));
  2324. // }
  2325. // xFile.close();
  2326. checktrace(xPlan);
  2327. // std::cout<<"pp size is "<<xvectorPP.size()<<std::endl;
  2328. return 0;
  2329. if(nfind_obj < 0)return -2;
  2330. if(pRoad != pRoad_obj)return -3; //temp,simple plan
  2331. if(pgeob != pgeob_obj)return -4; //temp,simple geo
  2332. if(!pgeob->CheckIfLine())return -5; //temp,only line plan;
  2333. int nlane = nlanesel;
  2334. if(nlane <= 0 )nlane = 1;
  2335. if(nlane >= pRoad->GetLaneSection(0)->GetLaneCount())
  2336. {
  2337. nlane = pRoad->GetLaneSection(0)->GetLaneCount()-1;
  2338. }
  2339. double bianxiandis = 0;
  2340. double bianxiandis_obj = 0;
  2341. double park_x,park_y;//Park point
  2342. bianxiandis = pRoad->GetLaneSection(0)->GetLane(1)->GetWidthValue(1)/2.0;
  2343. // int i = 1;
  2344. for(i=1;i<nlane;i++)
  2345. {
  2346. bianxiandis = bianxiandis + pRoad->GetLaneSection(0)->GetLane(i)->GetWidthValue(1)/2.0
  2347. +pRoad->GetLaneSection(0)->GetLane(i+1)->GetWidthValue(1)/2.0;
  2348. }
  2349. double bianxianx1 = bianxiandis;
  2350. bianxiandis = fabs(s - bianxiandis);
  2351. bianxiandis_obj = 0;
  2352. int ag = pRoad->GetLaneSection(0)->GetLaneCount();
  2353. for(i=(nlane +1);i<pRoad->GetLaneSection(0)->GetLaneCount();i++)
  2354. {
  2355. bianxiandis_obj = bianxiandis_obj
  2356. +pRoad->GetLaneSection(0)->GetLane(i-1)->GetWidthValue(1)/2.0
  2357. +pRoad->GetLaneSection(0)->GetLane(i)->GetWidthValue(1)/2.0;
  2358. }
  2359. // double x_objreal = nearx_obj + bianxiandis_obj * cos(nearhead_obj - M_PI/2.0);
  2360. // park_x = nearx_obj + (bianxiandis_obj +bianxianx1 + pRoad->GetLaneSection(0)->GetLane(1)->GetWidthValue(0)/2.0)*cos(nearhead_obj -M_PI/2.0);
  2361. // park_y = neary_obj + (bianxiandis_obj +bianxianx1+ pRoad->GetLaneSection(0)->GetLane(1)->GetWidthValue(0)/2.0)*sin(nearhead_obj -M_PI/2.0);
  2362. park_x = nearx_obj + (bianxiandis_obj +bianxianx1 )*cos(nearhead_obj -M_PI/2.0);
  2363. park_y = neary_obj + (bianxiandis_obj +bianxianx1 )*sin(nearhead_obj -M_PI/2.0);
  2364. const double bianxian_ang = 0.2;
  2365. double src_len,dst_len;
  2366. src_len = bianxiandis/atan(bianxian_ang);
  2367. dst_len = bianxiandis_obj/atan(bianxian_ang);
  2368. double xl1,yl1,xl2,yl2;
  2369. xl1 = nearx + src_len * cos(nearhead);
  2370. yl1 = neary + src_len * sin(nearhead);
  2371. xl2 = nearx_obj - dst_len * cos(nearhead_obj);
  2372. yl2 = neary_obj - dst_len * sin(nearhead_obj);
  2373. xl1 = xl1 + bianxianx1 * cos(nearhead - M_PI/2.0);
  2374. yl1 = yl1 + bianxianx1 * sin(nearhead - M_PI/2.0);
  2375. xl2 = xl2 + bianxianx1 * cos(nearhead_obj - M_PI/2.0);
  2376. yl2 = yl2 + bianxianx1 * sin(nearhead_obj - M_PI/2.0);
  2377. double q0[3],q1[3];
  2378. gTempPP.clear();
  2379. q0[0] = x_now;q0[1] = y_now; q0[2] = head;
  2380. q1[0] = xl1;q1[1] =yl1;q1[2] = nearhead;
  2381. int indexp = 0;
  2382. double turning_radius = 15.0;
  2383. double speedvalue = 3;
  2384. DubinsPath path;
  2385. dubins_shortest_path( &path, q0, q1, turning_radius);
  2386. dubins_path_sample_many( &path, 0.1, getPoint, &speedvalue);
  2387. for(i=indexp;i<gTempPP.size();i++)gTempPP.at(i).lanmp = 1;
  2388. indexp = gTempPP.size();
  2389. if(pRoad->GetLaneSection(0)->GetLane(nlane)->GetLaneSpeedCount()>1)
  2390. speedvalue = pRoad->GetLaneSection(0)->GetLane(nlane)->GetLaneSpeed(1)->GetMax();
  2391. else speedvalue = 10.0;
  2392. memcpy(q0,q1,3*sizeof(double));
  2393. q1[0]=xl2; q1[1]=yl2; q1[2]=nearhead;
  2394. dubins_shortest_path( &path, q0, q1, turning_radius);
  2395. dubins_path_sample_many( &path, 0.1, getPoint, &speedvalue);
  2396. for(i=indexp;i<gTempPP.size();i++)gTempPP.at(i).lanmp = 0;
  2397. indexp = gTempPP.size();
  2398. double vx = 3.0;
  2399. for(i= (gTempPP.size() -1);i>0;i--)
  2400. {
  2401. gTempPP.at(i).speed = vx;
  2402. vx = vx + 0.03;
  2403. gTempPP.at(i).lanmp = -1;
  2404. if(vx > speedvalue)break;
  2405. }
  2406. speedvalue = 3.0;
  2407. memcpy(q0,q1,3*sizeof(double));
  2408. q1[0]=park_x; q1[1]=park_y; q1[2]=nearhead_obj;
  2409. dubins_shortest_path( &path, q0, q1, turning_radius);
  2410. dubins_path_sample_many( &path, 0.1, getPoint, &speedvalue);
  2411. for(i=indexp;i<gTempPP.size();i++)gTempPP.at(i).lanmp = -1;
  2412. indexp = gTempPP.size();
  2413. double parkx_ext = park_x + 30 * cos(nearhead);
  2414. double parky_ext = park_y + 30 * sin(nearhead);
  2415. speedvalue = 0.0;
  2416. memcpy(q0,q1,3*sizeof(double));
  2417. q1[0]=parkx_ext; q1[1]=parky_ext; q1[2]=nearhead;
  2418. dubins_shortest_path( &path, q0, q1, turning_radius);
  2419. dubins_path_sample_many( &path, 0.1, getPoint, &speedvalue);
  2420. for(i=indexp;i<gTempPP.size();i++)gTempPP.at(i).lanmp = 0;
  2421. indexp = gTempPP.size();
  2422. for(i=0;i<gTempPP.size();i++)
  2423. {
  2424. xPlan.push_back(gTempPP.at(i));
  2425. }
  2426. return 0;
  2427. PlanPoint pp;
  2428. double hdgsrc,hdgdst;
  2429. double ldis1 = sqrt(pow(xl1 -x_now,2) + pow(yl1 -y_now,2) );
  2430. if(ldis1 > 0)
  2431. {
  2432. hdgsrc = asin((yl1-y_now)/ldis1);
  2433. if(xl1 < x_now)hdgsrc = M_PI - hdgsrc;
  2434. if(hdgsrc < 0)hdgsrc = hdgsrc + 2.0 * M_PI;
  2435. }
  2436. double ldis2 = sqrt(pow(park_x-xl2,2)+pow(park_y-yl2,2));
  2437. if(ldis2 > 0)
  2438. {
  2439. hdgdst = asin((park_y - yl2)/ldis2);
  2440. if(park_x < xl2)hdgdst = M_PI - hdgdst;
  2441. if(hdgdst < 0)hdgdst = hdgdst + 2.0*M_PI;
  2442. }
  2443. double xv,yv,speed;
  2444. i = 0;
  2445. double disx = 0.0;
  2446. const double step = 0.1;
  2447. xv = x_now;
  2448. yv = y_now;
  2449. pp.x = xv;pp.y = yv;pp.hdg = hdgsrc;pp.speed= 3.0;pp.lanmp = 1;xPlan.push_back(pp);
  2450. // qDebug("%d %f %f",i,xv,yv);
  2451. if(ldis1 > 0)
  2452. {
  2453. while((disx+step) < ldis1)
  2454. {
  2455. disx = disx + step;
  2456. i++;
  2457. xv = x_now + disx * cos(hdgsrc);
  2458. yv = y_now + disx * sin(hdgsrc);
  2459. pp.x = xv;pp.y = yv;pp.hdg = hdgsrc;pp.speed= 3.0;xPlan.push_back(pp);
  2460. // qDebug("%d %f %f",i,xv,yv);
  2461. }
  2462. }
  2463. i++;
  2464. xv = xl1;yv = yl1;
  2465. // qDebug("1:%d %f %f",i,xv,yv);
  2466. pp.x = xv;pp.y = yv;pp.hdg = hdgsrc;pp.speed= 3.0;pp.lanmp = 0;xPlan.push_back(pp);
  2467. double dis2p = sqrt(pow(xl2-xl1,2) + pow(yl2 -yl1,2));
  2468. disx = 0;
  2469. if(dis2p > 0)
  2470. {
  2471. while((disx+step) < dis2p)
  2472. {
  2473. disx = disx + step;
  2474. i++;
  2475. xv = xl1 + disx * cos(nearhead);
  2476. yv = yl1 + disx * sin(nearhead);
  2477. if(pRoad->GetLaneSection(0)->GetLane(nlane)->GetLaneSpeedCount()>1)
  2478. speed = pRoad->GetLaneSection(0)->GetLane(nlane)->GetLaneSpeed(1)->GetMax();
  2479. else speed = 10.0;
  2480. if((dis2p -disx)<((speed - 3.0)*5)){
  2481. speed = 3.0;
  2482. pp.lanmp = -1;
  2483. }
  2484. else
  2485. {
  2486. pp.lanmp = 0;
  2487. }
  2488. pp.x = xv;pp.y = yv;pp.hdg = nearhead;pp.speed= speed;xPlan.push_back(pp);
  2489. // qDebug("%d %f %f speed is %f",i,xv,yv,speed);
  2490. }
  2491. }
  2492. i++;
  2493. xv = xl2;yv = yl2;
  2494. pp.x = xv;pp.y = yv;pp.hdg = hdgdst;pp.speed= 3.0;pp.lanmp = -1;xPlan.push_back(pp);
  2495. // qDebug("2: %d %f %f",i,xv,yv);
  2496. disx = 0;
  2497. if(ldis2 > 0)
  2498. {
  2499. while((disx+step) < ldis2)
  2500. {
  2501. disx = disx + step;
  2502. i++;
  2503. xv = xl2 + disx * cos(hdgdst);
  2504. yv = yl2 + disx * sin(hdgdst);
  2505. speed = 3.0;
  2506. pp.x = xv;pp.y = yv;pp.hdg = hdgdst;pp.speed= 3.0;pp.lanmp = -1;xPlan.push_back(pp);
  2507. // qDebug("%d %f %f",i,xv,yv);
  2508. }
  2509. }
  2510. i++;
  2511. xv = park_x;yv = park_y;
  2512. pp.x = xv;pp.y = yv;pp.hdg = nearhead_obj;pp.speed= 0.0;pp.lanmp = 0;xPlan.push_back(pp);
  2513. // qDebug("obj: %d %f %f",i,xv,yv);
  2514. disx = 0;
  2515. while((disx+step) < 30)
  2516. {
  2517. disx = disx + step;
  2518. i++;
  2519. xv = park_x + disx * cos(nearhead);
  2520. yv = park_y + disx * sin(nearhead);
  2521. speed = 0.0;
  2522. pp.x = xv;pp.y = yv;pp.hdg = nearhead_obj;pp.speed= speed;pp.lanmp = 0;xPlan.push_back(pp);
  2523. // qDebug("%d %f %f",i,xv,yv);
  2524. }
  2525. }