| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2020-2025, LAAS-CNRS, University of Edinburgh | ||
| 5 | // Heriot-Watt University | ||
| 6 | // Copyright note valid unless otherwise stated in individual files. | ||
| 7 | // All rights reserved. | ||
| 8 | /////////////////////////////////////////////////////////////////////////////// | ||
| 9 | |||
| 10 | // Auto-generated file for float | ||
| 11 | #include "crocoddyl/multibody/contacts/contact-1d.hpp" | ||
| 12 | |||
| 13 | #include "python/crocoddyl/multibody/multibody.hpp" | ||
| 14 | |||
| 15 | namespace crocoddyl { | ||
| 16 | namespace python { | ||
| 17 | |||
| 18 | template <typename Model> | ||
| 19 | struct ContactModel1DVisitor | ||
| 20 | : public bp::def_visitor<ContactModel1DVisitor<Model>> { | ||
| 21 | typedef typename Model::Scalar Scalar; | ||
| 22 | typedef typename Model::StateMultibody State; | ||
| 23 | typedef typename Model::Vector2s Vector2s; | ||
| 24 | template <class PyClass> | ||
| 25 | ✗ | void visit(PyClass& cl) const { | |
| 26 | ✗ | cl.def(bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, Scalar, | |
| 27 | pinocchio::ReferenceFrame, bp::optional<Vector2s>>( | ||
| 28 | bp::args("self", "state", "id", "xref", "type", "gains"), | ||
| 29 | "Initialize the contact model.\n\n" | ||
| 30 | ":param state: state of the multibody system\n" | ||
| 31 | ":param id: reference frame id of the contact\n" | ||
| 32 | ":param xref: contact position used for the Baumgarte " | ||
| 33 | "stabilization\n" | ||
| 34 | ":param type: type of contact\n" | ||
| 35 | ":param gains: gains of the contact model (default " | ||
| 36 | "np.matrix([0.,0.]))")) | ||
| 37 | ✗ | .def("calc", &Model::calc, bp::args("self", "data", "x"), | |
| 38 | "Compute the 1D contact Jacobian and drift.\n\n" | ||
| 39 | "The rigid contact model throught acceleration-base holonomic " | ||
| 40 | "constraint of the contact frame placement.\n" | ||
| 41 | ":param data: contact data\n" | ||
| 42 | ":param x: state point (dim. state.nx)") | ||
| 43 | ✗ | .def("calcDiff", &Model::calcDiff, bp::args("self", "data", "x"), | |
| 44 | "Compute the derivatives of the 1D contact holonomic " | ||
| 45 | "constraint.\n\n" | ||
| 46 | "The rigid contact model throught acceleration-base holonomic " | ||
| 47 | "constraint of the contact frame placement. It assumes that calc " | ||
| 48 | "has been run first.\n" | ||
| 49 | ":param data: cost data\n" | ||
| 50 | ":param x: state point (dim. state.nx)") | ||
| 51 | ✗ | .def("updateForce", &Model::updateForce, | |
| 52 | bp::args("self", "data", "force"), | ||
| 53 | "Convert the force into a stack of spatial forces.\n\n" | ||
| 54 | ":param data: cost data\n" | ||
| 55 | ":param force: force vector (dimension 1)") | ||
| 56 | ✗ | .def("createData", &Model::createData, | |
| 57 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
| 58 | bp::args("self", "data"), | ||
| 59 | "Create the 1D contact data.\n\n" | ||
| 60 | "Each contact model has its own data that needs to be allocated. " | ||
| 61 | "This function returns the allocated data for a predefined cost.\n" | ||
| 62 | ":param data: Pinocchio data\n" | ||
| 63 | ":return contact data.") | ||
| 64 | ✗ | .add_property( | |
| 65 | "reference", | ||
| 66 | bp::make_function(&Model::get_reference, | ||
| 67 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 68 | &Model::set_reference, "reference contact translation") | ||
| 69 | ✗ | .add_property("Raxis", | |
| 70 | bp::make_function(&Model::get_axis_rotation, | ||
| 71 | ✗ | bp::return_internal_reference<>()), | |
| 72 | &Model::set_axis_rotation, | ||
| 73 | "rotation of the reference frame's z axis") | ||
| 74 | ✗ | .add_property( | |
| 75 | "gains", | ||
| 76 | bp::make_function(&Model::get_gains, | ||
| 77 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 78 | "contact gains"); | ||
| 79 | ✗ | } | |
| 80 | }; | ||
| 81 | |||
| 82 | template <typename Data> | ||
| 83 | struct ContactData1DVisitor | ||
| 84 | : public bp::def_visitor<ContactData1DVisitor<Data>> { | ||
| 85 | template <class PyClass> | ||
| 86 | ✗ | void visit(PyClass& cl) const { | |
| 87 | ✗ | cl.add_property( | |
| 88 | "v", | ||
| 89 | ✗ | bp::make_getter(&Data::v, | |
| 90 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 91 | "spatial velocity of the contact body") | ||
| 92 | ✗ | .add_property( | |
| 93 | "a0_local", | ||
| 94 | ✗ | bp::make_getter(&Data::a0_local, bp::return_internal_reference<>()), | |
| 95 | ✗ | bp::make_setter(&Data::a0_local), | |
| 96 | "desired local contact acceleration") | ||
| 97 | ✗ | .add_property( | |
| 98 | "a0_skew", | ||
| 99 | ✗ | bp::make_getter(&Data::a0_skew, bp::return_internal_reference<>()), | |
| 100 | ✗ | bp::make_setter(&Data::a0_skew), | |
| 101 | "contact acceleration skew (local)") | ||
| 102 | ✗ | .add_property("a0_world_skew", | |
| 103 | ✗ | bp::make_getter(&Data::a0_world_skew, | |
| 104 | ✗ | bp::return_internal_reference<>()), | |
| 105 | ✗ | bp::make_setter(&Data::a0_world_skew), | |
| 106 | "contact acceleration skew (world)") | ||
| 107 | ✗ | .add_property( | |
| 108 | ✗ | "dp", bp::make_getter(&Data::dp, bp::return_internal_reference<>()), | |
| 109 | ✗ | bp::make_setter(&Data::dp), | |
| 110 | "Translation error computed for the Baumgarte regularization term") | ||
| 111 | ✗ | .add_property( | |
| 112 | "dp_local", | ||
| 113 | ✗ | bp::make_getter(&Data::dp_local, bp::return_internal_reference<>()), | |
| 114 | ✗ | bp::make_setter(&Data::dp_local), | |
| 115 | "local translation error computed for the Baumgarte " | ||
| 116 | "regularization term") | ||
| 117 | ✗ | .add_property( | |
| 118 | "f_local", | ||
| 119 | ✗ | bp::make_getter(&Data::f_local, bp::return_internal_reference<>()), | |
| 120 | ✗ | bp::make_setter(&Data::f_local), | |
| 121 | "spatial contact force in local coordinates") | ||
| 122 | ✗ | .add_property("da0_local_dx", | |
| 123 | ✗ | bp::make_getter(&Data::da0_local_dx, | |
| 124 | ✗ | bp::return_internal_reference<>()), | |
| 125 | ✗ | bp::make_setter(&Data::da0_local_dx), | |
| 126 | "Jacobian of the desired local contact acceleration") | ||
| 127 | ✗ | .add_property( | |
| 128 | "fJf", | ||
| 129 | ✗ | bp::make_getter(&Data::fJf, bp::return_internal_reference<>()), | |
| 130 | "local Jacobian of the contact frame") | ||
| 131 | ✗ | .add_property("v_partial_dq", | |
| 132 | ✗ | bp::make_getter(&Data::v_partial_dq, | |
| 133 | ✗ | bp::return_internal_reference<>()), | |
| 134 | "Jacobian of the spatial body velocity") | ||
| 135 | ✗ | .add_property("a_partial_dq", | |
| 136 | ✗ | bp::make_getter(&Data::a_partial_dq, | |
| 137 | ✗ | bp::return_internal_reference<>()), | |
| 138 | "Jacobian of the spatial body acceleration") | ||
| 139 | ✗ | .add_property("a_partial_dv", | |
| 140 | ✗ | bp::make_getter(&Data::a_partial_dv, | |
| 141 | ✗ | bp::return_internal_reference<>()), | |
| 142 | "Jacobian of the spatial body acceleration") | ||
| 143 | ✗ | .add_property("a_partial_da", | |
| 144 | ✗ | bp::make_getter(&Data::a_partial_da, | |
| 145 | ✗ | bp::return_internal_reference<>()), | |
| 146 | "Jacobian of the spatial body acceleration") | ||
| 147 | ✗ | .add_property( | |
| 148 | "oRf", | ||
| 149 | ✗ | bp::make_getter(&Data::oRf, bp::return_internal_reference<>()), | |
| 150 | "Rotation matrix of the contact body expressed in the world frame"); | ||
| 151 | ✗ | } | |
| 152 | }; | ||
| 153 | |||
| 154 | #define CROCODDYL_CONTACT_MODEL_1D_PYTHON_BINDINGS(Scalar) \ | ||
| 155 | typedef ContactModel1DTpl<Scalar> Model; \ | ||
| 156 | typedef ContactModelAbstractTpl<Scalar> ModelBase; \ | ||
| 157 | typedef Model::StateMultibody State; \ | ||
| 158 | typedef Model::Vector2s Vector2s; \ | ||
| 159 | typedef Model::Matrix3s Matrix3s; \ | ||
| 160 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 161 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
| 162 | "ContactModel1D", \ | ||
| 163 | "Rigid 1D contact model.\n\n" \ | ||
| 164 | "It defines a rigid 1D contact model (point contact) based on " \ | ||
| 165 | "acceleration-based holonomic constraints, in the z direction. The " \ | ||
| 166 | "calc and calcDiff functions compute the contact Jacobian and drift " \ | ||
| 167 | "(holonomic constraint) or the derivatives of the holonomic " \ | ||
| 168 | "constraint, respectively.", \ | ||
| 169 | bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, Scalar, \ | ||
| 170 | pinocchio::ReferenceFrame, Matrix3s, std::size_t, \ | ||
| 171 | bp::optional<Vector2s>>( \ | ||
| 172 | bp::args("self", "state", "id", "xref", "type", "rotation", "nu", \ | ||
| 173 | "gains"), \ | ||
| 174 | "Initialize the contact model.\n\n" \ | ||
| 175 | ":param state: state of the multibody system\n" \ | ||
| 176 | ":param id: reference frame id of the contact\n" \ | ||
| 177 | ":param xref: contact position used for the Baumgarte " \ | ||
| 178 | "stabilization\n" \ | ||
| 179 | ":param type: type of contact\n" \ | ||
| 180 | ":param rotation: rotation of the reference frame's z axis\n" \ | ||
| 181 | ":param nu: dimension of control vector\n" \ | ||
| 182 | ":param gains: gains of the contact model (default " \ | ||
| 183 | "np.matrix([0.,0.]))")) \ | ||
| 184 | .def(ContactModel1DVisitor<Model>()) \ | ||
| 185 | .def(CastVisitor<Model>()) \ | ||
| 186 | .def(PrintableVisitor<Model>()) \ | ||
| 187 | .def(CopyableVisitor<Model>()); | ||
| 188 | |||
| 189 | #define CROCODDYL_CONTACT_DATA_1D_PYTHON_BINDINGS(Scalar) \ | ||
| 190 | typedef ContactData1DTpl<Scalar> Data; \ | ||
| 191 | typedef ContactDataAbstractTpl<Scalar> DataBase; \ | ||
| 192 | typedef ContactModel1DTpl<Scalar> Model; \ | ||
| 193 | typedef pinocchio::DataTpl<Scalar> PinocchioData; \ | ||
| 194 | bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ | ||
| 195 | bp::class_<Data, bp::bases<DataBase>>( \ | ||
| 196 | "ContactData1D", "Data for 1D contact.\n\n", \ | ||
| 197 | bp::init<Model*, PinocchioData*>( \ | ||
| 198 | bp::args("self", "model", "data"), \ | ||
| 199 | "Create 1D contact data.\n\n" \ | ||
| 200 | ":param model: 1D contact model\n" \ | ||
| 201 | ":param data: Pinocchio data")[bp::with_custodian_and_ward< \ | ||
| 202 | 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \ | ||
| 203 | .def(ContactData1DVisitor<Data>()) \ | ||
| 204 | .def(CopyableVisitor<Data>()); | ||
| 205 | |||
| 206 | ✗ | void exposeContact1D() { | |
| 207 | ✗ | CROCODDYL_CONTACT_MODEL_1D_PYTHON_BINDINGS(float) | |
| 208 | ✗ | CROCODDYL_CONTACT_DATA_1D_PYTHON_BINDINGS(float) | |
| 209 | ✗ | } | |
| 210 | |||
| 211 | } // namespace python | ||
| 212 | } // namespace crocoddyl | ||
| 213 |