Skip to content

Commit 753504a

Browse files
Add the KDL implementation for the computation of the jacobian inverse
1 parent 652ec2c commit 753504a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

kinematics_interface_kdl/include/kinematics_interface_kdl/kinematics_interface_kdl.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@ class KinematicsInterfaceKDL : public kinematics_interface::KinematicsInterface
6060
const Eigen::VectorXd & joint_pos, const std::string & link_name,
6161
Eigen::Matrix<double, 6, Eigen::Dynamic> & jacobian) override;
6262

63+
bool calculate_jacobian_inverse(
64+
const Eigen::VectorXd & joint_pos, const std::string & link_name,
65+
Eigen::Matrix<double, Eigen::Dynamic, 6> & jacobian_inverse) override;
66+
6367
private:
6468
// verification methods
6569
bool verify_initialized();
6670
bool verify_link_name(const std::string & link_name);
6771
bool verify_joint_vector(const Eigen::VectorXd & joint_vector);
6872
bool verify_jacobian(const Eigen::Matrix<double, 6, Eigen::Dynamic> & jacobian);
73+
bool verify_jacobian_inverse(const Eigen::Matrix<double, Eigen::Dynamic, 6> & jacobian);
6974

7075
bool initialized = false;
7176
std::string root_name_;

kinematics_interface_kdl/src/kinematics_interface_kdl.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,31 @@ bool KinematicsInterfaceKDL::calculate_jacobian(
182182
return true;
183183
}
184184

185+
bool KinematicsInterfaceKDL::calculate_jacobian_inverse(
186+
const Eigen::VectorXd & joint_pos, const std::string & link_name,
187+
Eigen::Matrix<double, Eigen::Dynamic, 6> & jacobian_inverse)
188+
{
189+
// verify inputs
190+
if (
191+
!verify_initialized() || !verify_joint_vector(joint_pos) || !verify_link_name(link_name) ||
192+
!verify_jacobian_inverse(jacobian_inverse))
193+
{
194+
return false;
195+
}
196+
197+
// get joint array
198+
q_.data = joint_pos;
199+
200+
// calculate Jacobian
201+
jac_solver_->JntToJac(q_, *jacobian_, link_name_map_[link_name]);
202+
Eigen::Matrix<double, 6, Eigen::Dynamic> jacobian = jacobian_->data;
203+
204+
// damped inverse
205+
jacobian_inverse = (jacobian.transpose() * jacobian + alpha * I).inverse() * jacobian.transpose();
206+
207+
return true;
208+
}
209+
185210
bool KinematicsInterfaceKDL::calculate_link_transform(
186211
const Eigen::Matrix<double, Eigen::Dynamic, 1> & joint_pos, const std::string & link_name,
187212
Eigen::Isometry3d & transform)
@@ -269,6 +294,20 @@ bool KinematicsInterfaceKDL::verify_jacobian(
269294
return true;
270295
}
271296

297+
bool KinematicsInterfaceKDL::verify_jacobian_inverse(
298+
const Eigen::Matrix<double, Eigen::Dynamic, 6> & jacobian_inverse)
299+
{
300+
if (
301+
jacobian_inverse.rows() != jacobian_->columns() || jacobian_inverse.cols() != jacobian_->rows())
302+
{
303+
RCLCPP_ERROR(
304+
LOGGER, "The size of the jacobian (%zu, %zu) does not match the required size of (%u, %u)",
305+
jacobian_inverse.rows(), jacobian_inverse.cols(), jacobian_->columns(), jacobian_->rows());
306+
return false;
307+
}
308+
return true;
309+
}
310+
272311
} // namespace kinematics_interface_kdl
273312

274313
#include "pluginlib/class_list_macros.hpp"

0 commit comments

Comments
 (0)