libfranka 0.19.0
FCI C++ API
Loading...
Searching...
No Matches
robot_model.h
Go to the documentation of this file.
1// Copyright (c) 2025 Franka Robotics GmbH
2// Use of this source code is governed by the Apache-2.0 license, see LICENSE
3#pragma once
4
5#include <array>
6#include <string>
7
8#include <pinocchio/multibody/data.hpp>
9#include <pinocchio/multibody/model.hpp>
10
12
18namespace franka {
19
23class RobotModel : public RobotModelBase {
24 public:
25 RobotModel(const std::string& urdf);
26
27 void coriolis(const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
28 const std::array<double, 7>& dq, // NOLINT(readability-identifier-length)
29 const std::array<double, 9>& i_total,
30 double m_total,
31 const std::array<double, 3>& f_x_ctotal,
32 std::array<double, 7>& c_ne) override;
33
34 void coriolis(const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
35 const std::array<double, 7>& dq, // NOLINT(readability-identifier-length)
36 const std::array<double, 9>& i_total,
37 double m_total,
38 const std::array<double, 3>& f_x_ctotal,
39 const std::array<double, 3>& g_earth,
40 std::array<double, 7>& c_ne) override;
41
42 void gravity(const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
43 const std::array<double, 3>& g_earth,
44 double m_total,
45 const std::array<double, 3>& f_x_ctotal,
46 std::array<double, 7>& g_ne) override;
47
48 void mass(const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
49 const std::array<double, 9>& i_total,
50 double m_total,
51 const std::array<double, 3>& f_x_ctotal,
52 std::array<double, 49>& m_ne) override;
53 std::array<double, 16> pose(
54 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
55 int joint_index) override;
56 std::array<double, 16> poseEe(
57 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
58 const std::array<double, 16>& f_t_ee) override;
59 std::array<double, 16> poseFlange(
60 const std::array<double, 7>& q) override; // NOLINT(readability-identifier-length)
61 std::array<double, 16> poseStiffness(
62 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
63 const std::array<double, 16>& f_t_ee,
64 const std::array<double, 16>& ee_t_k) override;
65 std::array<double, 42> bodyJacobian(
66 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
67 int joint_index) override;
68 std::array<double, 42> bodyJacobianFlange(
69 const std::array<double, 7>& q) override; // NOLINT(readability-identifier-length)
70 std::array<double, 42> bodyJacobianEe(
71 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
72 const std::array<double, 16>& f_t_ee) override;
73 std::array<double, 42> bodyJacobianStiffness(
74 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
75 const std::array<double, 16>& f_t_ee,
76 const std::array<double, 16>& ee_t_k) override;
77 std::array<double, 42> zeroJacobian(
78 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
79 int joint_index) override;
80 std::array<double, 42> zeroJacobianFlange(
81 const std::array<double, 7>& q) override; // NOLINT(readability-identifier-length)
82 std::array<double, 42> zeroJacobianEe(
83 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
84 const std::array<double, 16>& f_t_ee) override;
85 std::array<double, 42> zeroJacobianStiffness(
86 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
87 const std::array<double, 16>& f_t_ee,
88 const std::array<double, 16>& ee_t_k) override;
89
90 private:
91 mutable pinocchio::Data data_;
92 mutable pinocchio::Data data_gravity_;
93
94 mutable Eigen::Matrix<double, 7, 1> q_eigen_;
95 mutable Eigen::Matrix<double, 7, 1> dq_eigen_;
96 mutable Eigen::Matrix<double, 7, 1> tau_eigen_;
97 mutable Eigen::Matrix<double, 7, 1> ddq_temp_eigen_;
98 mutable Eigen::Vector3d com_eigen_;
99 mutable Eigen::Matrix3d inertia_eigen_;
100
101 mutable std::array<double, 9> cached_i_total_;
102 mutable double cached_m_total_{-1.0};
103 mutable std::array<double, 3> cached_f_x_ctotal_;
104 mutable bool inertia_cache_valid_{false};
105
106 mutable pinocchio::Model pinocchio_model_;
112 pinocchio::Data computeForwardKinematics(
113 const std::array<double, 7>& q) const; // NOLINT(readability-identifier-length)
114
120 static std::array<double, 16> eigenToArray(const Eigen::Matrix4d& matrix);
121
127 static std::array<double, 42> eigenToArray(const Eigen::Matrix<double, 6, 7>& matrix);
128
134 pinocchio::Data initializeModelAndReturnData(const std::string& urdf);
135
143 pinocchio::FrameIndex addFrame(const std::string& name,
144 pinocchio::FrameIndex parent_frame_id,
145 const pinocchio::SE3& placement);
146
155 std::array<double, 42> computeJacobian(
156 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
157 int frame_or_joint_index,
158 bool is_joint,
159 pinocchio::ReferenceFrame reference_frame);
160
168 std::array<double, 42> computeEeJacobian(
169 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
170 const std::array<double, 16>& f_t_ee,
171 pinocchio::ReferenceFrame reference_frame);
172
181 std::array<double, 42> computeStiffnessJacobian(
182 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
183 const std::array<double, 16>& f_t_ee,
184 const std::array<double, 16>& ee_t_k,
185 pinocchio::ReferenceFrame reference_frame);
186
193 void updateFramePlacements(const std::array<double, 16>& f_t_ee,
194 const std::array<double, 16>& ee_t_k = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0,
195 1, 0, 0, 0, 0, 1},
196 bool update_stiffness = false);
197
204 void updateInertiaIfNeeded(const std::array<double, 9>& i_total,
205 double m_total,
206 const std::array<double, 3>& f_x_ctotal) const;
207
211 void restoreOriginalInertia() const;
212
219 void computeGravityVector(
220 const std::array<double, 7>& q, // NOLINT(readability-identifier-length)
221 const std::array<double, 3>& g_earth,
222 std::array<double, 7>& g_ne) const;
223
224 static constexpr const char* kLastLinkName = "link8";
225
226 pinocchio::Inertia initial_last_link_inertia_;
227 pinocchio::FrameIndex last_link_frame_index_;
228 pinocchio::JointIndex last_joint_index_;
229 void copyToEigenQ(const std::array<double, 7>& q) const; // NOLINT(readability-identifier-length)
230 void copyToEigenDQ(
231 const std::array<double, 7>& dq) const; // NOLINT(readability-identifier-length)
232 static void copyFromEigen(const Eigen::VectorXd& src, std::array<double, 7>& dst);
233 static void copyFromEigenMatrix(const Eigen::MatrixXd& src, std::array<double, 49>& dst);
234 pinocchio::FrameIndex ee_frame_index_;
235 pinocchio::FrameIndex stiffness_frame_index_;
236};
237
238} // namespace franka
Robot dynamic parameters computed from the URDF model with Pinocchio.
Definition robot_model_base.h:16
Implements of RobotModelBase using Pinocchio.
Definition robot_model.h:23
std::array< double, 42 > zeroJacobianEe(const std::array< double, 7 > &q, const std::array< double, 16 > &f_t_ee) override
Calculates the 6x7 zero Jacobian for the end effector frame, relative to the base frame.
std::array< double, 42 > bodyJacobianStiffness(const std::array< double, 7 > &q, const std::array< double, 16 > &f_t_ee, const std::array< double, 16 > &ee_t_k) override
Calculates the 6x7 body Jacobian for the stiffness frame, relative to that frame.
void gravity(const std::array< double, 7 > &q, const std::array< double, 3 > &g_earth, double m_total, const std::array< double, 3 > &f_x_ctotal, std::array< double, 7 > &g_ne) override
Calculates the gravity vector.
std::array< double, 16 > poseEe(const std::array< double, 7 > &q, const std::array< double, 16 > &f_t_ee) override
Calculates the homogeneous transformation matrix for the end effector, applying the end effector tran...
std::array< double, 16 > pose(const std::array< double, 7 > &q, int joint_index) override
Calculates the homogeneous transformation matrix for the specified joint or link.
std::array< double, 42 > zeroJacobianStiffness(const std::array< double, 7 > &q, const std::array< double, 16 > &f_t_ee, const std::array< double, 16 > &ee_t_k) override
Calculates the 6x7 zero Jacobian for the stiffness frame, relative to the base frame.
std::array< double, 42 > bodyJacobian(const std::array< double, 7 > &q, int joint_index) override
Calculates the 6x7 body Jacobian for the given joint, relative to that joint's frame.
std::array< double, 16 > poseStiffness(const std::array< double, 7 > &q, const std::array< double, 16 > &f_t_ee, const std::array< double, 16 > &ee_t_k) override
Calculates the homogeneous transformation matrix for the stiffness frame.
std::array< double, 16 > poseFlange(const std::array< double, 7 > &q) override
Calculates the homogeneous transformation matrix for the flange.
std::array< double, 42 > zeroJacobian(const std::array< double, 7 > &q, int joint_index) override
Calculates the 6x7 zero Jacobian for the given joint, relative to the base frame.
std::array< double, 42 > bodyJacobianFlange(const std::array< double, 7 > &q) override
Calculates the 6x7 body Jacobian for the flange frame, relative to that frame.
void 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, std::array< double, 49 > &m_ne) override
Calculates the 7x7 inertia matrix.
std::array< double, 42 > bodyJacobianEe(const std::array< double, 7 > &q, const std::array< double, 16 > &f_t_ee) override
Calculates the 6x7 body Jacobian for the end effector frame, relative to that frame.
std::array< double, 42 > zeroJacobianFlange(const std::array< double, 7 > &q) override
Calculates the 6x7 zero Jacobian for the flange frame, relative to the base frame.
void 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, std::array< double, 7 > &c_ne) override
Calculates the Coriolis force vector (state-space equation): , in .
void 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 std::array< double, 3 > &g_earth, std::array< double, 7 > &c_ne) override
Calculates the Coriolis force vector with configurable gravity (recommended implementation).
Abstract interface class for robot dynamic parameters computed from the URDF model with Pinocchio.