| 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 float | ||
| 10 | #include "crocoddyl/core/constraints/residual.hpp" | ||
| 11 | |||
| 12 | #include "python/crocoddyl/core/core.hpp" | ||
| 13 | |||
| 14 | namespace crocoddyl { | ||
| 15 | namespace python { | ||
| 16 | |||
| 17 | template <typename Model> | ||
| 18 | struct ConstraintModelResidualVisitor | ||
| 19 | : public bp::def_visitor<ConstraintModelResidualVisitor<Model>> { | ||
| 20 | typedef typename Model::ConstraintDataAbstract Data; | ||
| 21 | typedef typename Model::Base ModelBase; | ||
| 22 | typedef typename Model::StateAbstract State; | ||
| 23 | typedef typename Model::ResidualModelAbstract ResidualModel; | ||
| 24 | typedef typename Model::VectorXs VectorXs; | ||
| 25 | template <class PyClass> | ||
| 26 | ✗ | void visit(PyClass& cl) const { | |
| 27 | ✗ | cl.def(bp::init<std::shared_ptr<State>, std::shared_ptr<ResidualModel>, | |
| 28 | bp::optional<bool>>( | ||
| 29 | bp::args("self", "state", "residual", "T_act"), | ||
| 30 | "Initialize the residual constraint model as an equality " | ||
| 31 | "constraint.\n\n" | ||
| 32 | ":param state: state description\n" | ||
| 33 | ":param residual: residual model\n" | ||
| 34 | ":param T_act: false if we want to deactivate the residual at " | ||
| 35 | "the terminal node (default true)")) | ||
| 36 | ✗ | .def( | |
| 37 | "calc", | ||
| 38 | static_cast<void (Model::*)( | ||
| 39 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 40 | const Eigen::Ref<const VectorXs>&)>(&Model::calc), | ||
| 41 | bp::args("self", "data", "x", "u"), | ||
| 42 | "Compute the residual constraint.\n\n" | ||
| 43 | ":param data: constraint data\n" | ||
| 44 | ":param x: state point (dim. state.nx)\n" | ||
| 45 | ":param u: control input (dim. nu)") | ||
| 46 | ✗ | .def("calc", | |
| 47 | static_cast<void (Model::*)(const std::shared_ptr<Data>&, | ||
| 48 | const Eigen::Ref<const VectorXs>&)>( | ||
| 49 | &Model::calc), | ||
| 50 | bp::args("self", "data", "x"), | ||
| 51 | "Compute the residual constraint based on state only.\n\n" | ||
| 52 | "It updates the constraint based on the state only. This function " | ||
| 53 | "is commonly used in the terminal nodes of an optimal control " | ||
| 54 | "problem.\n" | ||
| 55 | ":param data: constraint data\n" | ||
| 56 | ":param x: state point (dim. state.nx)") | ||
| 57 | ✗ | .def( | |
| 58 | "calcDiff", | ||
| 59 | static_cast<void (Model::*)( | ||
| 60 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 61 | const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), | ||
| 62 | bp::args("self", "data", "x", "u"), | ||
| 63 | "Compute the derivatives of the residual constraint.\n\n" | ||
| 64 | "It assumes that calc has been run first.\n" | ||
| 65 | ":param data: constraint data\n" | ||
| 66 | ":param x: state point (dim. state.nx)\n" | ||
| 67 | ":param u: control input (dim. nu)\n") | ||
| 68 | ✗ | .def("calcDiff", | |
| 69 | static_cast<void (Model::*)(const std::shared_ptr<Data>&, | ||
| 70 | const Eigen::Ref<const VectorXs>&)>( | ||
| 71 | &Model::calcDiff), | ||
| 72 | bp::args("self", "data", "x"), | ||
| 73 | "Compute the derivatives of the residual constraint with respect " | ||
| 74 | "to the state only.\n\n" | ||
| 75 | "It updates the Jacobian of the constraint function based on the " | ||
| 76 | "state only. This function is commonly used in the terminal nodes " | ||
| 77 | "of an optimal control problem.\n" | ||
| 78 | ":param data: constraint data\n" | ||
| 79 | ":param x: state point (dim. state.nx)") | ||
| 80 | ✗ | .def("createData", &Model::createData, | |
| 81 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
| 82 | bp::args("self", "data"), | ||
| 83 | "Create the residual constraint data.\n\n" | ||
| 84 | "Each constraint model has its own data that needs to be " | ||
| 85 | "allocated. This function returns the allocated data for a " | ||
| 86 | "predefined constraint.\n" | ||
| 87 | ":param data: shared data\n" | ||
| 88 | ":return constraint data."); | ||
| 89 | ✗ | } | |
| 90 | }; | ||
| 91 | |||
| 92 | #define CROCODDYL_CONSTRAINT_MODEL_RESIDUAL_PYTHON_BINDINGS(Scalar) \ | ||
| 93 | typedef ConstraintModelResidualTpl<Scalar> Model; \ | ||
| 94 | typedef ConstraintModelAbstractTpl<Scalar> ModelBase; \ | ||
| 95 | typedef typename ModelBase::StateAbstract State; \ | ||
| 96 | typedef typename ModelBase::ResidualModelAbstract ResidualModel; \ | ||
| 97 | typedef typename ModelBase::VectorXs VectorXs; \ | ||
| 98 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 99 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
| 100 | "ConstraintModelResidual", \ | ||
| 101 | "This defines equality / inequality constraints based on a residual " \ | ||
| 102 | "vector and its bounds.", \ | ||
| 103 | bp::init<std::shared_ptr<State>, std::shared_ptr<ResidualModel>, \ | ||
| 104 | VectorXs, VectorXs, bp::optional<bool>>( \ | ||
| 105 | bp::args("self", "state", "residual", "lower", "upper", "T_act"), \ | ||
| 106 | "Initialize the residual constraint model as an inequality " \ | ||
| 107 | "constraint.\n\n" \ | ||
| 108 | ":param state: state description\n" \ | ||
| 109 | ":param residual: residual model\n" \ | ||
| 110 | ":param lower: lower bound\n" \ | ||
| 111 | ":param upper: upper bound\n" \ | ||
| 112 | ":param T_act: false if we want to deactivate the residual at the " \ | ||
| 113 | "terminal node (default true)")) \ | ||
| 114 | .def(ConstraintModelResidualVisitor<Model>()) \ | ||
| 115 | .def(CastVisitor<Model>()) \ | ||
| 116 | .def(PrintableVisitor<Model>()) \ | ||
| 117 | .def(CopyableVisitor<Model>()); | ||
| 118 | |||
| 119 | #define CROCODDYL_CONSTRAINT_DATA_RESIDUAL_PYTHON_BINDINGS(Scalar) \ | ||
| 120 | typedef ConstraintDataResidualTpl<Scalar> Data; \ | ||
| 121 | typedef ConstraintDataAbstractTpl<Scalar> DataBase; \ | ||
| 122 | typedef ConstraintModelResidualTpl<Scalar> Model; \ | ||
| 123 | typedef Model::DataCollectorAbstract DataCollector; \ | ||
| 124 | bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ | ||
| 125 | bp::class_<Data, bp::bases<DataBase>>( \ | ||
| 126 | "ConstraintDataResidual", "Data for residual constraint.\n\n", \ | ||
| 127 | bp::init<Model*, DataCollector*>( \ | ||
| 128 | bp::args("self", "model", "data"), \ | ||
| 129 | "Create residual constraint data.\n\n" \ | ||
| 130 | ":param model: residual constraint model\n" \ | ||
| 131 | ":param data: shared data")[bp::with_custodian_and_ward< \ | ||
| 132 | 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \ | ||
| 133 | .def(CopyableVisitor<Data>()); | ||
| 134 | |||
| 135 | ✗ | void exposeConstraintResidual() { | |
| 136 | ✗ | CROCODDYL_CONSTRAINT_MODEL_RESIDUAL_PYTHON_BINDINGS(float) | |
| 137 | ✗ | CROCODDYL_CONSTRAINT_DATA_RESIDUAL_PYTHON_BINDINGS(float) | |
| 138 | ✗ | } | |
| 139 | |||
| 140 | } // namespace python | ||
| 141 | } // namespace crocoddyl | ||
| 142 |