GCC Code Coverage Report


Directory: ./
File: bindings/python/algorithm/expose-contact-dynamics.cpp
Date: 2025-04-30 16:14:33
Exec Total Coverage
Lines: 42 42 100.0%
Branches: 77 174 44.3%

Line Branch Exec Source
1 //
2 // Copyright (c) 2020-2021 INRIA
3 //
4
5 #include "pinocchio/bindings/python/algorithm/algorithms.hpp"
6 #include "pinocchio/algorithm/contact-dynamics.hpp"
7
8 #include "pinocchio/bindings/python/utils/model-checker.hpp"
9
10 namespace pinocchio
11 {
12 namespace python
13 {
14
15 6 static const context::VectorXs forwardDynamics_proxy(
16 const context::Model & model,
17 context::Data & data,
18 const context::VectorXs & q,
19 const context::VectorXs & v,
20 const context::VectorXs & tau,
21 const context::MatrixXs & J,
22 const context::VectorXs & gamma,
23 const context::Scalar inv_damping = context::Scalar(0.0))
24 {
25
26 PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
27 PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
28
0/4
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
6 return forwardDynamics(model, data, q, v, tau, J, gamma, inv_damping);
29 PINOCCHIO_COMPILER_DIAGNOSTIC_POP
30 }
31
32 4 static const context::VectorXs forwardDynamics_proxy_no_q(
33 const context::Model & model,
34 context::Data & data,
35 const context::VectorXs & tau,
36 const context::MatrixXs & J,
37 const context::VectorXs & gamma,
38 const context::Scalar inv_damping = context::Scalar(0.0))
39 {
40
41 PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
42 PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
43
0/4
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
4 return forwardDynamics(model, data, tau, J, gamma, inv_damping);
44 PINOCCHIO_COMPILER_DIAGNOSTIC_POP
45 }
46
47 6 static const context::VectorXs impulseDynamics_proxy(
48 const context::Model & model,
49 context::Data & data,
50 const context::VectorXs & q,
51 const context::VectorXs & v_before,
52 const context::MatrixXs & J,
53 const context::Scalar r_coeff = context::Scalar(0.),
54 const context::Scalar inv_damping = context::Scalar(0.))
55 {
56
57 PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
58 PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
59
0/6
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
6 return impulseDynamics(model, data, q, v_before, J, r_coeff, inv_damping);
60 PINOCCHIO_COMPILER_DIAGNOSTIC_POP
61 }
62
63 6 static const context::VectorXs impulseDynamics_proxy_no_q(
64 const context::Model & model,
65 context::Data & data,
66 const context::VectorXs & v_before,
67 const context::MatrixXs & J,
68 const context::Scalar r_coeff = context::Scalar(0.),
69 const context::Scalar inv_damping = context::Scalar(0.))
70 {
71
72 PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
73 PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
74
0/6
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
6 return impulseDynamics(model, data, v_before, J, r_coeff, inv_damping);
75 PINOCCHIO_COMPILER_DIAGNOSTIC_POP
76 }
77
78 2 static context::MatrixXs computeKKTContactDynamicMatrixInverse_proxy(
79 const context::Model & model,
80 context::Data & data,
81 const context::VectorXs & q,
82 const context::MatrixXs & J,
83 const context::Scalar mu = context::Scalar(0))
84 {
85
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
2 context::MatrixXs KKTMatrix_inv(model.nv + J.rows(), model.nv + J.rows());
86
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 computeKKTContactDynamicMatrixInverse(model, data, q, J, KKTMatrix_inv, mu);
87 2 return KKTMatrix_inv;
88 }
89
90 2 static const context::MatrixXs getKKTContactDynamicMatrixInverse_proxy(
91 const context::Model & model, context::Data & data, const context::MatrixXs & J)
92 {
93
1/2
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
2 context::MatrixXs MJtJ_inv(model.nv + J.rows(), model.nv + J.rows());
94
95 PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
96 PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
97
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 getKKTContactDynamicMatrixInverse(model, data, J, MJtJ_inv);
98 PINOCCHIO_COMPILER_DIAGNOSTIC_POP
99
100 2 return MJtJ_inv;
101 }
102
103 72 void exposeContactDynamics()
104 {
105 using namespace Eigen;
106
107
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
108 "forwardDynamics", &forwardDynamics_proxy,
109
10/20
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 72 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 72 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 72 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 72 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 72 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 72 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 72 times.
✗ Branch 29 not taken.
216 (bp::arg("model"), bp::arg("data"), bp::arg("q"), bp::arg("v"), bp::arg("tau"),
110
6/12
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 72 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 72 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 72 times.
✗ Branch 17 not taken.
216 bp::arg("constraint_jacobian"), bp::arg("constraint_drift"), bp::arg("damping") = 0),
111 "Solves the constrained dynamics problem with contacts, puts the result in "
112 "context::Data::ddq and return it. The contact forces are stored in data.lambda_c.\n"
113 "Note: internally, pinocchio.computeAllTerms is called.",
114 72 mimic_not_supported_function<>(0));
115
116
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
117 "forwardDynamics", &forwardDynamics_proxy_no_q,
118
8/16
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 72 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 72 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 72 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 72 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 72 times.
✗ Branch 23 not taken.
216 (bp::arg("model"), bp::arg("data"), bp::arg("tau"), bp::arg("constraint_jacobian"),
119
4/8
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 72 times.
✗ Branch 11 not taken.
216 bp::arg("constraint_drift"), bp::arg("damping") = 0),
120 "Solves the forward dynamics problem with contacts, puts the result in "
121 "context::Data::ddq and return it. The contact forces are stored in data.lambda_c.\n"
122 "Note: this function assumes that pinocchio.computeAllTerms has been called first.",
123 72 mimic_not_supported_function<>(0));
124
125
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
126 "impulseDynamics", &impulseDynamics_proxy,
127
8/16
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 72 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 72 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 72 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 72 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 72 times.
✗ Branch 23 not taken.
216 (bp::arg("model"), bp::arg("data"), bp::arg("q"), bp::arg("v_before"),
128
4/8
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 72 times.
✗ Branch 11 not taken.
288 bp::arg("constraint_jacobian"), bp::arg("restitution_coefficient") = 0,
129
3/6
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
144 bp::arg("damping") = 0),
130 "Solves the impact dynamics problem with contacts, store the result in "
131 "context::Data::dq_after and return it. The contact impulses are stored in "
132 "data.impulse_c.\n"
133 "Note: internally, pinocchio.crba is called.",
134 72 mimic_not_supported_function<>(0));
135
136
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
137 "impulseDynamics", &impulseDynamics_proxy_no_q,
138
7/14
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 72 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 72 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 72 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 72 times.
✗ Branch 20 not taken.
144 (bp::arg("model"), bp::arg("data"), bp::arg("v_before"), bp::arg("constraint_jacobian"),
139
6/12
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 72 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 72 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 72 times.
✗ Branch 17 not taken.
144 bp::arg("restitution_coefficient") = 0, bp::arg("damping") = 0),
140 "Solves the impact dynamics problem with contacts, store the result in "
141 "context::Data::dq_after and return it. The contact impulses are stored in "
142 "data.impulse_c.\n"
143 "Note: this function assumes that pinocchio.crba has been called first.",
144 72 mimic_not_supported_function<>(0));
145
146
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
147 "computeKKTContactDynamicMatrixInverse", computeKKTContactDynamicMatrixInverse_proxy,
148
7/14
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 72 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 72 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 72 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 72 times.
✗ Branch 20 not taken.
216 (bp::arg("model"), bp::arg("data"), bp::arg("q"), bp::arg("constraint_jacobian"),
149
3/6
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 72 times.
✗ Branch 8 not taken.
144 bp::arg("damping") = 0),
150 "Computes the inverse of the constraint matrix [[M J^T], [J 0]].",
151 72 mimic_not_supported_function<>(0));
152
153
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 bp::def(
154 "getKKTContactDynamicMatrixInverse", getKKTContactDynamicMatrixInverse_proxy,
155
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
144 bp::args("model", "data", "constraint_jacobian"),
156 "Computes the inverse of the constraint matrix [[M Jt], [J 0]].\n forwardDynamics or "
157 "impulseDynamics must have been called first.\n"
158 "Note: the constraint Jacobian should be the same that was provided to "
159 "forwardDynamics or impulseDynamics.",
160 72 mimic_not_supported_function<>(0));
161 72 }
162
163 } // namespace python
164 } // namespace pinocchio
165