GCC Code Coverage Report


Directory: ./
File: include/tsid/bindings/python/tasks/task-com-equality.hpp
Date: 2024-11-10 01:12:44
Exec Total Coverage
Lines: 64 85 75.3%
Branches: 53 122 43.4%

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