Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/core/controls/poly-zero.cpp |
Date: | 2025-03-26 19:23:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 12 | 12 | 100.0% |
Branches: | 30 | 60 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2021-2025, University of Edinburgh, University of Trento | ||
5 | // Heriot-Watt University | ||
6 | // Copyright note valid unless otherwise stated in individual files. | ||
7 | // All rights reserved. | ||
8 | /////////////////////////////////////////////////////////////////////////////// | ||
9 | |||
10 | #include "crocoddyl/core/controls/poly-zero.hpp" | ||
11 | |||
12 | #include "python/crocoddyl/core/control-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 | template <typename Model> | ||
20 | struct ControlParametrizationModelPolyZeroVisitor | ||
21 | : public bp::def_visitor< | ||
22 | ControlParametrizationModelPolyZeroVisitor<Model>> { | ||
23 | typedef typename Model::Scalar Scalar; | ||
24 | typedef typename Model::ControlParametrizationDataAbstract Data; | ||
25 | typedef typename Model::VectorXs VectorXs; | ||
26 | template <class PyClass> | ||
27 | 40 | void visit(PyClass& cl) const { | |
28 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
40 | cl.def("calc", |
29 | static_cast<void (Model::*)( | ||
30 | const std::shared_ptr<Data>&, const Scalar, | ||
31 | const Eigen::Ref<const VectorXs>&) const>(&Model::calc), | ||
32 | bp::args("self", "data", "t", "u"), | ||
33 | "Compute the control value.\n\n" | ||
34 | ":param data: control-parametrization data\n" | ||
35 | ":param t: normalized time in [0, 1]\n" | ||
36 | ":param u: control parameters (dim control.nu)") | ||
37 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
80 | .def("calcDiff", |
38 | static_cast<void (Model::*)( | ||
39 | const std::shared_ptr<Data>&, const Scalar, | ||
40 | const Eigen::Ref<const VectorXs>&) const>(&Model::calcDiff), | ||
41 | bp::args("self", "data", "t", "u"), | ||
42 | "Compute the Jacobian of the control value with respect to the " | ||
43 | "control parameters.\n" | ||
44 | "It assumes that calc has been run first.\n\n" | ||
45 | ":param data: control-parametrization data\n" | ||
46 | ":param t: normalized time in [0, 1]\n" | ||
47 | ":param u: control parameters (dim control.nu)") | ||
48 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
80 | .def("createData", &Model::createData, bp::args("self"), |
49 | "Create the poly-zero data.") | ||
50 |
3/6✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
|
80 | .def("params", |
51 | static_cast<void (Model::*)( | ||
52 | const std::shared_ptr<Data>&, const Scalar, | ||
53 | const Eigen::Ref<const VectorXs>&) const>(&Model::params), | ||
54 | bp::args("self", "data", "t", "u"), | ||
55 | "Compute the control parameters.\n\n" | ||
56 | ":param data: control-parametrization data\n" | ||
57 | ":param t: normalized time in [0, 1]\n" | ||
58 | ":param w: control value (dim control.nw)") | ||
59 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
80 | .def("convertBounds", &Model::convertBounds, |
60 | bp::args("self", "u_lb", "u_ub"), | ||
61 | "Convert the bounds on the control to bounds on the control " | ||
62 | "parameters.\n\n" | ||
63 | ":param w_lb: lower bounds on w (dim control.nw)\n" | ||
64 | ":param w_ub: upper bounds on w (dim control.nw)\n" | ||
65 | ":return p_lb, p_ub: lower and upper bounds on the control " | ||
66 | "parameters (dim control.nu)") | ||
67 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
80 | .def( |
68 | "multiplyByJacobian", &Model::multiplyByJacobian_J, | ||
69 | bp::args("self", "data", "A"), | ||
70 | "Compute the product between the given matrix A and the derivative " | ||
71 | "of the control with respect to the " | ||
72 | "parameters.\n\n" | ||
73 | "It assumes that calc has been run first.\n" | ||
74 | ":param data: control-parametrization data\n" | ||
75 | ":param A: matrix to multiply (dim na x control.nw)\n" | ||
76 | ":return Product between A and the partial derivative of the value " | ||
77 | "function (dim na x control.nu)") | ||
78 |
3/6✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
|
40 | .def("multiplyJacobianTransposeBy", |
79 | &Model::multiplyJacobianTransposeBy_J, | ||
80 | bp::args("self", "data", "A"), | ||
81 | "Compute the product between the transpose of the derivative of " | ||
82 | "the " | ||
83 | "control with respect to the parameters\n" | ||
84 | "and a given matrix A.\n\n" | ||
85 | "It assumes that calc has been run first.\n" | ||
86 | ":param data: control-parametrization data\n" | ||
87 | ":param A: matrix to multiply (dim control.nw x na)\n" | ||
88 | ":return Product between the partial derivative of the value " | ||
89 | "function (transposed) and A (dim control.nu x " | ||
90 | "na)"); | ||
91 | 40 | } | |
92 | }; | ||
93 | |||
94 | #define CROCODDYL_CONTROL_PARAMETRIZATION_MODEL_POLYZERO_PYTHON_BINDINGS( \ | ||
95 | Scalar) \ | ||
96 | typedef ControlParametrizationModelPolyZeroTpl<Scalar> Model; \ | ||
97 | typedef ControlParametrizationModelAbstractTpl<Scalar> ModelBase; \ | ||
98 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
99 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
100 | "ControlParametrizationModelPolyZero", \ | ||
101 | "Constant control.\n\n" \ | ||
102 | "This control is a constant. The parameter vector corresponds to the " \ | ||
103 | "constant value of the differential control w, that is w=p.", \ | ||
104 | bp::init<std::size_t>( \ | ||
105 | bp::args("self", "nw"), \ | ||
106 | "Initialize the control dimensions.\n\n" \ | ||
107 | ":param nw: dimension of differential control space")) \ | ||
108 | .def(ControlParametrizationModelPolyZeroVisitor<Model>()) \ | ||
109 | .def(CastVisitor<Model>()) \ | ||
110 | .def(PrintableVisitor<Model>()) \ | ||
111 | .def(CopyableVisitor<Model>()); | ||
112 | |||
113 | 10 | void exposeControlParametrizationPolyZero() { | |
114 |
17/34✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 10 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 10 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 10 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 10 times.
✗ Branch 31 not taken.
✓ Branch 35 taken 10 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 10 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 10 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 10 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 10 times.
✗ Branch 48 not taken.
✓ Branch 50 taken 10 times.
✗ Branch 51 not taken.
✓ Branch 53 taken 10 times.
✗ Branch 54 not taken.
✓ Branch 56 taken 10 times.
✗ Branch 57 not taken.
|
20 | CROCODDYL_PYTHON_SCALARS( |
115 | CROCODDYL_CONTROL_PARAMETRIZATION_MODEL_POLYZERO_PYTHON_BINDINGS) | ||
116 | 10 | } | |
117 | |||
118 | } // namespace python | ||
119 | } // namespace crocoddyl | ||
120 |