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