damping.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #include "ros/ros.h"
00019 #include "cob_twist_controller/damping_methods/damping.h"
00020 
00021 /* BEGIN DampingBuilder *****************************************************************************************/
00025 DampingBase* DampingBuilder::createDamping(const TwistControllerParams& params)
00026 {
00027     DampingBase* db = NULL;
00028     switch (params.damping_method)
00029     {
00030         case NO_DAMPING:
00031             db = new DampingNone(params);
00032             break;
00033         case CONSTANT:
00034             db = new DampingConstant(params);
00035             break;
00036         case MANIPULABILITY:
00037             db = new DampingManipulability(params);
00038             break;
00039         case LEAST_SINGULAR_VALUE:
00040             db = new DampingLeastSingularValues(params);
00041             break;
00042         case SIGMOID:
00043             db = new DampingSigmoid(params);
00044             break;
00045         default:
00046             ROS_ERROR("DampingMethod %d not defined! Aborting!", params.damping_method);
00047             break;
00048     }
00049 
00050     return db;
00051 }
00052 /* END DampingBuilder *******************************************************************************************/
00053 
00054 
00055 /* BEGIN DampingNone ********************************************************************************************/
00059 inline Eigen::MatrixXd DampingNone::getDampingFactor(const Eigen::VectorXd& sorted_singular_values,
00060                                                      const Eigen::MatrixXd& jacobian_data) const
00061 {
00062     uint32_t rows = sorted_singular_values.rows();
00063     return Eigen::MatrixXd::Zero(rows, rows);
00064 }
00065 /* END DampingNone **********************************************************************************************/
00066 
00067 
00068 /* BEGIN DampingConstant ****************************************************************************************/
00072 inline Eigen::MatrixXd DampingConstant::getDampingFactor(const Eigen::VectorXd& sorted_singular_values,
00073                                                          const Eigen::MatrixXd& jacobian_data) const
00074 {
00075     uint32_t rows = sorted_singular_values.rows();
00076     return Eigen::MatrixXd::Identity(rows, rows) * pow(this->params_.damping_factor, 2);
00077 }
00078 /* END DampingConstant ******************************************************************************************/
00079 
00080 
00081 /* BEGIN DampingManipulability **********************************************************************************/
00086 Eigen::MatrixXd DampingManipulability::getDampingFactor(const Eigen::VectorXd& sorted_singular_values,
00087                                                         const Eigen::MatrixXd& jacobian_data) const
00088 {
00089     double w_threshold = this->params_.w_threshold;
00090     double lambda_max = this->params_.lambda_max;
00091     Eigen::MatrixXd prod = jacobian_data * jacobian_data.transpose();
00092     double d = prod.determinant();
00093     double w = std::sqrt(std::abs(d));
00094     double damping_factor;
00095     uint32_t rows = sorted_singular_values.rows();
00096     Eigen::MatrixXd damping_matrix = Eigen::MatrixXd::Zero(rows, rows);
00097 
00098     if (w < w_threshold)
00099     {
00100         double tmp_w = (1 - w / w_threshold);
00101         damping_factor = lambda_max * tmp_w * tmp_w;
00102         damping_matrix = Eigen::MatrixXd::Identity(rows, rows) * pow(damping_factor, 2);
00103     }
00104 
00105     return damping_matrix;
00106 }
00107 /* END DampingManipulability ************************************************************************************/
00108 
00109 
00110 /* BEGIN DampingLeastSingularValues **********************************************************************************/
00114 Eigen::MatrixXd DampingLeastSingularValues::getDampingFactor(const Eigen::VectorXd& sorted_singular_values,
00115                                                              const Eigen::MatrixXd& jacobian_data) const
00116 {
00117     // Formula 15 Singularity-robust Task-priority Redundandancy Resolution
00118     double least_singular_value = sorted_singular_values(sorted_singular_values.rows() - 1);
00119     uint32_t rows = sorted_singular_values.rows();
00120     Eigen::MatrixXd damping_matrix = Eigen::MatrixXd::Zero(rows, rows);
00121 
00122     if (least_singular_value < this->params_.eps_damping)
00123     {
00124         double lambda_quad = pow(this->params_.lambda_max, 2.0);
00125         double damping_factor = sqrt( (1.0 - pow(least_singular_value / this->params_.eps_damping, 2.0)) * lambda_quad);
00126         damping_matrix = Eigen::MatrixXd::Identity(rows, rows) * pow(damping_factor, 2);
00127     }
00128 
00129     return damping_matrix;
00130 }
00131 /* END DampingLeastSingularValues ************************************************************************************/
00132 
00133 /* BEGIN DampingSigmoid **********************************************************************************/
00137 Eigen::MatrixXd DampingSigmoid::getDampingFactor(const Eigen::VectorXd& sorted_singular_values,
00138                                                  const Eigen::MatrixXd& jacobian_data) const
00139 {
00140     // Formula will be described in a future paper (to add reference)
00141     uint32_t rows = sorted_singular_values.rows();
00142     Eigen::MatrixXd damping_matrix = Eigen::MatrixXd::Zero(rows, rows);
00143 
00144     for (unsigned i = 0; i < rows; i++)
00145     {
00146 
00147         double lambda_sig = params_.lambda_max / (1 + exp((sorted_singular_values[i] + params_.w_threshold) / params_.slope_damping));
00148         damping_matrix(i, i) = lambda_sig;
00149     }
00150 
00151     return damping_matrix;
00152 }
00153 /* END DampingSigmoid ************************************************************************************/


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Jun 6 2019 21:19:26