Directory: | ./ |
---|---|
File: | include/pinocchio/algorithm/contact-dynamics.hxx |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 91 | 96 | 94.8% |
Branches: | 84 | 416 | 20.2% |
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 | |||
103 | typedef DataTpl<Scalar, Options, JointCollectionTpl> Data; | ||
104 | |||
105 | 216 | typename Data::TangentVectorType & a = data.ddq; | |
106 | 216 | typename Data::VectorXs & lambda_c = data.lambda_c; | |
107 | |||
108 | // Compute the UDUt decomposition of data.M | ||
109 | 216 | cholesky::decompose(model, data); | |
110 | |||
111 | // Compute the dynamic drift (control - nle) | ||
112 |
1/2✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
|
216 | data.torque_residual = tau - data.nle; |
113 | 216 | cholesky::solve(model, data, data.torque_residual); | |
114 | |||
115 |
1/2✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
|
216 | data.sDUiJt = J.transpose(); |
116 | // Compute U^-1 * J.T | ||
117 | 216 | cholesky::Uiv(model, data, data.sDUiJt); | |
118 |
2/2✓ Branch 0 taken 6898 times.
✓ Branch 1 taken 216 times.
|
7114 | for (Eigen::DenseIndex k = 0; k < model.nv; ++k) |
119 |
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]); |
120 | |||
121 |
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; |
122 | |||
123 |
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; |
124 | |||
125 | // Compute the Lagrange Multipliers | ||
126 |
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; |
127 | // data.llt_JMinvJt.compute(data.JMinvJt); | ||
128 | // data.llt_JMinvJt.solveInPlace(lambda_c); | ||
129 | 216 | internal::PerformCholeskyCompute<Scalar>::run(data.JMinvJt, data.llt_JMinvJt); | |
130 | 216 | internal::PerformCholeskySolveInPlace<Scalar>::run(data.JMinvJt, data.llt_JMinvJt, lambda_c); | |
131 | |||
132 | // Compute the joint acceleration | ||
133 |
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; |
134 | 216 | cholesky::solve(model, data, a); | |
135 | 216 | a += data.torque_residual; | |
136 | |||
137 | 216 | return a; | |
138 | } | ||
139 | |||
140 | template< | ||
141 | typename Scalar, | ||
142 | int Options, | ||
143 | template<typename, int> class JointCollectionTpl, | ||
144 | typename ConfigVectorType, | ||
145 | typename TangentVectorType1, | ||
146 | typename TangentVectorType2, | ||
147 | typename ConstraintMatrixType, | ||
148 | typename DriftVectorType> | ||
149 | inline const typename DataTpl<Scalar, Options, JointCollectionTpl>::TangentVectorType & | ||
150 | 212 | forwardDynamics( | |
151 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
152 | DataTpl<Scalar, Options, JointCollectionTpl> & data, | ||
153 | const Eigen::MatrixBase<ConfigVectorType> & q, | ||
154 | const Eigen::MatrixBase<TangentVectorType1> & v, | ||
155 | const Eigen::MatrixBase<TangentVectorType2> & tau, | ||
156 | const Eigen::MatrixBase<ConstraintMatrixType> & J, | ||
157 | const Eigen::MatrixBase<DriftVectorType> & gamma, | ||
158 | const Scalar inv_damping) | ||
159 | { | ||
160 |
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); |
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(v.size(), model.nv); |
162 | |||
163 | 212 | computeAllTerms(model, data, q, v); | |
164 | |||
165 |
0/2✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
212 | return forwardDynamics(model, data, tau, J, gamma, inv_damping); |
166 | } | ||
167 | |||
168 | template< | ||
169 | typename Scalar, | ||
170 | int Options, | ||
171 | template<typename, int> class JointCollectionTpl, | ||
172 | typename ConfigVectorType, | ||
173 | typename ConstraintMatrixType, | ||
174 | typename KKTMatrixType> | ||
175 | 3 | void computeKKTContactDynamicMatrixInverse( | |
176 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
177 | DataTpl<Scalar, Options, JointCollectionTpl> & data, | ||
178 | const Eigen::MatrixBase<ConfigVectorType> & q, | ||
179 | const Eigen::MatrixBase<ConstraintMatrixType> & J, | ||
180 | const Eigen::MatrixBase<KKTMatrixType> & KKTMatrix_inv, | ||
181 | const Scalar & inv_damping) | ||
182 | { | ||
183 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | assert(model.check(data)); |
184 |
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( |
185 | check_expression_if_real<Scalar>(inv_damping >= 0.), "mu must be positive."); | ||
186 | |||
187 | // Compute the mass matrix. | ||
188 | 3 | crba(model, data, q, Convention::WORLD); | |
189 | |||
190 | // Compute the UDUt decomposition of data.M. | ||
191 | 3 | cholesky::decompose(model, data); | |
192 | |||
193 | using std::sqrt; | ||
194 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | data.sDUiJt = J.transpose(); |
195 | // Compute U^-1 * J.T | ||
196 | 3 | cholesky::Uiv(model, data, data.sDUiJt); | |
197 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 3 times.
|
99 | for (Eigen::DenseIndex k = 0; k < model.nv; ++k) |
198 |
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]); |
199 | |||
200 |
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; |
201 | |||
202 |
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; |
203 | // data.llt_JMinvJt.compute(data.JMinvJt); | ||
204 | 3 | internal::PerformCholeskyCompute<Scalar>::run(data.JMinvJt, data.llt_JMinvJt); | |
205 | |||
206 | PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH | ||
207 | PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS | ||
208 | 3 | getKKTContactDynamicMatrixInverse(model, data, J, KKTMatrix_inv.const_cast_derived()); | |
209 | PINOCCHIO_COMPILER_DIAGNOSTIC_POP | ||
210 | 3 | } | |
211 | |||
212 | template< | ||
213 | typename Scalar, | ||
214 | int Options, | ||
215 | template<typename, int> class JointCollectionTpl, | ||
216 | typename ConstraintMatrixType, | ||
217 | typename KKTMatrixType> | ||
218 | 7 | void getKKTContactDynamicMatrixInverse( | |
219 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
220 | const DataTpl<Scalar, Options, JointCollectionTpl> & data, | ||
221 | const Eigen::MatrixBase<ConstraintMatrixType> & J, | ||
222 | const Eigen::MatrixBase<KKTMatrixType> & KKTMatrix_inv) | ||
223 | { | ||
224 |
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)); |
225 |
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); |
226 |
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); |
227 | |||
228 | typedef DataTpl<Scalar, Options, JointCollectionTpl> Data; | ||
229 | 7 | const Eigen::DenseIndex nc = data.JMinvJt.cols(); | |
230 | |||
231 | 7 | KKTMatrixType & KKTMatrix_inv_ = PINOCCHIO_EIGEN_CONST_CAST(KKTMatrixType, KKTMatrix_inv); | |
232 | |||
233 | typedef Eigen::Block<KKTMatrixType> BlockType; | ||
234 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | BlockType topLeft = KKTMatrix_inv_.topLeftCorner(model.nv, model.nv); |
235 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | BlockType topRight = KKTMatrix_inv_.topRightCorner(model.nv, nc); |
236 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | BlockType bottomLeft = KKTMatrix_inv_.bottomLeftCorner(nc, model.nv); |
237 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | BlockType bottomRight = KKTMatrix_inv_.bottomRightCorner(nc, nc); |
238 | |||
239 |
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); |
240 | // data.llt_JMinvJt.solveInPlace(bottomRight); | ||
241 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | internal::PerformCholeskySolveInPlace<Scalar>::run(data.JMinvJt, data.llt_JMinvJt, bottomRight); |
242 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | topLeft.setIdentity(); |
243 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | cholesky::solve(model, data, topLeft); |
244 | |||
245 |
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; |
246 |
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); |
247 |
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; |
248 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | bottomLeft = topRight.transpose(); |
249 | 7 | } | |
250 | |||
251 | template< | ||
252 | typename Scalar, | ||
253 | int Options, | ||
254 | template<typename, int> class JointCollectionTpl, | ||
255 | typename ConfigVectorType, | ||
256 | typename TangentVectorType, | ||
257 | typename ConstraintMatrixType> | ||
258 | inline const typename DataTpl<Scalar, Options, JointCollectionTpl>::TangentVectorType & | ||
259 | 11 | impulseDynamics( | |
260 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
261 | DataTpl<Scalar, Options, JointCollectionTpl> & data, | ||
262 | const Eigen::MatrixBase<ConfigVectorType> & q, | ||
263 | const Eigen::MatrixBase<TangentVectorType> & v_before, | ||
264 | const Eigen::MatrixBase<ConstraintMatrixType> & J, | ||
265 | const Scalar r_coeff, | ||
266 | const Scalar inv_damping) | ||
267 | { | ||
268 |
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); |
269 | |||
270 | // Compute the mass matrix | ||
271 | 11 | crba(model, data, q, Convention::WORLD); | |
272 | |||
273 |
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); |
274 | } | ||
275 | |||
276 | template< | ||
277 | typename Scalar, | ||
278 | int Options, | ||
279 | template<typename, int> class JointCollectionTpl, | ||
280 | typename TangentVectorType, | ||
281 | typename ConstraintMatrixType> | ||
282 | inline const typename DataTpl<Scalar, Options, JointCollectionTpl>::TangentVectorType & | ||
283 | 17 | impulseDynamics( | |
284 | const ModelTpl<Scalar, Options, JointCollectionTpl> & model, | ||
285 | DataTpl<Scalar, Options, JointCollectionTpl> & data, | ||
286 | const Eigen::MatrixBase<TangentVectorType> & v_before, | ||
287 | const Eigen::MatrixBase<ConstraintMatrixType> & J, | ||
288 | const Scalar r_coeff, | ||
289 | const Scalar inv_damping) | ||
290 | { | ||
291 |
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); |
292 |
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); |
293 |
1/2✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
|
17 | assert(model.check(data) && "data is not consistent with model."); |
294 | |||
295 | typedef DataTpl<Scalar, Options, JointCollectionTpl> Data; | ||
296 | |||
297 | 17 | typename Data::VectorXs & impulse_c = data.impulse_c; | |
298 | 17 | typename Data::TangentVectorType & dq_after = data.dq_after; | |
299 | |||
300 | // Compute the UDUt decomposition of data.M | ||
301 | 17 | cholesky::decompose(model, data); | |
302 | |||
303 |
1/2✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
|
17 | data.sDUiJt = J.transpose(); |
304 | // Compute U^-1 * J.T | ||
305 | 17 | cholesky::Uiv(model, data, data.sDUiJt); | |
306 |
2/2✓ Branch 0 taken 544 times.
✓ Branch 1 taken 17 times.
|
561 | for (int k = 0; k < model.nv; ++k) |
307 |
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]); |
308 | |||
309 |
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; |
310 |
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; |
311 | |||
312 | // Compute the Lagrange Multipliers related to the contact impulses | ||
313 |
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); |
314 | // data.llt_JMinvJt.compute(data.JMinvJt); | ||
315 | // data.llt_JMinvJt.solveInPlace(impulse_c); | ||
316 | 17 | internal::PerformCholeskyCompute<Scalar>::run(data.JMinvJt, data.llt_JMinvJt); | |
317 | 17 | internal::PerformCholeskySolveInPlace<Scalar>::run(data.JMinvJt, data.llt_JMinvJt, impulse_c); | |
318 | |||
319 | // Compute the joint velocity after impacts | ||
320 |
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; |
321 | 17 | cholesky::solve(model, data, dq_after); | |
322 | 17 | dq_after += v_before; | |
323 | |||
324 | 17 | return dq_after; | |
325 | } | ||
326 | } // namespace pinocchio | ||
327 | |||
328 | #endif // ifndef __pinocchio_algorithm_constrained_dynamics_hxx__ | ||
329 |