|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <Eigen/Dense> |
| 4 | +#include <memory> |
| 5 | + |
| 6 | +#include <franka/model.h> |
| 7 | +#include <franka/robot_state.h> |
| 8 | + |
| 9 | +#include "franky/types.hpp" |
| 10 | + |
| 11 | +namespace franky { |
| 12 | + |
| 13 | +/** |
| 14 | + * @brief A wrapper around franka::Model that uses Eigen types. |
| 15 | + * |
| 16 | + * This class exposes the same functionality as franka::Model, but uses Eigen types for inputs and outputs |
| 17 | + * instead of std::array. All 2D arrays are returned as Eigen matrices. |
| 18 | + */ |
| 19 | +class Model { |
| 20 | + public: |
| 21 | + /** |
| 22 | + * @param model The underlying franka::Model instance to wrap. |
| 23 | + */ |
| 24 | + explicit Model(franka::Model model); |
| 25 | + |
| 26 | + Model(const Model &) = delete; |
| 27 | + Model &operator=(const Model &) = delete; |
| 28 | + |
| 29 | + Model(Model &&other) noexcept; |
| 30 | + Model &operator=(Model &&other) noexcept; |
| 31 | + |
| 32 | + /** |
| 33 | + * @brief Calculates the pose of a frame relative to the base frame. |
| 34 | + * |
| 35 | + * @param frame The frame whose pose should be returned. |
| 36 | + * @param state The current robot state. |
| 37 | + * @return The pose as an affine transformation matrix. |
| 38 | + */ |
| 39 | + [[nodiscard]] Affine pose(franka::Frame frame, const franka::RobotState &state) const; |
| 40 | + |
| 41 | + /** |
| 42 | + * @brief Calculates the pose of a frame relative to the base frame. |
| 43 | + * |
| 44 | + * @param frame The frame whose pose should be returned. |
| 45 | + * @param q Robot joint angles [rad]. |
| 46 | + * @param F_T_EE Transformation from flange to end-effector frame. |
| 47 | + * @param EE_T_K Transformation from end-effector frame to stiffness frame. |
| 48 | + * @return The pose as an affine transformation matrix. |
| 49 | + */ |
| 50 | + [[nodiscard]] Affine pose(franka::Frame frame, const Vector7d &q, const Affine &F_T_EE, const Affine &EE_T_K) const; |
| 51 | + |
| 52 | + /** |
| 53 | + * @brief Calculates the body Jacobian in base frame. |
| 54 | + * |
| 55 | + * @param frame The frame for which the Jacobian is computed. |
| 56 | + * @param state The current robot state. |
| 57 | + * @return The 6x7 body Jacobian matrix. |
| 58 | + */ |
| 59 | + [[nodiscard]] Jacobian bodyJacobian(franka::Frame frame, const franka::RobotState &state) const; |
| 60 | + |
| 61 | + /** |
| 62 | + * @brief Calculates the body Jacobian in base frame. |
| 63 | + * |
| 64 | + * @param frame The frame for which the Jacobian is computed. |
| 65 | + * @param q Robot joint angles [rad]. |
| 66 | + * @param F_T_EE Transformation from flange to end-effector frame. |
| 67 | + * @param EE_T_K Transformation from end-effector frame to stiffness frame. |
| 68 | + * @return The 6x7 body Jacobian matrix. |
| 69 | + */ |
| 70 | + [[nodiscard]] Jacobian bodyJacobian(franka::Frame frame, |
| 71 | + const Vector7d &q, |
| 72 | + const Affine &F_T_EE, |
| 73 | + const Affine &EE_T_K) const; |
| 74 | + |
| 75 | + /** |
| 76 | + * @brief Calculates the zero Jacobian in base frame. |
| 77 | + * |
| 78 | + * @param frame The frame for which the Jacobian is computed. |
| 79 | + * @param state The current robot state. |
| 80 | + * @return The 6x7 zero Jacobian matrix. |
| 81 | + */ |
| 82 | + [[nodiscard]] Jacobian zeroJacobian(franka::Frame frame, const franka::RobotState &state) const; |
| 83 | + |
| 84 | + /** |
| 85 | + * @brief Calculates the zero Jacobian in base frame. |
| 86 | + * |
| 87 | + * @param frame The frame for which the Jacobian is computed. |
| 88 | + * @param q Robot joint angles [rad]. |
| 89 | + * @param F_T_EE Transformation from flange to end-effector frame. |
| 90 | + * @param EE_T_K Transformation from end-effector frame to stiffness frame. |
| 91 | + * @return The 6x7 zero Jacobian matrix. |
| 92 | + */ |
| 93 | + [[nodiscard]] Jacobian zeroJacobian(franka::Frame frame, |
| 94 | + const Vector7d &q, |
| 95 | + const Affine &F_T_EE, |
| 96 | + const Affine &EE_T_K) const; |
| 97 | + |
| 98 | + /** |
| 99 | + * @brief Calculates the mass matrix. |
| 100 | + * |
| 101 | + * @param state The current robot state. |
| 102 | + * @return The 7x7 mass matrix. |
| 103 | + */ |
| 104 | + [[nodiscard]] Eigen::Matrix<double, 7, 7> mass(const franka::RobotState &state) const; |
| 105 | + |
| 106 | + /** |
| 107 | + * @brief Calculates the mass matrix. |
| 108 | + * |
| 109 | + * @param q Robot joint angles [rad]. |
| 110 | + * @param I_total Combined load and robot inertia [kg·m²]. |
| 111 | + * @param m_total Combined mass of robot and load [kg]. |
| 112 | + * @param F_x_Ctotal Center of mass relative to flange frame [m]. |
| 113 | + * @return The 7x7 mass matrix. |
| 114 | + */ |
| 115 | + [[nodiscard]] Eigen::Matrix<double, 7, 7> mass(const Vector7d &q, |
| 116 | + const Eigen::Matrix3d &I_total, |
| 117 | + double m_total, |
| 118 | + const Eigen::Vector3d &F_x_Ctotal) const; |
| 119 | + |
| 120 | + /** |
| 121 | + * @brief Calculates the Coriolis force vector. |
| 122 | + * |
| 123 | + * @param state The current robot state. |
| 124 | + * @return The Coriolis vector [Nm]. |
| 125 | + */ |
| 126 | + [[nodiscard]] Vector7d coriolis(const franka::RobotState &state) const; |
| 127 | + |
| 128 | + /** |
| 129 | + * @brief Calculates the Coriolis force vector. |
| 130 | + * |
| 131 | + * @param q Robot joint angles [rad]. |
| 132 | + * @param dq Robot joint velocities [rad/s]. |
| 133 | + * @param I_total Combined load and robot inertia [kg·m²]. |
| 134 | + * @param m_total Combined mass of robot and load [kg]. |
| 135 | + * @param F_x_Ctotal Center of mass relative to flange frame [m]. |
| 136 | + * @return The Coriolis vector [Nm]. |
| 137 | + */ |
| 138 | + [[nodiscard]] Vector7d coriolis(const Vector7d &q, |
| 139 | + const Vector7d &dq, |
| 140 | + const Eigen::Matrix3d &I_total, |
| 141 | + double m_total, |
| 142 | + const Eigen::Vector3d &F_x_Ctotal) const; |
| 143 | + |
| 144 | + /** |
| 145 | + * @brief Calculates the gravity vector. |
| 146 | + * |
| 147 | + * @param state The current robot state. |
| 148 | + * @param gravity_earth Gravity vector in base frame [m/s²]. |
| 149 | + * @return The gravity vector [Nm]. |
| 150 | + */ |
| 151 | + [[nodiscard]] Vector7d gravity(const franka::RobotState &state, const Eigen::Vector3d &gravity_earth) const; |
| 152 | + |
| 153 | + /** |
| 154 | + * @brief Calculates the gravity vector using default gravity direction (0, 0, -9.81). |
| 155 | + * |
| 156 | + * @param state The current robot state. |
| 157 | + * @return The gravity vector [Nm]. |
| 158 | + */ |
| 159 | + [[nodiscard]] Vector7d gravity(const franka::RobotState &state) const; |
| 160 | + |
| 161 | + /** |
| 162 | + * @brief Calculates the gravity vector. |
| 163 | + * |
| 164 | + * @param q Robot joint angles [rad]. |
| 165 | + * @param m_total Combined mass of robot and load [kg]. |
| 166 | + * @param F_x_Ctotal Center of mass relative to flange frame [m]. |
| 167 | + * @param gravity_earth Gravity vector in base frame [m/s²], default is (0, 0, -9.81). |
| 168 | + * @return The gravity vector [Nm]. |
| 169 | + */ |
| 170 | + [[nodiscard]] Vector7d gravity(const Vector7d &q, |
| 171 | + double m_total, |
| 172 | + const Eigen::Vector3d &F_x_Ctotal, |
| 173 | + const Eigen::Vector3d &gravity_earth = {0., 0., -9.81}) const; |
| 174 | + |
| 175 | + private: |
| 176 | + franka::Model model_; |
| 177 | +}; |
| 178 | + |
| 179 | +} // namespace franky |
0 commit comments