Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
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 }