path_circle.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Erwin Aertbelien  Mon May 10 19:10:36 CEST 2004  path_circle.cxx
00003 
00004                         path_circle.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_circle.cpp,v 1.1.1.1.2.5 2003/07/24 13:26:15 psoetens Exp $
00039  *              $Name:  $
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                                         // See what has the slowest eq. motion, and adapt
00079                                         // the other to this slower motion
00080                                         // use eqradius to transform between rot and transl.
00081                                         // the same as for lineair motion
00082                                         if (oalpha*eqradius > dist) {
00083                                                 // rotational_interpolation is the limitation
00084                                                 pathlength = oalpha*eqradius;
00085                                                 scalerot   = 1/eqradius;
00086                                                 scalelin   = dist/pathlength;
00087                                         } else {
00088                                                 // translation is the limitation
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 

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