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/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 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
10 |
void exposeActionLQR() { |
20 |
|
10 |
boost::python::register_ptr_to_python<boost::shared_ptr<ActionModelLQR> >(); |
21 |
|
|
|
22 |
✓✗ |
10 |
bp::class_<ActionModelLQR, bp::bases<ActionModelAbstract> >( |
23 |
|
|
"ActionModelLQR", |
24 |
|
|
"LQR action model.\n\n" |
25 |
|
|
"A Linear-Quadratic Regulator problem has a transition model of the " |
26 |
|
|
"form\n" |
27 |
|
|
"xnext(x,u) = Fx*x + Fu*u + f0. Its cost function is quadratic of the\n" |
28 |
|
|
"form: 1/2 [x,u].T [Lxx Lxu; Lxu.T Luu] [x,u] + [lx,lu].T [x,u].", |
29 |
✓✗ |
10 |
bp::init<int, int, bp::optional<bool> >( |
30 |
|
20 |
bp::args("self", "nx", "nu", "driftFree"), |
31 |
|
|
"Initialize the LQR action model.\n\n" |
32 |
|
|
":param nx: dimension of the state vector\n" |
33 |
|
|
":param nu: dimension of the control vector\n" |
34 |
|
|
":param driftFree: enable/disable the bias term of the linear " |
35 |
|
|
"dynamics (default True)")) |
36 |
|
|
.def<void (ActionModelLQR::*)( |
37 |
|
|
const boost::shared_ptr<ActionDataAbstract>&, |
38 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
39 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
40 |
✓✗ |
20 |
"calc", &ActionModelLQR::calc, bp::args("self", "data", "x", "u"), |
41 |
|
|
"Compute the next state and cost value.\n\n" |
42 |
|
|
"It describes the time-discrete evolution of the LQR system. " |
43 |
|
|
"Additionally it\n" |
44 |
|
|
"computes the cost value associated to this discrete\n" |
45 |
|
|
"state and control pair.\n" |
46 |
|
|
":param data: action data\n" |
47 |
|
|
":param x: state point (dim. state.nx)\n" |
48 |
|
20 |
":param u: control input (dim. nu)") |
49 |
|
|
.def<void (ActionModelLQR::*)( |
50 |
|
|
const boost::shared_ptr<ActionDataAbstract>&, |
51 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
52 |
✓✗✓✗
|
20 |
"calc", &ActionModelAbstract::calc, bp::args("self", "data", "x")) |
53 |
|
|
.def<void (ActionModelLQR::*)( |
54 |
|
|
const boost::shared_ptr<ActionDataAbstract>&, |
55 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
56 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
57 |
|
|
"calcDiff", &ActionModelLQR::calcDiff, |
58 |
✓✗ |
20 |
bp::args("self", "data", "x", "u"), |
59 |
|
|
"Compute the derivatives of the LQR dynamics and cost functions.\n\n" |
60 |
|
|
"It computes the partial derivatives of the LQR system and the\n" |
61 |
|
|
"cost function. It assumes that calc has been run first.\n" |
62 |
|
|
"This function builds a quadratic approximation of the\n" |
63 |
|
|
"action model (i.e. dynamical system and cost function).\n" |
64 |
|
|
":param data: action data\n" |
65 |
|
|
":param x: state point (dim. state.nx)\n" |
66 |
✓✗ |
10 |
":param u: control input (dim. nu)") |
67 |
|
|
.def<void (ActionModelLQR::*)( |
68 |
|
|
const boost::shared_ptr<ActionDataAbstract>&, |
69 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
70 |
|
|
"calcDiff", &ActionModelAbstract::calcDiff, |
71 |
✓✗✓✗
|
20 |
bp::args("self", "data", "x")) |
72 |
✓✗ |
20 |
.def("createData", &ActionModelLQR::createData, bp::args("self"), |
73 |
✓✗✓✗
|
20 |
"Create the LQR action data.") |
74 |
|
|
.add_property("Fx", |
75 |
|
|
bp::make_function(&ActionModelLQR::get_Fx, |
76 |
|
10 |
bp::return_internal_reference<>()), |
77 |
✓✗✓✗
|
10 |
&ActionModelLQR::set_Fx, "Jacobian of the dynamics") |
78 |
|
|
.add_property("Fu", |
79 |
|
|
bp::make_function(&ActionModelLQR::get_Fu, |
80 |
|
10 |
bp::return_internal_reference<>()), |
81 |
✓✗✓✗
|
10 |
&ActionModelLQR::set_Fu, "Jacobian of the dynamics") |
82 |
|
|
.add_property("f0", |
83 |
|
|
bp::make_function(&ActionModelLQR::get_f0, |
84 |
|
10 |
bp::return_internal_reference<>()), |
85 |
✓✗✓✗
|
10 |
&ActionModelLQR::set_f0, "dynamics drift") |
86 |
|
|
.add_property("lx", |
87 |
|
|
bp::make_function(&ActionModelLQR::get_lx, |
88 |
|
10 |
bp::return_internal_reference<>()), |
89 |
✓✗✓✗
|
10 |
&ActionModelLQR::set_lx, "Jacobian of the cost") |
90 |
|
|
.add_property("lu", |
91 |
|
|
bp::make_function(&ActionModelLQR::get_lu, |
92 |
|
10 |
bp::return_internal_reference<>()), |
93 |
✓✗✓✗
|
10 |
&ActionModelLQR::set_lu, "Jacobian of the cost") |
94 |
|
|
.add_property("Lxx", |
95 |
|
|
bp::make_function(&ActionModelLQR::get_Lxx, |
96 |
|
10 |
bp::return_internal_reference<>()), |
97 |
✓✗✓✗
|
10 |
&ActionModelLQR::set_Lxx, "Hessian of the cost") |
98 |
|
|
.add_property("Lxu", |
99 |
|
|
bp::make_function(&ActionModelLQR::get_Lxu, |
100 |
|
10 |
bp::return_internal_reference<>()), |
101 |
✓✗✓✗
|
10 |
&ActionModelLQR::set_Lxu, "Hessian of the cost") |
102 |
|
|
.add_property("Luu", |
103 |
|
|
bp::make_function(&ActionModelLQR::get_Luu, |
104 |
|
10 |
bp::return_internal_reference<>()), |
105 |
✓✗✓✗
|
10 |
&ActionModelLQR::set_Luu, "Hessian of the cost") |
106 |
✓✗ |
10 |
.def(CopyableVisitor<ActionModelLQR>()); |
107 |
|
|
|
108 |
|
10 |
boost::python::register_ptr_to_python<boost::shared_ptr<ActionDataLQR> >(); |
109 |
|
|
|
110 |
✓✗ |
10 |
bp::class_<ActionDataLQR, bp::bases<ActionDataAbstract> >( |
111 |
|
|
"ActionDataLQR", "Action data for the LQR system.", |
112 |
✓✗ |
20 |
bp::init<ActionModelLQR*>(bp::args("self", "model"), |
113 |
|
|
"Create LQR data.\n\n" |
114 |
|
|
":param model: LQR action model")) |
115 |
✓✗ |
10 |
.def(CopyableVisitor<ActionDataLQR>()); |
116 |
|
10 |
} |
117 |
|
|
|
118 |
|
|
} // namespace python |
119 |
|
|
} // namespace crocoddyl |