chainiksolverpos_nr_jl.cpp

Go to the documentation of this file.
00001 // Copyright  (C)  2007  Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00002 // Copyright  (C)  2008  Mikael Mayer
00003 // Copyright  (C)  2008  Julia Jesse
00004 
00005 // Version: 1.0
00006 // Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00007 // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00008 // URL: http://www.orocos.org/kdl
00009 
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00023 
00024 #include "chainiksolverpos_nr_jl.hpp"
00025 
00026 
00027 #ifndef M_PI
00028     #define M_PI    3.14159265358979323846 /* pi */
00029 #endif
00030 
00031 #ifndef M_PI_2
00032     #define M_PI_2  1.57079632679489661923 /* pi/2 */
00033 #endif
00034 
00035 namespace KDL
00036 {
00037     ChainIkSolverPos_NR_JL::ChainIkSolverPos_NR_JL(const Chain& _chain, const JntArray& _q_min, const JntArray& _q_max, ChainFkSolverPos& _fksolver,ChainIkSolverVel& _iksolver,
00038                                              unsigned int _maxiter, double _eps):
00039         chain(_chain), q_min(chain.getNrOfJoints()), q_max(chain.getNrOfJoints()), fksolver(_fksolver),iksolver(_iksolver),delta_q(_chain.getNrOfJoints()),
00040         maxiter(_maxiter),eps(_eps)
00041     {
00042         q_min = _q_min;
00043         q_max = _q_max;
00044     }
00045 
00046     int ChainIkSolverPos_NR_JL::CartToJnt(const JntArray& q_init, const Frame& p_in, JntArray& q_out)
00047     {
00048             q_out = q_init;
00049 
00050             unsigned int i;
00051             for(i=0;i<maxiter;i++){
00052                 fksolver.JntToCart(q_out,f);
00053                 delta_twist = diff(f,p_in);
00054 
00055                                 if(Equal(delta_twist,Twist::Zero(),eps))
00056                                         break;
00057 
00058                                 iksolver.CartToJnt(q_out,delta_twist,delta_q);
00059                 Add(q_out,delta_q,q_out);
00060 
00061                 for(unsigned int j=0; j<q_min.rows(); j++) {
00062                   if(q_out(j) < q_min(j))
00063                     //q_out(j) = q_min(j);
00064                     q_out(j) = q_out(j) + M_PI *2;
00065                 }
00066 
00067 
00068                 for(unsigned int j=0; j<q_max.rows(); j++) {
00069                     if(q_out(j) > q_max(j))
00070                       //q_out(j) = q_max(j);
00071                       q_out(j) = q_out(j) - M_PI *2;
00072                 }
00073             }
00074 
00075             if(i!=maxiter)
00076                 return 0;
00077             else
00078                 return -3;
00079     }
00080 
00081     ChainIkSolverPos_NR_JL::~ChainIkSolverPos_NR_JL()
00082     {
00083     }
00084 
00085 }
00086 

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