treefksolverpos_recursive.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 Julia Jesse
00003 
00004 // Version: 1.0
00005 // Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00006 // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00007 // URL: http://www.orocos.org/kdl
00008 
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 #include "treefksolverpos_recursive.hpp"
00024 #include <iostream>
00025 
00026 namespace KDL {
00027 
00028     TreeFkSolverPos_recursive::TreeFkSolverPos_recursive(const Tree& _tree):
00029         tree(_tree)
00030     {
00031     }
00032 
00033     int TreeFkSolverPos_recursive::JntToCart(const JntArray& q_in, Frame& p_out, std::string segmentName)
00034     {      
00035                 SegmentMap::const_iterator it = tree.getSegment(segmentName); 
00036        
00037         
00038         if(q_in.rows() != tree.getNrOfJoints())
00039                 return -1;
00040         else if(it == tree.getSegments().end()) //if the segment name is not found
00041                 return -2;
00042         else{
00043                 const TreeElement& currentElement = it->second;
00044                         p_out = recursiveFk(q_in, it);  
00045                 return 0;               
00046         }
00047     }
00048 
00049         Frame TreeFkSolverPos_recursive::recursiveFk(const JntArray& q_in, const SegmentMap::const_iterator& it)
00050         {
00051                 //gets the frame for the current element (segment)
00052                 const TreeElement& currentElement = it->second;
00053                 Frame currentFrame = currentElement.segment.pose(q_in(currentElement.q_nr));
00054                 
00055                 SegmentMap::const_iterator rootIterator = tree.getSegment("root");
00056                 if(it == rootIterator){
00057                         return currentFrame;    
00058                 }
00059                 else{
00060                         SegmentMap::const_iterator parentIt = currentElement.parent;
00061                         return recursiveFk(q_in, parentIt) * currentFrame;
00062                 }
00063         }
00064 
00065     TreeFkSolverPos_recursive::~TreeFkSolverPos_recursive()
00066     {
00067     }
00068 
00069 
00070 }

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