path_circle.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "path_circle.hpp"
00044 #include "utilities/error.h"
00045
00046 namespace KDL {
00047
00048
00049
00050 Path_Circle::Path_Circle(const Frame& F_base_start,
00051 const Vector& _V_base_center,
00052 const Vector& V_base_p,
00053 const Rotation& R_base_end,
00054 double alpha,
00055 RotationalInterpolation* _orient,
00056 double _eqradius,
00057 bool _aggregate) :
00058 orient(_orient) ,
00059 eqradius(_eqradius),
00060 aggregate(_aggregate)
00061 {
00062 F_base_center.p = _V_base_center;
00063 orient->SetStartEnd(F_base_start.M,R_base_end);
00064 double oalpha = orient->Angle();
00065
00066 Vector x(F_base_start.p - F_base_center.p);
00067 radius = x.Normalize();
00068 if (radius < epsilon)
00069 throw Error_MotionPlanning_Circle_ToSmall();
00070 Vector tmpv(V_base_p-F_base_center.p);
00071 tmpv.Normalize();
00072 Vector z( x * tmpv);
00073 double n = z.Normalize();
00074 if (n < epsilon)
00075 throw Error_MotionPlanning_Circle_No_Plane();
00076 F_base_center.M = Rotation(x,z*x,z);
00077 double dist = alpha*radius;
00078
00079
00080
00081
00082 if (oalpha*eqradius > dist) {
00083
00084 pathlength = oalpha*eqradius;
00085 scalerot = 1/eqradius;
00086 scalelin = dist/pathlength;
00087 } else {
00088
00089 pathlength = dist;
00090 scalerot = oalpha/pathlength;
00091 scalelin = 1;
00092 }
00093 }
00094
00095
00096
00097 double Path_Circle::LengthToS(double length) {
00098 return length/scalelin;
00099 }
00100
00101
00102 double Path_Circle::PathLength() {
00103 return pathlength;
00104 }
00105
00106 Frame Path_Circle::Pos(double s) const {
00107 double p = s*scalelin / radius;
00108 return Frame(orient->Pos(s*scalerot),
00109 F_base_center*Vector(radius*cos(p),radius*sin(p),0)
00110 );
00111
00112 }
00113
00114 Twist Path_Circle::Vel(double s,double sd) const {
00115 double p = s*scalelin / radius;
00116 double v = sd*scalelin / radius;
00117 return Twist( F_base_center.M*Vector(-radius*sin(p)*v,radius*cos(p)*v,0),
00118 orient->Vel(s*scalerot,sd*scalerot)
00119 );
00120 }
00121
00122 Twist Path_Circle::Acc(double s,double sd,double sdd) const {
00123 double p = s*scalelin / radius;
00124 double cp = cos(p);
00125 double sp = sin(p);
00126 double v = sd*scalelin / radius;
00127 double a = sdd*scalelin / radius;
00128 return Twist( F_base_center.M*Vector(
00129 -radius*cp*v*v - radius*sp*a,
00130 -radius*sp*v*v + radius*cp*a,
00131 0
00132 ),
00133 orient->Acc(s*scalerot,sd*scalerot,sdd*scalerot)
00134 );
00135 }
00136
00137 Path* Path_Circle::Clone() {
00138 return new Path_Circle(
00139 Pos(0),
00140 F_base_center.p,
00141 F_base_center.M.UnitY(),
00142 orient->Pos(pathlength*scalerot),
00143 pathlength*scalelin/radius/deg2rad,
00144 orient->Clone(),
00145 eqradius,
00146 aggregate
00147 );
00148 }
00149
00150 Path_Circle::~Path_Circle() {
00151 if (aggregate)
00152 delete orient;
00153 }
00154
00155
00156
00157 void Path_Circle::Write(std::ostream& os) {
00158 os << "CIRCLE[ ";
00159 os << " " << Pos(0) << std::endl;
00160 os << " " << F_base_center.p << std::endl;
00161 os << " " << F_base_center.M.UnitY() << std::endl;
00162 os << " " << orient->Pos(pathlength*scalerot) << std::endl;
00163 os << " " << pathlength*scalelin/radius/deg2rad << std::endl;
00164 os << " ";orient->Write(os);
00165 os << " " << eqradius;
00166 os << "]"<< std::endl;
00167 }
00168
00169
00170 }
00171