1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-2023, University of Edinburgh, University of Trento, |
5 |
|
|
// LAAS-CNRS, IRI: CSIC-UPC, Heriot-Watt University |
6 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
7 |
|
|
// All rights reserved. |
8 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
9 |
|
|
|
10 |
|
|
#include "crocoddyl/core/integrator/rk.hpp" |
11 |
|
|
|
12 |
|
|
#include "python/crocoddyl/core/core.hpp" |
13 |
|
|
#include "python/crocoddyl/core/integ-action-base.hpp" |
14 |
|
|
#include "python/crocoddyl/utils/copyable.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
10 |
void exposeIntegratedActionRK() { |
20 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<IntegratedActionModelRK> >(); |
21 |
|
|
|
22 |
|
20 |
bp::enum_<RKType>("RKType") |
23 |
✓✗ |
10 |
.value("two", two) |
24 |
✓✗ |
10 |
.value("three", three) |
25 |
✓✗ |
10 |
.value("four", four) |
26 |
✓✗ |
10 |
.export_values(); |
27 |
|
|
|
28 |
✓✗ |
10 |
bp::class_<IntegratedActionModelRK, |
29 |
|
|
bp::bases<IntegratedActionModelAbstract, ActionModelAbstract> >( |
30 |
|
|
"IntegratedActionModelRK", |
31 |
|
|
"RK integrator for differential action models.\n\n" |
32 |
|
|
"This class implements different RK integrator schemes.\n" |
33 |
|
|
"The available integrators are: RK2, RK3, and RK4.", |
34 |
✓✗ |
10 |
bp::init<boost::shared_ptr<DifferentialActionModelAbstract>, RKType, |
35 |
|
|
bp::optional<double, bool> >( |
36 |
|
20 |
bp::args("self", "diffModel", "rktype", "stepTime", |
37 |
|
|
"withCostResidual"), |
38 |
|
|
"Initialize the RK integrator.\n\n" |
39 |
|
|
":param diffModel: differential action model\n" |
40 |
|
|
":param rktype: type of RK integrator (options are two, three, and " |
41 |
|
|
"four)\n" |
42 |
|
|
":param stepTime: step time (default 1e-3)\n" |
43 |
|
|
":param withCostResidual: includes the cost residuals and " |
44 |
|
|
"derivatives (default True).")) |
45 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<DifferentialActionModelAbstract>, |
46 |
|
|
boost::shared_ptr<ControlParametrizationModelAbstract>, |
47 |
|
|
RKType, bp::optional<double, bool> >( |
48 |
✓✗ |
20 |
bp::args("self", "diffModel", "control", "rktype", "stepTime", |
49 |
|
|
"withCostResidual"), |
50 |
|
|
"Initialize the RK integrator.\n\n" |
51 |
|
|
":param diffModel: differential action model\n" |
52 |
|
|
":param control: the control parametrization\n" |
53 |
|
|
":param rktype: type of RK integrator (options are two, three, and " |
54 |
|
|
"four)\n" |
55 |
|
|
":param stepTime: step time (default 1e-3)\n" |
56 |
|
|
":param withCostResidual: includes the cost residuals and " |
57 |
✓✗ |
10 |
"derivatives (default True).")) |
58 |
|
|
.def<void (IntegratedActionModelRK::*)( |
59 |
|
|
const boost::shared_ptr<ActionDataAbstract>&, |
60 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
61 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
62 |
|
|
"calc", &IntegratedActionModelRK::calc, |
63 |
✓✗ |
20 |
bp::args("self", "data", "x", "u"), |
64 |
|
|
"Compute the time-discrete evolution of a differential action " |
65 |
|
|
"model.\n\n" |
66 |
|
|
"It describes the time-discrete evolution of action model.\n" |
67 |
|
|
":param data: action data\n" |
68 |
|
|
":param x: state point (dim. state.nx)\n" |
69 |
|
20 |
":param u: control input (dim. nu)") |
70 |
|
|
.def<void (IntegratedActionModelRK::*)( |
71 |
|
|
const boost::shared_ptr<ActionDataAbstract>&, |
72 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
73 |
✓✗✓✗
|
20 |
"calc", &ActionModelAbstract::calc, bp::args("self", "data", "x")) |
74 |
|
|
.def<void (IntegratedActionModelRK::*)( |
75 |
|
|
const boost::shared_ptr<ActionDataAbstract>&, |
76 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
77 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
78 |
|
|
"calcDiff", &IntegratedActionModelRK::calcDiff, |
79 |
✓✗ |
20 |
bp::args("self", "data", "x", "u"), |
80 |
|
|
"Computes the derivatives of the integrated action model wrt state " |
81 |
|
|
"and control. \n\n" |
82 |
|
|
"This function builds a quadratic approximation of the\n" |
83 |
|
|
"action model (i.e. dynamical system and cost function).\n" |
84 |
|
|
"It assumes that calc has been run first.\n" |
85 |
|
|
":param data: action data\n" |
86 |
|
|
":param x: state point (dim. state.nx)\n" |
87 |
✓✗ |
10 |
":param u: control input (dim. nu)") |
88 |
|
|
.def<void (IntegratedActionModelRK::*)( |
89 |
|
|
const boost::shared_ptr<ActionDataAbstract>&, |
90 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
91 |
|
|
"calcDiff", &ActionModelAbstract::calcDiff, |
92 |
✓✗✓✗
|
20 |
bp::args("self", "data", "x")) |
93 |
✓✗ |
20 |
.def("createData", &IntegratedActionModelRK::createData, bp::args("self"), |
94 |
✓✗✓✗
|
20 |
"Create the RK integrator data.") |
95 |
|
|
.add_property( |
96 |
|
|
"ni", |
97 |
✓✗ |
10 |
bp::make_function(&IntegratedActionModelRK::get_ni, |
98 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
99 |
✓✗ |
10 |
"number of nodes to be integrated") |
100 |
✓✗ |
10 |
.def(CopyableVisitor<IntegratedActionModelRK>()); |
101 |
|
|
|
102 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<IntegratedActionDataRK> >(); |
103 |
|
|
|
104 |
✓✗ |
10 |
bp::class_<IntegratedActionDataRK, bp::bases<IntegratedActionDataAbstract> >( |
105 |
|
|
"IntegratedActionDataRK", "RK integrator data.", |
106 |
✓✗ |
20 |
bp::init<IntegratedActionModelRK*>(bp::args("self", "model"), |
107 |
|
|
"Create RK integrator data.\n\n" |
108 |
|
|
":param model: RK integrator model")) |
109 |
|
|
.add_property( |
110 |
|
|
"differential", |
111 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::differential, |
112 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
113 |
✓✗ |
10 |
"list of differential action data") |
114 |
|
|
.add_property( |
115 |
|
|
"control", |
116 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::control, |
117 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
118 |
✓✗ |
10 |
"list of control parametrization data") |
119 |
|
|
.add_property( |
120 |
|
|
"integral", |
121 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::integral, |
122 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
123 |
✓✗ |
10 |
"list of RK terms related to the cost") |
124 |
|
|
.add_property("dx", |
125 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::dx, |
126 |
|
10 |
bp::return_internal_reference<>()), |
127 |
✓✗ |
10 |
"state rate.") |
128 |
|
|
.add_property("ki", |
129 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::ki, |
130 |
|
10 |
bp::return_internal_reference<>()), |
131 |
✓✗ |
10 |
"list of RK terms related to system dynamics") |
132 |
|
|
.add_property("y", |
133 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::y, |
134 |
|
10 |
bp::return_internal_reference<>()), |
135 |
✓✗ |
10 |
"list of states where f is evaluated in the RK integration") |
136 |
|
|
.add_property("ws", |
137 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::ws, |
138 |
|
10 |
bp::return_internal_reference<>()), |
139 |
✓✗ |
10 |
"control inputs evaluated in the RK integration") |
140 |
|
|
.add_property("dki_dx", |
141 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::dki_dx, |
142 |
|
10 |
bp::return_internal_reference<>()), |
143 |
|
|
"list of partial derivatives of RK nodes with respect to " |
144 |
|
|
"the state of the RK " |
145 |
✓✗ |
10 |
"integration. dki/dx") |
146 |
|
|
.add_property("dki_du", |
147 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::dki_du, |
148 |
|
10 |
bp::return_internal_reference<>()), |
149 |
|
|
"list of partial derivatives of RK nodes with respect to " |
150 |
|
|
"the control parameters of the RK " |
151 |
✓✗ |
10 |
"integration. dki/du") |
152 |
|
|
.add_property("dyi_dx", |
153 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::dyi_dx, |
154 |
|
10 |
bp::return_internal_reference<>()), |
155 |
|
|
"list of partial derivatives of RK dynamics with respect " |
156 |
✓✗ |
10 |
"to the state of the RK integrator. dyi/dx") |
157 |
|
|
.add_property("dyi_du", |
158 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::dyi_du, |
159 |
|
10 |
bp::return_internal_reference<>()), |
160 |
|
|
"list of partial derivatives of RK dynamics with respect " |
161 |
|
|
"to the control parameters of the " |
162 |
✓✗ |
10 |
"RK integrator. dyi/du") |
163 |
|
|
.add_property("dli_dx", |
164 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::dli_dx, |
165 |
|
10 |
bp::return_internal_reference<>()), |
166 |
|
|
"list of partial derivatives of the cost with respect to " |
167 |
|
|
"the state of the RK " |
168 |
✓✗ |
10 |
"integration. dli_dx") |
169 |
|
|
.add_property("dli_du", |
170 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::dli_du, |
171 |
|
10 |
bp::return_internal_reference<>()), |
172 |
|
|
"list of partial derivatives of the cost with respect to " |
173 |
|
|
"the control input of the RK " |
174 |
✓✗ |
10 |
"integration. dli_du") |
175 |
|
|
.add_property("ddli_ddx", |
176 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::ddli_ddx, |
177 |
|
10 |
bp::return_internal_reference<>()), |
178 |
|
|
"list of second partial derivatives of the cost with " |
179 |
|
|
"respect to the state of the RK " |
180 |
✓✗ |
10 |
"integration. ddli_ddx") |
181 |
|
|
.add_property("ddli_ddw", |
182 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::ddli_ddw, |
183 |
|
10 |
bp::return_internal_reference<>()), |
184 |
|
|
"list of second partial derivatives of the cost with " |
185 |
|
|
"respect to the control of the differential" |
186 |
✓✗ |
10 |
"action model w. ddli_ddw") |
187 |
|
|
.add_property("ddli_ddu", |
188 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::ddli_ddu, |
189 |
|
10 |
bp::return_internal_reference<>()), |
190 |
|
|
"list of second partial derivatives of the cost with " |
191 |
|
|
"respect to the control input of the RK " |
192 |
✓✗ |
10 |
"integration. ddli_ddu") |
193 |
|
|
.add_property("ddli_dxdw", |
194 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::ddli_dxdw, |
195 |
|
10 |
bp::return_internal_reference<>()), |
196 |
|
|
"list of second partial derivatives of the cost with " |
197 |
|
|
"respect to the state and control of the differential" |
198 |
✓✗ |
10 |
"action model. ddli_dxdw") |
199 |
|
|
.add_property("ddli_dxdu", |
200 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::ddli_dxdu, |
201 |
|
10 |
bp::return_internal_reference<>()), |
202 |
|
|
"list of second partial derivatives of the cost with " |
203 |
|
|
"respect to the state and control input " |
204 |
✓✗ |
10 |
"of the RK integration. ddli_dxdu") |
205 |
|
|
.add_property( |
206 |
|
|
"ddli_dwdu", |
207 |
✓✗ |
10 |
bp::make_getter(&IntegratedActionDataRK::ddli_dwdu, |
208 |
|
10 |
bp::return_internal_reference<>()), |
209 |
|
|
"list of second partial derivatives of the cost with respect to the " |
210 |
|
|
"control of the differential action" |
211 |
✓✗ |
10 |
"model and the control inputs of the RK integration. ddli_dwdu") |
212 |
✓✗ |
10 |
.def(CopyableVisitor<IntegratedActionDataRK>()); |
213 |
|
10 |
} |
214 |
|
|
|
215 |
|
|
} // namespace python |
216 |
|
|
} // namespace crocoddyl |