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