| Directory: | ./ |
|---|---|
| File: | include/pinocchio/bindings/python/multibody/joint/joint-derived.hpp |
| Date: | 2025-04-30 16:14:33 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 44 | 79 | 55.7% |
| Branches: | 34 | 73 | 46.6% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2015-2021 CNRS INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #ifndef __pinocchio_python_multibody_joint_joint_base_hpp__ | ||
| 6 | #define __pinocchio_python_multibody_joint_joint_base_hpp__ | ||
| 7 | |||
| 8 | #include <boost/python.hpp> | ||
| 9 | #include <eigenpy/exception.hpp> | ||
| 10 | |||
| 11 | #include "pinocchio/bindings/python/fwd.hpp" | ||
| 12 | #include "pinocchio/multibody/joint/joint-collection.hpp" | ||
| 13 | |||
| 14 | namespace pinocchio | ||
| 15 | { | ||
| 16 | namespace python | ||
| 17 | { | ||
| 18 | namespace bp = boost::python; | ||
| 19 | |||
| 20 | template<class JointModelDerived> | ||
| 21 | struct JointModelBasePythonVisitor | ||
| 22 | : public boost::python::def_visitor<JointModelBasePythonVisitor<JointModelDerived>> | ||
| 23 | { | ||
| 24 | public: | ||
| 25 | typedef typename JointModelDerived::JointDataDerived JointDataDerived; | ||
| 26 | |||
| 27 | template<class PyClass> | ||
| 28 | 3600 | void visit(PyClass & cl) const | |
| 29 | { | ||
| 30 |
2/4✓ Branch 2 taken 1800 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1800 times.
✗ Branch 6 not taken.
|
3600 | cl.def(bp::init<>(bp::arg("self"))) |
| 31 | // All are add_properties cause ReadOnly | ||
| 32 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
3600 | .add_property("id", &get_id) |
| 33 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
3600 | .add_property("idx_q", &get_idx_q) |
| 34 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
3600 | .add_property("idx_v", &get_idx_v) |
| 35 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
3600 | .add_property("idx_vExtended", &get_idx_vExtended) |
| 36 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
3600 | .add_property("nq", &get_nq) |
| 37 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
3600 | .add_property("nv", &get_nv) |
| 38 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
3600 | .add_property("nvExtended", &get_nvExtended) |
| 39 | 7200 | .add_property( | |
| 40 | "hasConfigurationLimit", &JointModelDerived::hasConfigurationLimit, | ||
| 41 | "Return vector of boolean if joint has configuration limits.") | ||
| 42 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
3600 | .add_property( |
| 43 | "hasConfigurationLimitInTangent", &JointModelDerived::hasConfigurationLimitInTangent, | ||
| 44 | "Return vector of boolean if joint has configuration limits in tangent space.") | ||
| 45 |
3/6✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1800 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1800 times.
✗ Branch 8 not taken.
|
7200 | .def("setIndexes", &setIndexes0, bp::args("self", "joint_id", "idx_q", "idx_v")) |
| 46 |
2/4✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1800 times.
✗ Branch 5 not taken.
|
7200 | .def( |
| 47 | "setIndexes", &setIndexes1, | ||
| 48 | bp::args("self", "joint_id", "idx_q", "idx_v", "idx_vExtended")) | ||
| 49 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
3600 | .def("classname", &JointModelDerived::classname) |
| 50 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
3600 | .staticmethod("classname") |
| 51 |
2/4✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1800 times.
✗ Branch 5 not taken.
|
7200 | .def("calc", &calc0, bp::args("self", "jdata", "q")) |
| 52 |
2/4✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1800 times.
✗ Branch 5 not taken.
|
7200 | .def("calc", &calc1, bp::args("self", "jdata", "q", "v")) |
| 53 | 7200 | .def( | |
| 54 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
7200 | "createData", &JointModelDerived::createData, bp::arg("self"), |
| 55 | "Create data associated to the joint model.") | ||
| 56 |
2/4✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1800 times.
✗ Branch 5 not taken.
|
7200 | .def( |
| 57 | "hasSameIndexes", &JointModelDerived::template hasSameIndexes<JointModelDerived>, | ||
| 58 | bp::args("self", "other"), "Check if this has same indexes than other.") | ||
| 59 |
2/4✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
|
3800 | .def( |
| 60 |
1/2✓ Branch 1 taken 1800 times.
✗ Branch 2 not taken.
|
7200 | "shortname", &JointModelDerived::shortname, bp::arg("self"), |
| 61 | "Returns string indicating the joint type (class name):" | ||
| 62 | "\n\t- JointModelR[*]: Revolute Joint, with rotation axis [*] ∈ [X,Y,Z]" | ||
| 63 | "\n\t- JointModelRevoluteUnaligned: Revolute Joint, with rotation axis not aligned " | ||
| 64 | "with X, Y, nor Z" | ||
| 65 | "\n\t- JointModelRUB[*]: Unbounded revolute Joint (without position limits), with " | ||
| 66 | "rotation axis [*] ∈ [X,Y,Z]" | ||
| 67 | "\n\t- JointModelRevoluteUnboundedUnaligned: Unbounded revolute Joint, with " | ||
| 68 | "rotation axis not aligned with X, Y, nor Z" | ||
| 69 | "\n\t- JointModelP[*]: Prismatic Joint, with rotation axis [*] ∈ [X,Y,Z]" | ||
| 70 | "\n\t- JointModelPlanar: Planar joint" | ||
| 71 | "\n\t- JointModelPrismaticUnaligned: Prismatic joint, with translation axis not " | ||
| 72 | "aligned with X, Y, nor Z" | ||
| 73 | "\n\t- JointModelSphericalZYX: Spherical joint (3D rotation)" | ||
| 74 | "\n\t- JointModelTranslation: Translation joint (3D translation)" | ||
| 75 | "\n\t- JointModelFreeFlyer: Joint enabling 3D rotation and translations.") | ||
| 76 | |||
| 77 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
| 78 |
2/4✓ Branch 1 taken 1700 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1700 times.
✗ Branch 6 not taken.
|
3400 | .def(bp::self == bp::self) |
| 79 |
1/2✓ Branch 2 taken 1700 times.
✗ Branch 3 not taken.
|
3400 | .def(bp::self != bp::self) |
| 80 | #endif | ||
| 81 | ; | ||
| 82 | 3600 | } | |
| 83 | |||
| 84 | 44 | static JointIndex get_id(const JointModelDerived & self) | |
| 85 | { | ||
| 86 | 44 | return self.id(); | |
| 87 | } | ||
| 88 | ✗ | static int get_idx_q(const JointModelDerived & self) | |
| 89 | { | ||
| 90 | ✗ | return self.idx_q(); | |
| 91 | } | ||
| 92 | ✗ | static int get_idx_v(const JointModelDerived & self) | |
| 93 | { | ||
| 94 | ✗ | return self.idx_v(); | |
| 95 | } | ||
| 96 | ✗ | static int get_idx_vExtended(const JointModelDerived & self) | |
| 97 | { | ||
| 98 | ✗ | return self.idx_vExtended(); | |
| 99 | } | ||
| 100 | 17 | static int get_nq(const JointModelDerived & self) | |
| 101 | { | ||
| 102 | 34 | return self.nq(); | |
| 103 | } | ||
| 104 | ✗ | static int get_nv(const JointModelDerived & self) | |
| 105 | { | ||
| 106 | ✗ | return self.nv(); | |
| 107 | } | ||
| 108 | ✗ | static int get_nvExtended(const JointModelDerived & self) | |
| 109 | { | ||
| 110 | ✗ | return self.nvExtended(); | |
| 111 | } | ||
| 112 | |||
| 113 | static void | ||
| 114 | ✗ | calc0(const JointModelDerived & self, JointDataDerived & jdata, const context::VectorXs & q) | |
| 115 | { | ||
| 116 | ✗ | self.calc(jdata, q); | |
| 117 | } | ||
| 118 | ✗ | static void calc1( | |
| 119 | const JointModelDerived & self, | ||
| 120 | JointDataDerived & jdata, | ||
| 121 | const context::VectorXs & q, | ||
| 122 | const context::VectorXs & v) | ||
| 123 | { | ||
| 124 | ✗ | self.calc(jdata, q, v); | |
| 125 | } | ||
| 126 | |||
| 127 | static void | ||
| 128 | ✗ | setIndexes0(JointModelDerived & self, const int & id, const int & idx_q, const int & idx_v) | |
| 129 | { | ||
| 130 | ✗ | self.setIndexes(id, idx_q, idx_v); | |
| 131 | } | ||
| 132 | |||
| 133 | ✗ | static void setIndexes1( | |
| 134 | JointModelDerived & self, | ||
| 135 | const int & id, | ||
| 136 | const int & idx_q, | ||
| 137 | const int & idx_v, | ||
| 138 | const int & idx_vExtended) | ||
| 139 | { | ||
| 140 | ✗ | self.setIndexes(id, idx_q, idx_v, idx_vExtended); | |
| 141 | } | ||
| 142 | }; | ||
| 143 | |||
| 144 | template<class JointDataDerived> | ||
| 145 | struct JointDataBasePythonVisitor | ||
| 146 | : public boost::python::def_visitor<JointDataBasePythonVisitor<JointDataDerived>> | ||
| 147 | { | ||
| 148 | public: | ||
| 149 | template<class PyClass> | ||
| 150 | 3600 | void visit(PyClass & cl) const | |
| 151 | { | ||
| 152 | 200 | cl | |
| 153 | // All are add_properties cause ReadOnly | ||
| 154 | 3600 | .add_property("joint_q", &get_joint_q) | |
| 155 | 3600 | .add_property("joint_v", &get_joint_v) | |
| 156 | 3600 | .add_property("S", &get_S) | |
| 157 | 3600 | .add_property("M", &get_M) | |
| 158 | 3600 | .add_property("v", &get_v) | |
| 159 | 3600 | .add_property("c", &get_c) | |
| 160 | 3600 | .add_property("U", &get_U) | |
| 161 | 3600 | .add_property("Dinv", &get_Dinv) | |
| 162 | 3600 | .add_property("UDinv", &get_UDinv) | |
| 163 |
1/2✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
|
3600 | .def("shortname", &JointDataDerived::shortname, bp::arg("self")) |
| 164 | |||
| 165 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
| 166 |
2/4✓ Branch 1 taken 1700 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1700 times.
✗ Branch 6 not taken.
|
3400 | .def(bp::self == bp::self) |
| 167 |
1/2✓ Branch 2 taken 1700 times.
✗ Branch 3 not taken.
|
3400 | .def(bp::self != bp::self) |
| 168 | #endif | ||
| 169 | ; | ||
| 170 | 3600 | } | |
| 171 | |||
| 172 | ✗ | static typename JointDataDerived::ConfigVector_t get_joint_q(const JointDataDerived & self) | |
| 173 | { | ||
| 174 | ✗ | return self.joint_q_accessor(); | |
| 175 | } | ||
| 176 | ✗ | static typename JointDataDerived::TangentVector_t get_joint_v(const JointDataDerived & self) | |
| 177 | { | ||
| 178 | ✗ | return self.joint_v_accessor(); | |
| 179 | } | ||
| 180 | // static typename JointDataDerived::Constraint_t get_S(const JointDataDerived & self) | ||
| 181 | // { return self.S_accessor(); } | ||
| 182 | ✗ | static typename JointDataDerived::Constraint_t::DenseBase get_S(const JointDataDerived & self) | |
| 183 | { | ||
| 184 | ✗ | return self.S_accessor().matrix(); | |
| 185 | } | ||
| 186 | ✗ | static typename JointDataDerived::Transformation_t get_M(const JointDataDerived & self) | |
| 187 | { | ||
| 188 | ✗ | return self.M_accessor(); | |
| 189 | } | ||
| 190 | ✗ | static typename JointDataDerived::Motion_t get_v(const JointDataDerived & self) | |
| 191 | { | ||
| 192 | ✗ | return self.v_accessor(); | |
| 193 | } | ||
| 194 | ✗ | static typename JointDataDerived::Bias_t get_c(const JointDataDerived & self) | |
| 195 | { | ||
| 196 | ✗ | return self.c_accessor(); | |
| 197 | } | ||
| 198 | ✗ | static typename JointDataDerived::U_t get_U(const JointDataDerived & self) | |
| 199 | { | ||
| 200 | ✗ | return self.U_accessor(); | |
| 201 | } | ||
| 202 | ✗ | static typename JointDataDerived::D_t get_Dinv(const JointDataDerived & self) | |
| 203 | { | ||
| 204 | ✗ | return self.Dinv_accessor(); | |
| 205 | } | ||
| 206 | static typename JointDataDerived::UD_t get_UDinv(const JointDataDerived & self) | ||
| 207 | { | ||
| 208 | ✗ | return self.UDinv_accessor(); | |
| 209 | } | ||
| 210 | |||
| 211 | static void expose() | ||
| 212 | { | ||
| 213 | } | ||
| 214 | }; | ||
| 215 | |||
| 216 | } // namespace python | ||
| 217 | } // namespace pinocchio | ||
| 218 | |||
| 219 | #endif // ifndef __pinocchio_python_multibody_joint_joint_base_hpp__ | ||
| 220 |