gradient_projection_method_solver.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 <set>
19 #include <cmath>
20 
22 
28 Eigen::MatrixXd GradientProjectionMethodSolver::solve(const Vector6d_t& in_cart_velocities,
29  const JointStates& joint_states)
30 {
31  Eigen::MatrixXd damped_pinv = pinv_calc_.calculate(this->params_, this->damping_, this->jacobian_data_);
32  Eigen::MatrixXd pinv = pinv_calc_.calculate(this->jacobian_data_);
33 
34  Eigen::MatrixXd particular_solution = damped_pinv * in_cart_velocities;
35 
36  // Eigen::MatrixXd ident = Eigen::MatrixXd::Identity(damped_pinv.rows(), this->jacobian_data_.cols());
37  // Eigen::MatrixXd projector = ident - damped_pinv * this->jacobian_data_;
38  Eigen::MatrixXd ident = Eigen::MatrixXd::Identity(pinv.rows(), this->jacobian_data_.cols());
39  Eigen::MatrixXd projector = ident - pinv * this->jacobian_data_;
40 
41  Eigen::MatrixXd homogeneous_solution = Eigen::MatrixXd::Zero(particular_solution.rows(), particular_solution.cols());
42  KDL::JntArrayVel predict_jnts_vel(joint_states.current_q_.rows());
43 
44  for (std::set<ConstraintBase_t>::iterator it = this->constraints_.begin(); it != this->constraints_.end(); ++it)
45  {
46  ROS_DEBUG_STREAM("task id: " << (*it)->getTaskId());
47  (*it)->update(joint_states, predict_jnts_vel, this->jacobian_data_);
48  Eigen::VectorXd q_dot_0 = (*it)->getPartialValues();
49  Eigen::MatrixXd tmp_projection = projector * q_dot_0;
50  double activation_gain = (*it)->getActivationGain(); // contribution of the homo. solution to the part. solution
51  double constraint_k_H = (*it)->getSelfMotionMagnitude(particular_solution, tmp_projection); // gain of homogenous solution (if active)
52  homogeneous_solution += (constraint_k_H * activation_gain * tmp_projection);
53  }
54 
55  Eigen::MatrixXd qdots_out = particular_solution + this->params_.k_H * homogeneous_solution; // weighting with k_H is done in loop
56 
57  // //DEBUG: for verification of nullspace projection
58  // std::stringstream ss_part;
59  // ss_part << "particular_solution: ";
60  // for(unsigned int i=0; i<particular_solution.rows(); i++)
61  // { ss_part << particular_solution(i,0) << " , "; }
62  // ROS_INFO_STREAM(ss_part.str());
63  // std::stringstream ss_hom;
64  // ss_hom << "homogeneous_solution: ";
65  // for(unsigned int i=0; i<homogeneous_solution.rows(); i++)
66  // { ss_hom << homogeneous_solution(i,0) << " , "; }
67  // ROS_INFO_STREAM(ss_hom.str());
68  // Vector6d_t resultingCartVelocities = this->jacobian_data_ * qdots_out;
69  // std::stringstream ss_fk;
70  // ss_fk << "resultingCartVelocities: ";
71  // for(unsigned int i=0; i<resultingCartVelocities.rows(); i++)
72  // { ss_fk << resultingCartVelocities(i,0) << " , "; }
73  // ROS_INFO_STREAM(ss_fk.str());
74 
75  return qdots_out;
76 }
unsigned int rows() const
boost::shared_ptr< DampingBase > damping_
References the current Jacobian (matrix data only).
Eigen::Matrix< double, 6, 1 > Vector6d_t
Matrix6Xd_t jacobian_data_
References the limiter parameters (up-to-date according to KinematicExtension).
virtual Eigen::MatrixXd solve(const Vector6d_t &in_cart_velocities, const JointStates &joint_states)
PInvBySVD pinv_calc_
The currently set damping method.
const TwistControllerParams & params_
Set of constraints.
std::set< ConstraintBase_t > constraints_
set inserts sorted (default less operator); if element has already been added it returns an iterator ...
virtual Eigen::MatrixXd calculate(const Eigen::MatrixXd &jacobian) const
#define ROS_DEBUG_STREAM(args)


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