Directory: | ./ |
---|---|
File: | include/tsid/bindings/python/tasks/task-joint-posture.hpp |
Date: | 2024-08-26 20:29:39 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 60 | 84 | 71.4% |
Branches: | 52 | 120 | 43.3% |
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_joint_hpp__ | ||
19 | #define __tsid_python_task_joint_hpp__ | ||
20 | |||
21 | #include "tsid/bindings/python/fwd.hpp" | ||
22 | |||
23 | #include "tsid/tasks/task-joint-posture.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 TaskJoint> | ||
33 | struct TaskJointPosturePythonVisitor | ||
34 | : public boost::python::def_visitor< | ||
35 | TaskJointPosturePythonVisitor<TaskJoint> > { | ||
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", &TaskJoint::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", &TaskJointPosturePythonVisitor::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( |
45 | "getDesiredAcceleration", | ||
46 | bp::make_function( | ||
47 | &TaskJointPosturePythonVisitor::getDesiredAcceleration, | ||
48 | 7 | bp::return_value_policy<bp::copy_const_reference>()), | |
49 | "Return Acc_desired") | ||
50 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("mask", |
51 | bp::make_function( | ||
52 | &TaskJointPosturePythonVisitor::getmask, | ||
53 | 7 | bp::return_value_policy<bp::copy_const_reference>()), | |
54 | "Return mask") | ||
55 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | .def("setMask", &TaskJointPosturePythonVisitor::setmask, |
56 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | bp::arg("mask")) |
57 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | .def("getAcceleration", &TaskJointPosturePythonVisitor::getAcceleration, |
58 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | bp::arg("dv")) |
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_error", |
60 | bp::make_function( | ||
61 | &TaskJointPosturePythonVisitor::position_error, | ||
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_error", |
64 | bp::make_function( | ||
65 | &TaskJointPosturePythonVisitor::velocity_error, | ||
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", |
68 | bp::make_function( | ||
69 | &TaskJointPosturePythonVisitor::position, | ||
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", |
72 | bp::make_function( | ||
73 | &TaskJointPosturePythonVisitor::velocity, | ||
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("position_ref", |
76 | bp::make_function( | ||
77 | &TaskJointPosturePythonVisitor::position_ref, | ||
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("velocity_ref", |
80 | bp::make_function( | ||
81 | &TaskJointPosturePythonVisitor::velocity_ref, | ||
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.
|
7 | .add_property("Kp", |
84 | bp::make_function( | ||
85 | &TaskJointPosturePythonVisitor::Kp, | ||
86 | 7 | bp::return_value_policy<bp::copy_const_reference>())) | |
87 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | .add_property("Kd", |
88 | bp::make_function( | ||
89 | &TaskJointPosturePythonVisitor::Kd, | ||
90 | 7 | bp::return_value_policy<bp::copy_const_reference>())) | |
91 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | .def("setKp", &TaskJointPosturePythonVisitor::setKp, bp::arg("Kp")) |
92 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | .def("setKd", &TaskJointPosturePythonVisitor::setKd, bp::arg("Kd")) |
93 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | .def("compute", &TaskJointPosturePythonVisitor::compute, |
94 | bp::args("t", "q", "v", "data")) | ||
95 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | .def("getConstraint", &TaskJointPosturePythonVisitor::getConstraint) |
96 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | .add_property("name", &TaskJointPosturePythonVisitor::name); |
97 | 7 | } | |
98 | ✗ | static std::string name(TaskJoint& self) { | |
99 | ✗ | std::string name = self.name(); | |
100 | ✗ | return name; | |
101 | } | ||
102 | 2000 | static math::ConstraintEquality compute(TaskJoint& self, const double t, | |
103 | const Eigen::VectorXd& q, | ||
104 | const Eigen::VectorXd& v, | ||
105 | pinocchio::Data& data) { | ||
106 |
2/4✓ Branch 2 taken 2000 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2000 times.
✗ Branch 6 not taken.
|
2000 | self.compute(t, q, v, data); |
107 |
3/6✓ Branch 1 taken 2000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2000 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2000 times.
✗ Branch 8 not taken.
|
4000 | math::ConstraintEquality cons(self.getConstraint().name(), |
108 |
3/6✓ Branch 1 taken 2000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2000 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2000 times.
✗ Branch 8 not taken.
|
2000 | self.getConstraint().matrix(), |
109 | 2000 | self.getConstraint().vector()); | |
110 | 2000 | return cons; | |
111 | } | ||
112 | ✗ | static math::ConstraintEquality getConstraint(const TaskJoint& self) { | |
113 | ✗ | math::ConstraintEquality cons(self.getConstraint().name(), | |
114 | ✗ | self.getConstraint().matrix(), | |
115 | ✗ | self.getConstraint().vector()); | |
116 | ✗ | return cons; | |
117 | } | ||
118 | 3000 | static void setReference(TaskJoint& self, | |
119 | const trajectories::TrajectorySample& ref) { | ||
120 | 3000 | self.setReference(ref); | |
121 | 3000 | } | |
122 | ✗ | static const Eigen::VectorXd& getDesiredAcceleration(const TaskJoint& self) { | |
123 | ✗ | return self.getDesiredAcceleration(); | |
124 | } | ||
125 | ✗ | static const Eigen::VectorXd& getmask(const TaskJoint& self) { | |
126 | ✗ | return self.getMask(); | |
127 | } | ||
128 | ✗ | static void setmask(TaskJoint& self, const Eigen::VectorXd mask) { | |
129 | ✗ | return self.setMask(mask); | |
130 | } | ||
131 | ✗ | static Eigen::VectorXd getAcceleration(TaskJoint& self, | |
132 | const Eigen::VectorXd dv) { | ||
133 | ✗ | return self.getAcceleration(dv); | |
134 | } | ||
135 | 2000 | static const Eigen::VectorXd& position_error(const TaskJoint& self) { | |
136 | 2000 | return self.position_error(); | |
137 | } | ||
138 | 20 | static const Eigen::VectorXd& velocity_error(const TaskJoint& self) { | |
139 | 20 | return self.velocity_error(); | |
140 | } | ||
141 | ✗ | static const Eigen::VectorXd& position(const TaskJoint& self) { | |
142 | ✗ | return self.position(); | |
143 | } | ||
144 | ✗ | static const Eigen::VectorXd& velocity(const TaskJoint& self) { | |
145 | ✗ | return self.velocity(); | |
146 | } | ||
147 | ✗ | static const Eigen::VectorXd& position_ref(const TaskJoint& self) { | |
148 | ✗ | return self.position_ref(); | |
149 | } | ||
150 | ✗ | static const Eigen::VectorXd& velocity_ref(const TaskJoint& self) { | |
151 | ✗ | return self.velocity_ref(); | |
152 | } | ||
153 | 2 | static const Eigen::VectorXd& Kp(TaskJoint& self) { return self.Kp(); } | |
154 | 2 | static const Eigen::VectorXd& Kd(TaskJoint& self) { return self.Kd(); } | |
155 | 3 | static void setKp(TaskJoint& self, const ::Eigen::VectorXd Kp) { | |
156 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | return self.Kp(Kp); |
157 | } | ||
158 | 3 | static void setKd(TaskJoint& self, const ::Eigen::VectorXd Kv) { | |
159 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | return self.Kd(Kv); |
160 | } | ||
161 | 7 | static void expose(const std::string& class_name) { | |
162 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
7 | std::string doc = "TaskJoint info."; |
163 |
1/2✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
|
7 | bp::class_<TaskJoint>(class_name.c_str(), doc.c_str(), bp::no_init) |
164 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | .def(TaskJointPosturePythonVisitor<TaskJoint>()); |
165 | |||
166 | // bp::register_ptr_to_python< boost::shared_ptr<math::ConstraintBase> >(); | ||
167 | 7 | } | |
168 | }; | ||
169 | } // namespace python | ||
170 | } // namespace tsid | ||
171 | |||
172 | #endif // ifndef __tsid_python_task_joint_hpp__ | ||
173 |