Directory: | ./ |
---|---|
File: | include/tsid/bindings/python/tasks/task-se3-equality.hpp |
Date: | 2024-11-10 01:12:44 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 62 | 87 | 71.3% |
Branches: | 57 | 130 | 43.8% |
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_task_se3_hpp__ | ||
19 | #define __tsid_python_task_se3_hpp__ | ||
20 | |||
21 | #include "tsid/bindings/python/fwd.hpp" | ||
22 | |||
23 | #include "tsid/tasks/task-se3-equality.hpp" | ||
24 | #include "tsid/robots/robot-wrapper.hpp" | ||
25 | #include "tsid/trajectories/trajectory-base.hpp" | ||
26 | #include "tsid/math/constraint-equality.hpp" | ||
27 | #include "tsid/math/constraint-base.hpp" | ||
28 | namespace tsid { | ||
29 | namespace python { | ||
30 | namespace bp = boost::python; | ||
31 | |||
32 | template <typename TaskSE3> | ||
33 | struct TaskSE3EqualityPythonVisitor | ||
34 | : public boost::python::def_visitor< | ||
35 | TaskSE3EqualityPythonVisitor<TaskSE3> > { | ||
36 | template <class PyClass> | ||
37 | |||
38 | 7 | void visit(PyClass& cl) const { | |
39 |
4/8✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
|
14 | cl.def(bp::init<std::string, robots::RobotWrapper&, std::string>( |
40 |
2/4✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
|
21 | (bp::arg("name"), bp::arg("robot"), bp::arg("framename")), |
41 | "Default Constructor")) | ||
42 | 14 | .add_property("dim", &TaskSE3::dim, "return dimension size") | |
43 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | .def("setReference", &TaskSE3EqualityPythonVisitor::setReference, |
44 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | bp::arg("ref")) |
45 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("getDesiredAcceleration", |
46 | bp::make_function( | ||
47 | &TaskSE3EqualityPythonVisitor::getDesiredAcceleration, | ||
48 | 7 | bp::return_value_policy<bp::copy_const_reference>()), | |
49 | "Return Acc_desired") | ||
50 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | .def("getAcceleration", &TaskSE3EqualityPythonVisitor::getAcceleration, |
51 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | bp::arg("dv")) |
52 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("position_error", |
53 | bp::make_function( | ||
54 | &TaskSE3EqualityPythonVisitor::position_error, | ||
55 | 7 | bp::return_value_policy<bp::copy_const_reference>())) | |
56 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("velocity_error", |
57 | bp::make_function( | ||
58 | &TaskSE3EqualityPythonVisitor::velocity_error, | ||
59 | 7 | bp::return_value_policy<bp::copy_const_reference>())) | |
60 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("position", |
61 | bp::make_function( | ||
62 | &TaskSE3EqualityPythonVisitor::position, | ||
63 | 7 | bp::return_value_policy<bp::copy_const_reference>())) | |
64 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("velocity", |
65 | bp::make_function( | ||
66 | &TaskSE3EqualityPythonVisitor::velocity, | ||
67 | 7 | bp::return_value_policy<bp::copy_const_reference>())) | |
68 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("position_ref", |
69 | bp::make_function( | ||
70 | &TaskSE3EqualityPythonVisitor::position_ref, | ||
71 | 7 | bp::return_value_policy<bp::copy_const_reference>())) | |
72 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("velocity_ref", |
73 | bp::make_function( | ||
74 | &TaskSE3EqualityPythonVisitor::velocity_ref, | ||
75 | 7 | bp::return_value_policy<bp::copy_const_reference>())) | |
76 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("Kp", |
77 | bp::make_function( | ||
78 | &TaskSE3EqualityPythonVisitor::Kp, | ||
79 | 7 | bp::return_value_policy<bp::copy_const_reference>())) | |
80 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("Kd", |
81 | bp::make_function( | ||
82 | &TaskSE3EqualityPythonVisitor::Kd, | ||
83 | 7 | bp::return_value_policy<bp::copy_const_reference>())) | |
84 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | .def("setKp", &TaskSE3EqualityPythonVisitor::setKp, bp::arg("Kp")) |
85 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | .def("setKd", &TaskSE3EqualityPythonVisitor::setKd, bp::arg("Kd")) |
86 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | .def("useLocalFrame", &TaskSE3EqualityPythonVisitor::useLocalFrame, |
87 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | bp::arg("local_frame")) |
88 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("mask", |
89 | bp::make_function( | ||
90 | &TaskSE3EqualityPythonVisitor::getMask, | ||
91 | 7 | bp::return_value_policy<bp::copy_const_reference>()), | |
92 | "Return mask") | ||
93 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | .def("setMask", &TaskSE3EqualityPythonVisitor::setMask, bp::arg("mask")) |
94 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | .def("compute", &TaskSE3EqualityPythonVisitor::compute, |
95 | bp::args("t", "q", "v", "data")) | ||
96 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | .def("getConstraint", &TaskSE3EqualityPythonVisitor::getConstraint) |
97 | 14 | .add_property("frame_id", &TaskSE3::frame_id, "frame id return") | |
98 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("name", &TaskSE3EqualityPythonVisitor::name); |
99 | 7 | } | |
100 | ✗ | static std::string name(TaskSE3& self) { | |
101 | ✗ | std::string name = self.name(); | |
102 | ✗ | return name; | |
103 | } | ||
104 | 1000 | static math::ConstraintEquality compute(TaskSE3& self, const double t, | |
105 | const Eigen::VectorXd& q, | ||
106 | const Eigen::VectorXd& v, | ||
107 | pinocchio::Data& data) { | ||
108 |
2/4✓ Branch 2 taken 1000 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1000 times.
✗ Branch 6 not taken.
|
1000 | self.compute(t, q, v, data); |
109 |
3/6✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1000 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1000 times.
✗ Branch 8 not taken.
|
2000 | math::ConstraintEquality cons(self.getConstraint().name(), |
110 |
3/6✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1000 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1000 times.
✗ Branch 8 not taken.
|
1000 | self.getConstraint().matrix(), |
111 | 1000 | self.getConstraint().vector()); | |
112 | 1000 | return cons; | |
113 | } | ||
114 | ✗ | static math::ConstraintEquality getConstraint(const TaskSE3& self) { | |
115 | ✗ | math::ConstraintEquality cons(self.getConstraint().name(), | |
116 | ✗ | self.getConstraint().matrix(), | |
117 | ✗ | self.getConstraint().vector()); | |
118 | ✗ | return cons; | |
119 | } | ||
120 | 1001 | static void setReference(TaskSE3& self, trajectories::TrajectorySample& ref) { | |
121 | 1001 | self.setReference(ref); | |
122 | 1001 | } | |
123 | ✗ | static const Eigen::VectorXd& getDesiredAcceleration(const TaskSE3& self) { | |
124 | ✗ | return self.getDesiredAcceleration(); | |
125 | } | ||
126 | ✗ | static Eigen::VectorXd getAcceleration(TaskSE3& self, | |
127 | const Eigen::VectorXd dv) { | ||
128 | ✗ | return self.getAcceleration(dv); | |
129 | } | ||
130 | 1000 | static const Eigen::VectorXd& position_error(const TaskSE3& self) { | |
131 | 1000 | return self.position_error(); | |
132 | } | ||
133 | 10 | static const Eigen::VectorXd& velocity_error(const TaskSE3& self) { | |
134 | 10 | return self.velocity_error(); | |
135 | } | ||
136 | ✗ | static const Eigen::VectorXd& position(const TaskSE3& self) { | |
137 | ✗ | return self.position(); | |
138 | } | ||
139 | ✗ | static const Eigen::VectorXd& velocity(const TaskSE3& self) { | |
140 | ✗ | return self.velocity(); | |
141 | } | ||
142 | ✗ | static const Eigen::VectorXd& position_ref(const TaskSE3& self) { | |
143 | ✗ | return self.position_ref(); | |
144 | } | ||
145 | ✗ | static const Eigen::VectorXd& velocity_ref(const TaskSE3& self) { | |
146 | ✗ | return self.velocity_ref(); | |
147 | } | ||
148 | 1 | static const Eigen::VectorXd& Kp(TaskSE3& self) { return self.Kp(); } | |
149 | 1 | static const Eigen::VectorXd& Kd(TaskSE3& self) { return self.Kd(); } | |
150 | 2 | static void setKp(TaskSE3& self, const ::Eigen::VectorXd Kp) { | |
151 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | return self.Kp(Kp); |
152 | } | ||
153 | 2 | static void setKd(TaskSE3& self, const ::Eigen::VectorXd Kv) { | |
154 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | return self.Kd(Kv); |
155 | } | ||
156 | ✗ | static void useLocalFrame(TaskSE3& self, const bool local_frame) { | |
157 | ✗ | self.useLocalFrame(local_frame); | |
158 | } | ||
159 | ✗ | static void getMask(TaskSE3& self) { self.getMask(); } | |
160 | ✗ | static void setMask(TaskSE3& self, const ::Eigen::VectorXd mask) { | |
161 | ✗ | self.setMask(mask); | |
162 | } | ||
163 | static Eigen::VectorXd frame_id(TaskSE3& self) { return self.frame_id(); } | ||
164 | 7 | static void expose(const std::string& class_name) { | |
165 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
7 | std::string doc = "TaskSE3 info."; |
166 |
1/2✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
|
7 | bp::class_<TaskSE3>(class_name.c_str(), doc.c_str(), bp::no_init) |
167 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | .def(TaskSE3EqualityPythonVisitor<TaskSE3>()); |
168 | |||
169 | // bp::register_ptr_to_python< boost::shared_ptr<math::ConstraintBase> >(); | ||
170 | 7 | } | |
171 | }; | ||
172 | } // namespace python | ||
173 | } // namespace tsid | ||
174 | |||
175 | #endif // ifndef __tsid_python_task_se3_hpp__ | ||
176 |