GCC Code Coverage Report


Directory: ./
File: include/pinocchio/algorithm/contact-dynamics.hxx
Date: 2025-04-30 16:14:33
Exec Total Coverage
Lines: 95 100 95.0%
Branches: 92 432 21.3%

Line Branch Exec Source
1 //
2 // Copyright (c) 2016-2020 CNRS INRIA
3 //
4
5 #ifndef __pinocchio_algorithm_constrained_dynamics_hxx__
6 #define __pinocchio_algorithm_constrained_dynamics_hxx__
7
8 #include "pinocchio/algorithm/compute-all-terms.hpp"
9 #include "pinocchio/algorithm/cholesky.hpp"
10 #include "pinocchio/algorithm/crba.hpp"
11 #include "pinocchio/algorithm/check.hpp"
12 #include "pinocchio/math/matrix.hpp"
13
14 #include <Eigen/Cholesky>
15
16 namespace pinocchio
17 {
18
19 namespace internal
20 {
21 template<typename Scalar, bool is_floating_point = pinocchio::is_floating_point<Scalar>::value>
22 struct PerformCholeskySolveInPlace
23 {
24 template<typename MatrixIn, typename MatrixLLT, typename MatrixOut>
25 static void run(
26 const Eigen::MatrixBase<MatrixIn> & mat,
27 Eigen::LLT<MatrixLLT> & llt,
28 const Eigen::MatrixBase<MatrixOut> & res,
29 const bool compute)
30 {
31 if (compute)
32 llt.compute(mat);
33 llt.solveInPlace(res.const_cast_derived());
34 }
35
36 template<typename MatrixIn, typename MatrixLLT, typename MatrixOut>
37 272 static void run(
38 const Eigen::MatrixBase<MatrixIn> & /*mat*/,
39 const Eigen::LLT<MatrixLLT> & llt,
40 const Eigen::MatrixBase<MatrixOut> & res)
41 {
42 272 llt.solveInPlace(res.const_cast_derived());
43 272 }
44 };
45
46 template<typename Scalar>
47 struct PerformCholeskySolveInPlace<Scalar, false>
48 {
49 template<typename MatrixIn, typename MatrixLLT, typename MatrixOut>
50 static void run(
51 const Eigen::MatrixBase<MatrixIn> & mat,
52 const Eigen::LLT<MatrixLLT> & /*llt*/,
53 const Eigen::MatrixBase<MatrixOut> & res)
54 {
55 typename PINOCCHIO_EIGEN_PLAIN_TYPE(MatrixIn) mat_inv(mat.rows(), mat.cols());
56 inverse(mat, mat_inv);
57 res.const_cast_derived() = mat_inv * res;
58 }
59 };
60
61 template<typename Scalar, bool is_floating_point = pinocchio::is_floating_point<Scalar>::value>
62 struct PerformCholeskyCompute
63 {
64 template<typename MatrixIn, typename MatrixLLT>
65 236 static void run(const Eigen::MatrixBase<MatrixIn> & mat, Eigen::LLT<MatrixLLT> & llt)
66 {
67 236 llt.compute(mat);
68 236 }
69 };
70
71 template<typename Scalar>
72 struct PerformCholeskyCompute<Scalar, false>
73 {
74 template<typename MatrixIn, typename MatrixLLT>
75 static void run(const Eigen::MatrixBase<MatrixIn> &, Eigen::LLT<MatrixLLT> &)
76 {
77 }
78 };
79
80 } // namespace internal
81
82 template<
83 typename Scalar,
84 int Options,
85 template<typename, int> class JointCollectionTpl,
86 typename TangentVectorType,
87 typename ConstraintMatrixType,
88 typename DriftVectorType>
89 inline const typename DataTpl<Scalar, Options, JointCollectionTpl>::TangentVectorType &
90 216 forwardDynamics(
91 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
92 DataTpl<Scalar, Options, JointCollectionTpl> & data,
93 const Eigen::MatrixBase<TangentVectorType> & tau,
94 const Eigen::MatrixBase<ConstraintMatrixType> & J,
95 const Eigen::MatrixBase<DriftVectorType> & gamma,
96 const Scalar inv_damping)
97 {
98
1/24
✗ Branch 1 not taken.
✓ Branch 2 taken 216 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
216 PINOCCHIO_CHECK_ARGUMENT_SIZE(tau.size(), model.nv);
99
1/24
✗ Branch 1 not taken.
✓ Branch 2 taken 216 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
216 PINOCCHIO_CHECK_ARGUMENT_SIZE(J.cols(), model.nv);
100
1/24
✗ Branch 2 not taken.
✓ Branch 3 taken 216 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
216 PINOCCHIO_CHECK_ARGUMENT_SIZE(J.rows(), gamma.size());
101
1/2
✓ Branch 1 taken 216 times.
✗ Branch 2 not taken.
216 assert(model.check(data) && "data is not consistent with model.");
102
2/4
✓ Branch 1 taken 216 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 216 times.
✗ Branch 4 not taken.
216 assert(model.check(MimicChecker()) && "Function does not support mimic joints");
103
104 typedef DataTpl<Scalar, Options, JointCollectionTpl> Data;
105
106 216 typename Data::TangentVectorType & a = data.ddq;
107 216 typename Data::VectorXs & lambda_c = data.lambda_c;
108
109 // Compute the UDUt decomposition of data.M
110 216 cholesky::decompose(model, data);
111
112 // Compute the dynamic drift (control - nle)
113
1/2
✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
216 data.torque_residual = tau - data.nle;
114 216 cholesky::solve(model, data, data.torque_residual);
115
116
1/2
✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
216 data.sDUiJt = J.transpose();
117 // Compute U^-1 * J.T
118 216 cholesky::Uiv(model, data, data.sDUiJt);
119
2/2
✓ Branch 0 taken 6898 times.
✓ Branch 1 taken 216 times.
7114 for (Eigen::DenseIndex k = 0; k < model.nv; ++k)
120
2/6
✓ Branch 2 taken 6898 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6898 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6898 data.sDUiJt.row(k) /= sqrt(data.D[k]);
121
122
3/6
✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 216 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 216 times.
✗ Branch 9 not taken.
216 data.JMinvJt.noalias() = data.sDUiJt.transpose() * data.sDUiJt;
123
124
2/4
✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 216 times.
✗ Branch 6 not taken.
216 data.JMinvJt.diagonal().array() += inv_damping;
125
126 // Compute the Lagrange Multipliers
127
4/8
✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 216 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 216 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 216 times.
✗ Branch 12 not taken.
216 lambda_c.noalias() = -J * data.torque_residual - gamma;
128 // data.llt_JMinvJt.compute(data.JMinvJt);
129 // data.llt_JMinvJt.solveInPlace(lambda_c);
130 216 internal::PerformCholeskyCompute<Scalar>::run(data.JMinvJt, data.llt_JMinvJt);
131 216 internal::PerformCholeskySolveInPlace<Scalar>::run(data.JMinvJt, data.llt_JMinvJt, lambda_c);
132
133 // Compute the joint acceleration
134
3/6
✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 216 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 216 times.
✗ Branch 9 not taken.
216 a.noalias() = J.transpose() * lambda_c;
135 216 cholesky::solve(model, data, a);
136 216 a += data.torque_residual;
137
138 216 return a;
139 }
140
141 template<
142 typename Scalar,
143 int Options,
144 template<typename, int> class JointCollectionTpl,
145 typename ConfigVectorType,
146 typename TangentVectorType1,
147 typename TangentVectorType2,
148 typename ConstraintMatrixType,
149 typename DriftVectorType>
150 inline const typename DataTpl<Scalar, Options, JointCollectionTpl>::TangentVectorType &
151 212 forwardDynamics(
152 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
153 DataTpl<Scalar, Options, JointCollectionTpl> & data,
154 const Eigen::MatrixBase<ConfigVectorType> & q,
155 const Eigen::MatrixBase<TangentVectorType1> & v,
156 const Eigen::MatrixBase<TangentVectorType2> & tau,
157 const Eigen::MatrixBase<ConstraintMatrixType> & J,
158 const Eigen::MatrixBase<DriftVectorType> & gamma,
159 const Scalar inv_damping)
160 {
161
1/24
✗ Branch 1 not taken.
✓ Branch 2 taken 212 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
212 PINOCCHIO_CHECK_ARGUMENT_SIZE(q.size(), model.nq);
162
1/24
✗ Branch 1 not taken.
✓ Branch 2 taken 212 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
212 PINOCCHIO_CHECK_ARGUMENT_SIZE(v.size(), model.nv);
163
164 212 computeAllTerms(model, data, q, v);
165
166
0/2
✗ Branch 2 not taken.
✗ Branch 3 not taken.
212 return forwardDynamics(model, data, tau, J, gamma, inv_damping);
167 }
168
169 template<
170 typename Scalar,
171 int Options,
172 template<typename, int> class JointCollectionTpl,
173 typename ConfigVectorType,
174 typename ConstraintMatrixType,
175 typename KKTMatrixType>
176 3 void computeKKTContactDynamicMatrixInverse(
177 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
178 DataTpl<Scalar, Options, JointCollectionTpl> & data,
179 const Eigen::MatrixBase<ConfigVectorType> & q,
180 const Eigen::MatrixBase<ConstraintMatrixType> & J,
181 const Eigen::MatrixBase<KKTMatrixType> & KKTMatrix_inv,
182 const Scalar & inv_damping)
183 {
184
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 assert(model.check(data));
185
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
3 assert(model.check(MimicChecker()) && "Function does not support mimic joints");
186
187
2/12
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
3 PINOCCHIO_CHECK_INPUT_ARGUMENT(
188 check_expression_if_real<Scalar>(inv_damping >= 0.), "mu must be positive.");
189
190 // Compute the mass matrix.
191 3 crba(model, data, q, Convention::WORLD);
192
193 // Compute the UDUt decomposition of data.M.
194 3 cholesky::decompose(model, data);
195
196 using std::sqrt;
197
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 data.sDUiJt = J.transpose();
198 // Compute U^-1 * J.T
199 3 cholesky::Uiv(model, data, data.sDUiJt);
200
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 3 times.
99 for (Eigen::DenseIndex k = 0; k < model.nv; ++k)
201
2/6
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 96 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
96 data.sDUiJt.row(k) /= sqrt(data.D[k]);
202
203
3/6
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
3 data.JMinvJt.noalias() = data.sDUiJt.transpose() * data.sDUiJt;
204
205
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 data.JMinvJt.diagonal().array() += inv_damping;
206 // data.llt_JMinvJt.compute(data.JMinvJt);
207 3 internal::PerformCholeskyCompute<Scalar>::run(data.JMinvJt, data.llt_JMinvJt);
208
209 PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
210 PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
211 3 getKKTContactDynamicMatrixInverse(model, data, J, KKTMatrix_inv.const_cast_derived());
212 PINOCCHIO_COMPILER_DIAGNOSTIC_POP
213 3 }
214
215 template<
216 typename Scalar,
217 int Options,
218 template<typename, int> class JointCollectionTpl,
219 typename ConstraintMatrixType,
220 typename KKTMatrixType>
221 7 void getKKTContactDynamicMatrixInverse(
222 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
223 const DataTpl<Scalar, Options, JointCollectionTpl> & data,
224 const Eigen::MatrixBase<ConstraintMatrixType> & J,
225 const Eigen::MatrixBase<KKTMatrixType> & KKTMatrix_inv)
226 {
227
2/4
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
7 assert(model.check(data));
228
2/4
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
7 assert(model.check(MimicChecker()) && "Function does not support mimic joints");
229
230
1/24
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
7 PINOCCHIO_CHECK_ARGUMENT_SIZE(KKTMatrix_inv.cols(), data.JMinvJt.cols() + model.nv);
231
1/24
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
7 PINOCCHIO_CHECK_ARGUMENT_SIZE(KKTMatrix_inv.rows(), data.JMinvJt.rows() + model.nv);
232
233 typedef DataTpl<Scalar, Options, JointCollectionTpl> Data;
234 7 const Eigen::DenseIndex nc = data.JMinvJt.cols();
235
236 7 KKTMatrixType & KKTMatrix_inv_ = PINOCCHIO_EIGEN_CONST_CAST(KKTMatrixType, KKTMatrix_inv);
237
238 typedef Eigen::Block<KKTMatrixType> BlockType;
239
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 BlockType topLeft = KKTMatrix_inv_.topLeftCorner(model.nv, model.nv);
240
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 BlockType topRight = KKTMatrix_inv_.topRightCorner(model.nv, nc);
241
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 BlockType bottomLeft = KKTMatrix_inv_.bottomLeftCorner(nc, model.nv);
242
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 BlockType bottomRight = KKTMatrix_inv_.bottomRightCorner(nc, nc);
243
244
3/6
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
7 bottomRight = -Data::MatrixXs::Identity(nc, nc);
245 // data.llt_JMinvJt.solveInPlace(bottomRight);
246
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 internal::PerformCholeskySolveInPlace<Scalar>::run(data.JMinvJt, data.llt_JMinvJt, bottomRight);
247
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 topLeft.setIdentity();
248
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 cholesky::solve(model, data, topLeft);
249
250
3/6
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
7 bottomLeft.noalias() = J * topLeft;
251
5/10
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 7 times.
✗ Branch 14 not taken.
7 topRight.noalias() = bottomLeft.transpose() * (-bottomRight);
252
3/6
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
7 topLeft.noalias() -= topRight * bottomLeft;
253
2/4
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
7 bottomLeft = topRight.transpose();
254 7 }
255
256 template<
257 typename Scalar,
258 int Options,
259 template<typename, int> class JointCollectionTpl,
260 typename ConfigVectorType,
261 typename TangentVectorType,
262 typename ConstraintMatrixType>
263 inline const typename DataTpl<Scalar, Options, JointCollectionTpl>::TangentVectorType &
264 11 impulseDynamics(
265 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
266 DataTpl<Scalar, Options, JointCollectionTpl> & data,
267 const Eigen::MatrixBase<ConfigVectorType> & q,
268 const Eigen::MatrixBase<TangentVectorType> & v_before,
269 const Eigen::MatrixBase<ConstraintMatrixType> & J,
270 const Scalar r_coeff,
271 const Scalar inv_damping)
272 {
273
1/24
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
11 PINOCCHIO_CHECK_ARGUMENT_SIZE(q.size(), model.nq);
274
275 // Compute the mass matrix
276 11 crba(model, data, q, Convention::WORLD);
277
278
0/4
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
11 return impulseDynamics(model, data, v_before, J, r_coeff, inv_damping);
279 }
280
281 template<
282 typename Scalar,
283 int Options,
284 template<typename, int> class JointCollectionTpl,
285 typename TangentVectorType,
286 typename ConstraintMatrixType>
287 inline const typename DataTpl<Scalar, Options, JointCollectionTpl>::TangentVectorType &
288 17 impulseDynamics(
289 const ModelTpl<Scalar, Options, JointCollectionTpl> & model,
290 DataTpl<Scalar, Options, JointCollectionTpl> & data,
291 const Eigen::MatrixBase<TangentVectorType> & v_before,
292 const Eigen::MatrixBase<ConstraintMatrixType> & J,
293 const Scalar r_coeff,
294 const Scalar inv_damping)
295 {
296
1/24
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
17 PINOCCHIO_CHECK_ARGUMENT_SIZE(v_before.size(), model.nv);
297
1/24
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
17 PINOCCHIO_CHECK_ARGUMENT_SIZE(J.cols(), model.nv);
298
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
17 assert(model.check(data) && "data is not consistent with model.");
299
2/4
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
✗ Branch 4 not taken.
17 assert(model.check(MimicChecker()) && "Function does not support mimic joints");
300
301 typedef DataTpl<Scalar, Options, JointCollectionTpl> Data;
302
303 17 typename Data::VectorXs & impulse_c = data.impulse_c;
304 17 typename Data::TangentVectorType & dq_after = data.dq_after;
305
306 // Compute the UDUt decomposition of data.M
307 17 cholesky::decompose(model, data);
308
309
1/2
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
17 data.sDUiJt = J.transpose();
310 // Compute U^-1 * J.T
311 17 cholesky::Uiv(model, data, data.sDUiJt);
312
2/2
✓ Branch 0 taken 544 times.
✓ Branch 1 taken 17 times.
561 for (int k = 0; k < model.nv; ++k)
313
2/6
✓ Branch 2 taken 544 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 544 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
544 data.sDUiJt.row(k) /= sqrt(data.D[k]);
314
315
3/6
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 17 times.
✗ Branch 9 not taken.
17 data.JMinvJt.noalias() = data.sDUiJt.transpose() * data.sDUiJt;
316
2/4
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
17 data.JMinvJt.diagonal().array() += inv_damping;
317
318 // Compute the Lagrange Multipliers related to the contact impulses
319
3/12
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 17 times.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
17 impulse_c.noalias() = (-r_coeff - 1.) * (J * v_before);
320 // data.llt_JMinvJt.compute(data.JMinvJt);
321 // data.llt_JMinvJt.solveInPlace(impulse_c);
322 17 internal::PerformCholeskyCompute<Scalar>::run(data.JMinvJt, data.llt_JMinvJt);
323 17 internal::PerformCholeskySolveInPlace<Scalar>::run(data.JMinvJt, data.llt_JMinvJt, impulse_c);
324
325 // Compute the joint velocity after impacts
326
3/6
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 17 times.
✗ Branch 9 not taken.
17 dq_after.noalias() = J.transpose() * impulse_c;
327 17 cholesky::solve(model, data, dq_after);
328 17 dq_after += v_before;
329
330 17 return dq_after;
331 }
332 } // namespace pinocchio
333
334 #endif // ifndef __pinocchio_algorithm_constrained_dynamics_hxx__
335