GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/multibody/impulses/impulse-3d.hpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 23 24 95.8%
Branches: 36 72 50.0%

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