8 #include <kdl/chain.hpp> 9 #include <kdl/chainfksolverpos_recursive.hpp> 10 #include <kdl/frames.hpp> 11 #include <kdl/solveri.hpp> 12 #include <kdl/tree.hpp> 39 Eigen::Matrix<double, 6, 6> mat = jacobian.
data * jacobian.
data.transpose();
40 Eigen::JacobiSVD<Eigen::MatrixXd> svd(mat, Eigen::ComputeFullU | Eigen::ComputeFullV);
41 double critical = svd.singularValues().tail(1)(0);
54 #if ROS_VERSION_MINIMUM(1, 15, 0) 63 default:
return "UNKNOWN ERROR";
68 const std::string& root,
69 const std::string& tip,
70 double singularity_threshold)
74 throw std::invalid_argument(
"Cannot construct KDL tree from URDF");
77 if (not tree.
getChain(root, tip, this->chain_)) {
78 throw std::invalid_argument(
"Cannot find chain within URDF tree from root '" + root +
79 "' to tip '" + tip +
"'. Do these links exist?");
82 ROS_INFO_STREAM(
"KDL Model initialized for chain from '" << root <<
"' -> '" << tip <<
"'");
86 const std::array<double, 16>& transform,
90 t.matrix() = Eigen::Matrix4d(transform.data());
96 const std::array<double, 3>& center_of_mass,
98 const std::array<double, 9>& inertia,
102 std::copy(center_of_mass.begin(), center_of_mass.end(), std::begin(kc.
data));
103 std::copy(inertia.begin(), inertia.end(), std::begin(ki.
data));
111 const std::array<double, 7>& q,
112 const std::array<double, 16>& F_T_EE,
113 const std::array<double, 16>& EE_T_K)
125 kq.
data = Eigen::Matrix<double, 7, 1>(q.data());
129 throw std::logic_error(
"KDL forward kinematics pose calculation failed with error: " +
135 std::array<double, 16>
result;
136 Eigen::MatrixXd::Map(&result[0], 4, 4) = p.matrix();
143 const std::array<double, 7>& q,
144 const std::array<double, 16>& F_T_EE,
145 const std::array<double, 16>& EE_T_K)
149 kq.
data = Eigen::Matrix<double, 7, 1>(q.data());
161 throw std::logic_error(
"KDL zero jacobian calculation failed with error: " +
strError(error));
166 auto transform =
pose(frame, q, F_T_EE, EE_T_K);
168 t.matrix() = Eigen::Matrix4d(transform.data());
178 std::array<double, 42>
result;
179 Eigen::MatrixXd::Map(&result[0], 6, 7) = J.
data;
186 const std::array<double, 7>& q,
187 const std::array<double, 16>& F_T_EE,
188 const std::array<double, 16>& EE_T_K)
192 kq.
data = Eigen::Matrix<double, 7, 1>(q.data());
203 throw std::logic_error(
"KDL zero jacobian calculation failed with error: " +
strError(error));
211 std::array<double, 42>
result;
212 Eigen::MatrixXd::Map(&result[0], 6, 7) = J.
data;
218 const std::array<double, 7>& q,
219 const std::array<double, 9>& I_total,
221 const std::array<double, 3>& F_x_Ctotal)
224 KDL::JntSpaceInertiaMatrix M(7);
225 kq.
data = Eigen::Matrix<double, 7, 1>(q.data());
228 augmentFrame(
"load", F_x_Ctotal, m_total, I_total, chain);
233 throw std::logic_error(
"KDL mass calculation failed with error: " +
strError(error));
236 std::array<double, 49>
result;
237 Eigen::MatrixXd::Map(&result[0], 7, 7) = M.data;
243 const std::array<double, 7>& q,
244 const std::array<double, 7>& dq,
245 const std::array<double, 9>& I_total,
247 const std::array<double, 3>& F_x_Ctotal)
250 kq.
data = Eigen::Matrix<double, 7, 1>(q.data());
251 kdq.
data = Eigen::Matrix<double, 7, 1>(dq.data());
254 augmentFrame(
"load", F_x_Ctotal, m_total, I_total, chain);
259 throw std::logic_error(
"KDL coriolis calculation failed with error: " +
strError(error));
262 std::array<double, 7>
result;
263 Eigen::VectorXd::Map(&result[0], kc.
data.size()) = kc.
data;
269 const std::array<double, 7>& q,
271 const std::array<double, 3>& F_x_Ctotal,
272 const std::array<double, 3>& gravity_earth)
const {
274 KDL::Vector grav(gravity_earth[0], gravity_earth[1], gravity_earth[2]);
275 kq.
data = Eigen::Matrix<double, 7, 1>(q.data());
278 augmentFrame(
"load", F_x_Ctotal, m_total, {1, 0, 0, 0, 1, 0, 0, 0, 1}, chain);
281 int error = solver.JntToGravity(kq, kg);
283 throw std::logic_error(
"KDL gravity calculation failed with error: " +
strError(error));
286 std::array<double, 7>
result;
287 Eigen::VectorXd::Map(&result[0], kg.
data.size()) = kg.
data;
virtual int JntToCart(const JntArray &q_in, Frame &p_out, int segmentNr=-1)
#define ROS_WARN_STREAM_THROTTLE(period, args)
KDL_PARSER_PUBLIC bool treeFromUrdfModel(const urdf::ModelInterface &robot_model, KDL::Tree &tree)
static int segment(franka::Frame frame)
void addSegment(const Segment &segment)
E_MAX_ITERATIONS_EXCEEDED
std::array< double, 42 > bodyJacobian(franka::Frame frame, const std::array< double, 7 > &q, const std::array< double, 16 > &F_T_EE, const std::array< double, 16 > &EE_T_K) const override
Gets the 6x7 Jacobian for the given frame, relative to that frame.
std::array< double, 7 > gravity(const std::array< double, 7 > &q, double m_total, const std::array< double, 3 > &F_x_Ctotal, const std::array< double, 3 > &gravity_earth) const override
Calculates the gravity vector.
void transformEigenToKDL(const Eigen::Affine3d &e, KDL::Frame &k)
static std::string strError(const int error)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Matrix< double, 6, Eigen::Dynamic > data
double singularity_threshold_
std::array< double, 7 > coriolis(const std::array< double, 7 > &q, const std::array< double, 7 > &dq, const std::array< double, 9 > &I_total, double m_total, const std::array< double, 3 > &F_x_Ctotal) const override
Calculates the Coriolis force vector (state-space equation): , in .
bool getChain(const std::string &chain_root, const std::string &chain_tip, Chain &chain) const
ModelKDL(const urdf::Model &model, const std::string &root, const std::string &tip, double singularity_threshold=-1)
Create a new implementation for the ModelBase with KDL as backend.
std::array< double, 49 > mass(const std::array< double, 7 > &q, const std::array< double, 9 > &I_total, double m_total, const std::array< double, 3 > &F_x_Ctotal) const override
Calculates the 7x7 mass matrix.
virtual int JntToCoriolis(const JntArray &q, const JntArray &q_dot, JntArray &coriolis)
static void augmentFrame(const std::string &name, const std::array< double, 16 > &transform, KDL::Chain &chain)
Augment a kinematic chain by adding a virtual frame to it.
void changeBase(const Rotation &rot)
#define ROS_INFO_STREAM(args)
bool isCloseToSingularity(const KDL::Jacobian &jacobian) const
std::array< double, 42 > zeroJacobian(franka::Frame frame, const std::array< double, 7 > &q, const std::array< double, 16 > &F_T_EE, const std::array< double, 16 > &EE_T_K) const override
Gets the 6x7 Jacobian for the given joint relative to the base frame.
void transformKDLToEigen(const KDL::Frame &k, Eigen::Affine3d &e)
virtual int JntToJac(const JntArray &q_in, Jacobian &jac, int seg_nr=-1)
virtual int JntToMass(const JntArray &q, JntSpaceInertiaMatrix &H)
std::array< double, 16 > pose(franka::Frame frame, const std::array< double, 7 > &q, const std::array< double, 16 > &F_T_EE, const std::array< double, 16 > &EE_T_K) const override
Gets the 4x4 pose matrix for the given frame in base frame.