| Directory: | ./ |
|---|---|
| File: | include/tsid/bindings/python/trajectories/trajectory-base.hpp |
| Date: | 2025-05-10 01:12:46 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 51 | 58 | 87.9% |
| Branches: | 45 | 94 | 47.9% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2018 CNRS | ||
| 3 | // | ||
| 4 | // This file is part of tsid | ||
| 5 | // tsid is free software: you can redistribute it | ||
| 6 | // and/or modify it under the terms of the GNU Lesser General Public | ||
| 7 | // License as published by the Free Software Foundation, either version | ||
| 8 | // 3 of the License, or (at your option) any later version. | ||
| 9 | // tsid is distributed in the hope that it will be | ||
| 10 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
| 11 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | // General Lesser Public License for more details. You should have | ||
| 13 | // received a copy of the GNU Lesser General Public License along with | ||
| 14 | // tsid If not, see | ||
| 15 | // <http://www.gnu.org/licenses/>. | ||
| 16 | // | ||
| 17 | |||
| 18 | #ifndef __tsid_python_traj_sample_hpp__ | ||
| 19 | #define __tsid_python_traj_sample_hpp__ | ||
| 20 | |||
| 21 | #include "tsid/bindings/python/fwd.hpp" | ||
| 22 | |||
| 23 | #include <tsid/math/utils.hpp> | ||
| 24 | #include "tsid/trajectories/trajectory-base.hpp" | ||
| 25 | |||
| 26 | #include <pinocchio/bindings/python/utils/deprecation.hpp> | ||
| 27 | #include <assert.h> | ||
| 28 | namespace tsid { | ||
| 29 | namespace python { | ||
| 30 | namespace bp = boost::python; | ||
| 31 | typedef pinocchio::SE3 SE3; | ||
| 32 | |||
| 33 | template <typename TrajSample> | ||
| 34 | struct TrajectorySamplePythonVisitor | ||
| 35 | : public boost::python::def_visitor< | ||
| 36 | TrajectorySamplePythonVisitor<TrajSample> > { | ||
| 37 | template <class PyClass> | ||
| 38 | |||
| 39 | 8 | void visit(PyClass& cl) const { | |
| 40 |
2/4✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
|
8 | cl.def(bp::init<unsigned int>((bp::arg("size")), |
| 41 | "Default Constructor with size")) | ||
| 42 |
3/6✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
|
8 | .def(bp::init<unsigned int, unsigned int>( |
| 43 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
16 | (bp::arg("value_size"), bp::arg("derivative_size")), |
| 44 | "Default Constructor with value and derivative size")) | ||
| 45 | |||
| 46 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
16 | .def("resize", &TrajectorySamplePythonVisitor::resize, bp::arg("size")) |
| 47 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
16 | .def("resize", &TrajectorySamplePythonVisitor::resize2, |
| 48 | bp::args("value_size", "derivative_size")) | ||
| 49 | |||
| 50 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("value", &TrajectorySamplePythonVisitor::value) |
| 51 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("derivative", &TrajectorySamplePythonVisitor::derivative) |
| 52 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("second_derivative", |
| 53 | &TrajectorySamplePythonVisitor::second_derivative) | ||
| 54 | |||
| 55 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("value", &TrajectorySamplePythonVisitor::setvalue_vec) |
| 56 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("value", &TrajectorySamplePythonVisitor::setvalue_se3) |
| 57 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("derivative", &TrajectorySamplePythonVisitor::setderivative) |
| 58 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("second_derivative", |
| 59 | &TrajectorySamplePythonVisitor::setsecond_derivative) | ||
| 60 | |||
| 61 | // Deprecated methods: | ||
| 62 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("pos", &TrajectorySamplePythonVisitor::value, |
| 63 |
2/4✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
|
16 | pinocchio::python::deprecated_function<>( |
| 64 | "This method is now deprecated. Please use .value")) | ||
| 65 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("vel", &TrajectorySamplePythonVisitor::derivative, |
| 66 |
2/4✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
|
16 | pinocchio::python::deprecated_function<>( |
| 67 | "This method is now deprecated. Please use .derivative")) | ||
| 68 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def( |
| 69 | "acc", &TrajectorySamplePythonVisitor::second_derivative, | ||
| 70 |
2/4✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
|
16 | pinocchio::python::deprecated_function<>( |
| 71 | "This method is now deprecated. Please use .second_derivative")) | ||
| 72 | |||
| 73 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("pos", &TrajectorySamplePythonVisitor::setvalue_vec, |
| 74 |
2/4✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
|
16 | pinocchio::python::deprecated_function<>( |
| 75 | "This method is now deprecated. Please use .value")) | ||
| 76 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("pos", &TrajectorySamplePythonVisitor::setvalue_se3, |
| 77 |
2/4✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
|
16 | pinocchio::python::deprecated_function<>( |
| 78 | "This method is now deprecated. Please use .value")) | ||
| 79 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("vel", &TrajectorySamplePythonVisitor::setderivative, |
| 80 |
2/4✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
|
16 | pinocchio::python::deprecated_function<>( |
| 81 | "This method is now deprecated. Please use .derivative")) | ||
| 82 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def("acc", &TrajectorySamplePythonVisitor::setsecond_derivative, |
| 83 |
2/4✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
|
16 | pinocchio::python::deprecated_function<>( |
| 84 | "This method is now deprecated. Please use " | ||
| 85 | ".second_derivative")); | ||
| 86 | 8 | } | |
| 87 | |||
| 88 | 2 | static void setvalue_vec(TrajSample& self, const Eigen::VectorXd value) { | |
| 89 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
|
2 | assert(self.getValue().size() == value.size()); |
| 90 | 2 | self.setValue(value); | |
| 91 | 2 | } | |
| 92 | ✗ | static void setvalue_se3(TrajSample& self, const pinocchio::SE3& value) { | |
| 93 | ✗ | assert(self.getValue().size() == 12); | |
| 94 | TSID_DISABLE_WARNING_PUSH | ||
| 95 | TSID_DISABLE_WARNING_DEPRECATED | ||
| 96 | ✗ | tsid::math::SE3ToVector(value, self.pos); | |
| 97 | TSID_DISABLE_WARNING_POP | ||
| 98 | } | ||
| 99 | 1 | static void setderivative(TrajSample& self, | |
| 100 | const Eigen::VectorXd derivative) { | ||
| 101 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | assert(self.getDerivative().size() == derivative.size()); |
| 102 | 1 | self.setDerivative(derivative); | |
| 103 | 1 | } | |
| 104 | 1 | static void setsecond_derivative(TrajSample& self, | |
| 105 | const Eigen::VectorXd second_derivative) { | ||
| 106 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | assert(self.getSecondDerivative().size() == second_derivative.size()); |
| 107 | 1 | self.setSecondDerivative(second_derivative); | |
| 108 | 1 | } | |
| 109 | ✗ | static void resize(TrajSample& self, const unsigned int& size) { | |
| 110 | ✗ | self.resize(size, size); | |
| 111 | } | ||
| 112 | ✗ | static void resize2(TrajSample& self, const unsigned int& value_size, | |
| 113 | const unsigned int& derivative_size) { | ||
| 114 | ✗ | self.resize(value_size, derivative_size); | |
| 115 | } | ||
| 116 | 7 | static Eigen::VectorXd value(const TrajSample& self) { | |
| 117 | 7 | return self.getValue(); | |
| 118 | } | ||
| 119 | 3 | static Eigen::VectorXd derivative(const TrajSample& self) { | |
| 120 | 3 | return self.getDerivative(); | |
| 121 | } | ||
| 122 | 3 | static Eigen::VectorXd second_derivative(const TrajSample& self) { | |
| 123 | 3 | return self.getSecondDerivative(); | |
| 124 | } | ||
| 125 | |||
| 126 | 8 | static void expose(const std::string& class_name) { | |
| 127 |
1/2✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
8 | std::string doc = "Trajectory Sample info."; |
| 128 |
1/2✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
|
8 | bp::class_<TrajSample>(class_name.c_str(), doc.c_str(), bp::no_init) |
| 129 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | .def(TrajectorySamplePythonVisitor<TrajSample>()); |
| 130 | 8 | } | |
| 131 | }; | ||
| 132 | } // namespace python | ||
| 133 | } // namespace tsid | ||
| 134 | |||
| 135 | #endif // ifndef __tsid_python_traj_euclidian_hpp__ | ||
| 136 |