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 |
✓✗ |
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 |
✓✗✓✗ ✓✗ |
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 |
✓✗✓✗ ✓✗ |
10 |
true>::expose("StdMap_ImpulseData"); |
41 |
|
|
|
42 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ImpulseItem>>(); |
43 |
|
|
|
44 |
✓✗ |
10 |
bp::class_<ImpulseItem>( |
45 |
|
|
"ImpulseItem", "Describe a impulse item.\n\n", |
46 |
✓✗ |
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 |
✓✗ |
10 |
.def_readwrite("name", &ImpulseItem::name, "impulse name") |
54 |
|
|
.add_property( |
55 |
|
|
"impulse", |
56 |
✓✗ |
10 |
bp::make_getter(&ImpulseItem::impulse, |
57 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
58 |
✓✗ |
10 |
"impulse model") |
59 |
✓✗ |
10 |
.def_readwrite("active", &ImpulseItem::active, "impulse status") |
60 |
✓✗ |
10 |
.def(CopyableVisitor<ImpulseItem>()) |
61 |
✓✗ |
10 |
.def(PrintableVisitor<ImpulseItem>()); |
62 |
|
|
; |
63 |
|
|
|
64 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ImpulseModelMultiple>>(); |
65 |
|
|
|
66 |
✓✗ |
10 |
bp::class_<ImpulseModelMultiple>( |
67 |
|
|
"ImpulseModelMultiple", |
68 |
✓✗ |
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 |
|
|
.def( |
73 |
|
|
"addImpulse", &ImpulseModelMultiple::addImpulse, |
74 |
✓✗ |
10 |
ImpulseModelMultiple_addImpulse_wrap( |
75 |
✓✗ |
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 |
✓✗ |
10 |
":param active: True if the impulse is activated (default true)")) |
80 |
|
|
.def("removeImpulse", &ImpulseModelMultiple::removeImpulse, |
81 |
✓✗ |
20 |
bp::args("self", "name"), |
82 |
|
|
"Remove an impulse item.\n\n" |
83 |
✓✗ |
10 |
":param name: impulse name") |
84 |
|
|
.def("changeImpulseStatus", &ImpulseModelMultiple::changeImpulseStatus, |
85 |
✓✗ |
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 |
✓✗ |
10 |
"inactive)") |
90 |
✓✗ |
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 |
✓✗ |
10 |
":param x: state point (dim. state.nx)") |
97 |
|
|
.def("calcDiff", &ImpulseModelMultiple::calcDiff, |
98 |
✓✗ |
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 |
✓✗ |
10 |
":param x: state point (dim. state.nx)") |
106 |
|
|
.def("updateVelocity", &ImpulseModelMultiple::updateVelocity, |
107 |
✓✗ |
20 |
bp::args("self", "data", "vnext"), |
108 |
|
|
"Update the system velocity after impulse.\n\n" |
109 |
|
|
":param data: impulse data\n" |
110 |
✓✗ |
10 |
":param vnext: velocity after impulse (dimension nv)") |
111 |
|
|
.def("updateForce", &ImpulseModelMultiple::updateForce, |
112 |
✓✗ |
20 |
bp::args("self", "data", "force"), |
113 |
|
|
"Update the spatial impulse defined in frame coordinate.\n\n" |
114 |
|
|
":param data: impulse data\n" |
115 |
✓✗ |
10 |
":param force: force vector (dimension ni)") |
116 |
|
|
.def("updateVelocityDiff", &ImpulseModelMultiple::updateVelocityDiff, |
117 |
✓✗ |
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 |
✓✗ |
10 |
"nv*ndx)") |
122 |
|
|
.def("updateForceDiff", &ImpulseModelMultiple::updateForceDiff, |
123 |
✓✗ |
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 |
✓✗ |
10 |
":param df_dx: Jacobian of the impulse force (dimension ni*ndx)") |
128 |
|
|
.def("updateRneaDiff", &ImpulseModelMultiple::updateRneaDiff, |
129 |
✓✗ |
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 |
✓✗ |
10 |
":param pinocchio: Pinocchio data") |
135 |
|
|
.def("createData", &ImpulseModelMultiple::createData, |
136 |
|
|
bp::with_custodian_and_ward_postcall<0, 2>(), |
137 |
✓✗ |
20 |
bp::args("self", "data"), |
138 |
|
|
"Create the total impulse data.\n\n" |
139 |
|
|
":param data: Pinocchio data\n" |
140 |
✓✗ |
10 |
":return total impulse data.") |
141 |
|
|
.add_property( |
142 |
|
|
"impulses", |
143 |
✓✗ |
10 |
bp::make_function(&ImpulseModelMultiple::get_impulses, |
144 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
145 |
✓✗ |
10 |
"stack of impulses") |
146 |
|
|
.add_property( |
147 |
|
|
"state", |
148 |
✓✗ |
10 |
bp::make_function(&ImpulseModelMultiple::get_state, |
149 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
150 |
✓✗ |
10 |
"state of the multibody system") |
151 |
✓✗ |
20 |
.add_property("nc", bp::make_function(&ImpulseModelMultiple::get_nc), |
152 |
✓✗ |
10 |
"dimension of the active impulse vector") |
153 |
|
|
.add_property("nc_total", |
154 |
✓✗ |
20 |
bp::make_function(&ImpulseModelMultiple::get_nc_total), |
155 |
✓✗ |
10 |
"dimension of the total impulse vector") |
156 |
|
|
.add_property( |
157 |
|
|
"active_set", |
158 |
✓✗ |
10 |
bp::make_function(&ImpulseModelMultiple::get_active_set, |
159 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
160 |
✓✗ |
10 |
"set of names of active impulse items") |
161 |
|
|
.add_property( |
162 |
|
|
"inactive_set", |
163 |
✓✗ |
10 |
bp::make_function(&ImpulseModelMultiple::get_inactive_set, |
164 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
165 |
✓✗ |
10 |
"set of names of inactive impulse items") |
166 |
|
|
.def("getImpulseStatus", &ImpulseModelMultiple::getImpulseStatus, |
167 |
✓✗ |
20 |
bp::args("self", "name"), |
168 |
|
|
"Return the impulse status of a given impulse name.\n\n" |
169 |
✓✗ |
10 |
":param name: impulse name") |
170 |
✓✗ |
10 |
.def(CopyableVisitor<ImpulseModelMultiple>()) |
171 |
✓✗ |
10 |
.def(PrintableVisitor<ImpulseModelMultiple>()); |
172 |
|
|
|
173 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ImpulseDataMultiple>>(); |
174 |
|
|
|
175 |
✓✗ |
10 |
bp::class_<ImpulseDataMultiple>( |
176 |
|
|
"ImpulseDataMultiple", "Data class for multiple impulses.\n\n", |
177 |
✓✗ |
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 |
|
10 |
":param data: Pinocchio data")[bp::with_custodian_and_ward< |
182 |
✓✗ |
20 |
1, 2, bp::with_custodian_and_ward<1, 3>>()]) |
183 |
|
|
.add_property("Jc", |
184 |
✓✗ |
10 |
bp::make_getter(&ImpulseDataMultiple::Jc, |
185 |
|
|
bp::return_internal_reference<>()), |
186 |
✓✗ |
20 |
bp::make_setter(&ImpulseDataMultiple::Jc), |
187 |
✓✗ |
10 |
"Jacobian for all impulses (active and inactive)") |
188 |
|
|
.add_property( |
189 |
|
|
"dv0_dq", |
190 |
✓✗ |
10 |
bp::make_getter(&ImpulseDataMultiple::dv0_dq, |
191 |
|
|
bp::return_internal_reference<>()), |
192 |
✓✗ |
20 |
bp::make_setter(&ImpulseDataMultiple::dv0_dq), |
193 |
✓✗ |
10 |
"Jacobian of the previous impulse velocity (active and inactive)") |
194 |
|
|
.add_property("vnext", |
195 |
✓✗ |
10 |
bp::make_getter(&ImpulseDataMultiple::vnext, |
196 |
|
|
bp::return_internal_reference<>()), |
197 |
✓✗ |
20 |
bp::make_setter(&ImpulseDataMultiple::vnext), |
198 |
✓✗ |
10 |
"impulse system velocity") |
199 |
|
|
.add_property("dvnext_dx", |
200 |
✓✗ |
10 |
bp::make_getter(&ImpulseDataMultiple::dvnext_dx, |
201 |
|
|
bp::return_internal_reference<>()), |
202 |
✓✗ |
20 |
bp::make_setter(&ImpulseDataMultiple::dvnext_dx), |
203 |
✓✗ |
10 |
"Jacobian of the impulse system velocity") |
204 |
|
|
.add_property( |
205 |
|
|
"impulses", |
206 |
✓✗ |
10 |
bp::make_getter(&ImpulseDataMultiple::impulses, |
207 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
208 |
✓✗ |
10 |
"stack of impulses data") |
209 |
|
|
.def_readwrite("fext", &ImpulseDataMultiple::fext, |
210 |
✓✗ |
10 |
"external spatial forces") |
211 |
✓✗ |
10 |
.def(CopyableVisitor<ImpulseDataMultiple>()); |
212 |
|
10 |
} |
213 |
|
|
|
214 |
|
|
} // namespace python |
215 |
|
|
} // namespace crocoddyl |