| 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 | // Auto-generated file for float | ||
| 11 | #include "crocoddyl/core/controls/poly-one.hpp" | ||
| 12 | |||
| 13 | #include "python/crocoddyl/core/control-base.hpp" | ||
| 14 | #include "python/crocoddyl/core/core.hpp" | ||
| 15 | #include "python/crocoddyl/utils/copyable.hpp" | ||
| 16 | |||
| 17 | namespace crocoddyl { | ||
| 18 | namespace python { | ||
| 19 | |||
| 20 | template <typename Model> | ||
| 21 | struct ControlParametrizationModelPolyOneVisitor | ||
| 22 | : public bp::def_visitor<ControlParametrizationModelPolyOneVisitor<Model>> { | ||
| 23 | typedef typename Model::Scalar Scalar; | ||
| 24 | typedef typename Model::ControlParametrizationDataAbstract Data; | ||
| 25 | typedef typename Model::VectorXs VectorXs; | ||
| 26 | template <class PyClass> | ||
| 27 | ✗ | void visit(PyClass& cl) const { | |
| 28 | ✗ | 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 | ✗ | .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\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 | ✗ | .def("createData", &Model::createData, bp::args("self"), | |
| 49 | "Create the poly-one data.") | ||
| 50 | ✗ | .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", "w"), | ||
| 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 | ✗ | .def("convertBounds", &Model::convertBounds, | |
| 60 | bp::args("self", "w_lb", "w_ub"), | ||
| 61 | "Convert the bounds on the control to bounds on the control " | ||
| 62 | "parameters.\n\n" | ||
| 63 | ":param w_lb: lower bounds on u (dim control.nw).\n" | ||
| 64 | ":param w_ub: upper bounds on u (dim control.nw).\n" | ||
| 65 | ":return p_lb, p_ub: lower and upper bounds on the control " | ||
| 66 | "parameters (dim control.nu).") | ||
| 67 | ✗ | .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 parameters.\n\n" | ||
| 72 | "It assumes that calc has been run first.\n" | ||
| 73 | ":param data: control-parametrization data\n" | ||
| 74 | ":param A: matrix to multiply (dim na x control.nw)\n" | ||
| 75 | ":return Product between A and the partial derivative of the value " | ||
| 76 | "function (dim na x control.nu)") | ||
| 77 | ✗ | .def("multiplyJacobianTransposeBy", | |
| 78 | &Model::multiplyJacobianTransposeBy_J, | ||
| 79 | bp::args("self", "data", "A"), | ||
| 80 | "Compute the product between the transpose of the derivative of " | ||
| 81 | "the control with respect to the parameters and a given matrix " | ||
| 82 | "A.\n\n" | ||
| 83 | "It assumes that calc has been run first.\n" | ||
| 84 | ":param data: control-parametrization data\n" | ||
| 85 | ":param A: matrix to multiply (dim control.nw x na)\n" | ||
| 86 | ":return Product between the partial derivative of the value " | ||
| 87 | "function (transposed) and A (dim control.nu x " | ||
| 88 | "na)"); | ||
| 89 | ✗ | } | |
| 90 | }; | ||
| 91 | |||
| 92 | template <typename Data> | ||
| 93 | struct ControlParametrizationDataPolyOneVisitor | ||
| 94 | : public bp::def_visitor<ControlParametrizationDataPolyOneVisitor<Data>> { | ||
| 95 | template <class PyClass> | ||
| 96 | ✗ | void visit(PyClass& cl) const { | |
| 97 | ✗ | cl.add_property( | |
| 98 | ✗ | "c", bp::make_getter(&Data::c, bp::return_internal_reference<>()), | |
| 99 | "polynomial coefficients of the linear control model that depends on " | ||
| 100 | "time"); | ||
| 101 | ✗ | } | |
| 102 | }; | ||
| 103 | |||
| 104 | #define CROCODDYL_CONTROL_PARAMETRIZATION_MODEL_POLYONE_PYTHON_BINDINGS( \ | ||
| 105 | Scalar) \ | ||
| 106 | typedef ControlParametrizationModelPolyOneTpl<Scalar> Model; \ | ||
| 107 | typedef ControlParametrizationModelAbstractTpl<Scalar> ModelBase; \ | ||
| 108 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 109 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
| 110 | "ControlParametrizationModelPolyOne", \ | ||
| 111 | "Linear polynomial control.\n\n" \ | ||
| 112 | "This control is a linear function of time (normalized in [0,1]). The " \ | ||
| 113 | "first half of the parameter vector contains the initial value of the " \ | ||
| 114 | "differential control w, whereas the second half contains the value of " \ | ||
| 115 | "w at t=0.5.", \ | ||
| 116 | bp::init<std::size_t>( \ | ||
| 117 | bp::args("self", "nw"), \ | ||
| 118 | "Initialize the control dimensions.\n\n" \ | ||
| 119 | ":param nw: dimension of differential control space")) \ | ||
| 120 | .def(ControlParametrizationModelPolyOneVisitor<Model>()) \ | ||
| 121 | .def(CastVisitor<Model>()) \ | ||
| 122 | .def(PrintableVisitor<Model>()) \ | ||
| 123 | .def(CopyableVisitor<Model>()); | ||
| 124 | |||
| 125 | #define CROCODDYL_CONTROL_PARAMETRIZATION_DATA_POLYONE_PYTHON_BINDINGS(Scalar) \ | ||
| 126 | typedef ControlParametrizationDataPolyOneTpl<Scalar> Data; \ | ||
| 127 | typedef ControlParametrizationDataAbstractTpl<Scalar> DataBase; \ | ||
| 128 | typedef ControlParametrizationModelPolyOneTpl<Scalar> Model; \ | ||
| 129 | bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ | ||
| 130 | bp::class_<Data, bp::bases<DataBase>>( \ | ||
| 131 | "ControlParametrizationDataPolyOne", \ | ||
| 132 | "Control-parametrization data for the linear polynomial control.", \ | ||
| 133 | bp::init<Model*>(bp::args("self", "model"), \ | ||
| 134 | "Create control-parametrization data.\n\n" \ | ||
| 135 | ":param model: linear polynomial control model")) \ | ||
| 136 | .def(ControlParametrizationDataPolyOneVisitor<Data>()) \ | ||
| 137 | .def(CopyableVisitor<Data>()); | ||
| 138 | |||
| 139 | ✗ | void exposeControlParametrizationPolyOne() { | |
| 140 | ✗ | CROCODDYL_CONTROL_PARAMETRIZATION_MODEL_POLYONE_PYTHON_BINDINGS(float) | |
| 141 | ✗ | CROCODDYL_CONTROL_PARAMETRIZATION_DATA_POLYONE_PYTHON_BINDINGS(float) | |
| 142 | ✗ | } | |
| 143 | |||
| 144 | } // namespace python | ||
| 145 | } // namespace crocoddyl | ||
| 146 |