| 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/multibody/residuals/impulse-com.hpp" | ||
| 11 | |||
| 12 | #include "python/crocoddyl/multibody/multibody.hpp" | ||
| 13 | |||
| 14 | namespace crocoddyl { | ||
| 15 | namespace python { | ||
| 16 | |||
| 17 | template <typename Model> | ||
| 18 | struct ResidualModelImpulseCoMVisitor | ||
| 19 | : public bp::def_visitor<ResidualModelImpulseCoMVisitor<Model>> { | ||
| 20 | typedef typename Model::ResidualDataAbstract Data; | ||
| 21 | typedef typename Model::Base ModelBase; | ||
| 22 | typedef typename Model::VectorXs VectorXs; | ||
| 23 | template <class PyClass> | ||
| 24 | ✗ | void visit(PyClass& cl) const { | |
| 25 | ✗ | cl.def("calc", | |
| 26 | static_cast<void (Model::*)( | ||
| 27 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 28 | const Eigen::Ref<const VectorXs>&)>(&Model::calc), | ||
| 29 | bp::args("self", "data", "x", "u"), | ||
| 30 | "Compute the CoM position residual.\n\n" | ||
| 31 | ":param data: residual data\n" | ||
| 32 | ":param x: state point (dim. state.nx)") | ||
| 33 | ✗ | .def( | |
| 34 | "calc", | ||
| 35 | static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&, | ||
| 36 | const Eigen::Ref<const VectorXs>&)>( | ||
| 37 | &ModelBase::calc), | ||
| 38 | bp::args("self", "data", "x")) | ||
| 39 | ✗ | .def( | |
| 40 | "calcDiff", | ||
| 41 | static_cast<void (Model::*)( | ||
| 42 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 43 | const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), | ||
| 44 | bp::args("self", "data", "x", "u"), | ||
| 45 | "Compute the derivatives of the CoM position residual for impulse " | ||
| 46 | "dynamics.\n\n" | ||
| 47 | "It assumes that calc has been run first.\n" | ||
| 48 | ":param data: action data\n" | ||
| 49 | ":param x: state point (dim. state.nx)") | ||
| 50 | ✗ | .def( | |
| 51 | "calcDiff", | ||
| 52 | static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&, | ||
| 53 | const Eigen::Ref<const VectorXs>&)>( | ||
| 54 | &ModelBase::calcDiff), | ||
| 55 | bp::args("self", "data", "x")) | ||
| 56 | ✗ | .def("createData", &Model::createData, | |
| 57 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
| 58 | bp::args("self", "data"), | ||
| 59 | "Create the CoM position residual data.\n\n" | ||
| 60 | "Each residual model has its own data that needs to be allocated. " | ||
| 61 | "This function returns the allocated data for the impulse CoM " | ||
| 62 | "residual.\n" | ||
| 63 | ":param data: shared data\n" | ||
| 64 | ":return residual data."); | ||
| 65 | ✗ | } | |
| 66 | }; | ||
| 67 | |||
| 68 | template <typename Data> | ||
| 69 | struct ResidualDataImpulseCoMVisitor | ||
| 70 | : public bp::def_visitor<ResidualDataImpulseCoMVisitor<Data>> { | ||
| 71 | template <class PyClass> | ||
| 72 | ✗ | void visit(PyClass& cl) const { | |
| 73 | ✗ | cl.add_property( | |
| 74 | "pinocchio", | ||
| 75 | ✗ | bp::make_getter(&Data::pinocchio, bp::return_internal_reference<>()), | |
| 76 | "pinocchio data") | ||
| 77 | ✗ | .add_property( | |
| 78 | "impulses", | ||
| 79 | ✗ | bp::make_getter(&Data::impulses, | |
| 80 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 81 | ✗ | bp::make_setter(&Data::impulses), | |
| 82 | "impulses data associated with the current residual") | ||
| 83 | ✗ | .add_property( | |
| 84 | "dvc_dq", | ||
| 85 | ✗ | bp::make_getter(&Data::dvc_dq, bp::return_internal_reference<>()), | |
| 86 | "Jacobian of the CoM velocity") | ||
| 87 | ✗ | .add_property( | |
| 88 | "ddv_dv", | ||
| 89 | ✗ | bp::make_getter(&Data::ddv_dv, bp::return_internal_reference<>()), | |
| 90 | "Jacobian of the impulse velocity") | ||
| 91 | ✗ | .add_property("pinocchio_internal", | |
| 92 | ✗ | bp::make_getter(&Data::pinocchio_internal, | |
| 93 | ✗ | bp::return_internal_reference<>()), | |
| 94 | "internal pinocchio data used for extra computations"); | ||
| 95 | ✗ | } | |
| 96 | }; | ||
| 97 | |||
| 98 | #define CROCODDYL_RESIDUAL_MODEL_IMPULSE_COM_PYTHON_BINDINGS(Scalar) \ | ||
| 99 | typedef ResidualModelImpulseCoMTpl<Scalar> Model; \ | ||
| 100 | typedef ResidualModelAbstractTpl<Scalar> ModelBase; \ | ||
| 101 | typedef typename Model::StateMultibody State; \ | ||
| 102 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 103 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
| 104 | "ResidualModelImpulseCoM", \ | ||
| 105 | "This residual function defines a residual vector as r = Jcom * " \ | ||
| 106 | "(vnext-v), with Jcom as the CoM Jacobian, and vnext the velocity " \ | ||
| 107 | "after impact and v the velocity before impact, respectively.", \ | ||
| 108 | bp::init<std::shared_ptr<State>>( \ | ||
| 109 | bp::args("self", "state"), \ | ||
| 110 | "Initialize the CoM position cost model for impulse dynamics.\n\n" \ | ||
| 111 | "The default nu is obtained from state.nv.\n" \ | ||
| 112 | ":param state: state of the multibody system")) \ | ||
| 113 | .def(ResidualModelImpulseCoMVisitor<Model>()) \ | ||
| 114 | .def(CastVisitor<Model>()) \ | ||
| 115 | .def(PrintableVisitor<Model>()) \ | ||
| 116 | .def(CopyableVisitor<Model>()); | ||
| 117 | |||
| 118 | #define CROCODDYL_RESIDUAL_DATA_IMPULSE_COM_PYTHON_BINDINGS(Scalar) \ | ||
| 119 | typedef ResidualDataImpulseCoMTpl<Scalar> Data; \ | ||
| 120 | typedef ResidualDataAbstractTpl<Scalar> DataBase; \ | ||
| 121 | typedef ResidualModelImpulseCoMTpl<Scalar> Model; \ | ||
| 122 | typedef Model::DataCollectorAbstract DataCollector; \ | ||
| 123 | bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ | ||
| 124 | bp::class_<Data, bp::bases<DataBase>>( \ | ||
| 125 | "ResidualDataImpulseCoM", "Data for impulse CoM residual.\n\n", \ | ||
| 126 | bp::init<Model*, DataCollector*>( \ | ||
| 127 | bp::args("self", "model", "data"), \ | ||
| 128 | "Create contact force residual data.\n\n" \ | ||
| 129 | ":param model: impulse CoM residual model\n" \ | ||
| 130 | ":param data: shared data")[bp::with_custodian_and_ward< \ | ||
| 131 | 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \ | ||
| 132 | .def(ResidualDataImpulseCoMVisitor<Data>()) \ | ||
| 133 | .def(CopyableVisitor<Data>()); | ||
| 134 | |||
| 135 | ✗ | void exposeResidualImpulseCoM() { | |
| 136 | ✗ | CROCODDYL_RESIDUAL_MODEL_IMPULSE_COM_PYTHON_BINDINGS(double) | |
| 137 | ✗ | CROCODDYL_RESIDUAL_DATA_IMPULSE_COM_PYTHON_BINDINGS(double) | |
| 138 | ✗ | } | |
| 139 | |||
| 140 | } // namespace python | ||
| 141 | } // namespace crocoddyl | ||
| 142 |