GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/multibody/contact-base.hpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 10 10 100.0%
Branches: 8 16 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2023, 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_CONTACT_BASE_HPP_
11 #define CROCODDYL_MULTIBODY_CONTACT_BASE_HPP_
12
13 #include <pinocchio/multibody/fwd.hpp>
14
15 #include "crocoddyl/core/mathbase.hpp"
16 #include "crocoddyl/core/utils/deprecate.hpp"
17 #include "crocoddyl/multibody/force-base.hpp"
18 #include "crocoddyl/multibody/fwd.hpp"
19 #include "crocoddyl/multibody/states/multibody.hpp"
20
21 namespace crocoddyl {
22
23 template <typename _Scalar>
24 class ContactModelAbstractTpl {
25 public:
26 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
27
28 typedef _Scalar Scalar;
29 typedef MathBaseTpl<Scalar> MathBase;
30 typedef ContactDataAbstractTpl<Scalar> ContactDataAbstract;
31 typedef StateMultibodyTpl<Scalar> StateMultibody;
32 typedef typename MathBase::VectorXs VectorXs;
33 typedef typename MathBase::MatrixXs MatrixXs;
34
35 /**
36 * @brief Initialize the contact abstraction
37 *
38 * @param[in] state State of the multibody system
39 * @param[in] type Type of contact
40 * @param[in] nc Dimension of the contact model
41 * @param[in] nu Dimension of the control vector
42 */
43 ContactModelAbstractTpl(boost::shared_ptr<StateMultibody> state,
44 const pinocchio::ReferenceFrame type,
45 const std::size_t nc, const std::size_t nu);
46 ContactModelAbstractTpl(boost::shared_ptr<StateMultibody> state,
47 const pinocchio::ReferenceFrame type,
48 const std::size_t nc);
49
50 DEPRECATED(
51 "Use constructor that passes the type type of contact, this assumes is "
52 "pinocchio::LOCAL",
53 ContactModelAbstractTpl(boost::shared_ptr<StateMultibody> state,
54 const std::size_t nc, const std::size_t nu);)
55 DEPRECATED(
56 "Use constructor that passes the type type of contact, this assumes is "
57 "pinocchio::LOCAL",
58 ContactModelAbstractTpl(boost::shared_ptr<StateMultibody> state,
59 const std::size_t nc);)
60 virtual ~ContactModelAbstractTpl();
61
62 /**
63 * @brief Compute the contact Jacobian and acceleration drift
64 *
65 * @param[in] data Contact data
66 * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$
67 * @param[in] u Control input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$
68 */
69 virtual void calc(const boost::shared_ptr<ContactDataAbstract>& data,
70 const Eigen::Ref<const VectorXs>& x) = 0;
71
72 /**
73 * @brief Compute the derivatives of the acceleration-based contact
74 *
75 * @param[in] data Contact data
76 * @param[in] x State point \f$\mathbf{x}\in\mathbb{R}^{ndx}\f$
77 * @param[in] u Control input \f$\mathbf{u}\in\mathbb{R}^{nu}\f$
78 */
79 virtual void calcDiff(const boost::shared_ptr<ContactDataAbstract>& data,
80 const Eigen::Ref<const VectorXs>& x) = 0;
81
82 /**
83 * @brief Convert the force into a stack of spatial forces
84 *
85 * @param[in] data Contact data
86 * @param[in] force Contact force
87 */
88 virtual void updateForce(const boost::shared_ptr<ContactDataAbstract>& data,
89 const VectorXs& force) = 0;
90
91 /**
92 * @brief Convert the force into a stack of spatial forces
93 *
94 * @param[in] data Contact data
95 * @param[in] force Contact force
96 */
97 void updateForceDiff(const boost::shared_ptr<ContactDataAbstract>& data,
98 const MatrixXs& df_dx, const MatrixXs& df_du) const;
99
100 /**
101 * @brief Set the stack of spatial forces to zero
102 *
103 * @param[in] data Contact data
104 */
105 void setZeroForce(const boost::shared_ptr<ContactDataAbstract>& data) const;
106
107 /**
108 * @brief Set the stack of spatial forces Jacobians to zero
109 *
110 * @param[in] data Contact data
111 */
112 void setZeroForceDiff(
113 const boost::shared_ptr<ContactDataAbstract>& data) const;
114
115 /**
116 * @brief Create the contact data
117 */
118 virtual boost::shared_ptr<ContactDataAbstract> createData(
119 pinocchio::DataTpl<Scalar>* const data);
120
121 /**
122 * @brief Return the state
123 */
124 const boost::shared_ptr<StateMultibody>& get_state() const;
125
126 /**
127 * @brief Return the dimension of the contact
128 */
129 std::size_t get_nc() const;
130
131 /**
132 * @brief Return the dimension of the control vector
133 */
134 std::size_t get_nu() const;
135
136 /**
137 * @brief Return the reference frame id
138 */
139 pinocchio::FrameIndex get_id() const;
140
141 /**
142 * @brief Modify the reference frame id
143 */
144 void set_id(const pinocchio::FrameIndex id);
145
146 /**
147 * @brief Modify the type of contact
148 */
149 void set_type(const pinocchio::ReferenceFrame type);
150
151 /**
152 * @brief Return the type of contact
153 */
154 pinocchio::ReferenceFrame get_type() const;
155
156 /**
157 * @brief Print information on the contact model
158 */
159 template <class Scalar>
160 friend std::ostream& operator<<(std::ostream& os,
161 const ContactModelAbstractTpl<Scalar>& model);
162
163 /**
164 * @brief Print relevant information of the contact model
165 *
166 * @param[out] os Output stream object
167 */
168 virtual void print(std::ostream& os) const;
169
170 protected:
171 boost::shared_ptr<StateMultibody> state_;
172 std::size_t nc_;
173 std::size_t nu_;
174 pinocchio::FrameIndex id_; //!< Reference frame id of the contact
175 pinocchio::ReferenceFrame type_; //!< Type of contact
176 };
177
178 template <typename _Scalar>
179 struct ContactDataAbstractTpl : public ForceDataAbstractTpl<_Scalar> {
180 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
181
182 typedef _Scalar Scalar;
183 typedef MathBaseTpl<Scalar> MathBase;
184 typedef ForceDataAbstractTpl<Scalar> Base;
185 typedef typename MathBase::VectorXs VectorXs;
186 typedef typename MathBase::MatrixXs MatrixXs;
187 typedef typename pinocchio::SE3Tpl<Scalar> SE3;
188
189 template <template <typename Scalar> class Model>
190 326646 ContactDataAbstractTpl(Model<Scalar>* const model,
191 pinocchio::DataTpl<Scalar>* const data)
192 : Base(model, data),
193
1/2
✓ Branch 1 taken 163341 times.
✗ Branch 2 not taken.
326646 fXj(jMf.inverse().toActionMatrix()),
194
1/2
✓ Branch 2 taken 163341 times.
✗ Branch 3 not taken.
326646 a0(model->get_nc()),
195
1/2
✓ Branch 5 taken 163341 times.
✗ Branch 6 not taken.
326646 da0_dx(model->get_nc(), model->get_state()->get_ndx()),
196
2/4
✓ Branch 2 taken 163341 times.
✗ Branch 3 not taken.
✓ Branch 11 taken 163341 times.
✗ Branch 12 not taken.
653292 dtau_dq(model->get_state()->get_nv(), model->get_state()->get_nv()) {
197
1/2
✓ Branch 1 taken 163341 times.
✗ Branch 2 not taken.
326646 a0.setZero();
198
1/2
✓ Branch 1 taken 163341 times.
✗ Branch 2 not taken.
326646 da0_dx.setZero();
199
1/2
✓ Branch 1 taken 163341 times.
✗ Branch 2 not taken.
326646 dtau_dq.setZero();
200 326646 }
201 163462 virtual ~ContactDataAbstractTpl() {}
202
203 using Base::df_du;
204 using Base::df_dx;
205 using Base::f;
206 using Base::frame;
207 using Base::Jc;
208 using Base::jMf;
209 using Base::pinocchio;
210
211 typename SE3::ActionMatrixType fXj;
212 VectorXs a0;
213 MatrixXs da0_dx;
214 MatrixXs dtau_dq;
215 };
216
217 } // namespace crocoddyl
218
219 /* --- Details -------------------------------------------------------------- */
220 /* --- Details -------------------------------------------------------------- */
221 /* --- Details -------------------------------------------------------------- */
222 #include "crocoddyl/multibody/contact-base.hxx"
223
224 #endif // CROCODDYL_MULTIBODY_CONTACT_BASE_HPP_
225