29 #include <console_bridge/console.h>
39 void KDLToEigen(
const KDL::Frame& frame, Eigen::Isometry3d& transform)
41 transform.setIdentity();
44 for (
int i = 0; i < 3; ++i)
45 transform(i, 3) = frame.p[i];
48 for (
int i = 0; i < 9; ++i)
49 transform(i / 3, i % 3) = frame.M.data[i];
52 void EigenToKDL(
const Eigen::Isometry3d& transform, KDL::Frame& frame)
54 for (
int i = 0; i < 3; ++i)
55 frame.p[i] = transform(i, 3);
57 for (
int i = 0; i < 9; ++i)
58 frame.M.data[i] = transform(i / 3, i % 3);
61 void KDLToEigen(
const KDL::Jacobian& jacobian, Eigen::Ref<Eigen::MatrixXd> matrix)
63 assert(matrix.rows() == jacobian.rows());
64 assert(matrix.cols() == jacobian.columns());
66 for (
unsigned i = 0; i < jacobian.rows(); ++i)
67 for (
unsigned j = 0; j < jacobian.columns(); ++j)
68 matrix(i, j) = jacobian(i, j);
71 void KDLToEigen(
const KDL::Jacobian& jacobian,
const std::vector<int>& q_nrs, Eigen::Ref<Eigen::MatrixXd> matrix)
73 assert(matrix.rows() == jacobian.rows());
74 assert(
static_cast<unsigned>(matrix.cols()) == q_nrs.size());
76 for (
int i = 0; i < static_cast<int>(jacobian.rows()); ++i)
77 for (
int j = 0; j < static_cast<int>(q_nrs.size()); ++j)
78 matrix(i, j) = jacobian(
static_cast<unsigned>(i),
static_cast<unsigned>(q_nrs[
static_cast<size_t>(j)]));
81 void EigenToKDL(
const Eigen::Ref<const Eigen::VectorXd>& vec, KDL::JntArray& joints) { joints.data = vec; }
83 void KDLToEigen(
const KDL::JntArray& joints, Eigen::Ref<Eigen::VectorXd> vec) { vec = joints.data; }
87 const std::vector<std::pair<std::string, std::string>>& chains)
96 CONSOLE_BRIDGE_logError(
"Failed to parse KDL tree from Scene Graph");
102 for (
const auto& chain : chains)
104 KDL::Chain sub_chain;
105 if (!results.
kdl_tree.getChain(chain.first, chain.second, sub_chain))
107 CONSOLE_BRIDGE_logError(
108 "Failed to initialize KDL between links: '%s' and '%s'", chain.first.c_str(), chain.second.c_str());
124 for (
unsigned i = 0, j = 0; i < results.
robot_chain.getNrOfSegments(); ++i)
126 const KDL::Segment& seg = results.
robot_chain.getSegment(i);
127 const KDL::Joint& jnt = seg.getJoint();
129 if (jnt.getType() == KDL::Joint::None)
135 results.
segment_index[seg.getName()] =
static_cast<int>(i + 1);
140 double lower = std::numeric_limits<float>::lowest();
141 double upper = std::numeric_limits<float>::max();
147 lower = std::max(joint->limits->lower, joint->safety->soft_lower_limit);
148 upper = std::min(joint->limits->upper, joint->safety->soft_upper_limit);
152 lower = joint->limits->lower;
153 upper = joint->limits->upper;
157 results.
q_min(j) = lower;
158 results.
q_max(j) = upper;
168 const std::string& base_name,
169 const std::string& tip_name)
171 std::vector<std::pair<std::string, std::string>> chains;
172 chains.emplace_back(base_name, tip_name);