| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2019-2025, University of Edinburgh, IRI: CSIC-UPC | ||
| 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/actuation/actuation-squashing.hpp" | ||
| 12 | |||
| 13 | #include "python/crocoddyl/core/core.hpp" | ||
| 14 | |||
| 15 | namespace crocoddyl { | ||
| 16 | namespace python { | ||
| 17 | |||
| 18 | template <typename Model> | ||
| 19 | struct ActuationModelSquashingVisitor | ||
| 20 | : public bp::def_visitor<ActuationModelSquashingVisitor<Model>> { | ||
| 21 | typedef typename Model::Scalar Scalar; | ||
| 22 | typedef typename Model::ActuationDataAbstract Data; | ||
| 23 | typedef typename Model::VectorXs VectorXs; | ||
| 24 | template <class PyClass> | ||
| 25 | ✗ | void visit(PyClass& cl) const { | |
| 26 | ✗ | cl.def("calc", | |
| 27 | static_cast<void (Model::*)( | ||
| 28 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 29 | const Eigen::Ref<const VectorXs>&)>(&Model::calc), | ||
| 30 | bp::args("self", "data", "x", "u"), | ||
| 31 | "Compute the actuation signal from the squashing input u.\n\n" | ||
| 32 | "It describes the time-continuos evolution of the actuation model.\n" | ||
| 33 | ":param data: actuation data\n" | ||
| 34 | ":param x: state point (dim. state.nx)\n" | ||
| 35 | ":param u: squashing function input") | ||
| 36 | ✗ | .def( | |
| 37 | "calcDiff", | ||
| 38 | static_cast<void (Model::*)( | ||
| 39 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 40 | const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), | ||
| 41 | bp::args("self", "data", "x", "u"), | ||
| 42 | "Compute the derivatives of the actuation model.\n\n" | ||
| 43 | "It computes the partial derivatives of the actuation model which " | ||
| 44 | "is\n" | ||
| 45 | "describes in continouos time. It assumes that calc has been run " | ||
| 46 | "first.\n" | ||
| 47 | ":param data: actuation data\n" | ||
| 48 | ":param x: state point (dim. state.nx)\n" | ||
| 49 | ":param u: control input (dim. nu).") | ||
| 50 | ✗ | .def("createData", &Model::createData, bp::args("self"), | |
| 51 | "Create the actuation squashing data.\n\n" | ||
| 52 | "Each actuation model (AM) has its own data that needs to be " | ||
| 53 | "allocated.\n" | ||
| 54 | "This function returns the allocated data for a predefined AM.\n" | ||
| 55 | ":return AM data.") | ||
| 56 | ✗ | .add_property( | |
| 57 | "squashing", | ||
| 58 | bp::make_function(&Model::get_squashing, | ||
| 59 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 60 | "squashing") | ||
| 61 | ✗ | .add_property( | |
| 62 | "actuation", | ||
| 63 | bp::make_function(&Model::get_actuation, | ||
| 64 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 65 | "actuation"); | ||
| 66 | ✗ | } | |
| 67 | }; | ||
| 68 | |||
| 69 | template <typename Data> | ||
| 70 | struct ActuationDataSquashingVisitor | ||
| 71 | : public bp::def_visitor<ActuationDataSquashingVisitor<Data>> { | ||
| 72 | template <class PyClass> | ||
| 73 | ✗ | void visit(PyClass& cl) const { | |
| 74 | ✗ | cl.add_property( | |
| 75 | "squashing", | ||
| 76 | ✗ | bp::make_getter(&Data::squashing, | |
| 77 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 78 | ✗ | bp::make_setter(&Data::squashing), | |
| 79 | "Data of the associated squashing model") | ||
| 80 | ✗ | .add_property( | |
| 81 | "actuation", | ||
| 82 | ✗ | bp::make_getter(&Data::actuation, | |
| 83 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 84 | ✗ | bp::make_setter(&Data::actuation), | |
| 85 | "Data of the associated actuation model"); | ||
| 86 | ✗ | } | |
| 87 | }; | ||
| 88 | |||
| 89 | #define CROCODDYL_ACTUATION_MODEL_SQUASHING_PYTHON_BINDINGS(Scalar) \ | ||
| 90 | typedef ActuationSquashingModelTpl<Scalar> Model; \ | ||
| 91 | typedef ActuationModelAbstractTpl<Scalar> ModelBase; \ | ||
| 92 | typedef SquashingModelAbstractTpl<Scalar> Squashing; \ | ||
| 93 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 94 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
| 95 | "ActuationSquashingModel", \ | ||
| 96 | "Class for squashing an actuation model.\n\n", \ | ||
| 97 | bp::init<std::shared_ptr<ModelBase>, std::shared_ptr<Squashing>, \ | ||
| 98 | std::size_t>( \ | ||
| 99 | bp::args("self", "actuation", "squashing", "nu"), \ | ||
| 100 | "Initialize the actuation model with squashing function.\n\n" \ | ||
| 101 | ":param actuation: actuation model to be squashed.\n" \ | ||
| 102 | ":param squashing: squashing function.\n" \ | ||
| 103 | ":param nu: number of controls")) \ | ||
| 104 | .def(ActuationModelSquashingVisitor<Model>()) \ | ||
| 105 | .def(CastVisitor<Model>()) \ | ||
| 106 | .def(PrintableVisitor<Model>()) \ | ||
| 107 | .def(CopyableVisitor<Model>()); | ||
| 108 | |||
| 109 | #define CROCODDYL_ACTUATION_DATA_SQUASHING_PYTHON_BINDINGS(Scalar) \ | ||
| 110 | typedef ActuationSquashingDataTpl<Scalar> Data; \ | ||
| 111 | typedef ActuationDataAbstractTpl<Scalar> DataBase; \ | ||
| 112 | typedef ActuationSquashingModelTpl<Scalar> Model; \ | ||
| 113 | bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ | ||
| 114 | bp::class_<Data, bp::bases<DataBase>>( \ | ||
| 115 | "ActuationSquashingData", \ | ||
| 116 | "Class for actuation datas using squashing functions.\n\n" \ | ||
| 117 | "In crocoddyl, an actuation data contains all the required information " \ | ||
| 118 | "for processing an user-defined actuation model. The actuation data " \ | ||
| 119 | "typically is allocated onces by running via model.createData().", \ | ||
| 120 | bp::init<Model*>( \ | ||
| 121 | bp::args("self", "model"), \ | ||
| 122 | "Create common data shared between actuation models.\n\n" \ | ||
| 123 | "The actuation data uses the model in order to first process it.\n" \ | ||
| 124 | ":param model: actuation model")) \ | ||
| 125 | .def(ActuationDataSquashingVisitor<Data>()) \ | ||
| 126 | .def(CopyableVisitor<Data>()); | ||
| 127 | |||
| 128 | ✗ | void exposeActuationSquashing() { | |
| 129 | ✗ | CROCODDYL_ACTUATION_MODEL_SQUASHING_PYTHON_BINDINGS(float) | |
| 130 | ✗ | CROCODDYL_ACTUATION_DATA_SQUASHING_PYTHON_BINDINGS(float) | |
| 131 | ✗ | } | |
| 132 | |||
| 133 | } // namespace python | ||
| 134 | } // namespace crocoddyl | ||
| 135 |