chainiksolvervel_wdls_coupling.cpp
Go to the documentation of this file.
1 // Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
2 
3 // Version: 1.0
4 // Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
5 // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
6 // URL: http://www.orocos.org/kdl
7 
8 // Modified by Juan A. Corrales, ISIR, UPMC
9 // Added coupled joint support based on a modified version of the patch by Federico Ruiz:
10 // http://www.orocos.org/forum/rtt/rtt-dev/patches-coupled-joints-locked-joints-and-python-executable-detection
11 
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Lesser General Public
14 // License as published by the Free Software Foundation; either
15 // version 2.1 of the License, or (at your option) any later version.
16 
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 
27 #include <kdl/utilities/svd_eigen_HH.hpp>
28 
29 namespace KDL
30 {
32  int _maxiter) :
33  chain(_chain),
34  jnt2jac(chain),
35  jac(chain.getNrOfIndJoints()),
36  U(MatrixXd::Zero(6, chain.getNrOfIndJoints())),
37  S(VectorXd::Zero(chain.getNrOfIndJoints())),
38  V(MatrixXd::Zero(chain.getNrOfIndJoints(), chain.getNrOfIndJoints())),
39  eps(_eps),
40  maxiter(_maxiter),
41  tmp(VectorXd::Zero(chain.getNrOfIndJoints())),
42  tmp_jac(MatrixXd::Zero(6, chain.getNrOfJoints())),
43  tmp_jac_weight1(MatrixXd::Zero(6, chain.getNrOfIndJoints())),
44  tmp_jac_weight2(MatrixXd::Zero(6, chain.getNrOfIndJoints())),
45  tmp_ts(MatrixXd::Zero(6, 6)),
46  tmp_js(MatrixXd::Zero(chain.getNrOfIndJoints(), chain.getNrOfIndJoints())),
47  weight_ts(MatrixXd::Identity(6, 6)),
48  weight_js(MatrixXd::Identity(chain.getNrOfIndJoints(), chain.getNrOfIndJoints())),
49  lambda(0.0)
50  {
51  }
52 
54  {
55  }
56 
58  {
59  weight_js = Mq;
60  }
61 
63  {
64  return weight_js;
65  }
66 
68  {
69  weight_ts = Mx;
70  }
71 
73  {
74  return weight_ts;
75  }
76 
77  void ChainIkSolverVel_wdls_coupling::setLambda(const double &lambda_in)
78  {
79  lambda = lambda_in;
80  }
81 
82  int ChainIkSolverVel_wdls_coupling::CartToJnt(const JntArray &q_in, const Twist &v_in, JntArray &qdot_out)
83  {
84  // Update the coupling matrix of the chain
85  this->chain.updateCoupling(q_in);
86  // Compute the Jacobian
87  jnt2jac.JntToJac(q_in, jac);
88 
89  double sum;
90  unsigned int i, j;
91 
92  // Create the Weighted jacobian
93  // tmp_jac_weight1 = jac.data.lazyProduct(weight_js); // RE-USE THIS LINE IF FAILURE
94  // tmp_jac_weight2 = weight_ts.lazyProduct(tmp_jac_weight1); // RE-USE THIS LINE IF FAILURE
95  tmp_jac_weight1.noalias() = jac.data * weight_js;
97 
98  // Compute the SVD of the weighted jacobian
99  int ret = svd_eigen_HH(tmp_jac_weight2, U, S, V, tmp, maxiter);
100  // Pre-multiply U and V by the task space and joint space weighting matrix respectively
101 
102  Eigen::MatrixXd U_temp(6, 6);
103  U_temp.setZero();
104 
105  if (U.cols() >= 6)
106  {
107  U_temp = U.topLeftCorner(6, 6);
108  }
109  else
110  {
111  U_temp.topLeftCorner(U.rows(), U.cols()) = U;
112  }
113 
114  // tmp_ts = weight_ts.lazyProduct(U_temp); // RE-USE THIS LINE IF FAILURE
115  tmp_js = weight_js.lazyProduct(V); // DO NOT REMOVE LAZY HERE
116  tmp_ts.noalias() = weight_ts * U_temp;
117 
118  // tmp = (Si*U'*Ly*y),
119  for (i = 0; i < jac.columns(); i++)
120  {
121  sum = 0.0;
122  for (j = 0; j < jac.rows(); j++)
123  {
124  if (i < 6)
125  {
126  sum += tmp_ts(j, i) * v_in(j);
127  }
128  else
129  {
130  sum += 0.0;
131  }
132  }
133  if (S(i) == 0 || S(i) < eps)
134  {
135  tmp(i) = sum * ((S(i) / (S(i) * S(i) + lambda * lambda)));
136  }
137  else
138  {
139  tmp(i) = sum / S(i);
140  }
141  }
142 
143  // qdot_out.data=(chain.cm*(tmp_js*tmp).lazy()).lazy();
144  qdot_out.data.noalias() = chain.cm * (tmp_js * tmp);
145  return ret;
146  }
147 } // namespace KDL
void updateCoupling(const JntArray &q)
int JntToJac(const JntArray &q_in, Jacobian &jac)
unsigned int columns() const
int svd_eigen_HH(const MatrixXd &A, MatrixXd &U, VectorXd &S, MatrixXd &V, VectorXd &tmp, int maxiter, double epsilon)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Matrix< double, 6, Eigen::Dynamic > data
Eigen::MatrixXd cm
Eigen::VectorXd data
ChainIkSolverVel_wdls_coupling(const Chain_coupling &chain, double eps=0.00001, int maxiter=150)
virtual int CartToJnt(const JntArray &q_in, const Twist &v_in, JntArray &qdot_out)
unsigned int rows() const


kdl_coupling
Author(s): Juan Antonio Corrales Ramon (UPMC)
autogenerated on Wed Oct 14 2020 04:05:04