GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/actions/lqr.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 107 107 100.0%
Branches: 108 216 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2024, 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/core/actions/lqr.hpp"
11
12 #include "python/crocoddyl/core/action-base.hpp"
13 #include "python/crocoddyl/core/core.hpp"
14 #include "python/crocoddyl/utils/copyable.hpp"
15 #include "python/crocoddyl/utils/deprecate.hpp"
16
17 namespace crocoddyl {
18 namespace python {
19
20 22 BOOST_PYTHON_FUNCTION_OVERLOADS(ActionModelLQR_Random_wrap,
21 ActionModelLQR::Random, 2, 4)
22
23 10 void exposeActionLQR() {
24 // TODO: Remove once the deprecated update call has been removed in a future
25 // release
26 #pragma GCC diagnostic push
27 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
28
29 10 boost::python::register_ptr_to_python<boost::shared_ptr<ActionModelLQR> >();
30
31
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ActionModelLQR, bp::bases<ActionModelAbstract> >(
32 "ActionModelLQR",
33 "LQR action model.\n\n"
34 "A linear-quadratic regulator (LQR) action has a transition model of the "
35 "form\n"
36 " xnext(x,u) = A x + B u + f.\n"
37 "Its cost function is quadratic of the form:\n"
38 " 1/2 [x,u].T [Q N; N.T R] [x,u] + [q,r].T [x,u],\n"
39 "and the linear equality and inequality constraints has the form:\n"
40 " g(x,u) = G [x,u] + g<=0\n"
41 " h(x,u) = H [x,u] + h.",
42
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd,
43 Eigen::MatrixXd, Eigen::MatrixXd>(
44 20 bp::args("self", "A", "B", "Q", "R", "N"),
45 "Initialize the LQR action model.\n\n"
46 ":param A: state matrix\n"
47 ":param B: input matrix\n"
48 ":param Q: state weight matrix\n"
49 ":param R: input weight matrix\n"
50 ":param N: state-input weight matrix"))
51
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def(bp::init<Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd,
52 Eigen::MatrixXd, Eigen::MatrixXd, Eigen::VectorXd,
53 Eigen::VectorXd, Eigen::VectorXd>(
54
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "A", "B", "Q", "R", "N", "f", "q", "r"),
55 "Initialize the differential LQR action model.\n\n"
56 ":param A: state matrix\n"
57 ":param B: input matrix\n"
58 ":param Q: state weight matrix\n"
59 ":param R: input weight matrix\n"
60 ":param N: state-input weight matrix\n"
61 ":param f: dynamics drift\n"
62 ":param q: state weight vector\n"
63 ":param r: input weight vector"))
64
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def(bp::init<Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd,
65 Eigen::MatrixXd, Eigen::MatrixXd, Eigen::MatrixXd,
66 Eigen::MatrixXd, Eigen::VectorXd, Eigen::VectorXd,
67 Eigen::VectorXd, Eigen::VectorXd, Eigen::VectorXd>(
68
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "A", "B", "Q", "R", "N", "G", "H", "f", "q", "r",
69 "g", "h"),
70 "Initialize the LQR action model.\n\n"
71 ":param A: state matrix\n"
72 ":param B: input matrix\n"
73 ":param Q: state weight matrix\n"
74 ":param R: input weight matrix\n"
75 ":param N: state-input weight matrix\n"
76 ":param G: state-input inequality constraint matrix\n"
77 ":param H: state-input equality constraint matrix\n"
78 ":param f: dynamics drift\n"
79 ":param q: state weight vector\n"
80 ":param r: input weight vector\n"
81 ":param g: state-input equality constraint bias\n"
82 ":param h: state-input inequality constraint bias"))
83
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def(bp::init<std::size_t, std::size_t, bp::optional<bool> >(
84
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "nx", "nu", "driftFree"),
85 "Initialize the LQR action model.\n\n"
86 ":param nx: dimension of the state vector\n"
87 ":param nu: dimension of the control vector\n"
88 ":param driftFree: enable/disable the bias term of the linear "
89 "dynamics (default True)"))
90 .def<void (ActionModelLQR::*)(
91 const boost::shared_ptr<ActionDataAbstract>&,
92 const Eigen::Ref<const Eigen::VectorXd>&,
93 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
94
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 "calc", &ActionModelLQR::calc, bp::args("self", "data", "x", "u"),
95 "Compute the next state and cost value.\n\n"
96 "It describes the time-discrete evolution of the LQR system. "
97 "Additionally it\n"
98 "computes the cost value associated to this discrete\n"
99 "state and control pair.\n"
100 ":param data: action data\n"
101 ":param x: state point (dim. state.nx)\n"
102 ":param u: control input (dim. nu)")
103 .def<void (ActionModelLQR::*)(
104 const boost::shared_ptr<ActionDataAbstract>&,
105
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
106
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 "calc", &ActionModelAbstract::calc, bp::args("self", "data", "x"))
107 .def<void (ActionModelLQR::*)(
108 const boost::shared_ptr<ActionDataAbstract>&,
109 const Eigen::Ref<const Eigen::VectorXd>&,
110
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
111 "calcDiff", &ActionModelLQR::calcDiff,
112
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
113 "Compute the derivatives of the LQR dynamics and cost functions.\n\n"
114 "It computes the partial derivatives of the LQR system and the\n"
115 "cost function. It assumes that calc has been run first.\n"
116 "This function builds a quadratic approximation of the\n"
117 "action model (i.e. dynamical system and cost function).\n"
118 ":param data: action data\n"
119 ":param x: state point (dim. state.nx)\n"
120 ":param u: control input (dim. nu)")
121 .def<void (ActionModelLQR::*)(
122 const boost::shared_ptr<ActionDataAbstract>&,
123
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
124 "calcDiff", &ActionModelAbstract::calcDiff,
125
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"))
126
3/6
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
20 .def("createData", &ActionModelLQR::createData, bp::args("self"),
127 "Create the LQR action data.")
128
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("Random", &ActionModelLQR::Random,
129
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 ActionModelLQR_Random_wrap(
130
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("nx", "nu", "ng", "nh"),
131 "Create a random LQR model.\n\n"
132 ":param nx: state dimension\n"
133 ":param nu: control dimension\n"
134 ":param ng: inequality constraint dimension (default 0)\n"
135 ":param nh: equality constraint dimension (default 0)"))
136
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .staticmethod("Random")
137
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("setLQR", &ActionModelLQR::set_LQR,
138
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "A", "B", "Q", "R", "N", "G", "H", "f", "q", "r",
139 "g", "h"),
140 "Modify the LQR action model.\n\n"
141 ":param A: state matrix\n"
142 ":param B: input matrix\n"
143 ":param Q: state weight matrix\n"
144 ":param R: input weight matrix\n"
145 ":param N: state-input weight matrix\n"
146 ":param G: state-input inequality constraint matrix\n"
147 ":param H: state-input equality constraint matrix\n"
148 ":param f: dynamics drift\n"
149 ":param q: state weight vector\n"
150 ":param r: input weight vector\n"
151 ":param g: state-input inequality constraint bias\n"
152 ":param h: state-input equality constraint bias")
153
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("A",
154
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_A,
155 10 bp::return_internal_reference<>()),
156 "state matrix")
157
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("B",
158
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_B,
159 10 bp::return_internal_reference<>()),
160 "input matrix")
161
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("f",
162
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_f,
163 10 bp::return_internal_reference<>()),
164 "dynamics drift")
165
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Q",
166
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_Q,
167 10 bp::return_internal_reference<>()),
168 "state weight matrix")
169
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("R",
170
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_R,
171 10 bp::return_internal_reference<>()),
172 "input weight matrix")
173
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("N",
174
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_N,
175 10 bp::return_internal_reference<>()),
176 "state-input weight matrix")
177
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("G",
178
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_G,
179 10 bp::return_internal_reference<>()),
180 "state-input inequality constraint matrix")
181
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("H",
182
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_H,
183 10 bp::return_internal_reference<>()),
184 "state-input equality constraint matrix")
185
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("q",
186
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_q,
187 10 bp::return_internal_reference<>()),
188 "state weight vector")
189
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("r",
190
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_r,
191 10 bp::return_internal_reference<>()),
192 "input weight vector")
193
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("g",
194
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_g,
195 10 bp::return_internal_reference<>()),
196 "state-input inequality constraint bias")
197
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("h",
198
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_h,
199 10 bp::return_internal_reference<>()),
200 "state-input equality constraint bias")
201 // deprecated function
202
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
203 "Fx",
204
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_A,
205
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<bp::return_internal_reference<> >(
206 "Deprecated. Use set_LQR.")),
207 &ActionModelLQR::set_Fx, "state matrix")
208
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
209 "Fu",
210
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_B,
211
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<bp::return_internal_reference<> >(
212 "Deprecated. Use B.")),
213
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&ActionModelLQR::set_Fu,
214
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<>("Deprecated. Use set_LQR.")),
215 "input matrix")
216
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
217 "f0",
218
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_f,
219
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<bp::return_internal_reference<> >(
220 "Deprecated. Use f.")),
221
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&ActionModelLQR::set_f0,
222
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<>("Deprecated. Use set_LQR.")),
223 "dynamics drift")
224
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
225 "lx",
226
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_q,
227
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<bp::return_internal_reference<> >(
228 "Deprecated. Use q.")),
229
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&ActionModelLQR::set_lx,
230
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<>("Deprecated. Use set_LQR.")),
231 "state weight vector")
232
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
233 "lu",
234
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_r,
235
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<bp::return_internal_reference<> >(
236 "Deprecated. Use r.")),
237
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&ActionModelLQR::set_lu,
238
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<>("Deprecated. Use set_LQR.")),
239 "input weight vector")
240
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
241 "Lxx",
242
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_Q,
243
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<bp::return_internal_reference<> >(
244 "Deprecated. Use Q.")),
245
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&ActionModelLQR::set_Lxx,
246
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<>("Deprecated. Use set_LQR.")),
247 "state weight matrix")
248
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
249 "Lxu",
250
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_N,
251
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<bp::return_internal_reference<> >(
252 "Deprecated. Use N.")),
253
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&ActionModelLQR::set_Lxu,
254
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<>("Deprecated. Use set_LQR.")),
255 "state-input weight matrix")
256
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
257 "Luu",
258
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ActionModelLQR::get_R,
259
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<bp::return_internal_reference<> >(
260 "Deprecated. Use R.")),
261
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&ActionModelLQR::set_Luu,
262
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
20 deprecated<>("Deprecated. Use set_LQR.")),
263 "input weight matrix")
264
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ActionModelLQR>());
265
266 10 boost::python::register_ptr_to_python<boost::shared_ptr<ActionDataLQR> >();
267
268
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ActionDataLQR, bp::bases<ActionDataAbstract> >(
269 "ActionDataLQR", "Action data for the LQR system.",
270
1/2
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
20 bp::init<ActionModelLQR*>(bp::args("self", "model"),
271 "Create LQR data.\n\n"
272 ":param model: LQR action model"))
273
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ActionDataLQR>());
274
275 #pragma GCC diagnostic pop
276 10 }
277
278 } // namespace python
279 } // namespace crocoddyl
280