|
@@ -0,0 +1,342 @@
|
|
|
+#include "sideparkcalc.h"
|
|
|
+
|
|
|
+#include "math.h"
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
+SideParkCalc::SideParkCalc(double x,double y,double hdg)
|
|
|
+{
|
|
|
+ mx = x;
|
|
|
+ my = y;
|
|
|
+ mhdg = hdg;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void SideParkCalc::CalcPark()
|
|
|
+{
|
|
|
+ if(mx< 0.5)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SideParkMode parkmode = CalcParkMode();
|
|
|
+
|
|
|
+ if(parkmode == SideParkMode::ParkAtRight)
|
|
|
+ {
|
|
|
+ ParkAtRightCalc();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ ParkAtLeftCalc();
|
|
|
+}
|
|
|
+
|
|
|
+SideParkMode SideParkCalc::CalcParkMode()
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ if(my>=0)return SideParkMode::ParkAtRight;
|
|
|
+
|
|
|
+ return SideParkMode::ParkAtLeft;
|
|
|
+}
|
|
|
+
|
|
|
+void SideParkCalc::ParkAtRightCalc()
|
|
|
+{
|
|
|
+ if(mhdg<=0.0)
|
|
|
+ {
|
|
|
+ ParkAtRightCalc_Model1();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ParkAtRightCalc_Model2();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void SideParkCalc::ParkAtRightCalc_Model1()
|
|
|
+{
|
|
|
+ double dx1,dy1,dx2,dy2,dx3,dy3,dx4,dy4,dx5,dy5,dx6,dy6;
|
|
|
+ dy6 = 0;
|
|
|
+ dx6 = mfLastDirectDis;
|
|
|
+ // double fMaxdx5 = mfRaidus * sin(mfMaxAngle );
|
|
|
+ double fMaxdy5 = mfRaidus *(1.0 - cos(mfMaxAngle));
|
|
|
+
|
|
|
+ // double fMaxdx3 = fMaxdx5;
|
|
|
+ // double fMaxdy3 = fMaxdy5;
|
|
|
+
|
|
|
+ dx2 = mfRaidus * sin(fabs(mhdg));
|
|
|
+ dy2 = mfRaidus * (1 - cos(fabs(mhdg)));
|
|
|
+
|
|
|
+
|
|
|
+ double fang ;//= mfMaxAngle;
|
|
|
+ if((my+dy2) >= (2*fMaxdy5) )
|
|
|
+ {
|
|
|
+ fang = mfMaxAngle;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fang = acos(1.0 - (my+dy2)/(2.0*mfRaidus)) ;
|
|
|
+ }
|
|
|
+
|
|
|
+ dx5 = mfRaidus * sin(fang);
|
|
|
+ dy5 = mfRaidus * (1.0 - cos(fang));
|
|
|
+
|
|
|
+ dx3 = dx5;
|
|
|
+ dy3 = dy5;
|
|
|
+
|
|
|
+ double thetax = mx - dx6 - dx3 - dx5 - dx2;
|
|
|
+
|
|
|
+ if(fabs(tan(fabs(mhdg )) + tan(fang ))<0.0001)
|
|
|
+ {
|
|
|
+ std::cout<<" divide error."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ dx4 = (my + thetax * tan(fabs(mhdg)) +dy2 - dy3 - dy5)/(tan(fabs(mhdg ) + tan(fang )));
|
|
|
+ dx1 = thetax - dx4;
|
|
|
+ dy1 = dx1 * tan(fabs(mhdg));
|
|
|
+ dy4 = my + dy1 +dy2 -dy3-dy5;
|
|
|
+
|
|
|
+ std::cout<<" compute. "<<std::endl;
|
|
|
+
|
|
|
+
|
|
|
+ // if((my+dy2) > (2*fMaxdy3) )
|
|
|
+ // {
|
|
|
+ // dy3 = fMaxdy3;
|
|
|
+ // dx3 = fMaxdx3;
|
|
|
+ // dx5 = fMaxdx5;
|
|
|
+ // dy5 = fMaxdy5;
|
|
|
+ // double thetax = mx - dx6 - fMaxdx3 - fMaxdx5 - dx2;
|
|
|
+ // dx4 = (my + thetax * tan(fabs(mhdg)) +dy2 - fMaxdy3 - fMaxdy5)/(tan(fabs(mhdg ) + tan(mfMaxAngle )));
|
|
|
+ // dx1 = thetax - dx4;
|
|
|
+ // dy1 = dx1 * tan(fabs(mhdg));
|
|
|
+ // dy4 = my + dy1 + dy2 -dy3-dy5;
|
|
|
+
|
|
|
+ // std::cout<<" compute. "<<std::endl;
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // double fang = acos(1.0 - (my+dy2)/(2.0*mfRaidus)) ;
|
|
|
+ // dx5 = mfRaidus * sin(fang);
|
|
|
+ // dy5 = mfRaidus * (1.0 - cos(fang));
|
|
|
+
|
|
|
+ // dx3 = dx5;
|
|
|
+ // dy3 = dy5;
|
|
|
+
|
|
|
+ // double thetax = mx - dx6 - dx3 - dx5 - dx2;
|
|
|
+ // dx4 = (my + thetax * tan(fabs(mhdg)) +dy2 - dy3 - dy5)/(tan(fabs(mhdg ) + tan(fang )));
|
|
|
+ // dx1 = thetax - dx4;
|
|
|
+ // dy1 = dx1 * tan(fabs(mhdg));
|
|
|
+ // dy4 = my + dy1 +dy2 -dy3-dy5;
|
|
|
+
|
|
|
+ // std::cout<<" compute. "<<std::endl;
|
|
|
+ // }
|
|
|
+}
|
|
|
+
|
|
|
+void SideParkCalc::ParkAtRightCalc_Model2()
|
|
|
+{
|
|
|
+ double dx1,dy1,dx2,dy2,dx3,dy3,dx4,dy4,dx5,dy5;
|
|
|
+ dy5 = 0;
|
|
|
+ dx5 = mfLastDirectDis;
|
|
|
+
|
|
|
+ double dx2fix = mfRaidus * sin(mhdg);
|
|
|
+ double dy2fix = mfRaidus * (1.0 - cos(mhdg));
|
|
|
+
|
|
|
+ double fMaxdy4 = mfRaidus *(1.0 - cos(mfMaxAngle));
|
|
|
+
|
|
|
+ double fang ;
|
|
|
+ if((my+dy2fix) >= (2*fMaxdy4) )
|
|
|
+ {
|
|
|
+ fang = mfMaxAngle;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fang = acos(1.0 - (my+dy2)/(2.0*mfRaidus)) ;
|
|
|
+ }
|
|
|
+
|
|
|
+ dx4 = mfRaidus * sin(fang);
|
|
|
+ dy4 = mfRaidus * (1.0 - cos(fang));
|
|
|
+
|
|
|
+ dx2 = dx4 - dx2fix;
|
|
|
+ dy2 = dy4 - dy2fix;
|
|
|
+
|
|
|
+ double thetax = mx - dx2 -dx4 -dx5;
|
|
|
+
|
|
|
+ double k1 = tan(mhdg);
|
|
|
+ double k3 = tan(fang);
|
|
|
+
|
|
|
+ if(fabs(k1-k3)<0.001)
|
|
|
+ {
|
|
|
+ dy1 = 0;
|
|
|
+ dx1 = 0;
|
|
|
+ dy3 = my - dy2 - dy4;
|
|
|
+ if(k3 > 0.001)
|
|
|
+ {
|
|
|
+ dx3 = dy3/k3;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(fabs(mx - dx1 - dx2 -dx3 -dx4 - dx5) > 0.1)
|
|
|
+ {
|
|
|
+ std::cout<<" no solve"<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dx3 = (my - dy2 - dy4 - k1 * thetax)/(k3 - k1);
|
|
|
+ dy3 = k3 * dx3;
|
|
|
+ dx1 = thetax - dx3;
|
|
|
+ dy1 = k1 * dx1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if((dx3<-0.1) || (dx1<-0.1))
|
|
|
+ {
|
|
|
+ if(cos(mhdg)> 0.001)
|
|
|
+ {
|
|
|
+ double fR = my/(1 - cos(mhdg));
|
|
|
+ double Rx = mx - fR*sin(mhdg);
|
|
|
+ if((Rx>0.3) && (fR >= mfRaidus))
|
|
|
+ {
|
|
|
+ std::cout<<" Have One Step soluton."<<std::endl;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout<<" have compute."<<std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+ std::cout<<" compute. "<<std::endl;
|
|
|
+}
|
|
|
+
|
|
|
+void SideParkCalc::ParkAtLeftCalc()
|
|
|
+{
|
|
|
+ if(mhdg>=0.0)
|
|
|
+ {
|
|
|
+ ParkAtLeftCalc_Model1();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ParkAtLeftCalc_Model2();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void SideParkCalc::ParkAtLeftCalc_Model1()
|
|
|
+{
|
|
|
+ double dx1,dy1,dx2,dy2,dx3,dy3,dx4,dy4,dx5,dy5,dx6,dy6;
|
|
|
+ dy6 = 0;
|
|
|
+ dx6 = mfLastDirectDis;
|
|
|
+
|
|
|
+ double fMaxdy5 = mfRaidus *(1.0 - cos(mfMaxAngle));
|
|
|
+
|
|
|
+
|
|
|
+ dx2 = mfRaidus * sin(fabs(mhdg));
|
|
|
+ dy2 = mfRaidus * (1 - cos(fabs(mhdg)));
|
|
|
+
|
|
|
+ // double x = mx;
|
|
|
+ double y = fabs(my);
|
|
|
+
|
|
|
+ double fang ;//= mfMaxAngle;
|
|
|
+ if((y+dy2) >= (2*fMaxdy5) )
|
|
|
+ {
|
|
|
+ fang = mfMaxAngle;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fang = acos(1.0 - (y+dy2)/(2.0*mfRaidus)) ;
|
|
|
+ }
|
|
|
+
|
|
|
+ dx5 = mfRaidus * sin(fang);
|
|
|
+ dy5 = mfRaidus * (1.0 - cos(fang));
|
|
|
+
|
|
|
+ dx3 = dx5;
|
|
|
+ dy3 = dy5;
|
|
|
+
|
|
|
+ double thetax = mx - dx6 - dx3 - dx5 - dx2;
|
|
|
+
|
|
|
+ if(fabs(tan(fabs(mhdg )) + tan(fang ))<0.0001)
|
|
|
+ {
|
|
|
+ std::cout<<" divide error."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ dx4 = (y + thetax * tan(fabs(mhdg)) +dy2 - dy3 - dy5)/(tan(fabs(mhdg ) + tan(fang )));
|
|
|
+ dx1 = thetax - dx4;
|
|
|
+ dy1 = dx1 * tan(fabs(mhdg));
|
|
|
+ dy4 = y + dy1 +dy2 -dy3-dy5;
|
|
|
+
|
|
|
+ std::cout<<" compute. "<<std::endl;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void SideParkCalc::ParkAtLeftCalc_Model2()
|
|
|
+{
|
|
|
+ double dx1,dy1,dx2,dy2,dx3,dy3,dx4,dy4,dx5,dy5;
|
|
|
+ dy5 = 0;
|
|
|
+ dx5 = mfLastDirectDis;
|
|
|
+
|
|
|
+ double dx2fix = mfRaidus * sin(fabs(mhdg));
|
|
|
+ double dy2fix = mfRaidus * (1.0 - cos(fabs(mhdg)));
|
|
|
+
|
|
|
+ double fMaxdy4 = mfRaidus *(1.0 - cos(mfMaxAngle));
|
|
|
+
|
|
|
+ double fang ;
|
|
|
+ double y = fabs(my);
|
|
|
+ if((y+dy2fix) >= (2*fMaxdy4) )
|
|
|
+ {
|
|
|
+ fang = mfMaxAngle;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fang = acos(1.0 - (y+dy2)/(2.0*mfRaidus)) ;
|
|
|
+ }
|
|
|
+
|
|
|
+ dx4 = mfRaidus * sin(fang);
|
|
|
+ dy4 = mfRaidus * (1.0 - cos(fang));
|
|
|
+
|
|
|
+ dx2 = dx4 - dx2fix;
|
|
|
+ dy2 = dy4 - dy2fix;
|
|
|
+
|
|
|
+ double thetax = mx - dx2 -dx4 -dx5;
|
|
|
+
|
|
|
+ double k1 = tan(mhdg);
|
|
|
+ double k3 = tan(fang);
|
|
|
+
|
|
|
+ if(fabs(k1-k3)<0.001)
|
|
|
+ {
|
|
|
+ dy1 = 0;
|
|
|
+ dx1 = 0;
|
|
|
+ dy3 = y - dy2 - dy4;
|
|
|
+ if(k3 > 0.001)
|
|
|
+ {
|
|
|
+ dx3 = dy3/k3;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(fabs(mx - dx1 - dx2 -dx3 -dx4 - dx5) > 0.1)
|
|
|
+ {
|
|
|
+ std::cout<<" no solve"<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dx3 = (y - dy2 - dy4 - k1 * thetax)/(k3 - k1);
|
|
|
+ dy3 = k3 * dx3;
|
|
|
+ dx1 = thetax - dx3;
|
|
|
+ dy1 = k1 * dx1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if((dx3<-0.1) || (dx1<-0.1))
|
|
|
+ {
|
|
|
+ if(cos(fabs(mhdg))> 0.001)
|
|
|
+ {
|
|
|
+ double fR = y/(1 - cos(fabs(mhdg)));
|
|
|
+ double Rx = mx - fR*sin(fabs(mhdg));
|
|
|
+ if((Rx>0.3) && (fR >= mfRaidus))
|
|
|
+ {
|
|
|
+ std::cout<<" Have One Step soluton."<<std::endl;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout<<" have compute."<<std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+ std::cout<<" compute. "<<std::endl;
|
|
|
+}
|