| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2021-2025, University of Edinburgh, Heriot-Watt University | ||
| 5 | // Copyright note valid unless otherwise stated in individual files. | ||
| 6 | // All rights reserved. | ||
| 7 | /////////////////////////////////////////////////////////////////////////////// | ||
| 8 | |||
| 9 | // Auto-generated file for double | ||
| 10 | #include "crocoddyl/core/residuals/control.hpp" | ||
| 11 | |||
| 12 | #include "python/crocoddyl/core/core.hpp" | ||
| 13 | |||
| 14 | namespace crocoddyl { | ||
| 15 | namespace python { | ||
| 16 | |||
| 17 | template <typename Model> | ||
| 18 | struct ResidualModelControlVisitor | ||
| 19 | : public bp::def_visitor<ResidualModelControlVisitor<Model>> { | ||
| 20 | typedef typename Model::ResidualDataAbstract Data; | ||
| 21 | typedef typename Model::Base ModelBase; | ||
| 22 | typedef typename Model::StateAbstract State; | ||
| 23 | typedef typename Model::VectorXs VectorXs; | ||
| 24 | template <class PyClass> | ||
| 25 | ✗ | void visit(PyClass& cl) const { | |
| 26 | ✗ | cl.def(bp::init<std::shared_ptr<State>, std::size_t>( | |
| 27 | bp::args("self", "state", "nu"), | ||
| 28 | "Initialize the control residual model.\n\n" | ||
| 29 | "The default reference control is obtained from np.zero(nu).\n" | ||
| 30 | ":param state: state description\n" | ||
| 31 | ":param nu: dimension of the control vector")) | ||
| 32 | ✗ | .def(bp::init<std::shared_ptr<State>>( | |
| 33 | bp::args("self", "state"), | ||
| 34 | "Initialize the control residual model.\n\n" | ||
| 35 | "The default reference control is obtained from np.zero(nu).\n" | ||
| 36 | ":param state: state description")) | ||
| 37 | ✗ | .def( | |
| 38 | "calc", | ||
| 39 | static_cast<void (Model::*)( | ||
| 40 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 41 | const Eigen::Ref<const VectorXs>&)>(&Model::calc), | ||
| 42 | bp::args("self", "data", "x", "u"), | ||
| 43 | "Compute the control residual.\n\n" | ||
| 44 | ":param data: residual data\n" | ||
| 45 | ":param x: state point (dim. state.nx)\n" | ||
| 46 | ":param u: control input (dim. nu)") | ||
| 47 | ✗ | .def("calc", | |
| 48 | static_cast<void (Model::*)(const std::shared_ptr<Data>&, | ||
| 49 | const Eigen::Ref<const VectorXs>&)>( | ||
| 50 | &Model::calc), | ||
| 51 | bp::args("self", "data", "x")) | ||
| 52 | ✗ | .def( | |
| 53 | "calcDiff", | ||
| 54 | static_cast<void (Model::*)( | ||
| 55 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 56 | const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), | ||
| 57 | bp::args("self", "data", "x", "u"), | ||
| 58 | "Compute the Jacobians of the control residual.\n\n" | ||
| 59 | "It assumes that calc has been run first.\n" | ||
| 60 | ":param data: action data\n" | ||
| 61 | ":param x: state point (dim. state.nx)\n" | ||
| 62 | ":param u: control input (dim. nu)") | ||
| 63 | ✗ | .def( | |
| 64 | "calcDiff", | ||
| 65 | static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&, | ||
| 66 | const Eigen::Ref<const VectorXs>&)>( | ||
| 67 | &ModelBase::calcDiff), | ||
| 68 | bp::args("self", "data", "x")) | ||
| 69 | ✗ | .def("createData", &Model::createData, | |
| 70 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
| 71 | bp::args("self", "data"), | ||
| 72 | "Create the control residual data.\n\n" | ||
| 73 | "Each residual model has its own data that needs to be allocated. " | ||
| 74 | "This function returns the allocated data for the control " | ||
| 75 | "residual.\n" | ||
| 76 | ":param data: shared data\n" | ||
| 77 | ":return residual data.") | ||
| 78 | ✗ | .add_property("reference", | |
| 79 | bp::make_function(&Model::get_reference, | ||
| 80 | ✗ | bp::return_internal_reference<>()), | |
| 81 | &Model::set_reference, "reference control vector"); | ||
| 82 | ✗ | } | |
| 83 | }; | ||
| 84 | |||
| 85 | #define CROCODDYL_RESIDUAL_MODEL_CONTROL_PYTHON_BINDINGS(Scalar) \ | ||
| 86 | typedef ResidualModelControlTpl<Scalar> Model; \ | ||
| 87 | typedef ResidualModelAbstractTpl<Scalar> ModelBase; \ | ||
| 88 | typedef typename ModelBase::StateAbstract State; \ | ||
| 89 | typedef typename ModelBase::VectorXs VectorXs; \ | ||
| 90 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 91 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
| 92 | "ResidualModelControl", \ | ||
| 93 | "This residual function defines a residual vector as r = u - uref, " \ | ||
| 94 | "with u and uref as the current and reference control, respectively.", \ | ||
| 95 | bp::init<std::shared_ptr<State>, VectorXs>( \ | ||
| 96 | bp::args("self", "state", "uref"), \ | ||
| 97 | "Initialize the control residual model.\n\n" \ | ||
| 98 | ":param state: state description\n" \ | ||
| 99 | ":param uref: reference control")) \ | ||
| 100 | .def(ResidualModelControlVisitor<Model>()) \ | ||
| 101 | .def(CastVisitor<Model>()) \ | ||
| 102 | .def(PrintableVisitor<Model>()) \ | ||
| 103 | .def(CopyableVisitor<Model>()); | ||
| 104 | |||
| 105 | ✗ | void exposeResidualControl() { | |
| 106 | ✗ | CROCODDYL_RESIDUAL_MODEL_CONTROL_PYTHON_BINDINGS(double) | |
| 107 | ✗ | } | |
| 108 | |||
| 109 | } // namespace python | ||
| 110 | } // namespace crocoddyl | ||
| 111 |