gradient_projection_method_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 <set>
00019 #include <cmath>
00020 
00021 #include "cob_twist_controller/constraint_solvers/solvers/gradient_projection_method_solver.h"
00022 
00028 Eigen::MatrixXd GradientProjectionMethodSolver::solve(const Vector6d_t& in_cart_velocities,
00029                                                       const JointStates& joint_states)
00030 {
00031     Eigen::MatrixXd damped_pinv = pinv_calc_.calculate(this->params_, this->damping_, this->jacobian_data_);
00032     Eigen::MatrixXd pinv = pinv_calc_.calculate(this->jacobian_data_);
00033 
00034     Eigen::MatrixXd particular_solution = damped_pinv * in_cart_velocities;
00035 
00036     // Eigen::MatrixXd ident = Eigen::MatrixXd::Identity(damped_pinv.rows(), this->jacobian_data_.cols());
00037     // Eigen::MatrixXd projector = ident - damped_pinv * this->jacobian_data_;
00038     Eigen::MatrixXd ident = Eigen::MatrixXd::Identity(pinv.rows(), this->jacobian_data_.cols());
00039     Eigen::MatrixXd projector = ident - pinv * this->jacobian_data_;
00040 
00041     Eigen::MatrixXd homogeneous_solution = Eigen::MatrixXd::Zero(particular_solution.rows(), particular_solution.cols());
00042     KDL::JntArrayVel predict_jnts_vel(joint_states.current_q_.rows());
00043 
00044     for (std::set<ConstraintBase_t>::iterator it = this->constraints_.begin(); it != this->constraints_.end(); ++it)
00045     {
00046         ROS_DEBUG_STREAM("task id: " << (*it)->getTaskId());
00047         (*it)->update(joint_states, predict_jnts_vel, this->jacobian_data_);
00048         Eigen::VectorXd q_dot_0 = (*it)->getPartialValues();
00049         Eigen::MatrixXd tmp_projection = projector * q_dot_0;
00050         double activation_gain = (*it)->getActivationGain();  // contribution of the homo. solution to the part. solution
00051         double constraint_k_H = (*it)->getSelfMotionMagnitude(particular_solution, tmp_projection);  // gain of homogenous solution (if active)
00052         homogeneous_solution += (constraint_k_H * activation_gain * tmp_projection);
00053     }
00054 
00055     Eigen::MatrixXd qdots_out = particular_solution + this->params_.k_H * homogeneous_solution;  // weighting with k_H is done in loop
00056 
00057     // //DEBUG: for verification of nullspace projection
00058     // std::stringstream ss_part;
00059     // ss_part << "particular_solution: ";
00060     // for(unsigned int i=0; i<particular_solution.rows(); i++)
00061     // {   ss_part << particular_solution(i,0) << " , ";    }
00062     // ROS_INFO_STREAM(ss_part.str());
00063     // std::stringstream ss_hom;
00064     // ss_hom << "homogeneous_solution: ";
00065     // for(unsigned int i=0; i<homogeneous_solution.rows(); i++)
00066     // {   ss_hom << homogeneous_solution(i,0) << " , ";    }
00067     // ROS_INFO_STREAM(ss_hom.str());
00068     // Vector6d_t resultingCartVelocities = this->jacobian_data_ * qdots_out;
00069     // std::stringstream ss_fk;
00070     // ss_fk << "resultingCartVelocities: ";
00071     // for(unsigned int i=0; i<resultingCartVelocities.rows(); i++)
00072     // {   ss_fk << resultingCartVelocities(i,0) << " , ";    }
00073     // ROS_INFO_STREAM(ss_fk.str());
00074 
00075     return qdots_out;
00076 }


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