Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/core/control-base.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 41 | 44 | 93.2% |
Branches: | 44 | 88 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
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 |
3/6✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
|
10 | true>::expose("StdVec_ControlParametrizationModel"); |
27 | StdVectorPythonVisitor<std::vector<ControlParametrizationDataPtr>, | ||
28 |
3/6✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
|
10 | true>::expose("StdVec_ControlParametrizationData"); |
29 | |||
30 | bp::register_ptr_to_python< | ||
31 | 10 | boost::shared_ptr<ControlParametrizationModelAbstract> >(); | |
32 | |||
33 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("calc", |
44 | pure_virtual(&ControlParametrizationModelAbstract_wrap::calc), | ||
45 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":param u: control parameters (dim control.nu)") | ||
50 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("calcDiff", |
51 | pure_virtual(&ControlParametrizationModelAbstract_wrap::calcDiff), | ||
52 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":param u: control parameters (dim control.nu)") | ||
59 | 20 | .def("createData", &ControlParametrizationModelAbstract_wrap::createData, | |
60 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | &ControlParametrizationModelAbstract_wrap::default_createData, |
61 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":return data.") | ||
68 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("params", |
69 | pure_virtual(&ControlParametrizationModelAbstract_wrap::params), | ||
70 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":param w: control inputs (dim control.nw)") | ||
76 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("convertBounds", |
77 | pure_virtual( | ||
78 | &ControlParametrizationModelAbstract_wrap::convertBounds_wrap), | ||
79 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | "parameters (dim control.nu)") | ||
86 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("multiplyByJacobian", |
87 | pure_virtual(&ControlParametrizationModelAbstract_wrap:: | ||
88 | multiplyByJacobian_wrap), | ||
89 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | "function (dim na x control.nu)") | ||
98 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("multiplyJacobianTransposeBy", |
99 | pure_virtual(&ControlParametrizationModelAbstract_wrap:: | ||
100 | multiplyJacobianTransposeBy_wrap), | ||
101 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | "na)") | ||
112 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
113 | "nw", | ||
114 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&ControlParametrizationModelAbstract_wrap::get_nw), |
115 | "dimension of control inputs") | ||
116 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
117 | "nu", | ||
118 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&ControlParametrizationModelAbstract_wrap::get_nu), |
119 | "dimension of the control parameters"); | ||
120 | |||
121 | bp::register_ptr_to_python< | ||
122 | 10 | boost::shared_ptr<ControlParametrizationDataAbstract> >(); | |
123 | |||
124 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ControlParametrizationDataAbstract>( |
125 | "ControlParametrizationDataAbstract", | ||
126 | "Abstract class for control parametrization data.\n", | ||
127 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("w", |
133 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ControlParametrizationDataAbstract::w, |
134 | ✗ | bp::return_internal_reference<>()), | |
135 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ControlParametrizationDataAbstract::w), |
136 | "differential control") | ||
137 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("u", |
138 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ControlParametrizationDataAbstract::u, |
139 | ✗ | bp::return_internal_reference<>()), | |
140 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ControlParametrizationDataAbstract::u), |
141 | "control parameters") | ||
142 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
143 | "dw_du", | ||
144 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ControlParametrizationDataAbstract::dw_du, |
145 | ✗ | bp::return_internal_reference<>()), | |
146 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ControlParametrizationDataAbstract::dw_du), |
147 | "Jacobian of the differential control wrt the control parameters") | ||
148 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ControlParametrizationDataAbstract>()); |
149 | 10 | } | |
150 | |||
151 | } // namespace python | ||
152 | } // namespace crocoddyl | ||
153 |