treeiksolverpos_nr_jl.cpp

Go to the documentation of this file.
00001 // Copyright  (C)  2007-2008  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 "treeiksolverpos_nr_jl.hpp"
00025 
00026 namespace KDL {
00027     TreeIkSolverPos_NR_JL::TreeIkSolverPos_NR_JL(const Tree& _tree,
00028                                                  const std::vector<std::string>& _endpoints,
00029                                                  const JntArray& _q_min, const JntArray& _q_max,
00030                                                  TreeFkSolverPos& _fksolver, TreeIkSolverVel& _iksolver,
00031                                                  unsigned int _maxiter, double _eps) :
00032         tree(_tree), q_min(tree.getNrOfJoints()), q_max(tree.getNrOfJoints()),
00033         fksolver(_fksolver), iksolver(_iksolver), delta_q(tree.getNrOfJoints()),
00034         endpoints(_endpoints), maxiter(_maxiter), eps(_eps) {
00035         
00036         q_min = _q_min;
00037         q_max = _q_max;
00038         
00039         for (size_t i = 0; i < endpoints.size(); i++) {
00040             frames.insert(Frames::value_type(endpoints[i], Frame::Identity()));
00041             delta_twists.insert(Twists::value_type(endpoints[i], Twist::Zero()));
00042         }
00043     }
00044     
00045     double TreeIkSolverPos_NR_JL::CartToJnt(const JntArray& q_init, const Frames& p_in, JntArray& q_out) {
00046         q_out = q_init;
00047         
00048         //First check if all elements in p_in are available:
00049         for(Frames::const_iterator f_des_it=p_in.begin();f_des_it!=p_in.end();++f_des_it)
00050             if(frames.find(f_des_it->first)==frames.end())
00051                 return -2;
00052         
00053         unsigned int k=0;
00054         while(++k <= maxiter) {
00055             for (Frames::const_iterator f_des_it=p_in.begin();f_des_it!=p_in.end();++f_des_it){
00056                 //Get all iterators for this endpoint
00057                 Frames::iterator f_it = frames.find(f_des_it->first);
00058                 Twists::iterator delta_twist = delta_twists.find(f_des_it->first);
00059                 
00060                 fksolver.JntToCart(q_out, f_it->second, f_it->first);
00061                 delta_twist->second = diff(f_it->second, f_des_it->second);
00062             }
00063             double res = iksolver.CartToJnt(q_out, delta_twists, delta_q);
00064             if (res < eps) return res;
00065             
00066             Add(q_out, delta_q, q_out);
00067             
00068             for (unsigned int j = 0; j < q_min.rows(); j++) {
00069                 if (q_out(j) < q_min(j))
00070                     q_out( j) = q_min(j);
00071                 else if (q_out(j) > q_max(j))
00072                     q_out( j) = q_max(j);
00073             }
00074         }
00075         if (k <= maxiter)
00076             return 0;
00077         else
00078             return -3;
00079     }
00080     
00081     
00082     TreeIkSolverPos_NR_JL::~TreeIkSolverPos_NR_JL() {
00083         
00084     }
00085     
00086 }//namespace
00087 

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