| 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/multibody/residuals/frame-velocity.hpp" | ||
| 11 | |||
| 12 | #include "python/crocoddyl/multibody/multibody.hpp" | ||
| 13 | |||
| 14 | namespace crocoddyl { | ||
| 15 | namespace python { | ||
| 16 | |||
| 17 | template <typename Model> | ||
| 18 | struct ResidualModelFrameVelocityVisitor | ||
| 19 | : public bp::def_visitor<ResidualModelFrameVelocityVisitor<Model>> { | ||
| 20 | typedef typename Model::ResidualDataAbstract Data; | ||
| 21 | typedef typename Model::Base ModelBase; | ||
| 22 | typedef typename Model::StateMultibody State; | ||
| 23 | typedef typename Model::Motion Motion; | ||
| 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>, pinocchio::FrameIndex, Motion, | |
| 28 | pinocchio::ReferenceFrame>( | ||
| 29 | bp::args("self", "state", "id", "velocity", "type"), | ||
| 30 | "Initialize the frame velocity residual model.\n\n" | ||
| 31 | ":param state: state of the multibody system\n" | ||
| 32 | ":param residual: residual model\n" | ||
| 33 | ":param id: reference frame id\n" | ||
| 34 | ":param velocity: reference velocity\n" | ||
| 35 | ":param type: reference type of velocity")) | ||
| 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 | "Compute the frame velocity residual.\n\n" | ||
| 42 | ":param data: residual data\n" | ||
| 43 | ":param x: state point (dim. state.nx)\n" | ||
| 44 | ":param u: control input (dim. nu)") | ||
| 45 | ✗ | .def( | |
| 46 | "calc", | ||
| 47 | static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&, | ||
| 48 | const Eigen::Ref<const VectorXs>&)>( | ||
| 49 | &ModelBase::calc), | ||
| 50 | bp::args("self", "data", "x")) | ||
| 51 | ✗ | .def( | |
| 52 | "calcDiff", | ||
| 53 | static_cast<void (Model::*)( | ||
| 54 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 55 | const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), | ||
| 56 | bp::args("self", "data", "x", "u"), | ||
| 57 | "Compute the Jacobians of the frame velocity residual.\n\n" | ||
| 58 | "It assumes that calc has been run first.\n" | ||
| 59 | ":param data: action data\n" | ||
| 60 | ":param x: state point (dim. state.nx)\n" | ||
| 61 | ":param u: control input (dim. nu)") | ||
| 62 | ✗ | .def( | |
| 63 | "calcDiff", | ||
| 64 | static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&, | ||
| 65 | const Eigen::Ref<const VectorXs>&)>( | ||
| 66 | &ModelBase::calcDiff), | ||
| 67 | bp::args("self", "data", "x")) | ||
| 68 | ✗ | .def("createData", &Model::createData, | |
| 69 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
| 70 | bp::args("self", "data"), | ||
| 71 | "Create the frame velocity residual data.\n\n" | ||
| 72 | "Each residual model has its own data that needs to be allocated. " | ||
| 73 | "This function\n" | ||
| 74 | "returns the allocated data for the frame velocity residual.\n" | ||
| 75 | ":param data: shared data\n" | ||
| 76 | ":return residual data.") | ||
| 77 | ✗ | .add_property("id", &Model::get_id, &Model::set_id, | |
| 78 | "reference frame id") | ||
| 79 | ✗ | .add_property("reference", | |
| 80 | bp::make_function(&Model::get_reference, | ||
| 81 | ✗ | bp::return_internal_reference<>()), | |
| 82 | &Model::set_reference, "reference velocity") | ||
| 83 | ✗ | .add_property("type", &Model::get_type, &Model::set_type, | |
| 84 | "reference type of velocity"); | ||
| 85 | ✗ | } | |
| 86 | }; | ||
| 87 | |||
| 88 | template <typename Data> | ||
| 89 | struct ResidualDataFrameVelocityVisitor | ||
| 90 | : public bp::def_visitor<ResidualDataFrameVelocityVisitor<Data>> { | ||
| 91 | template <class PyClass> | ||
| 92 | ✗ | void visit(PyClass& cl) const { | |
| 93 | ✗ | cl.add_property( | |
| 94 | "pinocchio", | ||
| 95 | ✗ | bp::make_getter(&Data::pinocchio, bp::return_internal_reference<>()), | |
| 96 | "pinocchio data"); | ||
| 97 | ✗ | } | |
| 98 | }; | ||
| 99 | |||
| 100 | #define CROCODDYL_RESIDUAL_MODEL_FRAME_VELOCITY_PYTHON_BINDINGS(Scalar) \ | ||
| 101 | typedef ResidualModelFrameVelocityTpl<Scalar> Model; \ | ||
| 102 | typedef ResidualModelAbstractTpl<Scalar> ModelBase; \ | ||
| 103 | typedef typename Model::StateMultibody State; \ | ||
| 104 | typedef typename Model::Motion Motion; \ | ||
| 105 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 106 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
| 107 | "ResidualModelFrameVelocity", \ | ||
| 108 | "This residual function defines r = v - vref, with v and vref as the " \ | ||
| 109 | "current and reference frame velocities, respectively.", \ | ||
| 110 | bp::init<std::shared_ptr<State>, std::size_t, Motion, \ | ||
| 111 | pinocchio::ReferenceFrame, std::size_t>( \ | ||
| 112 | bp::args("self", "state", "id", "velocity", "type", "nu"), \ | ||
| 113 | "Initialize the frame velocity residual model.\n\n" \ | ||
| 114 | ":param state: state of the multibody system\n" \ | ||
| 115 | ":param residual: residual model\n" \ | ||
| 116 | ":param id: reference frame id\n" \ | ||
| 117 | ":param velocity: reference velocity\n" \ | ||
| 118 | ":param type: reference type of velocity\n" \ | ||
| 119 | ":param nu: dimension of control vector")) \ | ||
| 120 | .def(ResidualModelFrameVelocityVisitor<Model>()) \ | ||
| 121 | .def(CastVisitor<Model>()) \ | ||
| 122 | .def(PrintableVisitor<Model>()) \ | ||
| 123 | .def(CopyableVisitor<Model>()); | ||
| 124 | |||
| 125 | #define CROCODDYL_RESIDUAL_DATA_FRAME_VELOCITY_PYTHON_BINDINGS(Scalar) \ | ||
| 126 | typedef ResidualDataFrameVelocityTpl<Scalar> Data; \ | ||
| 127 | typedef ResidualDataAbstractTpl<Scalar> DataBase; \ | ||
| 128 | typedef ResidualModelFrameVelocityTpl<Scalar> Model; \ | ||
| 129 | typedef Model::DataCollectorAbstract DataCollector; \ | ||
| 130 | bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ | ||
| 131 | bp::class_<Data, bp::bases<DataBase>>( \ | ||
| 132 | "ResidualDataFrameVelocity", "Data for frame velocity residual.\n\n", \ | ||
| 133 | bp::init<Model*, DataCollector*>( \ | ||
| 134 | bp::args("self", "model", "data"), \ | ||
| 135 | "Create frame velocity residual data.\n\n" \ | ||
| 136 | ":param model: frame Velocity residual model\n" \ | ||
| 137 | ":param data: shared data")[bp::with_custodian_and_ward< \ | ||
| 138 | 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \ | ||
| 139 | .def(ResidualDataFrameVelocityVisitor<Data>()) \ | ||
| 140 | .def(CopyableVisitor<Data>()); | ||
| 141 | |||
| 142 | ✗ | void exposeResidualFrameVelocity() { | |
| 143 | ✗ | CROCODDYL_RESIDUAL_MODEL_FRAME_VELOCITY_PYTHON_BINDINGS(float) | |
| 144 | ✗ | CROCODDYL_RESIDUAL_DATA_FRAME_VELOCITY_PYTHON_BINDINGS(float) | |
| 145 | ✗ | } | |
| 146 | |||
| 147 | } // namespace python | ||
| 148 | } // namespace crocoddyl | ||
| 149 |