inverse_differential_kinematics_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 <ros/ros.h>
20 #include <kdl/chainfksolvervel_recursive.hpp>
21 
23 
28  const KDL::Twist& v_in,
29  KDL::JntArray& qdot_out)
30 {
31  // ROS_INFO_STREAM("joint_states.current_q_: " << joint_states.current_q_.rows());
32  int8_t retStat = -1;
33 
35  KDL::Jacobian jac_chain(chain_.getNrOfJoints());
36  jnt2jac_.JntToJac(joint_states.current_q_, jac_chain);
37  // ROS_INFO_STREAM("jac_chain.rows: " << jac_chain.rows() << ", jac_chain.columns: " << jac_chain.columns());
38 
39  JointStates joint_states_full = this->kinematic_extension_->adjustJointStates(joint_states);
40  // ROS_INFO_STREAM("joint_states_full.current_q_: " << joint_states_full.current_q_.rows());
41 
43  KDL::Jacobian jac_full = this->kinematic_extension_->adjustJacobian(jac_chain);
44  // ROS_INFO_STREAM("jac_full.rows: " << jac_full.rows() << ", jac_full.columns: " << jac_full.columns());
45 
47  Vector6d_t v_in_vec;
48  KDL::Twist v_temp;
49  v_temp = this->limiters_->enforceLimits(v_in);
50  tf::twistKDLToEigen(v_temp, v_in_vec);
51 
52  Eigen::MatrixXd qdot_out_vec;
54  v_in_vec,
55  joint_states_full,
56  qdot_out_vec);
57 
59  KDL::JntArray qdot_out_full(jac_full.columns());
60  for (int i = 0; i < jac_full.columns(); i++)
61  {
62  qdot_out_full(i) = qdot_out_vec(i);
63  // ROS_INFO_STREAM("qdot_out_full " << i << ": " << qdot_out_full(i));
64  }
65  // ROS_INFO_STREAM("qdot_out_full.rows: " << qdot_out_full.rows());
66 
68  qdot_out_full = this->limiters_->enforceLimits(qdot_out_full, joint_states_full.current_q_);
69 
70  // ROS_INFO_STREAM("qdot_out_full.rows enforced: " << qdot_out_full.rows());
71  // for (int i = 0; i < jac_full.columns(); i++)
72  // {
73  // ROS_INFO_STREAM("i: " << i << ", qdot_out_full: " << qdot_out_full(i));
74  // }
75 
77  this->kinematic_extension_->processResultExtension(qdot_out_full);
78 
80  for (int i = 0; i < jac_chain.columns(); i++)
81  {
82  qdot_out(i) = qdot_out_full(i);
83  }
84 
85  return retStat;
86 }
87 
89 {
90  this->params_ = params;
91 
93  if (this->kinematic_extension_ == NULL) { return false; }
94  this->limiter_params_ = this->kinematic_extension_->adjustLimiterParams(this->params_.limiter_params);
95 
96  this->limiters_.reset(new LimiterContainer(this->limiter_params_));
97  this->limiters_->init();
98 
100  if (0 != this->constraint_solver_factory_.resetAll(this->params_, this->limiter_params_)) // params member as reference!!! else process will die!
101  {
102  ROS_ERROR("Failed to reset IDK constraint solver after dynamic_reconfigure.");
103  return false;
104  }
105  return true;
106 }
#define NULL
Eigen::Matrix< double, 6, 1 > Vector6d_t
Container for limiters, implementing interface methods.
Definition: limiter.h:29
int8_t resetAll(const TwistControllerParams &params, const LimiterParams &limiter_params)
unsigned int columns() const
virtual int CartToJnt(const JointStates &joint_states, const KDL::Twist &v_in, KDL::JntArray &qdot_out)
void twistKDLToEigen(const KDL::Twist &k, Eigen::Matrix< double, 6, 1 > &e)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Matrix< double, 6, Eigen::Dynamic > data
int8_t calculateJointVelocities(Matrix6Xd_t &jacobian_data, const Vector6d_t &in_cart_velocities, const JointStates &joint_states, Eigen::MatrixXd &out_jnt_velocities)
boost::shared_ptr< KinematicExtensionBase > kinematic_extension_
static KinematicExtensionBase * createKinematicExtension(const TwistControllerParams &params)
unsigned int getNrOfJoints() const
virtual int JntToJac(const JntArray &q_in, Jacobian &jac, int seg_nr=-1)
#define ROS_ERROR(...)


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