treeiksolvervel_wdls.cpp
Go to the documentation of this file.
1 /*
2  * TreeIkSolverVel_wdls.cpp
3  *
4  * Created on: Nov 28, 2008
5  * Author: rubensmits
6  */
7 
10 
11 namespace KDL {
12  TreeIkSolverVel_wdls::TreeIkSolverVel_wdls(const Tree& tree_in, const std::vector<std::string>& endpoints) :
13  tree(tree_in), jnttojacsolver(tree),
14  J(Eigen::MatrixXd::Zero(6 * endpoints.size(), tree.getNrOfJoints())),
15  Wy(Eigen::MatrixXd::Identity(J.rows(),J.rows())),
16  Wq(Eigen::MatrixXd::Identity(J.cols(),J.cols())),
17  J_Wq(J.rows(),J.cols()),Wy_J_Wq(J.rows(),J.cols()),
18  U(Eigen::MatrixXd::Identity(J.rows(),J.cols())),
19  V(Eigen::MatrixXd::Identity(J.cols(),J.cols())),
20  Wy_U(J.rows(),J.rows()),Wq_V(J.cols(),J.cols()),
21  t(Eigen::VectorXd::Zero(J.rows())), Wy_t(Eigen::VectorXd::Zero(J.rows())),
22  qdot(Eigen::VectorXd::Zero(J.cols())),
23  tmp(Eigen::VectorXd::Zero(J.cols())),S(Eigen::VectorXd::Zero(J.cols())),
24  lambda(0)
25  {
26 
27  for (size_t i = 0; i < endpoints.size(); ++i) {
28  jacobians.insert(Jacobians::value_type(endpoints[i], Jacobian(tree.getNrOfJoints())));
29  }
30 
31  }
32 
34  }
35 
36  void TreeIkSolverVel_wdls::setWeightJS(const Eigen::MatrixXd& Mq) {
37  Wq = Mq;
38  }
39 
40  void TreeIkSolverVel_wdls::setWeightTS(const Eigen::MatrixXd& Mx) {
41  Wy = Mx;
42  }
43 
44  void TreeIkSolverVel_wdls::setLambda(const double& lambda_in) {
45  lambda = lambda_in;
46  }
47 
48  double TreeIkSolverVel_wdls::CartToJnt(const JntArray& q_in, const Twists& v_in, JntArray& qdot_out) {
49 
50  //First check if we are configured for this Twists:
51  for (Twists::const_iterator v_it = v_in.begin(); v_it != v_in.end(); ++v_it) {
52  if (jacobians.find(v_it->first) == jacobians.end())
53  return -2;
54  }
55  //Check if q_in has the right size
56  if (q_in.rows() != tree.getNrOfJoints())
57  return -1;
58 
59  //Lets get all the jacobians we need:
60  unsigned int k = 0;
61  for (Jacobians::iterator jac_it = jacobians.begin(); jac_it
62  != jacobians.end(); ++jac_it) {
63  int ret = jnttojacsolver.JntToJac(q_in, jac_it->second, jac_it->first);
64  if (ret < 0)
65  return ret;
66  else {
67  //lets put the jacobian in the big matrix and put the twist in the big t:
68  J.block(6*k,0, 6,tree.getNrOfJoints()) = jac_it->second.data;
69  const Twist& twist=v_in.find(jac_it->first)->second;
70  t.segment(6*k,3) = Eigen::Map<const Eigen::Vector3d>(twist.vel.data);
71  t.segment(6*k+3,3) = Eigen::Map<const Eigen::Vector3d>(twist.rot.data);
72  }
73  ++k;
74  }
75 
76  //Lets use the wdls algorithm to find the qdot:
77  // Create the Weighted jacobian
78  J_Wq.noalias() = J * Wq;
79  Wy_J_Wq.noalias() = Wy * J_Wq;
80 
81  // Compute the SVD of the weighted jacobian
82  int ret = svd_eigen_HH(Wy_J_Wq, U, S, V, tmp);
83  if (ret < 0 )
84  return E_SVD_FAILED;
85  //Pre-multiply U and V by the task space and joint space weighting matrix respectively
86  Wy_t.noalias() = Wy * t;
87  Wq_V.noalias() = Wq * V;
88 
89  // tmp = (Si*Wy*U'*y),
90  for (unsigned int i = 0; i < J.cols(); i++) {
91  double sum = 0.0;
92  for (unsigned int j = 0; j < J.rows(); j++) {
93  if (i < Wy_t.rows())
94  sum += U(j, i) * Wy_t(j);
95  else
96  sum += 0.0;
97  }
98  tmp( i) = sum * ((S(i) / (S(i) * S(i) + lambda * lambda)));
99  }
100 
101  // x = Lx^-1*V*tmp + x
102  qdot_out.data.noalias() = Wq_V * tmp;
103 
104  return Wy_t.norm();
105  }
106 }
int JntToJac(const JntArray &q_in, Jacobian &jac, const std::string &segmentname)
void setWeightTS(const Eigen::MatrixXd &Mx)
virtual double CartToJnt(const JntArray &q_in, const Twists &v_in, JntArray &qdot_out)
unsigned int getNrOfJoints() const
Definition: tree.hpp:159
This class represents an fixed size array containing joint values of a KDL::Chain.
Definition: jntarray.hpp:69
unsigned int rows() const
Definition: jntarray.cpp:70
represents both translational and rotational velocities.
Definition: frames.hpp:723
void setLambda(const double &lambda)
Eigen::VectorXd data
Definition: jntarray.hpp:72
int svd_eigen_HH(const Eigen::MatrixXd &A, Eigen::MatrixXd &U, Eigen::VectorXd &S, Eigen::MatrixXd &V, Eigen::VectorXd &tmp, int maxiter, double epsilon)
TreeIkSolverVel_wdls(const Tree &tree, const std::vector< std::string > &endpoints)
Child SVD failed.
void setWeightJS(const Eigen::MatrixXd &Mq)
std::map< std::string, Twist > Twists
This class encapsulates a tree kinematic interconnection structure. It is built out of segments...
Definition: tree.hpp:99


orocos_kdl
Author(s):
autogenerated on Thu Apr 13 2023 02:19:14