libfranka 0.15.3
FCI C++ API
Loading...
Searching...
No Matches
robot_model.h
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 <pinocchio/algorithm/centroidal.hpp>
7#include <pinocchio/algorithm/crba.hpp>
8#include <pinocchio/algorithm/rnea.hpp>
9#include <pinocchio/multibody/model.hpp>
10#include <pinocchio/parsers/urdf.hpp>
11#include <string>
12
13#include "franka/robot_model_base.h"
14
15namespace franka {
16
20class RobotModel : public RobotModelBase {
21 public:
22 RobotModel(const std::string& urdf);
23
24 void coriolis(const std::array<double, 7>& q,
25 const std::array<double, 7>& dq,
26 const std::array<double, 9>& i_total,
27 double m_total,
28 const std::array<double, 3>& f_x_ctotal,
29 std::array<double, 7>& c_ne) override;
30
31 void coriolis(const std::array<double, 7>& q,
32 const std::array<double, 7>& dq,
33 const std::array<double, 9>& i_total,
34 double m_total,
35 const std::array<double, 3>& f_x_ctotal,
36 const std::array<double, 3>& g_earth,
37 std::array<double, 7>& c_ne) override;
38
39 void gravity(const std::array<double, 7>& q,
40 const std::array<double, 3>& g_earth,
41 double m_total,
42 const std::array<double, 3>& f_x_ctotal,
43 std::array<double, 7>& g_ne) override;
44
45 void mass(const std::array<double, 7>& q,
46 const std::array<double, 9>& i_total,
47 double m_total,
48 const std::array<double, 3>& f_x_ctotal,
49 std::array<double, 49>& m_ne) override;
50
51 private:
52 mutable pinocchio::Data data_;
53 mutable pinocchio::Data data_gravity_;
54
55 mutable Eigen::Matrix<double, 7, 1> q_eigen_;
56 mutable Eigen::Matrix<double, 7, 1> dq_eigen_;
57 mutable Eigen::Matrix<double, 7, 1> tau_eigen_;
58 mutable Eigen::Matrix<double, 7, 1> ddq_temp_eigen_;
59 mutable Eigen::Vector3d com_eigen_;
60 mutable Eigen::Matrix3d inertia_eigen_;
61
62 mutable std::array<double, 9> cached_i_total_;
63 mutable double cached_m_total_;
64 mutable std::array<double, 3> cached_f_x_ctotal_;
65 mutable bool inertia_cache_valid_;
66
67 mutable pinocchio::Model pinocchio_model_;
68 pinocchio::Inertia initial_last_link_inertia_;
69 pinocchio::FrameIndex last_link_frame_index_;
70 pinocchio::JointIndex last_joint_index_;
71
72 void updateInertiaIfNeeded(const std::array<double, 9>& i_total,
73 double m_total,
74 const std::array<double, 3>& f_x_ctotal) const;
75
76 void restoreOriginalInertia() const;
77
78 void computeGravityVector(const std::array<double, 7>& q,
79 const std::array<double, 3>& g_earth,
80 std::array<double, 7>& g_ne) const;
81
82 void copyToEigenQ(const std::array<double, 7>& q) const;
83 void copyToEigenDQ(const std::array<double, 7>& dq) const;
84 void copyFromEigen(const Eigen::VectorXd& src, std::array<double, 7>& dst) const;
85 void copyFromEigenMatrix(const Eigen::MatrixXd& src, std::array<double, 49>& dst) const;
86};
87
88} // namespace franka
Robot dynamic parameters computed from the URDF model with Pinocchio.
Definition robot_model_base.h:10
Optimized implementation of RobotModelBase using Pinocchio.
Definition robot_model.h:20
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.
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.
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).