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