orocos_kdl
path_roundedcomposite.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Erwin Aertbelien Mon May 10 19:10:36 CEST 2004 path_roundedcomposite.cxx
3 
4  path_roundedcomposite.cxx - description
5  -------------------
6  begin : Mon May 10 2004
7  copyright : (C) 2004 Erwin Aertbelien
8  email : erwin.aertbelien@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2.1 of the License, or (at your option) any later version. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19  * Lesser General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU Lesser General Public *
22  * License along with this library; if not, write to the Free Software *
23  * Foundation, Inc., 59 Temple Place, *
24  * Suite 330, Boston, MA 02111-1307 USA *
25  * *
26  ***************************************************************************/
27 /*****************************************************************************
28  * \author
29  * Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
30  *
31  * \version
32  * ORO_Geometry V0.2
33  *
34  * \par History
35  * - $log$
36  *
37  * \par Release
38  * $Id: path_roundedcomposite.cpp,v 1.1.1.1.2.5 2003/07/24 13:26:15 psoetens Exp $
39  * $Name: $
40  ****************************************************************************/
41 
42 
44 #include "path_line.hpp"
45 #include "path_circle.hpp"
46 #include "utilities/error.h"
47 #include "utilities/scoped_ptr.hpp"
48 #include <memory>
49 
50 
51 namespace KDL {
52 
53 // private constructor, to keep the type when cloning a Path_RoundedComposite, such that getIdentifier keeps on returning
54 // the correct value:
56  double _radius, double _eqradius, RotationalInterpolation* _orient,
57  bool _aggregate,int _nrofpoints):
58  comp(_comp), radius(_radius), eqradius(_eqradius), orient(_orient), nrofpoints(_nrofpoints), aggregate(_aggregate) {
59 }
60 
61 Path_RoundedComposite::Path_RoundedComposite(double _radius,double _eqradius,RotationalInterpolation* _orient, bool _aggregate) :
62  comp( new Path_Composite()), radius(_radius),eqradius(_eqradius), orient(_orient), aggregate(_aggregate)
63 {
64  nrofpoints = 0;
65  if (eqradius<=0) {
66  throw Error_MotionPlanning_Not_Feasible(1);
67  }
68 }
69 
70 void Path_RoundedComposite::Add(const Frame& F_base_point) {
71  double eps = 1E-7;
72  if (nrofpoints == 0) {
73  F_base_start = F_base_point;
74  } else if (nrofpoints == 1) {
75  F_base_via = F_base_point;
76  } else {
77  // calculate rounded segment : line + circle,
78  // determine the angle between the line segments :
79  Vector ab = F_base_via.p - F_base_start.p;
80  Vector bc = F_base_point.p - F_base_via.p;
81  double abdist = ab.Norm();
82  double bcdist = bc.Norm();
83  if (abdist < eps) {
84  throw Error_MotionPlanning_Not_Feasible(2);
85  }
86  if (bcdist < eps) {
87  throw Error_MotionPlanning_Not_Feasible(3);
88  }
89  // Clamp to avoid rounding errors (acos is defined between [-1 ; 1])
90  double alpha = acos(std::max(-1., std::min(dot(ab, bc) / abdist / bcdist, 1.)));
91  if ((PI - alpha) < eps) {
92  throw Error_MotionPlanning_Not_Feasible(4);
93  }
94  if (alpha < eps) {
95  // no rounding is done in the case of parallel line segments
96  comp->Add(
98  eqradius));
100  F_base_via = F_base_point;
101  } else {
102  double d = radius / tan((PI - alpha) / 2); // tan. is guaranteed not to return zero.
103  if (d >= abdist)
105 
106  if (d >= bcdist)
108 
109  scoped_ptr < Path
110  > line1(
112  orient->Clone(), eqradius));
113  scoped_ptr < Path
114  > line2(
115  new Path_Line(F_base_via, F_base_point,
116  orient->Clone(), eqradius));
117  Frame F_base_circlestart = line1->Pos(line1->LengthToS(abdist - d));
118  Frame F_base_circleend = line2->Pos(line2->LengthToS(d));
119  // end of circle segment, beginning of next line
120  Vector V_base_t = ab * (ab * bc);
121  V_base_t.Normalize();
122  comp->Add(
123  new Path_Line(F_base_start, F_base_circlestart,
124  orient->Clone(), eqradius));
125  comp->Add(
126  new Path_Circle(F_base_circlestart,
127  F_base_circlestart.p - V_base_t * radius,
128  F_base_circleend.p, F_base_circleend.M, alpha,
129  orient->Clone(), eqradius));
130  // shift for next line
131  F_base_start = F_base_circleend; // end of the circle segment
132  F_base_via = F_base_point;
133  }
134  }
135 
136  nrofpoints++;
137 }
138 
140  if (nrofpoints >= 1) {
141  comp->Add(
142  new Path_Line(F_base_start, F_base_via, orient->Clone(),
143  eqradius));
144  }
145 }
146 
147 double Path_RoundedComposite::LengthToS(double length) {
148  return comp->LengthToS(length);
149 }
150 
151 
153  return comp->PathLength();
154 }
155 
156 Frame Path_RoundedComposite::Pos(double s) const {
157  return comp->Pos(s);
158 }
159 
160 Twist Path_RoundedComposite::Vel(double s, double sd) const {
161  return comp->Vel(s, sd);
162 }
163 
164 Twist Path_RoundedComposite::Acc(double s, double sd, double sdd) const {
165  return comp->Acc(s, sd, sdd);
166 }
167 
169  comp->Write(os);
170 }
171 
173  return comp->GetNrOfSegments();
174 }
175 
177  return comp->GetSegment(i);
178 }
179 
181  return comp->GetLengthToEndOfSegment(i);
182 }
183 
185  int& segment_number, double& inner_s) {
186  comp->GetCurrentSegmentLocation(s,segment_number,inner_s);
187 }
188 
189 
190 
192  if (aggregate)
193  delete orient;
194  delete comp;
195 }
196 
197 
199  return new Path_RoundedComposite(static_cast<Path_Composite*>(comp->Clone()),radius,eqradius,orient->Clone(), true, nrofpoints);
200 }
201 
202 }
KDL::Path_RoundedComposite::Pos
virtual Frame Pos(double s) const
Definition: path_roundedcomposite.cpp:194
KDL::Path_Composite::GetSegment
virtual Path * GetSegment(int i)
Definition: path_composite.cpp:172
KDL::Path_Composite::Clone
virtual Path * Clone()
Definition: path_composite.cpp:151
KDL::Path_Line::eqradius
double eqradius
Definition: path_line.hpp:147
KDL::Path_RoundedComposite::PathLength
virtual double PathLength()
Definition: path_roundedcomposite.cpp:190
KDL::Path_RoundedComposite::orient
RotationalInterpolation * orient
Definition: path_roundedcomposite.hpp:144
KDL::Frame::p
Vector p
origine of the Frame
Definition: frames.hpp:574
KDL::Path_Composite::PathLength
virtual double PathLength()
Definition: path_composite.cpp:131
KDL::Path_RoundedComposite::aggregate
bool aggregate
Definition: path_roundedcomposite.hpp:151
KDL::Path_RoundedComposite::GetLengthToEndOfSegment
virtual double GetLengthToEndOfSegment(int i)
Definition: path_roundedcomposite.cpp:218
KDL::Path_RoundedComposite::Clone
virtual Path * Clone()
Definition: path_roundedcomposite.cpp:236
KDL::Vector::Norm
double Norm(double eps=epsilon) const
Definition: frames.cpp:142
KDL::Path_RoundedComposite::radius
double radius
Definition: path_roundedcomposite.hpp:142
KDL::Path_RoundedComposite::~Path_RoundedComposite
virtual ~Path_RoundedComposite()
Definition: path_roundedcomposite.cpp:229
KDL::Vector::Normalize
double Normalize(double eps=epsilon)
Definition: frames.cpp:172
KDL::Path_RoundedComposite::Path_RoundedComposite
Path_RoundedComposite(Path_Composite *comp, double radius, double eqradius, RotationalInterpolation *orient, bool aggregate, int nrofpoints)
Definition: path_roundedcomposite.cpp:93
KDL::Path_RoundedComposite::Add
void Add(const Frame &F_base_point)
Definition: path_roundedcomposite.cpp:108
KDL
Definition: kukaLWR_DHnew.cpp:25
KDL::Vector
A concrete implementation of a 3 dimensional vector class.
Definition: frames.hpp:162
KDL::Path_RoundedComposite::F_base_via
Frame F_base_via
Definition: path_roundedcomposite.hpp:147
KDL::Path_RoundedComposite::LengthToS
virtual double LengthToS(double length)
Definition: path_roundedcomposite.cpp:185
KDL::Path_RoundedComposite::nrofpoints
int nrofpoints
Definition: path_roundedcomposite.hpp:149
scoped_ptr.hpp
dot
doubleAcc dot(const VectorAcc &lhs, const VectorAcc &rhs)
Definition: frameacc.inl:137
KDL::Path_Circle
Definition: path_circle.hpp:99
std::ostream
KDL::Path_RoundedComposite::eqradius
double eqradius
Definition: path_roundedcomposite.hpp:143
KDL::Path_Composite::Write
virtual void Write(std::ostream &os)
Definition: path_composite.cpp:159
KDL::Frame
represents a frame transformation in 3D space (rotation + translation)
Definition: frames.hpp:572
KDL::Path_Line
Definition: path_line.hpp:98
KDL::tan
INLINE Rall1d< T, V, S > tan(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:351
error.h
KDL::PI
const double PI
the value of pi
Definition: utility.cxx:16
KDL::Path_Composite::GetLengthToEndOfSegment
virtual double GetLengthToEndOfSegment(int i)
Definition: path_composite.cpp:178
KDL::Error_MotionPlanning_Not_Feasible
Definition: error.h:222
KDL::Path_RoundedComposite::GetCurrentSegmentLocation
virtual void GetCurrentSegmentLocation(double s, int &segment_number, double &inner_s)
Definition: path_roundedcomposite.cpp:222
KDL::Path_RoundedComposite::Finish
void Finish()
Definition: path_roundedcomposite.cpp:177
memory
std::min
T min(T... args)
path_line.hpp
KDL::Path_Composite::Acc
virtual Twist Acc(double s, double sd, double sdd) const
Definition: path_composite.cpp:146
path_roundedcomposite.hpp
KDL::Path_RoundedComposite::GetSegment
virtual Path * GetSegment(int i)
Definition: path_roundedcomposite.cpp:214
KDL::Path_RoundedComposite::Acc
virtual Twist Acc(double s, double sd, double sdd) const
Definition: path_roundedcomposite.cpp:202
KDL::Path_Composite::Vel
virtual Twist Vel(double s, double sd) const
Definition: path_composite.cpp:141
KDL::Path_Composite::GetCurrentSegmentLocation
virtual void GetCurrentSegmentLocation(double s, int &segment_number, double &inner_s)
Definition: path_composite.cpp:184
KDL::Path_RoundedComposite::GetNrOfSegments
virtual int GetNrOfSegments()
Definition: path_roundedcomposite.cpp:210
KDL::Path_Composite
Definition: path_composite.hpp:107
KDL::Frame::M
Rotation M
Orientation of the Frame.
Definition: frames.hpp:575
KDL::Path_RoundedComposite::comp
Path_Composite * comp
Definition: path_roundedcomposite.hpp:139
path_circle.hpp
KDL::Path_RoundedComposite::Vel
virtual Twist Vel(double s, double sd) const
Definition: path_roundedcomposite.cpp:198
KDL::Path_RoundedComposite::F_base_start
Frame F_base_start
Definition: path_roundedcomposite.hpp:146
KDL::RotationalInterpolation::Clone
virtual RotationalInterpolation * Clone() const =0
KDL::Path_Composite::LengthToS
virtual double LengthToS(double length)
Definition: path_composite.cpp:126
std::max
T max(T... args)
KDL::scoped_ptr
Definition: scoped_ptr.hpp:55
KDL::Path_RoundedComposite::Write
virtual void Write(std::ostream &os)
Definition: path_roundedcomposite.cpp:206
KDL::Path
Definition: path.hpp:96
KDL::Path_Composite::Pos
virtual Frame Pos(double s) const
Definition: path_composite.cpp:136
KDL::acos
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
Definition: rall1d.h:423
KDL::Path_Composite::Add
void Add(Path *geom, bool aggregate=true)
Definition: path_composite.cpp:120
KDL::Path_Composite::GetNrOfSegments
virtual int GetNrOfSegments()
Definition: path_composite.cpp:168