path_roundedcomposite.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_roundedcomposite.hpp"
00044 #include "path_line.hpp"
00045 #include "path_circle.hpp"
00046 #include "utilities/error.h"
00047 #include <memory>
00048
00049
00050 namespace KDL {
00051
00052 Path_RoundedComposite::Path_RoundedComposite(double _radius,double _eqradius,RotationalInterpolation* _orient, bool _aggregate) :
00053 comp( new Path_Composite()), radius(_radius),eqradius(_eqradius), orient(_orient), aggregate(_aggregate)
00054 {
00055 nrofpoints = 0;
00056 }
00057
00058 void Path_RoundedComposite::Add(const Frame& F_base_point) {
00059 if (nrofpoints==0) {
00060 F_base_start = F_base_point;
00061 } else if (nrofpoints==1) {
00062 F_base_via = F_base_point;
00063 } else {
00064
00065
00066 Vector ab = F_base_via.p - F_base_start.p;
00067 Vector bc = F_base_point.p - F_base_via.p;
00068 double abdist = ab.Normalize();
00069 double alpha = ::acos(dot(ab,bc)/(ab.Norm()*bc.Norm()));
00070
00071 double d = radius/tan((PI-alpha)/2);
00072 double bcdist = bc.Normalize();
00073 if (d >= abdist)
00074 throw Error_MotionPlanning_Not_Feasible();
00075 if (d >= bcdist)
00076 throw Error_MotionPlanning_Not_Feasible();
00077 std::auto_ptr<Path> line1 (
00078 new Path_Line(F_base_start,F_base_via,orient->Clone(),eqradius)
00079 );
00080 std::auto_ptr<Path> line2 (
00081 new Path_Line(F_base_via,F_base_point,orient->Clone(),eqradius)
00082 );
00083 Frame F_base_circlestart = line1->Pos(line1->LengthToS(abdist-d));
00084 Frame F_base_circleend = line2->Pos(line2->LengthToS(d));
00085
00086 Vector V_base_t = ab*(ab*bc);
00087 V_base_t.Normalize();
00088 comp->Add(new Path_Line(
00089 F_base_start,F_base_circlestart,orient->Clone(),eqradius
00090 )
00091 );
00092 comp->Add(new Path_Circle(
00093 F_base_circlestart,
00094 F_base_circlestart.p - V_base_t * radius,
00095 F_base_circleend.p,
00096 F_base_circleend.M,
00097 PI-alpha,orient->Clone(),eqradius
00098 )
00099 );
00100
00101 F_base_start = F_base_circleend;
00102 F_base_via = F_base_point;
00103 }
00104 nrofpoints++;
00105 }
00106
00107 void Path_RoundedComposite::Finish() {
00108 if (nrofpoints>=1) {
00109 comp->Add(new Path_Line(F_base_start,F_base_via,orient->Clone(),eqradius));
00110 }
00111 }
00112
00113 double Path_RoundedComposite::LengthToS(double length) {
00114 return comp->LengthToS(length);
00115 }
00116
00117 double Path_RoundedComposite::PathLength() {
00118 return comp->PathLength();
00119 }
00120
00121 Frame Path_RoundedComposite::Pos(double s) const {
00122 return comp->Pos(s);
00123 }
00124
00125 Twist Path_RoundedComposite::Vel(double s,double sd) const {
00126 return comp->Vel(s,sd);
00127 }
00128
00129 Twist Path_RoundedComposite::Acc(double s,double sd,double sdd) const {
00130 return comp->Acc(s,sd,sdd);
00131 }
00132
00133 void Path_RoundedComposite::Write(std::ostream& os) {
00134 comp->Write(os);
00135 }
00136
00137 Path_RoundedComposite::~Path_RoundedComposite() {
00138 if (aggregate)
00139 delete orient;
00140 delete comp;
00141 }
00142
00143
00144 Path* Path_RoundedComposite::Clone() {
00145 return comp->Clone();
00146 }
00147
00148 }