unified_joint_limit_singularity_solver.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 "cob_twist_controller/constraint_solvers/solvers/unified_joint_limit_singularity_solver.h"
00019 
00024 Eigen::MatrixXd UnifiedJointLimitSingularitySolver::solve(const Vector6d_t& in_cart_velocities,
00025                                                const JointStates& joint_states)
00026 {
00027 
00028     Eigen::JacobiSVD<Eigen::MatrixXd> svd(this->jacobian_data_, Eigen::ComputeThinU | Eigen::ComputeThinV);
00029     Eigen::MatrixXd J=this->jacobian_data_;
00030     Eigen::MatrixXd J_T=J.transpose();
00031     Eigen::MatrixXd U=svd.matrixU();
00032     Eigen::MatrixXd U_T =U.transpose();
00033 
00034     Eigen::MatrixXd Q = this->calculateWeighting(in_cart_velocities, joint_states);
00035 
00036     Eigen::MatrixXd Wt=Q*svd.matrixV();
00037     Eigen::MatrixXd Wt_T=Wt.transpose();
00038 /*
00039     Eigen::VectorXd singularValues = svd.singularValues();
00040     for (int i=0;i<singularValues.rows();i++){
00041         singularValues(i)=singularValues(i)*Q(i,i);
00042     }
00043     Eigen::MatrixXd lambda = damping_->getDampingFactor(singularValues, this->jacobian_data_);
00044 
00045     Eigen::MatrixXd Ulambda =U*lambda;
00046     Eigen::MatrixXd UlambdaUt =Ulambda*U_T;
00047 
00048     Eigen::MatrixXd WtWt_T= Wt*Wt_T;
00049     Eigen::MatrixXd JWtWt_T=J*Wt*Wt_T;
00050     Eigen::MatrixXd JWtWt_TJ_T=JWtWt_T*J_T;
00051 
00052     Eigen::MatrixXd J_robust=JWtWt_TJ_T+UlambdaUt;
00053 
00054 
00055     Eigen::MatrixXd pinv=J_robust.inverse();
00056     Eigen::MatrixXd J_Tpinv= J_T*pinv;
00057     Eigen::MatrixXd WtWt_TJ_Tpinv= WtWt_T*J_Tpinv;
00058     Eigen::MatrixXd qdots_out =WtWt_TJ_Tpinv*in_cart_velocities;*/
00059 
00060     Eigen::MatrixXd J_robust=J*Wt*Wt_T*J_T;
00061     Eigen::MatrixXd pinv=pinv_calc_.calculate(this->params_, this->damping_, J_robust);
00062     Eigen::MatrixXd qdots_out =Wt*Wt_T*J_T*pinv*in_cart_velocities;
00063 
00064     return qdots_out;
00065 }
00066 
00070 Eigen::MatrixXd UnifiedJointLimitSingularitySolver::calculateWeighting(const Vector6d_t& in_cart_velocities, const JointStates& joint_states) const
00071 {
00072     Eigen::MatrixXd Jinv = pinv_calc_.calculate(this->params_, this->damping_, this->jacobian_data_);
00073     Eigen::VectorXd q_dot = Jinv * in_cart_velocities;
00074     std::vector<double> limits_min = this->limiter_params_.limits_min;
00075     std::vector<double> limits_max = this->limiter_params_.limits_max;
00076     uint32_t cols = this->jacobian_data_.cols();
00077 
00078     Eigen::VectorXd weighting = Eigen::VectorXd::Zero(cols);
00079     Eigen::VectorXd weighting_pos = Eigen::VectorXd::Zero(cols);
00080     Eigen::VectorXd weighting_speed = Eigen::VectorXd::Zero(cols);
00081 
00082     KDL::JntArray q = joint_states.current_q_;
00083 
00084     double sigma = this->params_.ujs_solver_params.sigma;
00085     double sigma_speed = this->params_.ujs_solver_params.sigma_speed;
00086     double delta_pos = this->params_.ujs_solver_params.delta_pos;
00087     double delta_speed = this->params_.ujs_solver_params.delta_speed;
00088     for (uint32_t i = 0; i < cols ; ++i)
00089     {
00090 
00091         weighting(i) = (1.0/(1.0+exp(-(q(i)-limits_min[i]-delta_pos)/sigma)))*(1.0/(1.0+exp((q(i)-limits_max[i]+delta_pos)/sigma)))+(1.0/(1.0+exp((q(i)*q_dot(i)+delta_speed)*sigma_speed)));
00092 
00093         if( (fabs(q(i)-limits_min[i])<params_.limiter_params.limits_tolerance*M_PI/180.0)){
00094             ROS_WARN("Joint %i tolerance distance to minimum position %f not respected",i,(fabs(q(i)-limits_min[i])));
00095         }
00096         if( (fabs(q(i)-limits_max[i])<params_.limiter_params.limits_tolerance*M_PI/180.0) ){
00097             ROS_WARN("Joint %i tolerance distance to maximum position %f not respected",i,(fabs(q(i)-limits_max[i])));
00098         }
00099         if( (fabs(q(i)-limits_min[i])<0.0)){
00100             ROS_ERROR("Joint %i distance to minimum position %f not respected",i,(fabs(q(i)-limits_min[i])));
00101         }
00102         if( (fabs(q(i)-limits_max[i])<0.0)){
00103             ROS_ERROR("Joint %i distance to maximum position %f not respected",i,(fabs(q(i)-limits_max[i])));
00104         }
00105 
00106         if(weighting(i)>1.0){
00107             weighting(i)=1.0;
00108         }
00109     }
00110 
00111     return weighting.asDiagonal();
00112 }


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