Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
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 }
00087