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/diff-lqr.hpp" |
11 |
|
|
|
12 |
|
|
#include "python/crocoddyl/core/core.hpp" |
13 |
|
|
#include "python/crocoddyl/core/diff-action-base.hpp" |
14 |
|
|
#include "python/crocoddyl/utils/copyable.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
10 |
void exposeDifferentialActionLQR() { |
20 |
|
|
boost::python::register_ptr_to_python< |
21 |
|
10 |
boost::shared_ptr<DifferentialActionModelLQR> >(); |
22 |
|
|
|
23 |
✓✗ |
10 |
bp::class_<DifferentialActionModelLQR, |
24 |
|
|
bp::bases<DifferentialActionModelAbstract> >( |
25 |
|
|
"DifferentialActionModelLQR", |
26 |
|
|
"Differential action model for linear dynamics and quadratic cost.\n\n" |
27 |
|
|
"This class implements a linear dynamics, and quadratic costs (i.e.\n" |
28 |
|
|
"LQR action). Since the DAM is a second order system, and the " |
29 |
|
|
"integrated\n" |
30 |
|
|
"action models are implemented as being second order integrators. This\n" |
31 |
|
|
"class implements a second order linear system given by\n" |
32 |
|
|
" x = [q, v]\n" |
33 |
|
|
" dv = Fq q + Fv v + Fu u + f0\n" |
34 |
|
|
"where Fq, Fv, Fu and f0 are randomly chosen constant terms. On the " |
35 |
|
|
"other\n" |
36 |
|
|
"hand the cost function is given by\n" |
37 |
|
|
" l(x,u) = 1/2 [x,u].T [Lxx Lxu; Lxu.T Luu] [x,u] + [lx,lu].T [x,u].", |
38 |
✓✗ |
10 |
bp::init<int, int, bp::optional<bool> >( |
39 |
|
20 |
bp::args("self", "nq", "nu", "driftFree"), |
40 |
|
|
"Initialize the differential LQR action model.\n\n" |
41 |
|
|
":param nx: dimension of the state vector\n" |
42 |
|
|
":param nu: dimension of the control vector\n" |
43 |
|
|
":param driftFree: enable/disable the bias term of the linear " |
44 |
|
|
"dynamics (default True)")) |
45 |
|
|
.def<void (DifferentialActionModelLQR::*)( |
46 |
|
|
const boost::shared_ptr<DifferentialActionDataAbstract>&, |
47 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
48 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
49 |
|
|
"calc", &DifferentialActionModelLQR::calc, |
50 |
✓✗ |
20 |
bp::args("self", "data", "x", "u"), |
51 |
|
|
"Compute the next state and cost value.\n\n" |
52 |
|
|
"It describes the time-continuous evolution of the LQR system. " |
53 |
|
|
"Additionally it\n" |
54 |
|
|
"computes the cost value associated to this discrete state and " |
55 |
|
|
"control pair.\n" |
56 |
|
|
":param data: action data\n" |
57 |
|
|
":param x: time-continuous state vector\n" |
58 |
|
20 |
":param u: time-continuous control input") |
59 |
|
|
.def<void (DifferentialActionModelLQR::*)( |
60 |
|
|
const boost::shared_ptr<DifferentialActionDataAbstract>&, |
61 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
62 |
|
|
"calc", &DifferentialActionModelAbstract::calc, |
63 |
✓✗✓✗
|
20 |
bp::args("self", "data", "x")) |
64 |
|
|
.def<void (DifferentialActionModelLQR::*)( |
65 |
|
|
const boost::shared_ptr<DifferentialActionDataAbstract>&, |
66 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
67 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
68 |
|
|
"calcDiff", &DifferentialActionModelLQR::calcDiff, |
69 |
✓✗ |
20 |
bp::args("self", "data", "x", "u"), |
70 |
|
|
"Compute the derivatives of the differential LQR dynamics and cost " |
71 |
|
|
"functions.\n\n" |
72 |
|
|
"It computes the partial derivatives of the differential LQR system " |
73 |
|
|
"and the\n" |
74 |
|
|
"cost function. It assumes that calc has been run first.\n" |
75 |
|
|
"This function builds a quadratic approximation of the\n" |
76 |
|
|
"action model (i.e. dynamical system and cost function).\n" |
77 |
|
|
":param data: action data\n" |
78 |
|
|
":param x: time-continuous state vector\n" |
79 |
✓✗ |
10 |
":param u: time-continuous control input\n") |
80 |
|
|
.def<void (DifferentialActionModelLQR::*)( |
81 |
|
|
const boost::shared_ptr<DifferentialActionDataAbstract>&, |
82 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
83 |
|
|
"calcDiff", &DifferentialActionModelAbstract::calcDiff, |
84 |
✓✗✓✗
|
20 |
bp::args("self", "data", "x")) |
85 |
|
|
.def("createData", &DifferentialActionModelLQR::createData, |
86 |
✓✗✓✗ ✓✗ |
20 |
bp::args("self"), "Create the differential LQR action data.") |
87 |
|
|
.add_property("Fq", |
88 |
|
|
bp::make_function(&DifferentialActionModelLQR::get_Fq, |
89 |
|
10 |
bp::return_internal_reference<>()), |
90 |
|
|
&DifferentialActionModelLQR::set_Fq, |
91 |
✓✗✓✗
|
10 |
"Jacobian of the dynamics") |
92 |
|
|
.add_property("Fv", |
93 |
|
|
bp::make_function(&DifferentialActionModelLQR::get_Fv, |
94 |
|
10 |
bp::return_internal_reference<>()), |
95 |
|
|
&DifferentialActionModelLQR::set_Fv, |
96 |
✓✗✓✗
|
10 |
"Jacobian of the dynamics") |
97 |
|
|
.add_property("Fu", |
98 |
|
|
bp::make_function(&DifferentialActionModelLQR::get_Fu, |
99 |
|
10 |
bp::return_internal_reference<>()), |
100 |
|
|
&DifferentialActionModelLQR::set_Fu, |
101 |
✓✗✓✗
|
10 |
"Jacobian of the dynamics") |
102 |
|
|
.add_property("f0", |
103 |
|
|
bp::make_function(&DifferentialActionModelLQR::get_f0, |
104 |
|
10 |
bp::return_internal_reference<>()), |
105 |
✓✗✓✗
|
10 |
&DifferentialActionModelLQR::set_f0, "dynamics drift") |
106 |
|
|
.add_property("lx", |
107 |
|
|
bp::make_function(&DifferentialActionModelLQR::get_lx, |
108 |
|
10 |
bp::return_internal_reference<>()), |
109 |
✓✗✓✗
|
10 |
&DifferentialActionModelLQR::set_lx, "Jacobian of the cost") |
110 |
|
|
.add_property("lu", |
111 |
|
|
bp::make_function(&DifferentialActionModelLQR::get_lu, |
112 |
|
10 |
bp::return_internal_reference<>()), |
113 |
✓✗✓✗
|
10 |
&DifferentialActionModelLQR::set_lu, "Jacobian of the cost") |
114 |
|
|
.add_property("Lxx", |
115 |
|
|
bp::make_function(&DifferentialActionModelLQR::get_Lxx, |
116 |
|
10 |
bp::return_internal_reference<>()), |
117 |
✓✗✓✗
|
10 |
&DifferentialActionModelLQR::set_Lxx, "Hessian of the cost") |
118 |
|
|
.add_property("Lxu", |
119 |
|
|
bp::make_function(&DifferentialActionModelLQR::get_Lxu, |
120 |
|
10 |
bp::return_internal_reference<>()), |
121 |
✓✗✓✗
|
10 |
&DifferentialActionModelLQR::set_Lxu, "Hessian of the cost") |
122 |
|
|
.add_property( |
123 |
|
|
"Luu", |
124 |
|
|
bp::make_function(&DifferentialActionModelLQR::get_Luu, |
125 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
126 |
✓✗✓✗
|
10 |
&DifferentialActionModelLQR::set_Luu, "Hessian of the cost") |
127 |
✓✗ |
10 |
.def(CopyableVisitor<DifferentialActionModelLQR>()); |
128 |
|
|
|
129 |
|
|
boost::python::register_ptr_to_python< |
130 |
|
10 |
boost::shared_ptr<DifferentialActionDataLQR> >(); |
131 |
|
|
|
132 |
✓✗ |
10 |
bp::class_<DifferentialActionDataLQR, |
133 |
|
|
bp::bases<DifferentialActionDataAbstract> >( |
134 |
|
|
"DifferentialActionDataLQR", |
135 |
|
|
"Action data for the differential LQR system.", |
136 |
✓✗ |
10 |
bp::init<DifferentialActionModelLQR*>( |
137 |
|
20 |
bp::args("self", "model"), |
138 |
|
|
"Create differential LQR data.\n\n" |
139 |
|
|
":param model: differential LQR action model")) |
140 |
✓✗ |
10 |
.def(CopyableVisitor<DifferentialActionDataLQR>()); |
141 |
|
10 |
} |
142 |
|
|
|
143 |
|
|
} // namespace python |
144 |
|
|
} // namespace crocoddyl |