damping.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include "ros/ros.h"
20 
21 /* BEGIN DampingBuilder *****************************************************************************************/
26 {
27  DampingBase* db = NULL;
28  switch (params.damping_method)
29  {
30  case NO_DAMPING:
31  db = new DampingNone(params);
32  break;
33  case CONSTANT:
34  db = new DampingConstant(params);
35  break;
36  case MANIPULABILITY:
37  db = new DampingManipulability(params);
38  break;
40  db = new DampingLeastSingularValues(params);
41  break;
42  case SIGMOID:
43  db = new DampingSigmoid(params);
44  break;
45  default:
46  ROS_ERROR("DampingMethod %d not defined! Aborting!", params.damping_method);
47  break;
48  }
49 
50  return db;
51 }
52 /* END DampingBuilder *******************************************************************************************/
53 
54 
55 /* BEGIN DampingNone ********************************************************************************************/
59 inline Eigen::MatrixXd DampingNone::getDampingFactor(const Eigen::VectorXd& sorted_singular_values,
60  const Eigen::MatrixXd& jacobian_data) const
61 {
62  uint32_t rows = sorted_singular_values.rows();
63  return Eigen::MatrixXd::Zero(rows, rows);
64 }
65 /* END DampingNone **********************************************************************************************/
66 
67 
68 /* BEGIN DampingConstant ****************************************************************************************/
72 inline Eigen::MatrixXd DampingConstant::getDampingFactor(const Eigen::VectorXd& sorted_singular_values,
73  const Eigen::MatrixXd& jacobian_data) const
74 {
75  uint32_t rows = sorted_singular_values.rows();
76  return Eigen::MatrixXd::Identity(rows, rows) * pow(this->params_.damping_factor, 2);
77 }
78 /* END DampingConstant ******************************************************************************************/
79 
80 
81 /* BEGIN DampingManipulability **********************************************************************************/
86 Eigen::MatrixXd DampingManipulability::getDampingFactor(const Eigen::VectorXd& sorted_singular_values,
87  const Eigen::MatrixXd& jacobian_data) const
88 {
89  double w_threshold = this->params_.w_threshold;
90  double lambda_max = this->params_.lambda_max;
91  Eigen::MatrixXd prod = jacobian_data * jacobian_data.transpose();
92  double d = prod.determinant();
93  double w = std::sqrt(std::abs(d));
94  double damping_factor;
95  uint32_t rows = sorted_singular_values.rows();
96  Eigen::MatrixXd damping_matrix = Eigen::MatrixXd::Zero(rows, rows);
97 
98  if (w < w_threshold)
99  {
100  double tmp_w = (1 - w / w_threshold);
101  damping_factor = lambda_max * tmp_w * tmp_w;
102  damping_matrix = Eigen::MatrixXd::Identity(rows, rows) * pow(damping_factor, 2);
103  }
104 
105  return damping_matrix;
106 }
107 /* END DampingManipulability ************************************************************************************/
108 
109 
110 /* BEGIN DampingLeastSingularValues **********************************************************************************/
114 Eigen::MatrixXd DampingLeastSingularValues::getDampingFactor(const Eigen::VectorXd& sorted_singular_values,
115  const Eigen::MatrixXd& jacobian_data) const
116 {
117  // Formula 15 Singularity-robust Task-priority Redundandancy Resolution
118  double least_singular_value = sorted_singular_values(sorted_singular_values.rows() - 1);
119  uint32_t rows = sorted_singular_values.rows();
120  Eigen::MatrixXd damping_matrix = Eigen::MatrixXd::Zero(rows, rows);
121 
122  if (least_singular_value < this->params_.eps_damping)
123  {
124  double lambda_quad = pow(this->params_.lambda_max, 2.0);
125  double damping_factor = sqrt( (1.0 - pow(least_singular_value / this->params_.eps_damping, 2.0)) * lambda_quad);
126  damping_matrix = Eigen::MatrixXd::Identity(rows, rows) * pow(damping_factor, 2);
127  }
128 
129  return damping_matrix;
130 }
131 /* END DampingLeastSingularValues ************************************************************************************/
132 
133 /* BEGIN DampingSigmoid **********************************************************************************/
137 Eigen::MatrixXd DampingSigmoid::getDampingFactor(const Eigen::VectorXd& sorted_singular_values,
138  const Eigen::MatrixXd& jacobian_data) const
139 {
140  // Formula will be described in a future paper (to add reference)
141  uint32_t rows = sorted_singular_values.rows();
142  Eigen::MatrixXd damping_matrix = Eigen::MatrixXd::Zero(rows, rows);
143 
144  for (unsigned i = 0; i < rows; i++)
145  {
146 
147  double lambda_sig = params_.lambda_max / (1 + exp((sorted_singular_values[i] + params_.w_threshold) / params_.slope_damping));
148  damping_matrix(i, i) = lambda_sig;
149  }
150 
151  return damping_matrix;
152 }
153 /* END DampingSigmoid ************************************************************************************/
d
#define NULL
virtual Eigen::MatrixXd getDampingFactor(const Eigen::VectorXd &sorted_singular_values, const Eigen::MatrixXd &jacobian_data) const
Definition: damping.cpp:114
virtual Eigen::MatrixXd getDampingFactor(const Eigen::VectorXd &sorted_singular_values, const Eigen::MatrixXd &jacobian_data) const
Definition: damping.cpp:86
virtual Eigen::MatrixXd getDampingFactor(const Eigen::VectorXd &sorted_singular_values, const Eigen::MatrixXd &jacobian_data) const
Definition: damping.cpp:137
Class implementing a method to return the constant factor.
Definition: damping.h:54
Class implementing a method to return a factor corresponding to the measure of manipulability.
Definition: damping.h:70
Class implementing a method to return a damping factor based on a sigmoid function.
Definition: damping.h:102
virtual Eigen::MatrixXd getDampingFactor(const Eigen::VectorXd &sorted_singular_values, const Eigen::MatrixXd &jacobian_data) const
Definition: damping.cpp:72
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
virtual Eigen::MatrixXd getDampingFactor(const Eigen::VectorXd &sorted_singular_values, const Eigen::MatrixXd &jacobian_data) const
Definition: damping.cpp:59
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
TFSIMD_FORCE_INLINE const tfScalar & w() const
Class implementing a method to return the constant factor.
Definition: damping.h:38
#define ROS_ERROR(...)
static DampingBase * createDamping(const TwistControllerParams &params)
Definition: damping.cpp:25
Base class for solvers, defining interface methods.
Definition: damping_base.h:24
Class implementing a method to return a damping factor based on least singular value.
Definition: damping.h:86


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Apr 8 2021 02:40:00