chainiksolverpos_nr.cpp
Go to the documentation of this file.
00001 // Copyright  (C)  2007  Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00002 
00003 // Version: 1.0
00004 // Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00005 // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00006 // URL: http://www.orocos.org/kdl
00007 
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Lesser General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2.1 of the License, or (at your option) any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Lesser General Public License for more details.
00017 
00018 // You should have received a copy of the GNU Lesser General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 
00022 #include "chainiksolverpos_nr.hpp"
00023 
00024 namespace KDL
00025 {
00026     ChainIkSolverPos_NR::ChainIkSolverPos_NR(const Chain& _chain,ChainFkSolverPos& _fksolver,ChainIkSolverVel& _iksolver,
00027                                              unsigned int _maxiter, double _eps):
00028         chain(_chain),iksolver(_iksolver),fksolver(_fksolver),delta_q(_chain.getNrOfJoints()),
00029         maxiter(_maxiter),eps(_eps)
00030     {
00031     }
00032 
00033     int ChainIkSolverPos_NR::CartToJnt(const JntArray& q_init, const Frame& p_in, JntArray& q_out)
00034     {
00035             q_out = q_init;
00036 
00037             unsigned int i;
00038             for(i=0;i<maxiter;i++){
00039                 fksolver.JntToCart(q_out,f);
00040                 delta_twist = diff(f,p_in);
00041                 const int rc = iksolver.CartToJnt(q_out,delta_twist,delta_q);
00042                 if (E_NOERROR > rc)
00043                     return (error = E_IKSOLVER_FAILED);
00044                 // we chose to continue if the child solver returned a positive
00045                 // "error", which may simply indicate a degraded solution
00046                 Add(q_out,delta_q,q_out);
00047                 if(Equal(delta_twist,Twist::Zero(),eps))
00048                     // converged, but possibly with a degraded solution
00049                     return (rc > E_NOERROR ? E_DEGRADED : E_NOERROR);
00050             }
00051             return (error = E_NO_CONVERGE);        // failed to converge
00052     }
00053 
00054     ChainIkSolverPos_NR::~ChainIkSolverPos_NR()
00055     {
00056     }
00057 
00058     const char* ChainIkSolverPos_NR::strError(const int error) const
00059     {
00060         if (E_IKSOLVER_FAILED == error) return "Child IK solver failed";
00061         else return SolverI::strError(error);
00062     }
00063 }
00064 


orocos_kdl
Author(s):
autogenerated on Mon Oct 6 2014 03:11:16