Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/multibody/impulses/multiple-impulses.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 83 | 89 | 93.3% |
Branches: | 75 | 150 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh, | ||
5 | // Heriot-Watt University | ||
6 | // Copyright note valid unless otherwise stated in individual files. | ||
7 | // All rights reserved. | ||
8 | /////////////////////////////////////////////////////////////////////////////// | ||
9 | |||
10 | #include "crocoddyl/multibody/impulses/multiple-impulses.hpp" | ||
11 | |||
12 | #include <functional> | ||
13 | #include <map> | ||
14 | #include <memory> | ||
15 | #include <string> | ||
16 | #include <utility> | ||
17 | |||
18 | #include "python/crocoddyl/multibody/multibody.hpp" | ||
19 | #include "python/crocoddyl/utils/copyable.hpp" | ||
20 | #include "python/crocoddyl/utils/map-converter.hpp" | ||
21 | #include "python/crocoddyl/utils/printable.hpp" | ||
22 | |||
23 | namespace crocoddyl { | ||
24 | namespace python { | ||
25 | |||
26 |
1/2✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
44 | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(ImpulseModelMultiple_addImpulse_wrap, |
27 | ImpulseModelMultiple::addImpulse, 2, 3) | ||
28 | |||
29 | 10 | void exposeImpulseMultiple() { | |
30 | // Register custom converters between std::map and Python dict | ||
31 | typedef boost::shared_ptr<ImpulseItem> ImpulseItemPtr; | ||
32 | typedef boost::shared_ptr<ImpulseDataAbstract> ImpulseDataPtr; | ||
33 | StdMapPythonVisitor< | ||
34 | std::string, ImpulseItemPtr, std::less<std::string>, | ||
35 | std::allocator<std::pair<const std::string, ImpulseItemPtr>>, | ||
36 |
3/6✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
|
10 | true>::expose("StdMap_ImpulseItem"); |
37 | StdMapPythonVisitor< | ||
38 | std::string, ImpulseDataPtr, std::less<std::string>, | ||
39 | std::allocator<std::pair<const std::string, ImpulseDataPtr>>, | ||
40 |
3/6✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
|
10 | true>::expose("StdMap_ImpulseData"); |
41 | |||
42 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ImpulseItem>>(); | |
43 | |||
44 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ImpulseItem>( |
45 | "ImpulseItem", "Describe a impulse item.\n\n", | ||
46 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<std::string, boost::shared_ptr<ImpulseModelAbstract>, |
47 | bp::optional<bool>>( | ||
48 | 20 | bp::args("self", "name", "impulse", "active"), | |
49 | "Initialize the impulse item.\n\n" | ||
50 | ":param name: impulse name\n" | ||
51 | ":param impulse: impulse model\n" | ||
52 | ":param active: True if the impulse is activated (default true)")) | ||
53 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def_readwrite("name", &ImpulseItem::name, "impulse name") |
54 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
55 | "impulse", | ||
56 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ImpulseItem::impulse, |
57 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
58 | "impulse model") | ||
59 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def_readwrite("active", &ImpulseItem::active, "impulse status") |
60 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ImpulseItem>()) |
61 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(PrintableVisitor<ImpulseItem>()); |
62 | ; | ||
63 | |||
64 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ImpulseModelMultiple>>(); | |
65 | |||
66 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ImpulseModelMultiple>( |
67 | "ImpulseModelMultiple", | ||
68 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<boost::shared_ptr<StateMultibody>>( |
69 | 20 | bp::args("self", "state"), | |
70 | "Initialize the multiple impulse model.\n\n" | ||
71 | ":param state: state of the multibody system")) | ||
72 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def( |
73 | "addImpulse", &ImpulseModelMultiple::addImpulse, | ||
74 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | ImpulseModelMultiple_addImpulse_wrap( |
75 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "name", "impulse", "active"), |
76 | "Add an impulse item.\n\n" | ||
77 | ":param name: impulse name\n" | ||
78 | ":param impulse: impulse model\n" | ||
79 | ":param active: True if the impulse is activated (default true)")) | ||
80 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("removeImpulse", &ImpulseModelMultiple::removeImpulse, |
81 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "name"), |
82 | "Remove an impulse item.\n\n" | ||
83 | ":param name: impulse name") | ||
84 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("changeImpulseStatus", &ImpulseModelMultiple::changeImpulseStatus, |
85 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "name", "active"), |
86 | "Change the impulse status.\n\n" | ||
87 | ":param name: impulse name\n" | ||
88 | ":param active: impulse status (true for active and false for " | ||
89 | "inactive)") | ||
90 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("calc", &ImpulseModelMultiple::calc, bp::args("self", "data", "x"), |
91 | "Compute the impulse Jacobian and drift.\n\n" | ||
92 | "The rigid impulse model throught acceleration-base holonomic " | ||
93 | "constraint\n" | ||
94 | "of the impulse frame placement.\n" | ||
95 | ":param data: impulse data\n" | ||
96 | ":param x: state point (dim. state.nx)") | ||
97 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("calcDiff", &ImpulseModelMultiple::calcDiff, |
98 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x"), |
99 | "Compute the derivatives of the impulse holonomic constraint.\n\n" | ||
100 | "The rigid impulse model throught acceleration-base holonomic " | ||
101 | "constraint\n" | ||
102 | "of the impulse frame placement.\n" | ||
103 | "It assumes that calc has been run first.\n" | ||
104 | ":param data: impulse data\n" | ||
105 | ":param x: state point (dim. state.nx)") | ||
106 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("updateVelocity", &ImpulseModelMultiple::updateVelocity, |
107 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "vnext"), |
108 | "Update the system velocity after impulse.\n\n" | ||
109 | ":param data: impulse data\n" | ||
110 | ":param vnext: velocity after impulse (dimension nv)") | ||
111 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("updateForce", &ImpulseModelMultiple::updateForce, |
112 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "force"), |
113 | "Update the spatial impulse defined in frame coordinate.\n\n" | ||
114 | ":param data: impulse data\n" | ||
115 | ":param force: force vector (dimension ni)") | ||
116 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("updateVelocityDiff", &ImpulseModelMultiple::updateVelocityDiff, |
117 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "dvnext_dx"), |
118 | "Update the Jacobian of the system velocity after impulse.\n\n" | ||
119 | ":param data: impulse data\n" | ||
120 | ":param dvnext_dx: Jacobian of the impulse velocity (dimension " | ||
121 | "nv*ndx)") | ||
122 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("updateForceDiff", &ImpulseModelMultiple::updateForceDiff, |
123 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "df_dx"), |
124 | "Update the Jacobian of the spatial impulse defined in frame " | ||
125 | "coordinate.\n\n" | ||
126 | ":param data: impulse data\n" | ||
127 | ":param df_dx: Jacobian of the impulse force (dimension ni*ndx)") | ||
128 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("updateRneaDiff", &ImpulseModelMultiple::updateRneaDiff, |
129 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "pinocchio"), |
130 | "Update the RNEA derivative dtau_dq by by adding the skew term " | ||
131 | "(necessary for impulses expressed in\n" | ||
132 | "LOCAL_WORLD_ALIGNED / WORLD).\n\n" | ||
133 | ":param data: impulse data\n" | ||
134 | ":param pinocchio: Pinocchio data") | ||
135 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("createData", &ImpulseModelMultiple::createData, |
136 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
137 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data"), |
138 | "Create the total impulse data.\n\n" | ||
139 | ":param data: Pinocchio data\n" | ||
140 | ":return total impulse data.") | ||
141 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
142 | "impulses", | ||
143 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ImpulseModelMultiple::get_impulses, |
144 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
145 | "stack of impulses") | ||
146 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
147 | "state", | ||
148 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ImpulseModelMultiple::get_state, |
149 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
150 | "state of the multibody system") | ||
151 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .add_property("nc", bp::make_function(&ImpulseModelMultiple::get_nc), |
152 | "dimension of the active impulse vector") | ||
153 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("nc_total", |
154 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&ImpulseModelMultiple::get_nc_total), |
155 | "dimension of the total impulse vector") | ||
156 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
157 | "active_set", | ||
158 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ImpulseModelMultiple::get_active_set, |
159 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
160 | "set of names of active impulse items") | ||
161 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
162 | "inactive_set", | ||
163 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ImpulseModelMultiple::get_inactive_set, |
164 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
165 | "set of names of inactive impulse items") | ||
166 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("getImpulseStatus", &ImpulseModelMultiple::getImpulseStatus, |
167 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "name"), |
168 | "Return the impulse status of a given impulse name.\n\n" | ||
169 | ":param name: impulse name") | ||
170 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ImpulseModelMultiple>()) |
171 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(PrintableVisitor<ImpulseModelMultiple>()); |
172 | |||
173 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ImpulseDataMultiple>>(); | |
174 | |||
175 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ImpulseDataMultiple>( |
176 | "ImpulseDataMultiple", "Data class for multiple impulses.\n\n", | ||
177 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ImpulseModelMultiple*, pinocchio::Data*>( |
178 | 10 | bp::args("self", "model", "data"), | |
179 | "Create multi-impulse data.\n\n" | ||
180 | ":param model: multi-impulse model\n" | ||
181 | ✗ | ":param data: Pinocchio data")[bp::with_custodian_and_ward< | |
182 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | 1, 2, bp::with_custodian_and_ward<1, 3>>()]) |
183 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("Jc", |
184 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ImpulseDataMultiple::Jc, |
185 | ✗ | bp::return_internal_reference<>()), | |
186 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ImpulseDataMultiple::Jc), |
187 | "Jacobian for all impulses (active and inactive)") | ||
188 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
189 | "dv0_dq", | ||
190 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ImpulseDataMultiple::dv0_dq, |
191 | ✗ | bp::return_internal_reference<>()), | |
192 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ImpulseDataMultiple::dv0_dq), |
193 | "Jacobian of the previous impulse velocity (active and inactive)") | ||
194 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("vnext", |
195 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ImpulseDataMultiple::vnext, |
196 | ✗ | bp::return_internal_reference<>()), | |
197 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ImpulseDataMultiple::vnext), |
198 | "impulse system velocity") | ||
199 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("dvnext_dx", |
200 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ImpulseDataMultiple::dvnext_dx, |
201 | ✗ | bp::return_internal_reference<>()), | |
202 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ImpulseDataMultiple::dvnext_dx), |
203 | "Jacobian of the impulse system velocity") | ||
204 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
205 | "impulses", | ||
206 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ImpulseDataMultiple::impulses, |
207 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
208 | "stack of impulses data") | ||
209 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def_readwrite("fext", &ImpulseDataMultiple::fext, |
210 | "external spatial forces") | ||
211 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ImpulseDataMultiple>()); |
212 | 10 | } | |
213 | |||
214 | } // namespace python | ||
215 | } // namespace crocoddyl | ||
216 |