| Directory: | ./ |
|---|---|
| File: | bindings/python/algorithm/expose-rnea-derivatives.cpp |
| Date: | 2025-04-30 16:14:33 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 32 | 32 | 100.0% |
| Branches: | 18 | 36 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2018-2021 CNRS INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #include "pinocchio/bindings/python/algorithm/algorithms.hpp" | ||
| 6 | #include "pinocchio/algorithm/rnea-derivatives.hpp" | ||
| 7 | #include "pinocchio/bindings/python/utils/eigen.hpp" | ||
| 8 | #include "pinocchio/bindings/python/utils/model-checker.hpp" | ||
| 9 | |||
| 10 | namespace pinocchio | ||
| 11 | { | ||
| 12 | namespace python | ||
| 13 | { | ||
| 14 | |||
| 15 | namespace bp = boost::python; | ||
| 16 | typedef PINOCCHIO_ALIGNED_STD_VECTOR(context::Force) ForceAlignedVector; | ||
| 17 | |||
| 18 | 1 | context::Data::MatrixXs computeGeneralizedGravityDerivatives( | |
| 19 | const context::Model & model, context::Data & data, const context::VectorXs & q) | ||
| 20 | { | ||
| 21 | 1 | context::Data::MatrixXs res(model.nv, model.nv); | |
| 22 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | res.setZero(); |
| 23 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pinocchio::computeGeneralizedGravityDerivatives(model, data, q, res); |
| 24 | 1 | return res; | |
| 25 | } | ||
| 26 | |||
| 27 | 1 | context::Data::MatrixXs computeStaticTorqueDerivatives( | |
| 28 | const context::Model & model, | ||
| 29 | context::Data & data, | ||
| 30 | const context::VectorXs & q, | ||
| 31 | const ForceAlignedVector & fext) | ||
| 32 | { | ||
| 33 | 1 | context::Data::MatrixXs res(model.nv, model.nv); | |
| 34 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | res.setZero(); |
| 35 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pinocchio::computeStaticTorqueDerivatives(model, data, q, fext, res); |
| 36 | 1 | return res; | |
| 37 | } | ||
| 38 | |||
| 39 | 4 | bp::tuple computeRNEADerivatives( | |
| 40 | const context::Model & model, | ||
| 41 | context::Data & data, | ||
| 42 | const context::VectorXs & q, | ||
| 43 | const context::VectorXs & v, | ||
| 44 | const context::VectorXs & a) | ||
| 45 | { | ||
| 46 | 4 | pinocchio::computeRNEADerivatives(model, data, q, v, a); | |
| 47 | 4 | make_symmetric(data.M); | |
| 48 |
3/6✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
|
8 | return bp::make_tuple(make_ref(data.dtau_dq), make_ref(data.dtau_dv), make_ref(data.M)); |
| 49 | } | ||
| 50 | |||
| 51 | 2 | bp::tuple computeRNEADerivatives_fext( | |
| 52 | const context::Model & model, | ||
| 53 | context::Data & data, | ||
| 54 | const context::VectorXs & q, | ||
| 55 | const context::VectorXs & v, | ||
| 56 | const context::VectorXs & a, | ||
| 57 | const ForceAlignedVector & fext) | ||
| 58 | { | ||
| 59 | 2 | pinocchio::computeRNEADerivatives(model, data, q, v, a, fext); | |
| 60 | 2 | make_symmetric(data.M); | |
| 61 |
3/6✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
|
4 | return bp::make_tuple(make_ref(data.dtau_dq), make_ref(data.dtau_dv), make_ref(data.M)); |
| 62 | } | ||
| 63 | |||
| 64 | 72 | void exposeRNEADerivatives() | |
| 65 | { | ||
| 66 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 67 | "computeGeneralizedGravityDerivatives", computeGeneralizedGravityDerivatives, | ||
| 68 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | bp::args("model", "data", "q"), |
| 69 | "Computes the partial derivative of the generalized gravity contribution\n" | ||
| 70 | "with respect to the joint configuration.\n\n" | ||
| 71 | "Parameters:\n" | ||
| 72 | "\tmodel: model of the kinematic tree\n" | ||
| 73 | "\tdata: data related to the model\n" | ||
| 74 | "\tq: the joint configuration vector (size model.nq)\n" | ||
| 75 | "Returns: dtau_statique_dq\n", | ||
| 76 | 72 | mimic_not_supported_function<>(0)); | |
| 77 | |||
| 78 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 79 | "computeStaticTorqueDerivatives", computeStaticTorqueDerivatives, | ||
| 80 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | bp::args("model", "data", "q", "fext"), |
| 81 | "Computes the partial derivative of the generalized gravity and external forces " | ||
| 82 | "contributions (a.k.a static torque vector)\n" | ||
| 83 | "with respect to the joint configuration.\n\n" | ||
| 84 | "Parameters:\n" | ||
| 85 | "\tmodel: model of the kinematic tree\n" | ||
| 86 | "\tdata: data related to the model\n" | ||
| 87 | "\tq: the joint configuration vector (size model.nq)\n" | ||
| 88 | "\tfext: list of external forces expressed in the local frame of the joints (size " | ||
| 89 | "model.njoints)\n" | ||
| 90 | "Returns: dtau_statique_dq\n", | ||
| 91 | 72 | mimic_not_supported_function<>(0)); | |
| 92 | |||
| 93 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 94 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | "computeRNEADerivatives", computeRNEADerivatives, bp::args("model", "data", "q", "v", "a"), |
| 95 | "Computes the RNEA partial derivatives, store the result in data.dtau_dq, " | ||
| 96 | "data.dtau_dv and data.M (aka dtau_da)\n" | ||
| 97 | "which correspond to the partial derivatives of the torque output with respect to " | ||
| 98 | "the joint configuration,\n" | ||
| 99 | "velocity and acceleration vectors.\n\n" | ||
| 100 | "Parameters:\n" | ||
| 101 | "\tmodel: model of the kinematic tree\n" | ||
| 102 | "\tdata: data related to the model\n" | ||
| 103 | "\tq: the joint configuration vector (size model.nq)\n" | ||
| 104 | "\tv: the joint velocity vector (size model.nv)\n" | ||
| 105 | "\ta: the joint acceleration vector (size model.nv)\n\n" | ||
| 106 | "Returns: (dtau_dq, dtau_dv, dtau_da)\n", | ||
| 107 | 72 | mimic_not_supported_function<>(0)); | |
| 108 | |||
| 109 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 110 | "computeRNEADerivatives", computeRNEADerivatives_fext, | ||
| 111 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | bp::args("model", "data", "q", "v", "a", "fext"), |
| 112 | "Computes the RNEA partial derivatives with external contact foces,\n" | ||
| 113 | "store the result in data.dtau_dq, data.dtau_dv and data.M (aka dtau_da)\n" | ||
| 114 | "which correspond to the partial derivatives of the torque output with respect to " | ||
| 115 | "the joint configuration,\n" | ||
| 116 | "velocity and acceleration vectors.\n\n" | ||
| 117 | "Parameters:\n" | ||
| 118 | "\tmodel: model of the kinematic tree\n" | ||
| 119 | "\tdata: data related to the model\n" | ||
| 120 | "\tq: the joint configuration vector (size model.nq)\n" | ||
| 121 | "\tv: the joint velocity vector (size model.nv)\n" | ||
| 122 | "\ta: the joint acceleration vector (size model.nv)\n" | ||
| 123 | "\tfext: list of external forces expressed in the local frame of the joints (size " | ||
| 124 | "model.njoints)\n\n" | ||
| 125 | "Returns: (dtau_dq, dtau_dv, dtau_da)\n", | ||
| 126 | 72 | mimic_not_supported_function<>(0)); | |
| 127 | 72 | } | |
| 128 | |||
| 129 | } // namespace python | ||
| 130 | } // namespace pinocchio | ||
| 131 |