kinematic_extension_dof.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 <limits>
21 
22 /* BEGIN KinematicExtensionDOF ********************************************************************************************/
31 KDL::Jacobian KinematicExtensionDOF::adjustJacobianDof(const KDL::Jacobian& jac_chain, const KDL::Frame eb_frame_ct, const KDL::Frame cb_frame_eb, const ActiveCartesianDimension active_dim)
32 {
34  KDL::Jacobian jac_full;
35 
36  // jacobian matrix for the extension
37  Eigen::Matrix<double, 6, Eigen::Dynamic> jac_ext;
38  jac_ext.resize(6, ext_dof_);
39  jac_ext.setZero();
40 
41  // rotation from base_frame of primary chain to base_frame of extension (eb)
42  Eigen::Quaterniond quat_cb;
43  tf::quaternionKDLToEigen(cb_frame_eb.M, quat_cb);
44  Eigen::Matrix3d rot_cb = quat_cb.toRotationMatrix();
45 
47  // omega wrt eb
48  Eigen::Vector3d w_x_eb(1, 0, 0);
49  Eigen::Vector3d w_y_eb(0, 1, 0);
50  Eigen::Vector3d w_z_eb(0, 0, 1);
51 
52  // transform to cb
53  Eigen::Vector3d w_x_cb = quat_cb * w_x_eb;
54  Eigen::Vector3d w_y_cb = quat_cb * w_y_eb;
55  Eigen::Vector3d w_z_cb = quat_cb * w_z_eb;
56 
58  // vector from base_frame of extension (eb) to endeffector (ct)
59  Eigen::Vector3d p_eb(eb_frame_ct.p.x(), eb_frame_ct.p.y(), eb_frame_ct.p.z());
60 
61  // transform to cb
62  Eigen::Vector3d p_cb = quat_cb * p_eb;
63 
64  // Calculate tangential velocity
65  Eigen::Vector3d vel_x_cb = w_x_cb.cross(p_cb);
66  Eigen::Vector3d vel_y_cb = w_y_cb.cross(p_cb);
67  Eigen::Vector3d vel_z_cb = w_z_cb.cross(p_cb);
68 
70  // effect of lin_x motion
71  jac_ext(0, 0) = rot_cb(0, 0) * active_dim.lin_x;
72  jac_ext(1, 0) = rot_cb(1, 0) * active_dim.lin_x;
73  jac_ext(2, 0) = rot_cb(2, 0) * active_dim.lin_x;
74  jac_ext(3, 0) = 0.0;
75  jac_ext(4, 0) = 0.0;
76  jac_ext(5, 0) = 0.0;
77 
78  // effect of lin_y motion
79  jac_ext(0, 1) = rot_cb(0, 1) * active_dim.lin_y;
80  jac_ext(1, 1) = rot_cb(1, 1) * active_dim.lin_y;
81  jac_ext(2, 1) = rot_cb(2, 1) * active_dim.lin_y;
82  jac_ext(3, 1) = 0.0;
83  jac_ext(4, 1) = 0.0;
84  jac_ext(5, 1) = 0.0;
85 
86  // effect of lin_z motion
87  jac_ext(0, 2) = rot_cb(0, 2) * active_dim.lin_z;
88  jac_ext(1, 2) = rot_cb(1, 2) * active_dim.lin_z;
89  jac_ext(2, 2) = rot_cb(2, 2) * active_dim.lin_z;
90  jac_ext(3, 2) = 0.0;
91  jac_ext(4, 2) = 0.0;
92  jac_ext(5, 2) = 0.0;
93 
94  // effect of rot_x motion
95  jac_ext(0, 3) = vel_x_cb(0) * active_dim.rot_x;
96  jac_ext(1, 3) = vel_x_cb(1) * active_dim.rot_x;
97  jac_ext(2, 3) = vel_x_cb(2) * active_dim.rot_x;
98  jac_ext(3, 3) = w_x_cb(0) * active_dim.rot_x;
99  jac_ext(4, 3) = w_x_cb(1) * active_dim.rot_x;
100  jac_ext(5, 3) = w_x_cb(2) * active_dim.rot_x;
101 
102  // effect of rot_y motion
103  jac_ext(0, 4) = vel_y_cb(0) * active_dim.rot_y;
104  jac_ext(1, 4) = vel_y_cb(1) * active_dim.rot_y;
105  jac_ext(2, 4) = vel_y_cb(2) * active_dim.rot_y;
106  jac_ext(3, 4) = w_y_cb(0) * active_dim.rot_y;
107  jac_ext(4, 4) = w_y_cb(1) * active_dim.rot_y;
108  jac_ext(5, 4) = w_y_cb(2) * active_dim.rot_y;
109 
110  // effect of rot_z motion
111  jac_ext(0, 5) = vel_z_cb(0) * active_dim.rot_z;
112  jac_ext(1, 5) = vel_z_cb(1) * active_dim.rot_z;
113  jac_ext(2, 5) = vel_z_cb(2) * active_dim.rot_z;
114  jac_ext(3, 5) = w_z_cb(0) * active_dim.rot_z;
115  jac_ext(4, 5) = w_z_cb(1) * active_dim.rot_z;
116  jac_ext(5, 5) = w_z_cb(2) * active_dim.rot_z;
117 
118  // scale with extension_ratio
119  jac_ext *= params_.extension_ratio;
120 
121  // combine Jacobian of primary chain and extension
122  Matrix6Xd_t jac_full_matrix;
123  jac_full_matrix.resize(6, jac_chain.data.cols() + jac_ext.cols());
124  jac_full_matrix << jac_chain.data, jac_ext;
125  jac_full.resize(jac_chain.data.cols() + jac_ext.cols());
126  jac_full.data << jac_full_matrix;
127 
128  return jac_full;
129 }
130 /* END KinematicExtensionDOF **********************************************************************************************/
131 
132 
133 /* BEGIN KinematicExtensionBaseActive ********************************************************************************************/
135 {
136  base_vel_pub_ = nh_.advertise<geometry_msgs::Twist>("base/command", 1);
137 
138  min_vel_lin_base_ = 0.005; // used to avoid infinitesimal motion
139  min_vel_rot_base_ = 0.005; // used to avoid infinitesimal motion
140  max_vel_lin_base_ = 0.5;
141  max_vel_rot_base_ = 0.5;
142 
143  this->ext_dof_ = 6;
144  this->joint_states_.last_q_.resize(ext_dof_);
145  this->joint_states_.last_q_dot_.resize(ext_dof_);
146  this->joint_states_.current_q_.resize(ext_dof_);
147  this->joint_states_.current_q_dot_.resize(ext_dof_);
148 
149  for (unsigned int i = 0; i < ext_dof_; i++)
150  {
151  limits_max_.push_back(std::numeric_limits<double>::max());
152  limits_min_.push_back(-std::numeric_limits<double>::max());
153  if (i < 3)
154  {
155  limits_vel_.push_back(max_vel_lin_base_);
156  }
157  else
158  {
159  limits_vel_.push_back(max_vel_rot_base_);
160  }
161  limits_acc_.push_back(std::numeric_limits<double>::max());
162  }
163 
164  return true;
165 }
166 
170 KDL::Jacobian KinematicExtensionBaseActive::adjustJacobian(const KDL::Jacobian& jac_chain)
171 {
172  tf::StampedTransform bl_transform_ct, cb_transform_bl;
173  KDL::Frame bl_frame_ct, cb_frame_bl;
174  ActiveCartesianDimension active_dim;
175 
177  try
178  {
179  ros::Time now = ros::Time(0);
181  tf_listener_.lookupTransform("base_link", params_.chain_tip_link, now, bl_transform_ct);
182 
184  tf_listener_.lookupTransform(params_.chain_base_link, "base_link", now, cb_transform_bl);
185  }
186  catch (tf::TransformException& ex)
187  {
188  ROS_ERROR("%s", ex.what());
189  }
190 
191  bl_frame_ct.p = KDL::Vector(bl_transform_ct.getOrigin().x(), bl_transform_ct.getOrigin().y(), bl_transform_ct.getOrigin().z());
192  bl_frame_ct.M = KDL::Rotation::Quaternion(bl_transform_ct.getRotation().x(), bl_transform_ct.getRotation().y(), bl_transform_ct.getRotation().z(), bl_transform_ct.getRotation().w());
193 
194  cb_frame_bl.p = KDL::Vector(cb_transform_bl.getOrigin().x(), cb_transform_bl.getOrigin().y(), cb_transform_bl.getOrigin().z());
195  cb_frame_bl.M = KDL::Rotation::Quaternion(cb_transform_bl.getRotation().x(), cb_transform_bl.getRotation().y(), cb_transform_bl.getRotation().z(), cb_transform_bl.getRotation().w());
196 
198  active_dim.lin_x = 1;
199  active_dim.lin_y = 1;
200  active_dim.lin_z = 0;
201 
202  active_dim.rot_x = 0;
203  active_dim.rot_y = 0;
204  active_dim.rot_z = 1;
205 
206  return adjustJacobianDof(jac_chain, bl_frame_ct, cb_frame_bl, active_dim);
207 }
208 
213 {
214  JointStates js;
215  unsigned int chain_dof = joint_states.current_q_.rows();
216  js.current_q_.resize(chain_dof + ext_dof_);
217  js.last_q_.resize(chain_dof + ext_dof_);
218  js.current_q_dot_.resize(chain_dof + ext_dof_);
219  js.last_q_dot_.resize(chain_dof + ext_dof_);
220 
221  for (unsigned int i = 0; i< chain_dof; i++)
222  {
223  js.current_q_(i) = joint_states.current_q_(i);
224  js.last_q_(i) = joint_states.last_q_(i);
225  js.current_q_dot_(i) = joint_states.current_q_dot_(i);
226  js.last_q_dot_(i) = joint_states.last_q_dot_(i);
227  }
228  for (unsigned int i = 0; i < ext_dof_; i++)
229  {
230  js.current_q_(chain_dof + i) = 0.0;
231  js.last_q_(chain_dof + i) = 0.0;
232  js.current_q_dot_(chain_dof + i) = 0.0;
233  js.last_q_dot_(chain_dof + i) = 0.0;
234  }
235  return js;
236 }
237 
242 {
243  LimiterParams lp = limiter_params;
244  for (unsigned int i = 0; i < ext_dof_; i++)
245  {
246  lp.limits_max.push_back(std::numeric_limits<double>::max());
247  lp.limits_min.push_back(-std::numeric_limits<double>::max());
248  if (i < 3)
249  {
250  lp.limits_vel.push_back(max_vel_lin_base_);
251  }
252  else
253  {
254  lp.limits_vel.push_back(max_vel_rot_base_);
255  }
256  lp.limits_acc.push_back(std::numeric_limits<double>::max());
257  }
258  return lp;
259 }
260 
264 void KinematicExtensionBaseActive::processResultExtension(const KDL::JntArray& q_dot_ik)
265 {
266  geometry_msgs::Twist base_vel_msg;
267 
268  base_vel_msg.linear.x = (std::fabs(q_dot_ik(params_.dof)) < min_vel_lin_base_) ? 0.0 : q_dot_ik(params_.dof);
269  base_vel_msg.linear.y = (std::fabs(q_dot_ik(params_.dof+1)) < min_vel_lin_base_) ? 0.0 : q_dot_ik(params_.dof+1);
270  base_vel_msg.linear.z = (std::fabs(q_dot_ik(params_.dof+2)) < min_vel_lin_base_) ? 0.0 : q_dot_ik(params_.dof+2);
271  base_vel_msg.angular.x = (std::fabs(q_dot_ik(params_.dof+3)) < min_vel_rot_base_) ? 0.0 : q_dot_ik(params_.dof+3);
272  base_vel_msg.angular.y = (std::fabs(q_dot_ik(params_.dof+4)) < min_vel_rot_base_) ? 0.0 : q_dot_ik(params_.dof+4);
273  base_vel_msg.angular.z = (std::fabs(q_dot_ik(params_.dof+5)) < min_vel_rot_base_) ? 0.0 : q_dot_ik(params_.dof+5);
274 
275  base_vel_pub_.publish(base_vel_msg);
276 }
277 /* END KinematicExtensionBaseActive **********************************************************************************************/
278 
tf::Transform::getRotation
Quaternion getRotation() const
JointStates::last_q_dot_
KDL::JntArray last_q_dot_
Definition: cob_twist_controller_data_types.h:117
KinematicExtensionBase::nh_
ros::NodeHandle nh_
Definition: kinematic_extension_base.h:47
LimiterParams::limits_min
std::vector< double > limits_min
Definition: cob_twist_controller_data_types.h:189
KinematicExtensionDOF::limits_acc_
std::vector< double > limits_acc_
Definition: kinematic_extension_dof.h:56
KinematicExtensionBaseActive::adjustJacobian
KDL::Jacobian adjustJacobian(const KDL::Jacobian &jac_chain)
Definition: kinematic_extension_dof.cpp:170
KinematicExtensionBase::tf_listener_
tf::TransformListener tf_listener_
Definition: kinematic_extension_base.h:48
ActiveCartesianDimension::rot_z
double rot_z
Definition: cob_twist_controller_data_types.h:130
TwistControllerParams::extension_ratio
double extension_ratio
Definition: cob_twist_controller_data_types.h:286
JointStates::last_q_
KDL::JntArray last_q_
Definition: cob_twist_controller_data_types.h:115
LimiterParams::limits_acc
std::vector< double > limits_acc
Definition: cob_twist_controller_data_types.h:191
TwistControllerParams::dof
uint8_t dof
Definition: cob_twist_controller_data_types.h:255
JointStates::current_q_dot_
KDL::JntArray current_q_dot_
Definition: cob_twist_controller_data_types.h:116
KinematicExtensionBaseActive::processResultExtension
void processResultExtension(const KDL::JntArray &q_dot_ik)
Definition: kinematic_extension_dof.cpp:264
ActiveCartesianDimension::lin_y
double lin_y
Definition: cob_twist_controller_data_types.h:126
tf::StampedTransform
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
KinematicExtensionBaseActive::adjustLimiterParams
LimiterParams adjustLimiterParams(const LimiterParams &limiter_params)
Definition: kinematic_extension_dof.cpp:241
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
KinematicExtensionBase::params_
const TwistControllerParams & params_
Definition: kinematic_extension_base.h:49
ActiveCartesianDimension::lin_z
double lin_z
Definition: cob_twist_controller_data_types.h:127
ActiveCartesianDimension
Definition: cob_twist_controller_data_types.h:120
KinematicExtensionBaseActive::initExtension
bool initExtension()
Definition: kinematic_extension_dof.cpp:134
KinematicExtensionBaseActive::adjustJointStates
JointStates adjustJointStates(const JointStates &joint_states)
Definition: kinematic_extension_dof.cpp:212
KinematicExtensionDOF::limits_max_
std::vector< double > limits_max_
Definition: kinematic_extension_dof.h:53
LimiterParams::limits_vel
std::vector< double > limits_vel
Definition: cob_twist_controller_data_types.h:190
ROS_ERROR
#define ROS_ERROR(...)
KinematicExtensionDOF::limits_min_
std::vector< double > limits_min_
Definition: kinematic_extension_dof.h:54
tf::Transformer::waitForTransform
bool waitForTransform(const std::string &target_frame, const ros::Time &target_time, const std::string &source_frame, const ros::Time &source_time, const std::string &fixed_frame, const ros::Duration &timeout, const ros::Duration &polling_sleep_duration=ros::Duration(0.01), std::string *error_msg=NULL) const
tf::quaternionKDLToEigen
void quaternionKDLToEigen(const KDL::Rotation &k, Eigen::Quaterniond &e)
KinematicExtensionBaseActive::min_vel_lin_base_
double min_vel_lin_base_
Definition: kinematic_extension_dof.h:82
ActiveCartesianDimension::rot_x
double rot_x
Definition: cob_twist_controller_data_types.h:128
Matrix6Xd_t
Eigen::Matrix< double, 6, Eigen::Dynamic > Matrix6Xd_t
Definition: cob_twist_controller_data_types.h:451
LimiterParams
Definition: cob_twist_controller_data_types.h:162
ActiveCartesianDimension::lin_x
double lin_x
Definition: cob_twist_controller_data_types.h:125
ros::Time
KinematicExtensionDOF::adjustJacobianDof
KDL::Jacobian adjustJacobianDof(const KDL::Jacobian &jac_chain, const KDL::Frame eb_frame_ct, const KDL::Frame cb_frame_eb, const ActiveCartesianDimension active_dim)
Definition: kinematic_extension_dof.cpp:31
KinematicExtensionBaseActive::base_vel_pub_
ros::Publisher base_vel_pub_
Definition: kinematic_extension_dof.h:80
kinematic_extension_dof.h
KinematicExtensionDOF::joint_states_
JointStates joint_states_
Definition: kinematic_extension_dof.h:52
TwistControllerParams::chain_tip_link
std::string chain_tip_link
Definition: cob_twist_controller_data_types.h:257
LimiterParams::limits_max
std::vector< double > limits_max
Definition: cob_twist_controller_data_types.h:188
KinematicExtensionDOF::ext_dof_
unsigned int ext_dof_
Definition: kinematic_extension_dof.h:50
JointStates
Definition: cob_twist_controller_data_types.h:112
eigen_kdl.h
JointStates::current_q_
KDL::JntArray current_q_
Definition: cob_twist_controller_data_types.h:114
KinematicExtensionBaseActive::max_vel_rot_base_
double max_vel_rot_base_
Definition: kinematic_extension_dof.h:85
tf::Transformer::lookupTransform
void lookupTransform(const std::string &target_frame, const ros::Time &target_time, const std::string &source_frame, const ros::Time &source_time, const std::string &fixed_frame, StampedTransform &transform) const
TwistControllerParams::chain_base_link
std::string chain_base_link
Definition: cob_twist_controller_data_types.h:256
tf2::TransformException
ActiveCartesianDimension::rot_y
double rot_y
Definition: cob_twist_controller_data_types.h:129
ros::Duration
KinematicExtensionDOF::limits_vel_
std::vector< double > limits_vel_
Definition: kinematic_extension_dof.h:55
KinematicExtensionBaseActive::max_vel_lin_base_
double max_vel_lin_base_
Definition: kinematic_extension_dof.h:84
tf::Transform::getOrigin
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
KinematicExtensionBaseActive::min_vel_rot_base_
double min_vel_rot_base_
Definition: kinematic_extension_dof.h:83


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Mon May 1 2023 02:44:43