GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/tsid/bindings/python/trajectories/trajectory-base.hpp Lines: 42 49 85.7 %
Date: 2024-02-02 08:47:34 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
7
  void visit(PyClass& cl) const {
40

7
    cl.def(bp::init<unsigned int>((bp::arg("size")),
41
                                  "Default Constructor with size"))
42

7
        .def(bp::init<unsigned int, unsigned int>(
43
            (bp::arg("value_size"), bp::arg("derivative_size")),
44
            "Default Constructor with value and derivative size"))
45
46


14
        .def("resize", &TrajectorySamplePythonVisitor::resize, bp::arg("size"))
47

14
        .def("resize", &TrajectorySamplePythonVisitor::resize2,
48
             bp::args("value_size", "derivative_size"))
49
50

14
        .def("value", &TrajectorySamplePythonVisitor::value)
51
7
        .def("derivative", &TrajectorySamplePythonVisitor::derivative)
52
7
        .def("second_derivative",
53
             &TrajectorySamplePythonVisitor::second_derivative)
54
55
7
        .def("value", &TrajectorySamplePythonVisitor::setvalue_vec)
56
7
        .def("value", &TrajectorySamplePythonVisitor::setvalue_se3)
57
7
        .def("derivative", &TrajectorySamplePythonVisitor::setderivative)
58
7
        .def("second_derivative",
59
             &TrajectorySamplePythonVisitor::setsecond_derivative)
60
61
        // Deprecated methods:
62
7
        .def("pos", &TrajectorySamplePythonVisitor::value,
63
             pinocchio::python::deprecated_function<>(
64
                 "This method is now deprecated. Please use .value"))
65

14
        .def("vel", &TrajectorySamplePythonVisitor::derivative,
66
             pinocchio::python::deprecated_function<>(
67
                 "This method is now deprecated. Please use .derivative"))
68

14
        .def(
69
            "acc", &TrajectorySamplePythonVisitor::second_derivative,
70
            pinocchio::python::deprecated_function<>(
71
                "This method is now deprecated. Please use .second_derivative"))
72
73

14
        .def("pos", &TrajectorySamplePythonVisitor::setvalue_vec,
74
             pinocchio::python::deprecated_function<>(
75
                 "This method is now deprecated. Please use .value"))
76

14
        .def("pos", &TrajectorySamplePythonVisitor::setvalue_se3,
77
             pinocchio::python::deprecated_function<>(
78
                 "This method is now deprecated. Please use .value"))
79

14
        .def("vel", &TrajectorySamplePythonVisitor::setderivative,
80
             pinocchio::python::deprecated_function<>(
81
                 "This method is now deprecated. Please use .derivative"))
82

14
        .def("acc", &TrajectorySamplePythonVisitor::setsecond_derivative,
83
             pinocchio::python::deprecated_function<>(
84
                 "This method is now deprecated. Please use "
85
                 ".second_derivative"));
86
7
  }
87
88
2
  static void setvalue_vec(TrajSample& self, const Eigen::VectorXd value) {
89
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
    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
    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
7
  static void expose(const std::string& class_name) {
127
7
    std::string doc = "Trajectory Sample info.";
128

7
    bp::class_<TrajSample>(class_name.c_str(), doc.c_str(), bp::no_init)
129
        .def(TrajectorySamplePythonVisitor<TrajSample>());
130
7
  }
131
};
132
}  // namespace python
133
}  // namespace tsid
134
135
#endif  // ifndef __tsid_python_traj_euclidian_hpp__