pseudo_inversion.h
Go to the documentation of this file.
1 // Author: Enrico Corvaglia
2 // https://github.com/CentroEPiaggio/kuka-lwr/blob/master/lwr_controllers/include/utils/pseudo_inversion.h
3 // File provided under public domain
4 // pseudo_inverse() computes the pseudo inverse of matrix M_ using SVD decomposition (can choose
5 // between damped and not)
6 // returns the pseudo inverted matrix M_pinv_
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <Eigen/LU>
12 #include <Eigen/SVD>
13 
15 
16 inline void pseudoInverse(const Eigen::MatrixXd& M_, Eigen::MatrixXd& M_pinv_, bool damped = true) {
17  double lambda_ = damped ? 0.2 : 0.0;
18 
19  Eigen::JacobiSVD<Eigen::MatrixXd> svd(M_, Eigen::ComputeFullU | Eigen::ComputeFullV);
20  Eigen::JacobiSVD<Eigen::MatrixXd>::SingularValuesType sing_vals_ = svd.singularValues();
21  Eigen::MatrixXd S_ = M_; // copying the dimensions of M_, its content is not needed.
22  S_.setZero();
23 
24  for (int i = 0; i < sing_vals_.size(); i++)
25  S_(i, i) = (sing_vals_(i)) / (sing_vals_(i) * sing_vals_(i) + lambda_ * lambda_);
26 
27  M_pinv_ = Eigen::MatrixXd(svd.matrixV() * S_.transpose() * svd.matrixU().transpose());
28 }
29 
30 } // namespace franka_example_controllers
void pseudoInverse(const Eigen::MatrixXd &M_, Eigen::MatrixXd &M_pinv_, bool damped=true)


franka_example_controllers
Author(s): Franka Emika GmbH
autogenerated on Fri Oct 23 2020 03:47:17