|
@@ -380,13 +380,51 @@ void GeometrySpiral::ComputeVars()
|
|
|
{
|
|
|
mA=0;
|
|
|
|
|
|
+ mLengthBase = 0;
|
|
|
+ mX0 = 0;
|
|
|
+ mY0 = 0;
|
|
|
+ mHDG0 = 0;
|
|
|
+
|
|
|
+ mHDG0Cos = 1.0;
|
|
|
+ mHDG0Sin = 0.0;
|
|
|
+
|
|
|
//if the curvatureEnd is the non-zero curvature, then the motion is in normal direction along the spiral
|
|
|
- if ((fabs(mCurvatureEnd)>1.00e-15)&&(fabs(mCurvatureStart)<=1.00e-15))
|
|
|
+ // if ((fabs(mCurvatureEnd)>1.00e-15)&&(fabs(mCurvatureStart)<=1.00e-15))
|
|
|
+ if ((fabs(mCurvatureEnd))>(fabs(mCurvatureStart)))
|
|
|
{
|
|
|
mNormalDir=true;
|
|
|
- mCurvature=mCurvatureEnd;
|
|
|
+ mCurvature=mCurvatureEnd;
|
|
|
//Calculate the normalization term : a = 1.0/sqrt(2*End_Radius*Total_Curve_Length)
|
|
|
- mA=1.0/sqrt(2*1.0/fabs(double(mCurvature))*mLength);
|
|
|
+ mA=1.0/sqrt(2*1.0/fabs(double(mCurvature))*mLength);
|
|
|
+
|
|
|
+ double xLength = mLength;
|
|
|
+ if(fabs(mCurvatureStart)>0.00001)
|
|
|
+ {
|
|
|
+ mLengthBase = mLength * fabs(mCurvatureStart)/(fabs(mCurvatureEnd) - fabs(mCurvatureStart));
|
|
|
+ xLength = mLength + mLengthBase;
|
|
|
+ mA=1.0/sqrt(2*1.0/fabs(double(mCurvature))*xLength);
|
|
|
+
|
|
|
+
|
|
|
+ double l_start =mLengthBase *mA/sqrtPiO2;
|
|
|
+
|
|
|
+ //Solve the Fresnel Integrals
|
|
|
+ fresnl(l_start,&mY0,&mX0);
|
|
|
+
|
|
|
+ if (mCurvature<0)
|
|
|
+ mY0=-mY0;
|
|
|
+
|
|
|
+ l_start =mLengthBase*mA;
|
|
|
+ double tangentAngle = l_start*l_start;
|
|
|
+ if (mCurvature<0)
|
|
|
+ tangentAngle=-tangentAngle;
|
|
|
+
|
|
|
+ mHDG0 = tangentAngle;
|
|
|
+
|
|
|
+ mHDG0Cos = cos(-mHDG0);
|
|
|
+ mHDG0Sin = sin(-mHDG0);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
//Denormalization Factor
|
|
|
mDenormalizeFactor=1.0/mA;
|
|
|
|
|
@@ -395,30 +433,74 @@ void GeometrySpiral::ComputeVars()
|
|
|
mRotSin=sin(mHdg);
|
|
|
}
|
|
|
//else the motion is in the inverse direction along the spiral
|
|
|
- else
|
|
|
+ else
|
|
|
{
|
|
|
+
|
|
|
mNormalDir=false;
|
|
|
- mCurvature=mCurvatureStart;
|
|
|
+ mCurvature=mCurvatureStart;
|
|
|
+
|
|
|
//Calculate the normalization term : a = 1.0/sqrt(2*End_Radius*Total_Curve_Length)
|
|
|
- mA=1.0/sqrt(2*1.0/fabs(mCurvature)*mLength);
|
|
|
+ mA=1.0/sqrt(2*1.0/fabs(mCurvature)*mLength);
|
|
|
+
|
|
|
+
|
|
|
+ if(fabs(mCurvatureEnd)>0.00001)
|
|
|
+ {
|
|
|
+ mLengthBase = mLength * fabs(mCurvatureEnd)/(fabs(mCurvatureStart) - fabs(mCurvatureEnd));
|
|
|
+ double xLength = mLength + mLengthBase;
|
|
|
+ mA=1.0/sqrt(2*1.0/fabs(double(mCurvature))*xLength);
|
|
|
+ //not complete, when have this type spiral, change this code.
|
|
|
+
|
|
|
+ double l_start =mLengthBase *mA/sqrtPiO2;
|
|
|
+
|
|
|
+ //Solve the Fresnel Integrals
|
|
|
+ fresnl(l_start,&mY0,&mX0);
|
|
|
+
|
|
|
+ if (mCurvature<0)
|
|
|
+ mY0=-mY0;
|
|
|
+
|
|
|
+ l_start =mLengthBase*mA;
|
|
|
+ double tangentAngle = l_start*l_start;
|
|
|
+ if (mCurvature<0)
|
|
|
+ tangentAngle=-tangentAngle;
|
|
|
+
|
|
|
+ mHDG0 = tangentAngle;
|
|
|
+
|
|
|
+ mHDG0Cos = cos(-mHDG0);
|
|
|
+ mHDG0Sin = sin(-mHDG0);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//Because we move in the inverse direction, we need to rotate the curve according to the heading
|
|
|
//around the last point of the normalized spiral
|
|
|
//Calculate the total length, normalize it and divide by sqrtPiO2, then, calculate the position of the final point.
|
|
|
- double L=(mS2-mS)*mA/sqrtPiO2;
|
|
|
+ double L=(mS2-mS + mLengthBase)*mA/sqrtPiO2;
|
|
|
fresnl(L,&mEndY,&mEndX);
|
|
|
//Invert the curve if the curvature is negative
|
|
|
if (mCurvature<0)
|
|
|
mEndY=-mEndY;
|
|
|
|
|
|
+ mEndX = mEndX - mX0;
|
|
|
+ mEndY = mEndY - mY0;
|
|
|
+
|
|
|
+ double tx,ty;
|
|
|
+ tx = mEndX;
|
|
|
+ ty = mEndY;
|
|
|
+
|
|
|
+ mEndX=tx*mHDG0Cos -ty*mHDG0Sin;
|
|
|
+ mEndY=ty*mHDG0Cos+tx*mHDG0Sin;
|
|
|
+
|
|
|
//Denormalization factor
|
|
|
- mDenormalizeFactor=1.0/mA;
|
|
|
+
|
|
|
+ mDenormalizeFactor=1.0/mA;
|
|
|
+
|
|
|
//Find the x,y coords of the final point of the curve in local curve coordinates
|
|
|
mEndX*=mDenormalizeFactor*sqrtPiO2;
|
|
|
mEndY*=mDenormalizeFactor*sqrtPiO2;
|
|
|
|
|
|
+ double L2=(mLengthBase)*mA/sqrtPiO2;
|
|
|
//Calculate the tangent angle
|
|
|
- differenceAngle=L*L*(sqrtPiO2*sqrtPiO2);
|
|
|
+ differenceAngle=L*L*(sqrtPiO2*sqrtPiO2) - L2*L2*(sqrtPiO2*sqrtPiO2);
|
|
|
double diffAngle;
|
|
|
//Calculate the tangent and heading angle difference that will be used to rotate the spiral
|
|
|
if (mCurvature<0)
|
|
@@ -517,35 +599,50 @@ void GeometrySpiral::GetCoords(double s_check, double &retX, double &retY, doubl
|
|
|
double l=0.0;
|
|
|
double tmpX=0.0, tmpY=0.0;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
//Depending on the moving direction, calculate the length of the curve from its beginning to the current point and normalize
|
|
|
//it by multiplying with the "a" normalization term
|
|
|
//Cephes lib for solving Fresnel Integrals, uses cos/sin (PI/2 * X^2) format in its function.
|
|
|
//So, in order to use the function, transform the argument (which is just L) by dividing it by the sqrt(PI/2) factor and multiply the results by it.
|
|
|
if (mNormalDir)
|
|
|
{
|
|
|
- l=(s_check-mS)*mA/sqrtPiO2;
|
|
|
+ l=(s_check-mS + mLengthBase)*mA/sqrtPiO2;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- l=(mS2-s_check)*mA/sqrtPiO2;
|
|
|
+ l=(mS2-s_check + mLengthBase)*mA/sqrtPiO2;
|
|
|
}
|
|
|
|
|
|
//Solve the Fresnel Integrals
|
|
|
fresnl(l,&tmpY,&tmpX);
|
|
|
+
|
|
|
+
|
|
|
//If the curvature is negative, invert the curve on the Y axis
|
|
|
if (mCurvature<0)
|
|
|
tmpY=-tmpY;
|
|
|
|
|
|
+
|
|
|
+ tmpX = tmpX - mX0;
|
|
|
+ tmpY = tmpY - mY0;
|
|
|
+
|
|
|
+ double tx,ty;
|
|
|
+ tx = tmpX;
|
|
|
+ ty = tmpY;
|
|
|
+
|
|
|
+ tmpX=tx*mHDG0Cos -ty*mHDG0Sin;
|
|
|
+ tmpY=ty*mHDG0Cos+tx*mHDG0Sin;
|
|
|
+
|
|
|
//Denormalize the results and multiply by the sqrt(PI/2) term
|
|
|
tmpX*=mDenormalizeFactor*sqrtPiO2;
|
|
|
tmpY*=mDenormalizeFactor*sqrtPiO2;
|
|
|
|
|
|
//Calculate the heading at the found position. Kill the sqrt(PI/2) term that was added to the L
|
|
|
- l=(s_check-mS)*mA;
|
|
|
+ l=(s_check-mS+mLengthBase)*mA;
|
|
|
double tangentAngle = l*l;
|
|
|
if (mCurvature<0)
|
|
|
tangentAngle=-tangentAngle;
|
|
|
- retHDG=mHdg+tangentAngle;
|
|
|
+ retHDG=mHdg+tangentAngle -mHDG0;
|
|
|
|
|
|
|
|
|
if (!mNormalDir)
|