Line |
Branch |
Exec |
Source |
1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-2025, 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 |
|
|
// Auto-generated file for float |
11 |
|
|
#include "crocoddyl/multibody/impulses/multiple-impulses.hpp" |
12 |
|
|
|
13 |
|
|
#include "python/crocoddyl/multibody/multibody.hpp" |
14 |
|
|
#include "python/crocoddyl/utils/map-converter.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
|
template <typename Model> |
20 |
|
|
struct ImpulseItemVisitor : public bp::def_visitor<ImpulseItemVisitor<Model>> { |
21 |
|
|
template <class PyClass> |
22 |
|
✗ |
void visit(PyClass& cl) const { |
23 |
|
✗ |
cl.def_readwrite("name", &Model::name, "impulse name") |
24 |
|
✗ |
.add_property( |
25 |
|
|
"impulse", |
26 |
|
|
bp::make_getter(&Model::impulse, |
27 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
28 |
|
|
"impulse model") |
29 |
|
✗ |
.def_readwrite("active", &Model::active, "impulse status") |
30 |
|
✗ |
.def(CopyableVisitor<Model>()); |
31 |
|
|
} |
32 |
|
|
}; |
33 |
|
|
|
34 |
|
|
template <typename Model> |
35 |
|
|
struct ImpulseModelMultipleVisitor |
36 |
|
|
: public bp::def_visitor<ImpulseModelMultipleVisitor<Model>> { |
37 |
|
✗ |
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(ImpulseModelMultiple_addImpulse_wrap, |
38 |
|
|
Model::addImpulse, 2, 3) |
39 |
|
|
template <class PyClass> |
40 |
|
✗ |
void visit(PyClass& cl) const { |
41 |
|
✗ |
cl.def( |
42 |
|
|
"addImpulse", &Model::addImpulse, |
43 |
|
✗ |
ImpulseModelMultiple_addImpulse_wrap( |
44 |
|
|
bp::args("self", "name", "impulse", "active"), |
45 |
|
|
"Add an impulse item.\n\n" |
46 |
|
|
":param name: impulse name\n" |
47 |
|
|
":param impulse: impulse model\n" |
48 |
|
|
":param active: True if the impulse is activated (default true)")) |
49 |
|
✗ |
.def("removeImpulse", &Model::removeImpulse, bp::args("self", "name"), |
50 |
|
|
"Remove an impulse item.\n\n" |
51 |
|
|
":param name: impulse name") |
52 |
|
✗ |
.def("changeImpulseStatus", &Model::changeImpulseStatus, |
53 |
|
|
bp::args("self", "name", "active"), |
54 |
|
|
"Change the impulse status.\n\n" |
55 |
|
|
":param name: impulse name\n" |
56 |
|
|
":param active: impulse status (true for active and false for " |
57 |
|
|
"inactive)") |
58 |
|
✗ |
.def("calc", &Model::calc, bp::args("self", "data", "x"), |
59 |
|
|
"Compute the impulse Jacobian and drift.\n\n" |
60 |
|
|
"The rigid impulse model throught acceleration-base holonomic " |
61 |
|
|
"constraint of the impulse frame placement.\n" |
62 |
|
|
":param data: impulse data\n" |
63 |
|
|
":param x: state point (dim. state.nx)") |
64 |
|
✗ |
.def("calcDiff", &Model::calcDiff, bp::args("self", "data", "x"), |
65 |
|
|
"Compute the derivatives of the impulse holonomic constraint.\n\n" |
66 |
|
|
"The rigid impulse model throught acceleration-base holonomic " |
67 |
|
|
"constraint of the impulse frame placement. It assumes that calc " |
68 |
|
|
"has been run first.\n" |
69 |
|
|
":param data: impulse data\n" |
70 |
|
|
":param x: state point (dim. state.nx)") |
71 |
|
✗ |
.def("updateVelocity", &Model::updateVelocity, |
72 |
|
|
bp::args("self", "data", "vnext"), |
73 |
|
|
"Update the system velocity after impulse.\n\n" |
74 |
|
|
":param data: impulse data\n" |
75 |
|
|
":param vnext: velocity after impulse (dimension nv)") |
76 |
|
✗ |
.def("updateForce", &Model::updateForce, |
77 |
|
|
bp::args("self", "data", "force"), |
78 |
|
|
"Update the spatial impulse defined in frame coordinate.\n\n" |
79 |
|
|
":param data: impulse data\n" |
80 |
|
|
":param force: force vector (dimension ni)") |
81 |
|
✗ |
.def("updateVelocityDiff", &Model::updateVelocityDiff, |
82 |
|
|
bp::args("self", "data", "dvnext_dx"), |
83 |
|
|
"Update the Jacobian of the system velocity after impulse.\n\n" |
84 |
|
|
":param data: impulse data\n" |
85 |
|
|
":param dvnext_dx: Jacobian of the impulse velocity (dimension " |
86 |
|
|
"nv*ndx)") |
87 |
|
✗ |
.def("updateForceDiff", &Model::updateForceDiff, |
88 |
|
|
bp::args("self", "data", "df_dx"), |
89 |
|
|
"Update the Jacobian of the spatial impulse defined in frame " |
90 |
|
|
"coordinate.\n\n" |
91 |
|
|
":param data: impulse data\n" |
92 |
|
|
":param df_dx: Jacobian of the impulse force (dimension ni*ndx)") |
93 |
|
✗ |
.def("updateRneaDiff", &Model::updateRneaDiff, |
94 |
|
|
bp::args("self", "data", "pinocchio"), |
95 |
|
|
"Update the RNEA derivative dtau_dq by by adding the skew term " |
96 |
|
|
"(necessary for impulses expressed in LOCAL_WORLD_ALIGNED / " |
97 |
|
|
"WORLD).\n\n" |
98 |
|
|
":param data: impulse data\n" |
99 |
|
|
":param pinocchio: Pinocchio data") |
100 |
|
✗ |
.def("createData", &Model::createData, |
101 |
|
✗ |
bp::with_custodian_and_ward_postcall<0, 2>(), |
102 |
|
|
bp::args("self", "data"), |
103 |
|
|
"Create the total impulse data.\n\n" |
104 |
|
|
":param data: Pinocchio data\n" |
105 |
|
|
":return total impulse data.") |
106 |
|
✗ |
.add_property( |
107 |
|
|
"impulses", |
108 |
|
|
bp::make_function(&Model::get_impulses, |
109 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
110 |
|
|
"stack of impulses") |
111 |
|
✗ |
.add_property( |
112 |
|
|
"state", |
113 |
|
|
bp::make_function(&Model::get_state, |
114 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
115 |
|
|
"state of the multibody system") |
116 |
|
✗ |
.add_property("nc", bp::make_function(&Model::get_nc), |
117 |
|
|
"dimension of the active impulse vector") |
118 |
|
✗ |
.add_property("nc_total", bp::make_function(&Model::get_nc_total), |
119 |
|
|
"dimension of the total impulse vector") |
120 |
|
✗ |
.add_property( |
121 |
|
|
"active_set", |
122 |
|
|
bp::make_function(&Model::get_active_set, |
123 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
124 |
|
|
"set of names of active impulse items") |
125 |
|
✗ |
.add_property( |
126 |
|
|
"inactive_set", |
127 |
|
|
bp::make_function(&Model::get_inactive_set, |
128 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
129 |
|
|
"set of names of inactive impulse items") |
130 |
|
✗ |
.def("getImpulseStatus", &Model::getImpulseStatus, |
131 |
|
|
bp::args("self", "name"), |
132 |
|
|
"Return the impulse status of a given impulse name.\n\n" |
133 |
|
|
":param name: impulse name"); |
134 |
|
|
} |
135 |
|
|
}; |
136 |
|
|
|
137 |
|
|
template <typename Data> |
138 |
|
|
struct ImpulseDataMultipleVisitor |
139 |
|
|
: public bp::def_visitor<ImpulseDataMultipleVisitor<Data>> { |
140 |
|
|
template <class PyClass> |
141 |
|
✗ |
void visit(PyClass& cl) const { |
142 |
|
✗ |
cl.add_property( |
143 |
|
✗ |
"Jc", bp::make_getter(&Data::Jc, bp::return_internal_reference<>()), |
144 |
|
|
bp::make_setter(&Data::Jc), |
145 |
|
|
"Jacobian for all impulses (active and inactive)") |
146 |
|
✗ |
.add_property( |
147 |
|
|
"dv0_dq", |
148 |
|
✗ |
bp::make_getter(&Data::dv0_dq, bp::return_internal_reference<>()), |
149 |
|
|
bp::make_setter(&Data::dv0_dq), |
150 |
|
|
"Jacobian of the previous impulse velocity (active and inactive)") |
151 |
|
✗ |
.add_property( |
152 |
|
|
"vnext", |
153 |
|
✗ |
bp::make_getter(&Data::vnext, bp::return_internal_reference<>()), |
154 |
|
|
bp::make_setter(&Data::vnext), "impulse system velocity") |
155 |
|
✗ |
.add_property("dvnext_dx", |
156 |
|
|
bp::make_getter(&Data::dvnext_dx, |
157 |
|
✗ |
bp::return_internal_reference<>()), |
158 |
|
|
bp::make_setter(&Data::dvnext_dx), |
159 |
|
|
"Jacobian of the impulse system velocity") |
160 |
|
✗ |
.add_property( |
161 |
|
|
"impulses", |
162 |
|
|
bp::make_getter(&Data::impulses, |
163 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
164 |
|
|
"stack of impulses data") |
165 |
|
✗ |
.def_readwrite("fext", &Data::fext, "external spatial forces"); |
166 |
|
|
} |
167 |
|
|
}; |
168 |
|
|
|
169 |
|
|
#define CROCODDYL_IMPULSE_ITEM_PYTHON_BINDINGS(Scalar) \ |
170 |
|
|
typedef ImpulseItemTpl<Scalar> Item; \ |
171 |
|
|
typedef Item::ImpulseModelAbstract ImpulseModel; \ |
172 |
|
|
typedef std::shared_ptr<Item> ImpulseItemPtr; \ |
173 |
|
|
typedef ImpulseDataAbstractTpl<Scalar> ImpulseData; \ |
174 |
|
|
typedef std::shared_ptr<ImpulseData> ImpulseDataPtr; \ |
175 |
|
|
StdMapPythonVisitor< \ |
176 |
|
|
std::string, ImpulseItemPtr, std::less<std::string>, \ |
177 |
|
|
std::allocator<std::pair<const std::string, ImpulseItemPtr>>, \ |
178 |
|
|
true>::expose("StdMap_ImpulseItem"); \ |
179 |
|
|
StdMapPythonVisitor< \ |
180 |
|
|
std::string, ImpulseDataPtr, std::less<std::string>, \ |
181 |
|
|
std::allocator<std::pair<const std::string, ImpulseDataPtr>>, \ |
182 |
|
|
true>::expose("StdMap_ImpulseData"); \ |
183 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Item>>(); \ |
184 |
|
|
bp::class_<Item>( \ |
185 |
|
|
"ImpulseItem", "Describe a impulse item.\n\n", \ |
186 |
|
|
bp::init<std::string, std::shared_ptr<ImpulseModel>, \ |
187 |
|
|
bp::optional<bool>>( \ |
188 |
|
|
bp::args("self", "name", "impulse", "active"), \ |
189 |
|
|
"Initialize the impulse item.\n\n" \ |
190 |
|
|
":param name: impulse name\n" \ |
191 |
|
|
":param impulse: impulse model\n" \ |
192 |
|
|
":param active: True if the impulse is activated (default true)")) \ |
193 |
|
|
.def(ImpulseItemVisitor<Item>()) \ |
194 |
|
|
.def(CastVisitor<Item>()) \ |
195 |
|
|
.def(PrintableVisitor<Item>()) \ |
196 |
|
|
.def(CopyableVisitor<Item>()); |
197 |
|
|
|
198 |
|
|
#define CROCODDYL_IMPULSE_MODEL_MULTIPLE_PYTHON_BINDINGS(Scalar) \ |
199 |
|
|
typedef ImpulseModelMultipleTpl<Scalar> Model; \ |
200 |
|
|
typedef Model::StateMultibody State; \ |
201 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ |
202 |
|
|
bp::class_<Model>("ImpulseModelMultiple", \ |
203 |
|
|
bp::init<std::shared_ptr<State>>( \ |
204 |
|
|
bp::args("self", "state"), \ |
205 |
|
|
"Initialize the multiple impulse model.\n\n" \ |
206 |
|
|
":param state: state of the multibody system")) \ |
207 |
|
|
.def(ImpulseModelMultipleVisitor<Model>()) \ |
208 |
|
|
.def(CastVisitor<Model>()) \ |
209 |
|
|
.def(PrintableVisitor<Model>()) \ |
210 |
|
|
.def(CopyableVisitor<Model>()); |
211 |
|
|
|
212 |
|
|
#define CROCODDYL_IMPULSE_DATA_MULTIPLE_PYTHON_BINDINGS(Scalar) \ |
213 |
|
|
typedef ImpulseDataMultipleTpl<Scalar> Data; \ |
214 |
|
|
typedef ImpulseModelMultipleTpl<Scalar> Model; \ |
215 |
|
|
typedef pinocchio::DataTpl<Scalar> PinocchioData; \ |
216 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ |
217 |
|
|
bp::class_<Data>( \ |
218 |
|
|
"ImpulseDataMultiple", "Data class for multiple impulses.\n\n", \ |
219 |
|
|
bp::init<Model*, PinocchioData*>( \ |
220 |
|
|
bp::args("self", "model", "data"), \ |
221 |
|
|
"Create multi-impulse data.\n\n" \ |
222 |
|
|
":param model: multi-impulse model\n" \ |
223 |
|
|
":param data: Pinocchio data")[bp::with_custodian_and_ward< \ |
224 |
|
|
1, 2, bp::with_custodian_and_ward<1, 3>>()]) \ |
225 |
|
|
.def(ImpulseDataMultipleVisitor<Data>()) \ |
226 |
|
|
.def(CopyableVisitor<Data>()); |
227 |
|
|
|
228 |
|
✗ |
void exposeImpulseMultiple() { |
229 |
|
✗ |
CROCODDYL_IMPULSE_ITEM_PYTHON_BINDINGS(float) |
230 |
|
✗ |
CROCODDYL_IMPULSE_MODEL_MULTIPLE_PYTHON_BINDINGS(float) |
231 |
|
✗ |
CROCODDYL_IMPULSE_DATA_MULTIPLE_PYTHON_BINDINGS(float) |
232 |
|
|
} |
233 |
|
|
|
234 |
|
|
} // namespace python |
235 |
|
|
} // namespace crocoddyl |
236 |
|
|
|