1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2021-2023, LAAS-CNRS, University of Edinburgh, |
5 |
|
|
// University of Trento, Heriot-Watt University |
6 |
|
|
// Copyright note valid unless otherwise controld in individual files. |
7 |
|
|
// All rights reserved. |
8 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
9 |
|
|
|
10 |
|
|
#include "python/crocoddyl/core/control-base.hpp" |
11 |
|
|
|
12 |
|
|
#include "python/crocoddyl/core/core.hpp" |
13 |
|
|
#include "python/crocoddyl/utils/copyable.hpp" |
14 |
|
|
#include "python/crocoddyl/utils/vector-converter.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
10 |
void exposeControlParametrizationAbstract() { |
20 |
|
|
// Register custom converters between std::vector and Python list |
21 |
|
|
typedef boost::shared_ptr<ControlParametrizationModelAbstract> |
22 |
|
|
ControlParametrizationModelPtr; |
23 |
|
|
typedef boost::shared_ptr<ControlParametrizationDataAbstract> |
24 |
|
|
ControlParametrizationDataPtr; |
25 |
|
|
StdVectorPythonVisitor<std::vector<ControlParametrizationModelPtr>, |
26 |
✓✗✓✗ ✓✗ |
10 |
true>::expose("StdVec_ControlParametrizationModel"); |
27 |
|
|
StdVectorPythonVisitor<std::vector<ControlParametrizationDataPtr>, |
28 |
✓✗✓✗ ✓✗ |
10 |
true>::expose("StdVec_ControlParametrizationData"); |
29 |
|
|
|
30 |
|
|
bp::register_ptr_to_python< |
31 |
|
10 |
boost::shared_ptr<ControlParametrizationModelAbstract> >(); |
32 |
|
|
|
33 |
✓✗ |
10 |
bp::class_<ControlParametrizationModelAbstract_wrap, boost::noncopyable>( |
34 |
|
|
"ControlParametrizationModelAbstract", |
35 |
|
|
"Abstract class for the control parametrization.\n\n" |
36 |
|
|
"A control is a function of time (normalized in [0,1]) and the control " |
37 |
|
|
"parameters u.", |
38 |
✓✗ |
10 |
bp::init<std::size_t, std::size_t>( |
39 |
|
20 |
bp::args("self", "nw", "nu"), |
40 |
|
|
"Initialize the control dimensions.\n\n" |
41 |
|
|
":param nw: dimension of control inputs\n" |
42 |
|
|
":param nu: dimension of control parameters")) |
43 |
|
|
.def("calc", |
44 |
|
|
pure_virtual(&ControlParametrizationModelAbstract_wrap::calc), |
45 |
✓✗ |
20 |
bp::args("self", "t", "u"), |
46 |
|
|
"Compute the control inputs.\n\n" |
47 |
|
|
":param data: control-parametrization data\n" |
48 |
|
|
":param t: normalized time in [0, 1]\n" |
49 |
✓✗✓✗
|
10 |
":param u: control parameters (dim control.nu)") |
50 |
|
|
.def("calcDiff", |
51 |
|
|
pure_virtual(&ControlParametrizationModelAbstract_wrap::calcDiff), |
52 |
✓✗ |
20 |
bp::args("self", "data", "t", "u"), |
53 |
|
|
"Compute the Jacobian of the control inputs with respect to the " |
54 |
|
|
"control parameters.\n" |
55 |
|
|
"It assumes that calc has been run first.\n\n" |
56 |
|
|
":param data: control-parametrization data\n" |
57 |
|
|
":param t: normalized time in [0, 1]\n" |
58 |
✓✗✓✗
|
10 |
":param u: control parameters (dim control.nu)") |
59 |
|
|
.def("createData", &ControlParametrizationModelAbstract_wrap::createData, |
60 |
|
|
&ControlParametrizationModelAbstract_wrap::default_createData, |
61 |
✓✗ |
20 |
bp::args("self"), |
62 |
|
|
"Create the control-parametrization data.\n\n" |
63 |
|
|
"Each control parametrization model has its own data that needs to " |
64 |
|
|
"be allocated.\n" |
65 |
|
|
"This function returns the allocated data for a predefined control " |
66 |
|
|
"parametrization model.\n" |
67 |
✓✗ |
10 |
":return data.") |
68 |
|
|
.def("params", |
69 |
|
|
pure_virtual(&ControlParametrizationModelAbstract_wrap::params), |
70 |
✓✗ |
20 |
bp::args("self", "data", "t", "w"), |
71 |
|
|
"Update the control parameters u for a specified time t given the " |
72 |
|
|
"control input w.\n\n" |
73 |
|
|
":param data: control-parametrization data\n" |
74 |
|
|
":param t: normalized time in [0, 1]\n" |
75 |
✓✗✓✗
|
10 |
":param w: control inputs (dim control.nw)") |
76 |
|
|
.def("convertBounds", |
77 |
|
|
pure_virtual( |
78 |
|
|
&ControlParametrizationModelAbstract_wrap::convertBounds_wrap), |
79 |
✓✗ |
20 |
bp::args("self", "w_lb", "w_ub"), |
80 |
|
|
"Convert the bounds on the control inputs w to bounds on the " |
81 |
|
|
"control parameters u.\n\n" |
82 |
|
|
":param w_lb: control lower bounds (dim control.nw)\n" |
83 |
|
|
":param w_ub: control upper bounds (dim control.nw)\n" |
84 |
|
|
":return p_lb, p_ub: lower and upper bounds on the control " |
85 |
✓✗✓✗
|
10 |
"parameters (dim control.nu)") |
86 |
|
|
.def("multiplyByJacobian", |
87 |
|
|
pure_virtual(&ControlParametrizationModelAbstract_wrap:: |
88 |
|
|
multiplyByJacobian_wrap), |
89 |
✓✗ |
20 |
bp::args("self", "data", "A"), |
90 |
|
|
"Compute the product between the given matrix A and the derivative " |
91 |
|
|
"of the control input \n" |
92 |
|
|
"with respect to the control parameters (i.e., A*dw_du).\n\n" |
93 |
|
|
"It assumes that calc has been run first.\n" |
94 |
|
|
":param data: control-parametrization data\n" |
95 |
|
|
":param A: matrix to multiply (dim na x control.nw)\n" |
96 |
|
|
":return Product between A and the partial derivative of the calc " |
97 |
✓✗✓✗
|
10 |
"function (dim na x control.nu)") |
98 |
|
|
.def("multiplyJacobianTransposeBy", |
99 |
|
|
pure_virtual(&ControlParametrizationModelAbstract_wrap:: |
100 |
|
|
multiplyJacobianTransposeBy_wrap), |
101 |
✓✗ |
20 |
bp::args("self", "data", "A"), |
102 |
|
|
"Compute the product between the transpose of the derivative of the " |
103 |
|
|
"control input \n" |
104 |
|
|
"with respect to the control parameters and a given matrix A (i.e., " |
105 |
|
|
"dw_du^T*A).\n\n" |
106 |
|
|
"It assumes that calc has been run first.\n" |
107 |
|
|
":param data: control-parametrization data\n" |
108 |
|
|
":param A: matrix to multiply (dim control.nw x na)\n" |
109 |
|
|
":return Product between the partial derivative of the calc " |
110 |
|
|
"function (transposed) and A (dim control.nu x " |
111 |
✓✗✓✗
|
10 |
"na)") |
112 |
|
|
.add_property( |
113 |
|
|
"nw", |
114 |
✓✗ |
20 |
bp::make_function(&ControlParametrizationModelAbstract_wrap::get_nw), |
115 |
✓✗ |
10 |
"dimension of control inputs") |
116 |
|
|
.add_property( |
117 |
|
|
"nu", |
118 |
✓✗ |
20 |
bp::make_function(&ControlParametrizationModelAbstract_wrap::get_nu), |
119 |
✓✗ |
10 |
"dimension of the control parameters"); |
120 |
|
|
|
121 |
|
|
bp::register_ptr_to_python< |
122 |
|
10 |
boost::shared_ptr<ControlParametrizationDataAbstract> >(); |
123 |
|
|
|
124 |
✓✗ |
10 |
bp::class_<ControlParametrizationDataAbstract>( |
125 |
|
|
"ControlParametrizationDataAbstract", |
126 |
|
|
"Abstract class for control parametrization data.\n", |
127 |
✓✗ |
10 |
bp::init<ControlParametrizationModelAbstract*>( |
128 |
|
20 |
bp::args("self", "model"), |
129 |
|
|
"Create common data shared between control parametrization " |
130 |
|
|
"models.\n\n" |
131 |
|
|
":param model: control parametrization model")) |
132 |
|
|
.add_property("w", |
133 |
✓✗ |
10 |
bp::make_getter(&ControlParametrizationDataAbstract::w, |
134 |
|
|
bp::return_internal_reference<>()), |
135 |
✓✗ |
20 |
bp::make_setter(&ControlParametrizationDataAbstract::w), |
136 |
✓✗ |
10 |
"differential control") |
137 |
|
|
.add_property("u", |
138 |
✓✗ |
10 |
bp::make_getter(&ControlParametrizationDataAbstract::u, |
139 |
|
|
bp::return_internal_reference<>()), |
140 |
✓✗ |
20 |
bp::make_setter(&ControlParametrizationDataAbstract::u), |
141 |
✓✗ |
10 |
"control parameters") |
142 |
|
|
.add_property( |
143 |
|
|
"dw_du", |
144 |
✓✗ |
10 |
bp::make_getter(&ControlParametrizationDataAbstract::dw_du, |
145 |
|
|
bp::return_internal_reference<>()), |
146 |
✓✗ |
20 |
bp::make_setter(&ControlParametrizationDataAbstract::dw_du), |
147 |
✓✗ |
10 |
"Jacobian of the differential control wrt the control parameters") |
148 |
✓✗ |
10 |
.def(CopyableVisitor<ControlParametrizationDataAbstract>()); |
149 |
|
10 |
} |
150 |
|
|
|
151 |
|
|
} // namespace python |
152 |
|
|
} // namespace crocoddyl |