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) {
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 :
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) {
85  }
86  if (bcdist < eps) {
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) {
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(
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 
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 
168 void Path_RoundedComposite::Write(std::ostream& os) {
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 }
void Add(Path *geom, bool aggregate=true)
void Add(const Frame &F_base_point)
virtual Frame Pos(double s) const
virtual Twist Acc(double s, double sd, double sdd) const
virtual double PathLength()
double Normalize(double eps=epsilon)
Definition: frames.cpp:148
const double PI
the value of pi
virtual Twist Acc(double s, double sd, double sdd) const
virtual RotationalInterpolation * Clone() const =0
virtual double LengthToS(double length)
virtual Twist Vel(double s, double sd) const
doubleAcc dot(const VectorAcc &lhs, const VectorAcc &rhs)
Definition: frameacc.hpp:138
virtual Path * GetSegment(int i)
Rotation M
Orientation of the Frame.
Definition: frames.hpp:573
represents both translational and rotational velocities.
Definition: frames.hpp:720
A concrete implementation of a 3 dimensional vector class.
Definition: frames.hpp:160
double Norm() const
Definition: frames.cpp:118
virtual void Write(std::ostream &os)
virtual void GetCurrentSegmentLocation(double s, int &segment_number, double &inner_s)
Path_RoundedComposite(Path_Composite *comp, double radius, double eqradius, RotationalInterpolation *orient, bool aggregate, int nrofpoints)
Vector p
origine of the Frame
Definition: frames.hpp:572
double min(double a, double b)
Definition: utility.h:206
virtual Twist Vel(double s, double sd) const
virtual void GetCurrentSegmentLocation(double s, int &segment_number, double &inner_s)
virtual int GetNrOfSegments()
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
Definition: rall1d.h:401
virtual Path * Clone()
virtual void Write(std::ostream &os)
represents a frame transformation in 3D space (rotation + translation)
Definition: frames.hpp:570
virtual double GetLengthToEndOfSegment(int i)
INLINE Rall1d< T, V, S > tan(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:329
virtual Frame Pos(double s) const
virtual double LengthToS(double length)
double max(double a, double b)
Definition: utility.h:198
RotationalInterpolation * orient
virtual double GetLengthToEndOfSegment(int i)


orocos_kdl
Author(s):
autogenerated on Sat Jun 15 2019 19:07:36