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 double |
11 |
|
|
#include "crocoddyl/core/actions/diff-lqr.hpp" |
12 |
|
|
|
13 |
|
|
#include "python/crocoddyl/core/core.hpp" |
14 |
|
|
#include "python/crocoddyl/core/diff-action-base.hpp" |
15 |
|
|
#include "python/crocoddyl/utils/deprecate.hpp" |
16 |
|
|
|
17 |
|
|
namespace crocoddyl { |
18 |
|
|
namespace python { |
19 |
|
|
|
20 |
|
|
template <typename Model> |
21 |
|
|
struct DifferentialActionModelLQRVisitor |
22 |
|
|
: public bp::def_visitor<DifferentialActionModelLQRVisitor<Model>> { |
23 |
|
|
typedef typename Model::DifferentialActionDataAbstract Data; |
24 |
|
|
typedef typename Model::Base ModelBase; |
25 |
|
|
typedef typename Model::MatrixXs MatrixXs; |
26 |
|
|
typedef typename Model::VectorXs VectorXs; |
27 |
|
✗ |
BOOST_PYTHON_FUNCTION_OVERLOADS(DifferentialActionModelLQR_Random_wrap, |
28 |
|
|
Model::Random, 2, 4) |
29 |
|
|
template <class PyClass> |
30 |
|
✗ |
void visit(PyClass& cl) const { |
31 |
|
✗ |
cl.def(bp::init<MatrixXs, MatrixXs, MatrixXs, MatrixXs, MatrixXs, MatrixXs, |
32 |
|
|
VectorXs, VectorXs, VectorXs>( |
33 |
|
|
bp::args("self", "Aq", "Av", "B", "Q", "R", "N", "f", "q", "r"), |
34 |
|
|
"Initialize the differential LQR action model.\n\n" |
35 |
|
|
":param Aq: position matrix\n" |
36 |
|
|
":param Av: velocity matrix\n" |
37 |
|
|
":param B: input matrix\n" |
38 |
|
|
":param Q: state weight matrix\n" |
39 |
|
|
":param R: input weight matrix\n" |
40 |
|
|
":param N: state-input weight matrix\n" |
41 |
|
|
":param f: dynamics drift\n" |
42 |
|
|
":param q: state weight vector\n" |
43 |
|
|
":param r: input weight vector")) |
44 |
|
✗ |
.def(bp::init<MatrixXs, MatrixXs, MatrixXs, MatrixXs, MatrixXs, |
45 |
|
|
MatrixXs, MatrixXs, MatrixXs, VectorXs, VectorXs, |
46 |
|
|
VectorXs, VectorXs, VectorXs>( |
47 |
|
|
bp::args("self", "Aq", "Av", "B", "Q", "R", "N", "G", "H", "f", "q", |
48 |
|
|
"r", "g", "h"), |
49 |
|
|
"Initialize the differential LQR action model.\n\n" |
50 |
|
|
":param Aq: position matrix\n" |
51 |
|
|
":param Av: velocity matrix\n" |
52 |
|
|
":param B: input matrix\n" |
53 |
|
|
":param Q: state weight matrix\n" |
54 |
|
|
":param R: input weight matrix\n" |
55 |
|
|
":param N: state-input weight matrix\n" |
56 |
|
|
":param G: state-input inequality constraint matrix\n" |
57 |
|
|
":param H: state-input equality constraint matrix\n" |
58 |
|
|
":param f: dynamics drift\n" |
59 |
|
|
":param q: state weight vector\n" |
60 |
|
|
":param r: input weight vector\n" |
61 |
|
|
":param g: state-input inequality constraint bias\n" |
62 |
|
|
":param h: state-input equality constraint bias")) |
63 |
|
✗ |
.def(bp::init<std::size_t, std::size_t, bp::optional<bool>>( |
64 |
|
|
bp::args("self", "nq", "nu", "driftFree"), |
65 |
|
|
"Initialize the differential LQR action model.\n\n" |
66 |
|
|
":param nx: dimension of the state vector\n" |
67 |
|
|
":param nu: dimension of the control vector\n" |
68 |
|
|
":param driftFree: enable/disable the bias term of the linear " |
69 |
|
|
"dynamics (default True)")) |
70 |
|
✗ |
.def( |
71 |
|
|
"calc", |
72 |
|
|
static_cast<void (Model::*)( |
73 |
|
|
const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, |
74 |
|
|
const Eigen::Ref<const VectorXs>&)>(&Model::calc), |
75 |
|
|
bp::args("self", "data", "x", "u"), |
76 |
|
|
"Compute the next state and cost value.\n\n" |
77 |
|
|
"It describes the time-continuous evolution of the LQR system. " |
78 |
|
|
"Additionally it computes the cost value associated to this " |
79 |
|
|
"discrete state and control pair.\n" |
80 |
|
|
":param data: action data\n" |
81 |
|
|
":param x: time-continuous state vector\n" |
82 |
|
|
":param u: time-continuous control input") |
83 |
|
✗ |
.def("calc", |
84 |
|
|
static_cast<void (Model::*)(const std::shared_ptr<Data>&, |
85 |
|
|
const Eigen::Ref<const VectorXs>&)>( |
86 |
|
|
&Model::calc), |
87 |
|
|
bp::args("self", "data", "x")) |
88 |
|
✗ |
.def( |
89 |
|
|
"calcDiff", |
90 |
|
|
static_cast<void (Model::*)( |
91 |
|
|
const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, |
92 |
|
|
const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), |
93 |
|
|
bp::args("self", "data", "x", "u"), |
94 |
|
|
"Compute the derivatives of the differential LQR dynamics and cost " |
95 |
|
|
"functions.\n\n" |
96 |
|
|
"It computes the partial derivatives of the differential LQR " |
97 |
|
|
"system " |
98 |
|
|
"and the\n" |
99 |
|
|
"cost function. It assumes that calc has been run first.\n" |
100 |
|
|
"This function builds a quadratic approximation of the\n" |
101 |
|
|
"action model (i.e. dynamical system and cost function).\n" |
102 |
|
|
":param data: action data\n" |
103 |
|
|
":param x: time-continuous state vector\n" |
104 |
|
|
":param u: time-continuous control input\n") |
105 |
|
✗ |
.def("calcDiff", |
106 |
|
|
static_cast<void (Model::*)(const std::shared_ptr<Data>&, |
107 |
|
|
const Eigen::Ref<const VectorXs>&)>( |
108 |
|
|
&Model::calcDiff), |
109 |
|
|
bp::args("self", "data", "x")) |
110 |
|
✗ |
.def("createData", &Model::createData, bp::args("self"), |
111 |
|
|
"Create the differential LQR action data.") |
112 |
|
✗ |
.def("Random", &Model::Random, |
113 |
|
✗ |
DifferentialActionModelLQR_Random_wrap( |
114 |
|
|
bp::args("nq", "nu", "ng", "nh"), |
115 |
|
|
"Create a random LQR model.\n\n" |
116 |
|
|
":param: nq: position dimension\n" |
117 |
|
|
":param nu: control dimension\n" |
118 |
|
|
":param ng: inequality constraint dimension (default 0)\n" |
119 |
|
|
":param nh: equality constraint dimension (default 0)")) |
120 |
|
✗ |
.staticmethod("Random") |
121 |
|
✗ |
.def("setLQR", &Model::set_LQR, |
122 |
|
|
bp::args("self", "Aq", "Av", "B", "Q", "R", "N", "f", "q", "r"), |
123 |
|
|
"Modify the LQR action model.\n\n" |
124 |
|
|
":param Aq: position matrix\n" |
125 |
|
|
":param Av: velocity matrix\n" |
126 |
|
|
":param B: input matrix\n" |
127 |
|
|
":param Q: state weight matrix\n" |
128 |
|
|
":param R: input weight matrix\n" |
129 |
|
|
":param N: state-input weight matrix\n" |
130 |
|
|
":param f: dynamics drift\n" |
131 |
|
|
":param q: state weight vector\n" |
132 |
|
|
":param r: input weight vector") |
133 |
|
✗ |
.add_property("Aq", |
134 |
|
|
bp::make_function(&Model::get_Aq, |
135 |
|
✗ |
bp::return_internal_reference<>()), |
136 |
|
|
"position matrix") |
137 |
|
✗ |
.add_property("Av", |
138 |
|
|
bp::make_function(&Model::get_Av, |
139 |
|
✗ |
bp::return_internal_reference<>()), |
140 |
|
|
"velocity matrix") |
141 |
|
✗ |
.add_property( |
142 |
|
|
"B", |
143 |
|
✗ |
bp::make_function(&Model::get_B, bp::return_internal_reference<>()), |
144 |
|
|
"input matrix") |
145 |
|
✗ |
.add_property( |
146 |
|
|
"f", |
147 |
|
✗ |
bp::make_function(&Model::get_f, bp::return_internal_reference<>()), |
148 |
|
|
"dynamics drift") |
149 |
|
✗ |
.add_property( |
150 |
|
|
"Q", |
151 |
|
✗ |
bp::make_function(&Model::get_Q, bp::return_internal_reference<>()), |
152 |
|
|
"state weight matrix") |
153 |
|
✗ |
.add_property( |
154 |
|
|
"R", |
155 |
|
✗ |
bp::make_function(&Model::get_R, bp::return_internal_reference<>()), |
156 |
|
|
"input weight matrix") |
157 |
|
✗ |
.add_property( |
158 |
|
|
"N", |
159 |
|
✗ |
bp::make_function(&Model::get_N, bp::return_internal_reference<>()), |
160 |
|
|
"state-input weight matrix") |
161 |
|
✗ |
.add_property( |
162 |
|
|
"G", |
163 |
|
✗ |
bp::make_function(&Model::get_G, bp::return_internal_reference<>()), |
164 |
|
|
"state-input inequality constraint matrix") |
165 |
|
✗ |
.add_property( |
166 |
|
|
"H", |
167 |
|
✗ |
bp::make_function(&Model::get_H, bp::return_internal_reference<>()), |
168 |
|
|
"state-input equality constraint matrix") |
169 |
|
✗ |
.add_property( |
170 |
|
|
"q", |
171 |
|
✗ |
bp::make_function(&Model::get_q, bp::return_internal_reference<>()), |
172 |
|
|
"state weight vector") |
173 |
|
✗ |
.add_property( |
174 |
|
|
"r", |
175 |
|
✗ |
bp::make_function(&Model::get_r, bp::return_internal_reference<>()), |
176 |
|
|
"input weight vector") |
177 |
|
✗ |
.add_property( |
178 |
|
|
"g", |
179 |
|
✗ |
bp::make_function(&Model::get_g, bp::return_internal_reference<>()), |
180 |
|
|
"state-input inequality constraint bias") |
181 |
|
✗ |
.add_property( |
182 |
|
|
"h", |
183 |
|
✗ |
bp::make_function(&Model::get_h, bp::return_internal_reference<>()), |
184 |
|
|
"state-input equality constraint bias") |
185 |
|
|
// deprecated function |
186 |
|
✗ |
.add_property( |
187 |
|
|
"Fq", |
188 |
|
|
bp::make_function(&Model::get_Aq, |
189 |
|
✗ |
deprecated<bp::return_internal_reference<>>( |
190 |
|
|
"Deprecated. Use Aq.")), |
191 |
|
|
bp::make_function(&Model::set_Fq, |
192 |
|
✗ |
deprecated<>("Deprecated. Use set_LQR.")), |
193 |
|
|
"position matrix") |
194 |
|
✗ |
.add_property( |
195 |
|
|
"Fv", |
196 |
|
|
bp::make_function(&Model::get_Av, |
197 |
|
✗ |
deprecated<bp::return_internal_reference<>>( |
198 |
|
|
"Deprecated. Use Av.")), |
199 |
|
|
bp::make_function(&Model::set_Fv, |
200 |
|
✗ |
deprecated<>("Deprecated. Use set_LQR.")), |
201 |
|
|
"position matrix") |
202 |
|
✗ |
.add_property( |
203 |
|
|
"Fu", |
204 |
|
|
bp::make_function(&Model::get_B, |
205 |
|
✗ |
deprecated<bp::return_internal_reference<>>( |
206 |
|
|
"Deprecated. Use B.")), |
207 |
|
|
bp::make_function(&Model::set_Fu, |
208 |
|
✗ |
deprecated<>("Deprecated. Use set_LQR.")), |
209 |
|
|
"input matrix") |
210 |
|
✗ |
.add_property( |
211 |
|
|
"f0", |
212 |
|
|
bp::make_function(&Model::get_f, |
213 |
|
✗ |
deprecated<bp::return_internal_reference<>>( |
214 |
|
|
"Deprecated. Use f.")), |
215 |
|
|
bp::make_function(&Model::set_f0, |
216 |
|
✗ |
deprecated<>("Deprecated. Use set_LQR.")), |
217 |
|
|
"dynamics drift") |
218 |
|
✗ |
.add_property( |
219 |
|
|
"lx", |
220 |
|
|
bp::make_function(&Model::get_q, |
221 |
|
✗ |
deprecated<bp::return_internal_reference<>>( |
222 |
|
|
"Deprecated. Use q.")), |
223 |
|
|
bp::make_function(&Model::set_lx, |
224 |
|
✗ |
deprecated<>("Deprecated. Use set_LQR.")), |
225 |
|
|
"state weight vector") |
226 |
|
✗ |
.add_property( |
227 |
|
|
"lu", |
228 |
|
|
bp::make_function(&Model::get_r, |
229 |
|
✗ |
deprecated<bp::return_internal_reference<>>( |
230 |
|
|
"Deprecated. Use r.")), |
231 |
|
|
bp::make_function(&Model::set_lu, |
232 |
|
✗ |
deprecated<>("Deprecated. Use set_LQR.")), |
233 |
|
|
"input weight vector") |
234 |
|
✗ |
.add_property( |
235 |
|
|
"Lxx", |
236 |
|
|
bp::make_function(&Model::get_Q, |
237 |
|
✗ |
deprecated<bp::return_internal_reference<>>( |
238 |
|
|
"Deprecated. Use Q.")), |
239 |
|
|
bp::make_function(&Model::set_Lxx, |
240 |
|
✗ |
deprecated<>("Deprecated. Use set_LQR.")), |
241 |
|
|
"state weight matrix") |
242 |
|
✗ |
.add_property( |
243 |
|
|
"Lxu", |
244 |
|
|
bp::make_function(&Model::get_N, |
245 |
|
✗ |
deprecated<bp::return_internal_reference<>>( |
246 |
|
|
"Deprecated. Use N.")), |
247 |
|
|
bp::make_function(&Model::set_Lxu, |
248 |
|
✗ |
deprecated<>("Deprecated. Use set_LQR.")), |
249 |
|
|
"state-input weight matrix") |
250 |
|
✗ |
.add_property( |
251 |
|
|
"Luu", |
252 |
|
|
bp::make_function(&Model::get_R, |
253 |
|
✗ |
deprecated<bp::return_internal_reference<>>( |
254 |
|
|
"Deprecated. Use R.")), |
255 |
|
|
bp::make_function(&Model::set_Luu, |
256 |
|
✗ |
deprecated<>("Deprecated. Use set_LQR.")), |
257 |
|
|
"input weight matrix"); |
258 |
|
|
} |
259 |
|
|
}; |
260 |
|
|
|
261 |
|
|
#define CROCODDYL_DIFFACTION_MODEL_LQR_PYTHON_BINDINGS(Scalar) \ |
262 |
|
|
typedef DifferentialActionModelLQRTpl<Scalar> Model; \ |
263 |
|
|
typedef DifferentialActionModelAbstractTpl<Scalar> ModelBase; \ |
264 |
|
|
typedef typename ModelBase::MatrixXs MatrixXs; \ |
265 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ |
266 |
|
|
bp::class_<Model, bp::bases<ModelBase>>( \ |
267 |
|
|
"DifferentialActionModelLQR", \ |
268 |
|
|
"Differential action model for linear dynamics and quadratic cost.\n\n" \ |
269 |
|
|
"This class implements a linear dynamics, quadratic costs, and linear " \ |
270 |
|
|
"constraints (i.e. LQR action). Since the DAM is a second order " \ |
271 |
|
|
"system, and the integrated action models are implemented as being " \ |
272 |
|
|
"second order integrators. This class implements a second order linear " \ |
273 |
|
|
"system given by\n" \ |
274 |
|
|
" x = [q, v]\n" \ |
275 |
|
|
" dv = Fq q + Fv v + Fu u + f0\n" \ |
276 |
|
|
"where Fq, Fv, Fu and f are randomly chosen constant terms. On the " \ |
277 |
|
|
"other hand, the cost function is given by" \ |
278 |
|
|
" l(x,u) = 1/2 [x,u].T [Q N; N.T R] [x,u] + [q,r].T [x,u],\n" \ |
279 |
|
|
"and the linear equality and inequality constraints has the form:\n" \ |
280 |
|
|
" g(x,u) = G [x,u] + g<=0\n" \ |
281 |
|
|
" h(x,u) = H [x,u] + h.", \ |
282 |
|
|
bp::init<MatrixXs, MatrixXs, MatrixXs, MatrixXs, MatrixXs, MatrixXs>( \ |
283 |
|
|
bp::args("self", "Aq", "Av", "B", "Q", "R", "N"), \ |
284 |
|
|
"Initialize the differential LQR action model.\n\n" \ |
285 |
|
|
":param Aq: position matrix\n" \ |
286 |
|
|
":param Av: velocity matrix\n" \ |
287 |
|
|
":param B: input matrix\n" \ |
288 |
|
|
":param Q: state weight matrix\n" \ |
289 |
|
|
":param R: input weight matrix\n" \ |
290 |
|
|
":param N: state-input weight matrix")) \ |
291 |
|
|
.def(DifferentialActionModelLQRVisitor<Model>()) \ |
292 |
|
|
.def(CastVisitor<Model>()) \ |
293 |
|
|
.def(PrintableVisitor<Model>()) \ |
294 |
|
|
.def(CopyableVisitor<Model>()); |
295 |
|
|
|
296 |
|
|
#define CROCODDYL_DIFFACTION_DATA_LQR_PYTHON_BINDINGS(Scalar) \ |
297 |
|
|
typedef DifferentialActionDataLQRTpl<Scalar> Data; \ |
298 |
|
|
typedef DifferentialActionDataAbstractTpl<Scalar> DataBase; \ |
299 |
|
|
typedef DifferentialActionModelLQRTpl<Scalar> Model; \ |
300 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ |
301 |
|
|
bp::class_<Data, bp::bases<DataBase>>( \ |
302 |
|
|
"DifferentialActionDataLQR", \ |
303 |
|
|
"Action data for the differential LQR system.", \ |
304 |
|
|
bp::init<Model*>(bp::args("self", "model"), \ |
305 |
|
|
"Create differential LQR data.\n\n" \ |
306 |
|
|
":param model: differential LQR action model")) \ |
307 |
|
|
.def(CopyableVisitor<Data>()); |
308 |
|
|
|
309 |
|
✗ |
void exposeDifferentialActionLQR() { |
310 |
|
|
// TODO: Remove once the deprecated update call has been removed in a future |
311 |
|
|
// release |
312 |
|
|
#pragma GCC diagnostic push |
313 |
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
314 |
|
|
|
315 |
|
✗ |
CROCODDYL_DIFFACTION_MODEL_LQR_PYTHON_BINDINGS(double) |
316 |
|
✗ |
CROCODDYL_DIFFACTION_DATA_LQR_PYTHON_BINDINGS(double) |
317 |
|
|
|
318 |
|
|
#pragma GCC diagnostic pop |
319 |
|
|
} |
320 |
|
|
|
321 |
|
|
} // namespace python |
322 |
|
|
} // namespace crocoddyl |
323 |
|
|
|