task_priority_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 
21 
26 Eigen::MatrixXd TaskPrioritySolver::solve(const Vector6d_t& in_cart_velocities,
27  const JointStates& joint_states)
28 {
30  double cycle = (now - this->last_time_).toSec();
31  this->last_time_ = now;
32 
33  double derivative_cost_func_value;
34  double current_cost_func_value;
35  double activation_gain;
36  double magnitude;
37 
38  Eigen::MatrixXd qdots_out = Eigen::MatrixXd::Zero(this->jacobian_data_.cols(), 1);
39  Eigen::VectorXd partial_cost_func = Eigen::VectorXd::Zero(this->jacobian_data_.cols());
40  Eigen::MatrixXd damped_pinv = pinv_calc_.calculate(this->params_, this->damping_, this->jacobian_data_);
41  Eigen::MatrixXd pinv = pinv_calc_.calculate(this->jacobian_data_);
42 
43  Eigen::MatrixXd particular_solution = damped_pinv * in_cart_velocities;
44 
45  Eigen::MatrixXd ident = Eigen::MatrixXd::Identity(pinv.rows(), this->jacobian_data_.cols());
46  Eigen::MatrixXd projector = ident - pinv * this->jacobian_data_;
47 
48  KDL::JntArrayVel predict_jnts_vel(joint_states.current_q_.rows());
49 
50  // predict next joint states!
51  for (uint8_t i = 0; i < joint_states.current_q_.rows(); ++i)
52  {
53  predict_jnts_vel.q(i) = particular_solution(i, 0) * cycle + joint_states.current_q_(i);
54  predict_jnts_vel.qdot(i) = particular_solution(i, 0);
55  }
56 
57  if (this->constraints_.size() > 0)
58  {
59  for (std::set<ConstraintBase_t>::iterator it = this->constraints_.begin(); it != this->constraints_.end(); ++it)
60  {
61  (*it)->update(joint_states, predict_jnts_vel, this->jacobian_data_);
62  current_cost_func_value = (*it)->getValue();
63  derivative_cost_func_value = (*it)->getDerivativeValue();
64  partial_cost_func = (*it)->getPartialValues(); // Equal to (partial g) / (partial q) = J_g
65  activation_gain = (*it)->getActivationGain();
66  magnitude = (*it)->getSelfMotionMagnitude(Eigen::MatrixXd::Zero(1, 1), Eigen::MatrixXd::Zero(1, 1)); // not necessary to pass valid values here.
67 
68  ROS_INFO_STREAM("activation_gain: " << activation_gain);
69  ROS_INFO_STREAM("smm: " << magnitude);
70  }
71 
72  Eigen::MatrixXd jac_inv_2nd_term = Eigen::MatrixXd::Zero(projector.cols(), partial_cost_func.cols());
73  if (activation_gain > 0.0)
74  {
75  Eigen::MatrixXd tmp_matrix = partial_cost_func.transpose() * projector;
76  jac_inv_2nd_term = pinv_calc_.calculate(tmp_matrix);
77  }
78 
79  Eigen::MatrixXd m_derivative_cost_func_value = derivative_cost_func_value * Eigen::MatrixXd::Identity(1, 1);
80  qdots_out = particular_solution + this->params_.k_H * activation_gain * jac_inv_2nd_term * (magnitude * m_derivative_cost_func_value - partial_cost_func.transpose() * particular_solution);
81  }
82  else
83  {
84  qdots_out = particular_solution;
85  ROS_ERROR_STREAM("Should not occur solution: " << std::endl << qdots_out);
86  }
87 
88  // Eigen::MatrixXd qdots_out = particular_solution + homogeneousSolution; // weighting with k_H is done in loop
89  return qdots_out;
90 }
91 
double now()
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).
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_INFO_STREAM(args)
static Time now()
#define ROS_ERROR_STREAM(args)
virtual Eigen::MatrixXd solve(const Vector6d_t &in_cart_velocities, const JointStates &joint_states)


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