| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2019-2025, University of Edinburgh, University of Trento, | ||
| 5 | // LAAS-CNRS, IRI: CSIC-UPC, Heriot-Watt University | ||
| 6 | // Copyright note valid unless otherwise stated in individual files. | ||
| 7 | // All rights reserved. | ||
| 8 | /////////////////////////////////////////////////////////////////////////////// | ||
| 9 | |||
| 10 | // Auto-generated file for double | ||
| 11 | #include "crocoddyl/core/integrator/rk.hpp" | ||
| 12 | |||
| 13 | #include "python/crocoddyl/core/core.hpp" | ||
| 14 | #include "python/crocoddyl/core/integ-action-base.hpp" | ||
| 15 | |||
| 16 | #define SCALAR_float64 | ||
| 17 | |||
| 18 | namespace crocoddyl { | ||
| 19 | namespace python { | ||
| 20 | |||
| 21 | template <typename Model> | ||
| 22 | struct IntegratedActionModelRKVisitor | ||
| 23 | : public bp::def_visitor<IntegratedActionModelRKVisitor<Model>> { | ||
| 24 | typedef typename Model::Scalar Scalar; | ||
| 25 | typedef typename Model::ActionDataAbstract Data; | ||
| 26 | typedef | ||
| 27 | typename Model::DifferentialActionModelAbstract DifferentialActionModel; | ||
| 28 | typedef typename Model::ControlParametrizationModelAbstract | ||
| 29 | ControlParametrizationModel; | ||
| 30 | typedef typename Model::VectorXs VectorXs; | ||
| 31 | template <class PyClass> | ||
| 32 | ✗ | void visit(PyClass& cl) const { | |
| 33 | ✗ | cl.def(bp::init<std::shared_ptr<DifferentialActionModel>, | |
| 34 | std::shared_ptr<ControlParametrizationModel>, RKType, | ||
| 35 | bp::optional<Scalar, bool>>( | ||
| 36 | bp::args("self", "diffModel", "control", "rktype", "stepTime", | ||
| 37 | "withCostResidual"), | ||
| 38 | "Initialize the RK integrator.\n\n" | ||
| 39 | ":param diffModel: differential action model\n" | ||
| 40 | ":param control: the control parametrization\n" | ||
| 41 | ":param rktype: type of RK integrator (options are two, three, " | ||
| 42 | "and four)\n" | ||
| 43 | ":param stepTime: step time (default 1e-3)\n" | ||
| 44 | ":param withCostResidual: includes the cost residuals and " | ||
| 45 | "derivatives (default True).")) | ||
| 46 | ✗ | .def( | |
| 47 | "calc", | ||
| 48 | static_cast<void (Model::*)( | ||
| 49 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 50 | const Eigen::Ref<const VectorXs>&)>(&Model::calc), | ||
| 51 | bp::args("self", "data", "x", "u"), | ||
| 52 | "Compute the time-discrete evolution of a differential action " | ||
| 53 | "model.\n\n" | ||
| 54 | "It describes the time-discrete evolution of action model.\n" | ||
| 55 | ":param data: action data\n" | ||
| 56 | ":param x: state point (dim. state.nx)\n" | ||
| 57 | ":param u: control input (dim. nu)") | ||
| 58 | ✗ | .def("calc", | |
| 59 | static_cast<void (Model::*)(const std::shared_ptr<Data>&, | ||
| 60 | const Eigen::Ref<const VectorXs>&)>( | ||
| 61 | &Model::calc), | ||
| 62 | bp::args("self", "data", "x")) | ||
| 63 | ✗ | .def( | |
| 64 | "calcDiff", | ||
| 65 | static_cast<void (Model::*)( | ||
| 66 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 67 | const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), | ||
| 68 | bp::args("self", "data", "x", "u"), | ||
| 69 | "Computes the derivatives of the integrated action model wrt state " | ||
| 70 | "and control. \n\n" | ||
| 71 | "This function builds a quadratic approximation of the action " | ||
| 72 | "model (i.e. dynamical system and cost function). It assumes that " | ||
| 73 | "calc has been run first.\n" | ||
| 74 | ":param data: action data\n" | ||
| 75 | ":param x: state point (dim. state.nx)\n" | ||
| 76 | ":param u: control input (dim. nu)") | ||
| 77 | ✗ | .def("calcDiff", | |
| 78 | static_cast<void (Model::*)(const std::shared_ptr<Data>&, | ||
| 79 | const Eigen::Ref<const VectorXs>&)>( | ||
| 80 | &Model::calcDiff), | ||
| 81 | bp::args("self", "data", "x")) | ||
| 82 | ✗ | .def("createData", &Model::createData, bp::args("self"), | |
| 83 | "Create the RK integrator data.") | ||
| 84 | ✗ | .add_property( | |
| 85 | "ni", | ||
| 86 | bp::make_function(&Model::get_ni, | ||
| 87 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 88 | "number of nodes to be integrated") | ||
| 89 | ✗ | .add_property( | |
| 90 | "ng", bp::make_function(&Model::get_ng), "number of equality constraints") | ||
| 91 | ✗ | .add_property( | |
| 92 | "nh", bp::make_function(&Model::get_nh), "number of inequality constraints") | ||
| 93 | ✗ | .add_property( | |
| 94 | "ng_T", bp::make_function(&Model::get_ng_T), "number of equality terminal constraints") | ||
| 95 | ✗ | .add_property( | |
| 96 | "nh_T", bp::make_function(&Model::get_nh_T), "number of inequality terminal constraints"); | ||
| 97 | ✗ | } | |
| 98 | }; | ||
| 99 | |||
| 100 | template <typename Data> | ||
| 101 | struct IntegratedActionDataRKVisitor | ||
| 102 | : public bp::def_visitor<IntegratedActionDataRKVisitor<Data>> { | ||
| 103 | template <class PyClass> | ||
| 104 | ✗ | void visit(PyClass& cl) const { | |
| 105 | ✗ | cl.add_property( | |
| 106 | "differential", | ||
| 107 | ✗ | bp::make_getter(&Data::differential, | |
| 108 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 109 | "list of differential action data") | ||
| 110 | ✗ | .add_property( | |
| 111 | "control", | ||
| 112 | ✗ | bp::make_getter(&Data::control, | |
| 113 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 114 | "list of control parametrization data") | ||
| 115 | ✗ | .add_property( | |
| 116 | "integral", | ||
| 117 | ✗ | bp::make_getter(&Data::integral, | |
| 118 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 119 | "list of RK terms related to the cost") | ||
| 120 | ✗ | .add_property( | |
| 121 | ✗ | "dx", bp::make_getter(&Data::dx, bp::return_internal_reference<>()), | |
| 122 | "state rate.") | ||
| 123 | ✗ | .add_property( | |
| 124 | ✗ | "ki", bp::make_getter(&Data::ki, bp::return_internal_reference<>()), | |
| 125 | "list of RK terms related to system dynamics") | ||
| 126 | ✗ | .add_property( | |
| 127 | ✗ | "y", bp::make_getter(&Data::y, bp::return_internal_reference<>()), | |
| 128 | "list of states where f is evaluated in the RK integration") | ||
| 129 | ✗ | .add_property( | |
| 130 | ✗ | "ws", bp::make_getter(&Data::ws, bp::return_internal_reference<>()), | |
| 131 | "control inputs evaluated in the RK integration") | ||
| 132 | ✗ | .add_property( | |
| 133 | "dki_dx", | ||
| 134 | ✗ | bp::make_getter(&Data::dki_dx, bp::return_internal_reference<>()), | |
| 135 | "list of partial derivatives of RK nodes with respect to the state " | ||
| 136 | "of the RK integration. dki/dx") | ||
| 137 | ✗ | .add_property( | |
| 138 | "dki_du", | ||
| 139 | ✗ | bp::make_getter(&Data::dki_du, bp::return_internal_reference<>()), | |
| 140 | "list of partial derivatives of RK nodes with respect to the " | ||
| 141 | "control parameters of the RK integration. dki/du") | ||
| 142 | ✗ | .add_property( | |
| 143 | "dyi_dx", | ||
| 144 | ✗ | bp::make_getter(&Data::dyi_dx, bp::return_internal_reference<>()), | |
| 145 | "list of partial derivatives of RK dynamics with respect to the " | ||
| 146 | "state of the RK integrator. dyi/dx") | ||
| 147 | ✗ | .add_property( | |
| 148 | "dyi_du", | ||
| 149 | ✗ | bp::make_getter(&Data::dyi_du, bp::return_internal_reference<>()), | |
| 150 | "list of partial derivatives of RK dynamics with respect to the " | ||
| 151 | "control parameters of the RK integrator. dyi/du") | ||
| 152 | ✗ | .add_property( | |
| 153 | "dli_dx", | ||
| 154 | ✗ | bp::make_getter(&Data::dli_dx, bp::return_internal_reference<>()), | |
| 155 | "list of partial derivatives of the cost with respect to the state " | ||
| 156 | "of the RK integration. dli_dx") | ||
| 157 | ✗ | .add_property( | |
| 158 | "dli_du", | ||
| 159 | ✗ | bp::make_getter(&Data::dli_du, bp::return_internal_reference<>()), | |
| 160 | "list of partial derivatives of the cost with respect to the " | ||
| 161 | "control input of the RK integration. dli_du") | ||
| 162 | ✗ | .add_property( | |
| 163 | "ddli_ddx", | ||
| 164 | ✗ | bp::make_getter(&Data::ddli_ddx, bp::return_internal_reference<>()), | |
| 165 | "list of second partial derivatives of the cost with respect to " | ||
| 166 | "the state of the RK integration. ddli_ddx") | ||
| 167 | ✗ | .add_property( | |
| 168 | "ddli_ddw", | ||
| 169 | ✗ | bp::make_getter(&Data::ddli_ddw, bp::return_internal_reference<>()), | |
| 170 | "list of second partial derivatives of the cost with respect to " | ||
| 171 | "the control of the differential action model w. ddli_ddw") | ||
| 172 | ✗ | .add_property( | |
| 173 | "ddli_ddu", | ||
| 174 | ✗ | bp::make_getter(&Data::ddli_ddu, bp::return_internal_reference<>()), | |
| 175 | "list of second partial derivatives of the cost with respect to " | ||
| 176 | "the control input of the RK integration. ddli_ddu") | ||
| 177 | ✗ | .add_property( | |
| 178 | "ddli_dxdw", | ||
| 179 | ✗ | bp::make_getter(&Data::ddli_dxdw, | |
| 180 | ✗ | bp::return_internal_reference<>()), | |
| 181 | "list of second partial derivatives of the cost with respect to " | ||
| 182 | "the state and control of the differential action model. ddli_dxdw") | ||
| 183 | ✗ | .add_property( | |
| 184 | "ddli_dxdu", | ||
| 185 | ✗ | bp::make_getter(&Data::ddli_dxdu, | |
| 186 | ✗ | bp::return_internal_reference<>()), | |
| 187 | "list of second partial derivatives of the cost with respect to " | ||
| 188 | "the state and control input of the RK integration. ddli_dxdu") | ||
| 189 | ✗ | .add_property( | |
| 190 | "ddli_dwdu", | ||
| 191 | ✗ | bp::make_getter(&Data::ddli_dwdu, | |
| 192 | ✗ | bp::return_internal_reference<>()), | |
| 193 | "list of second partial derivatives of the cost with respect to " | ||
| 194 | "the control of the differential action model and the control " | ||
| 195 | "inputs of the RK integration. ddli_dwdu"); | ||
| 196 | ✗ | } | |
| 197 | }; | ||
| 198 | |||
| 199 | #define CROCODDYL_INTACTION_MODEL_RK_PYTHON_BINDINGS(Scalar) \ | ||
| 200 | typedef IntegratedActionModelRKTpl<Scalar> Model; \ | ||
| 201 | typedef IntegratedActionModelAbstractTpl<Scalar> ModelBase; \ | ||
| 202 | typedef ActionModelAbstractTpl<Scalar> ActionBase; \ | ||
| 203 | typedef DifferentialActionModelAbstractTpl<Scalar> DiffActionBase; \ | ||
| 204 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 205 | bp::class_<Model, bp::bases<ModelBase, ActionBase>>( \ | ||
| 206 | "IntegratedActionModelRK", \ | ||
| 207 | "RK integrator for differential action models.\n\n" \ | ||
| 208 | "This class implements different RK integrator schemes. The available " \ | ||
| 209 | "integrators are: RK2, RK3, and RK4.", \ | ||
| 210 | bp::init<std::shared_ptr<DiffActionBase>, RKType, \ | ||
| 211 | bp::optional<Scalar, bool>>( \ | ||
| 212 | bp::args("self", "diffModel", "rktype", "stepTime", \ | ||
| 213 | "withCostResidual"), \ | ||
| 214 | "Initialize the RK integrator.\n\n" \ | ||
| 215 | ":param diffModel: differential action model\n" \ | ||
| 216 | ":param rktype: type of RK integrator (options are two, three, and " \ | ||
| 217 | "four)\n" \ | ||
| 218 | ":param stepTime: step time (default 1e-3)\n" \ | ||
| 219 | ":param withCostResidual: includes the cost residuals and " \ | ||
| 220 | "derivatives (default True).")) \ | ||
| 221 | .def(IntegratedActionModelRKVisitor<Model>()) \ | ||
| 222 | .def(CastVisitor<Model>()) \ | ||
| 223 | .def(PrintableVisitor<Model>()) \ | ||
| 224 | .def(CopyableVisitor<Model>()); | ||
| 225 | |||
| 226 | #define CROCODDYL_INTACTION_DATA_RK_PYTHON_BINDINGS(Scalar) \ | ||
| 227 | typedef IntegratedActionDataRKTpl<Scalar> Data; \ | ||
| 228 | typedef IntegratedActionDataAbstractTpl<Scalar> DataBase; \ | ||
| 229 | typedef IntegratedActionModelRKTpl<Scalar> Model; \ | ||
| 230 | bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ | ||
| 231 | bp::class_<Data, bp::bases<DataBase>>( \ | ||
| 232 | "IntegratedActionDataRK", "RK integrator data.", \ | ||
| 233 | bp::init<Model*>(bp::args("self", "model"), \ | ||
| 234 | "Create RK integrator data.\n\n" \ | ||
| 235 | ":param model: RK integrator model")) \ | ||
| 236 | .def(IntegratedActionDataRKVisitor<Data>()) \ | ||
| 237 | .def(CopyableVisitor<Data>()); | ||
| 238 | |||
| 239 | ✗ | void exposeIntegratedActionRK() { | |
| 240 | #ifdef SCALAR_float64 | ||
| 241 | ✗ | bp::enum_<RKType>("RKType") | |
| 242 | ✗ | .value("two", two) | |
| 243 | ✗ | .value("three", three) | |
| 244 | ✗ | .value("four", four) | |
| 245 | ✗ | .export_values(); | |
| 246 | #endif | ||
| 247 | |||
| 248 | ✗ | CROCODDYL_INTACTION_MODEL_RK_PYTHON_BINDINGS(double) | |
| 249 | ✗ | CROCODDYL_INTACTION_DATA_RK_PYTHON_BINDINGS(double) | |
| 250 | ✗ | } | |
| 251 | |||
| 252 | } // namespace python | ||
| 253 | } // namespace crocoddyl | ||
| 254 |