| Directory: | ./ |
|---|---|
| File: | bindings/python/algorithm/expose-com.cpp |
| Date: | 2025-04-30 16:14:33 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 59 | 66 | 89.4% |
| Branches: | 83 | 166 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2015-2020 CNRS INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #include "pinocchio/bindings/python/algorithm/algorithms.hpp" | ||
| 6 | #include "pinocchio/algorithm/center-of-mass.hpp" | ||
| 7 | |||
| 8 | #include "pinocchio/bindings/python/utils/model-checker.hpp" | ||
| 9 | |||
| 10 | #include <boost/python/overloads.hpp> | ||
| 11 | |||
| 12 | namespace pinocchio | ||
| 13 | { | ||
| 14 | namespace python | ||
| 15 | { | ||
| 16 | |||
| 17 | 10 | static context::SE3::Vector3 com_0_proxy( | |
| 18 | const context::Model & model, | ||
| 19 | context::Data & data, | ||
| 20 | const context::VectorXs & q, | ||
| 21 | bool computeSubtreeComs = true) | ||
| 22 | { | ||
| 23 | 10 | return centerOfMass(model, data, q, computeSubtreeComs); | |
| 24 | } | ||
| 25 | |||
| 26 | 38 | static context::SE3::Vector3 com_1_proxy( | |
| 27 | const context::Model & model, | ||
| 28 | context::Data & data, | ||
| 29 | const context::VectorXs & q, | ||
| 30 | const context::VectorXs & v, | ||
| 31 | bool computeSubtreeComs = true) | ||
| 32 | { | ||
| 33 | 38 | return centerOfMass(model, data, q, v, computeSubtreeComs); | |
| 34 | } | ||
| 35 | |||
| 36 | 3 | static context::SE3::Vector3 com_2_proxy( | |
| 37 | const context::Model & model, | ||
| 38 | context::Data & data, | ||
| 39 | const context::VectorXs & q, | ||
| 40 | const context::VectorXs & v, | ||
| 41 | const context::VectorXs & a, | ||
| 42 | bool computeSubtreeComs = true) | ||
| 43 | { | ||
| 44 | 3 | return centerOfMass(model, data, q, v, a, computeSubtreeComs); | |
| 45 | } | ||
| 46 | |||
| 47 | 3 | static const context::Data::Vector3 & com_level_proxy( | |
| 48 | const context::Model & model, | ||
| 49 | context::Data & data, | ||
| 50 | KinematicLevel kinematic_level, | ||
| 51 | bool computeSubtreeComs = true) | ||
| 52 | { | ||
| 53 | 3 | return centerOfMass(model, data, kinematic_level, computeSubtreeComs); | |
| 54 | } | ||
| 55 | |||
| 56 | 7 | static const context::Data::Vector3 & com_default_proxy( | |
| 57 | const context::Model & model, context::Data & data, bool computeSubtreeComs = true) | ||
| 58 | { | ||
| 59 | 7 | return centerOfMass(model, data, computeSubtreeComs); | |
| 60 | } | ||
| 61 | |||
| 62 | 2 | static context::Data::Matrix3x jacobian_subtree_com_kinematics_proxy( | |
| 63 | const context::Model & model, | ||
| 64 | context::Data & data, | ||
| 65 | const context::VectorXs & q, | ||
| 66 | context::Model::JointIndex jointId) | ||
| 67 | { | ||
| 68 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | context::Data::Matrix3x J(3, model.nv); |
| 69 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | J.setZero(); |
| 70 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | jacobianSubtreeCenterOfMass(model, data, q, jointId, J); |
| 71 | |||
| 72 | 2 | return J; | |
| 73 | } | ||
| 74 | |||
| 75 | 1 | static context::Data::Matrix3x jacobian_subtree_com_proxy( | |
| 76 | const context::Model & model, context::Data & data, context::Model::JointIndex jointId) | ||
| 77 | { | ||
| 78 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | context::Data::Matrix3x J(3, model.nv); |
| 79 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | J.setZero(); |
| 80 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | jacobianSubtreeCenterOfMass(model, data, jointId, J); |
| 81 | |||
| 82 | 1 | return J; | |
| 83 | } | ||
| 84 | |||
| 85 | 1 | static context::Data::Matrix3x get_jacobian_subtree_com_proxy( | |
| 86 | const context::Model & model, context::Data & data, context::Model::JointIndex jointId) | ||
| 87 | { | ||
| 88 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | context::Data::Matrix3x J(3, model.nv); |
| 89 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | J.setZero(); |
| 90 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | getJacobianSubtreeCenterOfMass(model, data, jointId, J); |
| 91 | |||
| 92 | 1 | return J; | |
| 93 | } | ||
| 94 | |||
| 95 | 72 | void exposeCOM() | |
| 96 | { | ||
| 97 | typedef context::Scalar Scalar; | ||
| 98 | typedef context::VectorXs VectorXs; | ||
| 99 | enum | ||
| 100 | { | ||
| 101 | Options = context::Options | ||
| 102 | }; | ||
| 103 | |||
| 104 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 105 | "computeTotalMass", | ||
| 106 | (Scalar(*)( | ||
| 107 | const context::Model &))&computeTotalMass<Scalar, Options, JointCollectionDefaultTpl>, | ||
| 108 | 144 | bp::args("model"), "Compute the total mass of the model and return it."); | |
| 109 | |||
| 110 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 111 | "computeTotalMass", | ||
| 112 | (Scalar(*)( | ||
| 113 | const context::Model &, | ||
| 114 | context::Data &))&computeTotalMass<Scalar, Options, JointCollectionDefaultTpl>, | ||
| 115 | 144 | bp::args("model", "data"), | |
| 116 | "Compute the total mass of the model, put it in data.mass[0] and return it."); | ||
| 117 | |||
| 118 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 119 | "computeSubtreeMasses", | ||
| 120 | (void (*)( | ||
| 121 | const context::Model &, | ||
| 122 | context::Data &))&computeSubtreeMasses<Scalar, Options, JointCollectionDefaultTpl>, | ||
| 123 | 144 | bp::args("model", "data"), | |
| 124 | "Compute the mass of each kinematic subtree and store it in the vector data.mass."); | ||
| 125 | |||
| 126 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 127 | "centerOfMass", com_0_proxy, | ||
| 128 |
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.
|
144 | (bp::arg("model"), bp::arg("data"), bp::arg("q"), bp::arg("compute_subtree_coms") = true), |
| 129 | "Compute the center of mass, putting the result in context::Data and return it." | ||
| 130 | "If compute_subtree_coms is True, the algorithm also computes the center of mass of the " | ||
| 131 | "subtrees.", | ||
| 132 | ✗ | bp::return_value_policy<bp::return_by_value>()); | |
| 133 | |||
| 134 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 135 | "centerOfMass", com_1_proxy, | ||
| 136 |
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("v"), |
| 137 |
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("compute_subtree_coms") = true), |
| 138 | "Computes the center of mass position and velocity by storing the result in context::Data. " | ||
| 139 | "It returns the center of mass position expressed in the WORLD frame.\n" | ||
| 140 | "If compute_subtree_coms is True, the algorithm also computes the center of mass of the " | ||
| 141 | "subtrees.", | ||
| 142 | ✗ | bp::return_value_policy<bp::return_by_value>()); | |
| 143 | |||
| 144 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 145 | "centerOfMass", com_2_proxy, | ||
| 146 |
9/18✓ 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.
|
216 | (bp::arg("model"), bp::arg("data"), bp::arg("q"), bp::arg("v"), bp::arg("a"), |
| 147 |
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("compute_subtree_coms") = true), |
| 148 | "Computes the center of mass position, velocity and acceleration by storing the result in " | ||
| 149 | "context::Data. It returns the center of mass position expressed in the WORLD frame.\n" | ||
| 150 | "If compute_subtree_coms is True, the algorithm also computes the center of mass of the " | ||
| 151 | "subtrees.", | ||
| 152 | ✗ | bp::return_value_policy<bp::return_by_value>()); | |
| 153 | |||
| 154 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 155 | "centerOfMass", com_level_proxy, | ||
| 156 |
5/10✓ 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.
|
216 | (bp::arg("model"), bp::arg("data"), bp::arg("kinematic_level"), |
| 157 |
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("compute_subtree_coms") = true), |
| 158 | "Computes the center of mass position, velocity or acceleration of a given model according " | ||
| 159 | "to the current kinematic values contained in data and the requested kinematic_level.\n" | ||
| 160 | "If kinematic_level = POSITION, computes the CoM position, if kinematic_level = VELOCITY, " | ||
| 161 | "also computes the CoM velocity and if kinematic_level = ACCELERATION, it also computes " | ||
| 162 | "the CoM acceleration.\n" | ||
| 163 | "If compute_subtree_coms is True, the algorithm also computes the center of mass of the " | ||
| 164 | "subtrees.", | ||
| 165 | ✗ | bp::return_value_policy<bp::return_by_value>()); | |
| 166 | |||
| 167 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 168 | "centerOfMass", com_default_proxy, | ||
| 169 |
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("model"), bp::arg("data"), bp::arg("compute_subtree_coms") = true), |
| 170 | "Computes the center of mass position, velocity and acceleration of a given model " | ||
| 171 | "according to the current kinematic values contained in data.\n" | ||
| 172 | "If compute_subtree_coms is True, the algorithm also computes the center of mass of " | ||
| 173 | "the subtrees.", | ||
| 174 | ✗ | bp::return_value_policy<bp::return_by_value>()); | |
| 175 | |||
| 176 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 177 | "jacobianCenterOfMass", | ||
| 178 | (const context::Data::Matrix3x & (*)(const context::Model &, context::Data &, | ||
| 179 | const Eigen::MatrixBase<VectorXs> &, bool)) | ||
| 180 | & jacobianCenterOfMass<Scalar, Options, JointCollectionDefaultTpl, VectorXs>, | ||
| 181 |
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.
|
144 | (bp::arg("model"), bp::arg("data"), bp::arg("q"), bp::arg("compute_subtree_coms") = true), |
| 182 | "Computes the Jacobian of the center of mass, puts the result in context::Data and return " | ||
| 183 | "it.\n" | ||
| 184 | "If compute_subtree_coms is True, the algorithm also computes the center of mass of the " | ||
| 185 | "subtrees.", | ||
| 186 | ✗ | bp::return_value_policy<bp::return_by_value>()); | |
| 187 | |||
| 188 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 189 | "jacobianCenterOfMass", | ||
| 190 | (const context::Data::Matrix3x & (*)(const context::Model &, context::Data &, bool)) | ||
| 191 | & jacobianCenterOfMass<Scalar, Options, JointCollectionDefaultTpl>, | ||
| 192 |
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("model"), bp::arg("data"), bp::arg("compute_subtree_coms") = true), |
| 193 | "Computes the Jacobian of the center of mass, puts the result in context::Data and " | ||
| 194 | "return it.\n" | ||
| 195 | "If compute_subtree_coms is True, the algorithm also computes the center of mass of " | ||
| 196 | "the subtrees.", | ||
| 197 | ✗ | bp::return_value_policy<bp::return_by_value>()); | |
| 198 | |||
| 199 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 200 | "jacobianSubtreeCenterOfMass", jacobian_subtree_com_kinematics_proxy, | ||
| 201 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | bp::args("model", "data", "q", "subtree_root_joint_id"), |
| 202 | "Computes the Jacobian of the CoM of the given subtree (subtree_root_joint_id) " | ||
| 203 | "expressed in the WORLD frame, according to the given joint configuration.", | ||
| 204 | 72 | mimic_not_supported_function<>(0)); | |
| 205 | |||
| 206 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 207 | "jacobianSubtreeCenterOfMass", jacobian_subtree_com_proxy, | ||
| 208 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | bp::args("model", "data", "subtree_root_joint_id"), |
| 209 | "Computes the Jacobian of the CoM of the given subtree (subtree_root_joint_id) " | ||
| 210 | "expressed in the WORLD frame, according to the given entries in data.", | ||
| 211 | 72 | mimic_not_supported_function<>(0)); | |
| 212 | |||
| 213 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | bp::def( |
| 214 | "getJacobianSubtreeCenterOfMass", get_jacobian_subtree_com_proxy, | ||
| 215 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
144 | bp::args("model", "data", "subtree_root_joint_id"), |
| 216 | "Get the Jacobian of the CoM of the given subtree expressed in the world frame, " | ||
| 217 | "according to the given entries in data. It assumes that jacobianCenterOfMass has " | ||
| 218 | "been called first.", | ||
| 219 | 72 | mimic_not_supported_function<>(0)); | |
| 220 | 72 | } | |
| 221 | |||
| 222 | } // namespace python | ||
| 223 | } // namespace pinocchio | ||
| 224 |