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;
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 
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 
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 
std::vector< double > limits_min
double now()
tf::TransformListener tf_listener_
unsigned int rows() const
void resize(unsigned int newNrOfColumns)
static Rotation Quaternion(double x, double y, double z, double w)
std::vector< double > limits_max_
std::vector< double > limits_min_
void processResultExtension(const KDL::JntArray &q_dot_ik)
void quaternionKDLToEigen(const KDL::Rotation &k, Eigen::Quaterniond &e)
LimiterParams adjustLimiterParams(const LimiterParams &limiter_params)
double z() const
KDL::Jacobian adjustJacobian(const KDL::Jacobian &jac_chain)
Rotation M
bool waitForTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration &timeout, const ros::Duration &polling_sleep_duration=ros::Duration(0.01), std::string *error_msg=NULL) const
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Matrix< double, 6, Eigen::Dynamic > data
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & z() const
std::vector< double > limits_acc
std::vector< double > limits_vel_
KDL::Jacobian adjustJacobianDof(const KDL::Jacobian &jac_chain, const KDL::Frame eb_frame_ct, const KDL::Frame cb_frame_eb, const ActiveCartesianDimension active_dim)
double y() const
double x() const
const TwistControllerParams & params_
TFSIMD_FORCE_INLINE const tfScalar & y() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
void lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, StampedTransform &transform) const
void resize(unsigned int newSize)
std::vector< double > limits_max
std::vector< double > limits_acc_
Quaternion getRotation() const
Eigen::Matrix< double, 6, Eigen::Dynamic > Matrix6Xd_t
JointStates adjustJointStates(const JointStates &joint_states)
#define ROS_ERROR(...)
std::vector< double > limits_vel


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