treefksolverpos_recursive.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /** \file itasc/kdl/treefksolverpos_recursive.cpp
  2. * \ingroup itasc
  3. */
  4. // Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
  5. // Copyright (C) 2008 Julia Jesse
  6. // Version: 1.0
  7. // Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
  8. // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
  9. // URL: http://www.orocos.org/kdl
  10. // This library is free software; you can redistribute it and/or
  11. // modify it under the terms of the GNU Lesser General Public
  12. // License as published by the Free Software Foundation; either
  13. // version 2.1 of the License, or (at your option) any later version.
  14. // This library is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. // Lesser General Public License for more details.
  18. // You should have received a copy of the GNU Lesser General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. #include "treefksolverpos_recursive.hpp"
  22. #include <iostream>
  23. namespace KDL {
  24. TreeFkSolverPos_recursive::TreeFkSolverPos_recursive(const Tree& _tree):
  25. tree(_tree)
  26. {
  27. }
  28. int TreeFkSolverPos_recursive::JntToCart(const JntArray& q_in, Frame& p_out, const std::string& segmentName, const std::string& baseName)
  29. {
  30. SegmentMap::value_type const* it = tree.getSegmentPtr(segmentName);
  31. SegmentMap::value_type const* baseit = tree.getSegmentPtr(baseName);
  32. if(q_in.rows() != tree.getNrOfJoints())
  33. return -1;
  34. else if(!it) //if the segment name is not found
  35. return -2;
  36. else if(!baseit) //if the base segment name is not found
  37. return -3;
  38. else{
  39. p_out = recursiveFk(q_in, it, baseit);
  40. return 0;
  41. }
  42. }
  43. Frame TreeFkSolverPos_recursive::recursiveFk(const JntArray& q_in, SegmentMap::value_type const* it, SegmentMap::value_type const* baseit)
  44. {
  45. //gets the frame for the current element (segment)
  46. const TreeElement& currentElement = it->second;
  47. if(it == baseit){
  48. return KDL::Frame::Identity();
  49. }
  50. else{
  51. Frame currentFrame = currentElement.segment.pose(((JntArray&)q_in)(currentElement.q_nr));
  52. return recursiveFk(q_in, currentElement.parent, baseit) * currentFrame;
  53. }
  54. }
  55. TreeFkSolverPos_recursive::~TreeFkSolverPos_recursive()
  56. {
  57. }
  58. }