path_roundedcomposite.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Erwin Aertbelien  Mon May 10 19:10:36 CEST 2004  path_roundedcomposite.cxx
00003 
00004                         path_roundedcomposite.cxx -  description
00005                            -------------------
00006     begin                : Mon May 10 2004
00007     copyright            : (C) 2004 Erwin Aertbelien
00008     email                : erwin.aertbelien@mech.kuleuven.ac.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place,                                    *
00024  *   Suite 330, Boston, MA  02111-1307  USA                                *
00025  *                                                                         *
00026  ***************************************************************************/
00027 /*****************************************************************************
00028  *  \author
00029  *      Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
00030  *
00031  *  \version
00032  *              ORO_Geometry V0.2
00033  *
00034  *      \par History
00035  *              - $log$
00036  *
00037  *      \par Release
00038  *              $Id: path_roundedcomposite.cpp,v 1.1.1.1.2.5 2003/07/24 13:26:15 psoetens Exp $
00039  *              $Name:  $
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                 // calculate rounded segment : line + circle,
00065                 // determine the angle between the line segments :
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             //double alpha  = ::acos(dot(ab,bc));
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                                 // end of circle segment, beginning of next line
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                 // shift for next line
00101                 F_base_start = F_base_circleend;  // end of the circle segment
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 }

Generated on Wed Nov 23 19:00:25 2011 for FreeCAD by  doxygen 1.6.1