| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh, | ||
| 5 | // Heriot-Watt University | ||
| 6 | // Copyright note valid unless otherwise stated in individual files. | ||
| 7 | // All rights reserved. | ||
| 8 | /////////////////////////////////////////////////////////////////////////////// | ||
| 9 | |||
| 10 | #ifndef CROCODDYL_MULTIBODY_IMPULSES_IMPULSE_3D_HPP_ | ||
| 11 | #define CROCODDYL_MULTIBODY_IMPULSES_IMPULSE_3D_HPP_ | ||
| 12 | |||
| 13 | #include "crocoddyl/multibody/fwd.hpp" | ||
| 14 | #include "crocoddyl/multibody/impulse-base.hpp" | ||
| 15 | |||
| 16 | namespace crocoddyl { | ||
| 17 | |||
| 18 | template <typename _Scalar> | ||
| 19 | class ImpulseModel3DTpl : public ImpulseModelAbstractTpl<_Scalar> { | ||
| 20 | public: | ||
| 21 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
| 22 | ✗ | CROCODDYL_DERIVED_CAST(ImpulseModelBase, ImpulseModel3DTpl) | |
| 23 | |||
| 24 | typedef _Scalar Scalar; | ||
| 25 | typedef MathBaseTpl<Scalar> MathBase; | ||
| 26 | typedef ImpulseModelAbstractTpl<Scalar> Base; | ||
| 27 | typedef ImpulseData3DTpl<Scalar> Data; | ||
| 28 | typedef StateMultibodyTpl<Scalar> StateMultibody; | ||
| 29 | typedef ImpulseDataAbstractTpl<Scalar> ImpulseDataAbstract; | ||
| 30 | typedef typename MathBase::Vector2s Vector2s; | ||
| 31 | typedef typename MathBase::Vector3s Vector3s; | ||
| 32 | typedef typename MathBase::VectorXs VectorXs; | ||
| 33 | typedef typename MathBase::MatrixXs Matrix3s; | ||
| 34 | typedef typename MathBase::MatrixXs MatrixXs; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * @brief Initialize the 3d impulse model | ||
| 38 | * | ||
| 39 | * @param[in] state State of the multibody system | ||
| 40 | * @param[in] id Reference frame id of the impulse | ||
| 41 | * @param[in] type Type of impulse (default LOCAL) | ||
| 42 | */ | ||
| 43 | ImpulseModel3DTpl( | ||
| 44 | std::shared_ptr<StateMultibody> state, const pinocchio::FrameIndex id, | ||
| 45 | const pinocchio::ReferenceFrame type = pinocchio::ReferenceFrame::LOCAL); | ||
| 46 | ✗ | virtual ~ImpulseModel3DTpl() = default; | |
| 47 | |||
| 48 | /** | ||
| 49 | * @brief Compute the 6d impulse Jacobian | ||
| 50 | * | ||
| 51 | * @param[in] data 6d impulse data | ||
| 52 | * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ | ||
| 53 | */ | ||
| 54 | virtual void calc(const std::shared_ptr<ImpulseDataAbstract>& data, | ||
| 55 | const Eigen::Ref<const VectorXs>& x) override; | ||
| 56 | |||
| 57 | /** | ||
| 58 | * @brief Compute the derivatives of the 6d impulse holonomic constraint | ||
| 59 | * | ||
| 60 | * @param[in] data 6d impulse data | ||
| 61 | * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$ | ||
| 62 | */ | ||
| 63 | virtual void calcDiff(const std::shared_ptr<ImpulseDataAbstract>& data, | ||
| 64 | const Eigen::Ref<const VectorXs>& x) override; | ||
| 65 | |||
| 66 | /** | ||
| 67 | * @brief Convert the force into a stack of spatial forces | ||
| 68 | * | ||
| 69 | * @param[in] data 6d impulse data | ||
| 70 | * @param[in] force 6d impulse | ||
| 71 | */ | ||
| 72 | virtual void updateForce(const std::shared_ptr<ImpulseDataAbstract>& data, | ||
| 73 | const VectorXs& force) override; | ||
| 74 | |||
| 75 | /** | ||
| 76 | * @brief Create the 6d impulse data | ||
| 77 | */ | ||
| 78 | virtual std::shared_ptr<ImpulseDataAbstract> createData( | ||
| 79 | pinocchio::DataTpl<Scalar>* const data) override; | ||
| 80 | |||
| 81 | /** | ||
| 82 | * @brief Cast the impulse-3d model to a different scalar type. | ||
| 83 | * | ||
| 84 | * It is useful for operations requiring different precision or scalar types. | ||
| 85 | * | ||
| 86 | * @tparam NewScalar The new scalar type to cast to. | ||
| 87 | * @return ImpulseModel3DTpl<NewScalar> An impulse model with the | ||
| 88 | * new scalar type. | ||
| 89 | */ | ||
| 90 | template <typename NewScalar> | ||
| 91 | ImpulseModel3DTpl<NewScalar> cast() const; | ||
| 92 | |||
| 93 | /** | ||
| 94 | * @brief Print relevant information of the 3d impulse model | ||
| 95 | * | ||
| 96 | * @param[out] os Output stream object | ||
| 97 | */ | ||
| 98 | virtual void print(std::ostream& os) const override; | ||
| 99 | |||
| 100 | protected: | ||
| 101 | using Base::id_; | ||
| 102 | using Base::state_; | ||
| 103 | using Base::type_; | ||
| 104 | }; | ||
| 105 | |||
| 106 | template <typename _Scalar> | ||
| 107 | struct ImpulseData3DTpl : public ImpulseDataAbstractTpl<_Scalar> { | ||
| 108 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
| 109 | |||
| 110 | typedef _Scalar Scalar; | ||
| 111 | typedef MathBaseTpl<Scalar> MathBase; | ||
| 112 | typedef ImpulseDataAbstractTpl<Scalar> Base; | ||
| 113 | typedef typename MathBase::Vector3s Vector3s; | ||
| 114 | typedef typename MathBase::Matrix3s Matrix3s; | ||
| 115 | typedef typename MathBase::Matrix3xs Matrix3xs; | ||
| 116 | typedef typename MathBase::Matrix6xs Matrix6xs; | ||
| 117 | typedef typename pinocchio::ForceTpl<Scalar> Force; | ||
| 118 | |||
| 119 | template <template <typename Scalar> class Model> | ||
| 120 | ✗ | ImpulseData3DTpl(Model<Scalar>* const model, | |
| 121 | pinocchio::DataTpl<Scalar>* const data) | ||
| 122 | : Base(model, data), | ||
| 123 | ✗ | f_local(Force::Zero()), | |
| 124 | ✗ | dv0_local_dq(3, model->get_state()->get_nv()), | |
| 125 | ✗ | fJf(6, model->get_state()->get_nv()), | |
| 126 | ✗ | v_partial_dq(6, model->get_state()->get_nv()), | |
| 127 | ✗ | v_partial_dv(6, model->get_state()->get_nv()), | |
| 128 | ✗ | fJf_df(3, model->get_state()->get_nv()) { | |
| 129 | ✗ | frame = model->get_id(); | |
| 130 | ✗ | jMf = | |
| 131 | ✗ | model->get_state()->get_pinocchio()->frames[model->get_id()].placement; | |
| 132 | ✗ | fXj = jMf.inverse().toActionMatrix(); | |
| 133 | ✗ | v0.setZero(); | |
| 134 | ✗ | dv0_local_dq.setZero(); | |
| 135 | ✗ | fJf.setZero(); | |
| 136 | ✗ | v_partial_dq.setZero(); | |
| 137 | ✗ | v_partial_dv.setZero(); | |
| 138 | ✗ | v0_skew.setZero(); | |
| 139 | ✗ | v0_world_skew.setZero(); | |
| 140 | ✗ | f_skew.setZero(); | |
| 141 | ✗ | fJf_df.setZero(); | |
| 142 | ✗ | } | |
| 143 | ✗ | virtual ~ImpulseData3DTpl() = default; | |
| 144 | |||
| 145 | using Base::df_dx; | ||
| 146 | using Base::dv0_dq; | ||
| 147 | using Base::f; | ||
| 148 | using Base::frame; | ||
| 149 | using Base::fXj; | ||
| 150 | using Base::Jc; | ||
| 151 | using Base::jMf; | ||
| 152 | using Base::pinocchio; | ||
| 153 | |||
| 154 | Vector3s v0; | ||
| 155 | Force f_local; | ||
| 156 | Matrix3xs dv0_local_dq; | ||
| 157 | Matrix6xs fJf; | ||
| 158 | Matrix6xs v_partial_dq; | ||
| 159 | Matrix6xs v_partial_dv; | ||
| 160 | Matrix3s v0_skew; | ||
| 161 | Matrix3s v0_world_skew; | ||
| 162 | Matrix3s f_skew; | ||
| 163 | Matrix3xs fJf_df; | ||
| 164 | }; | ||
| 165 | |||
| 166 | } // namespace crocoddyl | ||
| 167 | |||
| 168 | /* --- Details -------------------------------------------------------------- */ | ||
| 169 | /* --- Details -------------------------------------------------------------- */ | ||
| 170 | /* --- Details -------------------------------------------------------------- */ | ||
| 171 | #include "crocoddyl/multibody/impulses/impulse-3d.hxx" | ||
| 172 | |||
| 173 | CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(crocoddyl::ImpulseModel3DTpl) | ||
| 174 | CROCODDYL_DECLARE_EXTERN_TEMPLATE_STRUCT(crocoddyl::ImpulseData3DTpl) | ||
| 175 | |||
| 176 | #endif // CROCODDYL_MULTIBODY_IMPULSES_IMPULSE_3D_HPP_ | ||
| 177 |