| Directory: | ./ |
|---|---|
| File: | bindings/python/crocoddyl/multibody/impulses/impulse-3d.cpp |
| Date: | 2025-03-26 19:23:43 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 23 | 23 | 100.0% |
| Branches: | 51 | 102 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2019-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 | #include "crocoddyl/multibody/impulses/impulse-3d.hpp" | ||
| 11 | |||
| 12 | #include "python/crocoddyl/multibody/multibody.hpp" | ||
| 13 | |||
| 14 | namespace crocoddyl { | ||
| 15 | namespace python { | ||
| 16 | |||
| 17 | template <typename Model> | ||
| 18 | struct ImpulseModel3DVisitor | ||
| 19 | : public bp::def_visitor<ImpulseModel3DVisitor<Model>> { | ||
| 20 | template <class PyClass> | ||
| 21 | 40 | void visit(PyClass& cl) const { | |
| 22 | 40 | cl.def("calc", &Model::calc, bp::args("self", "data", "x"), | |
| 23 | "Compute the 3D impulse Jacobian and drift.\n\n" | ||
| 24 | "The rigid impulse model throught acceleration-base holonomic " | ||
| 25 | "constraint of the impulse frame placement.\n" | ||
| 26 | ":param data: impulse data\n" | ||
| 27 | ":param x: state point (dim. state.nx)") | ||
| 28 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
80 | .def("calcDiff", &Model::calcDiff, bp::args("self", "data", "x"), |
| 29 | "Compute the derivatives of the 3D impulse holonomic " | ||
| 30 | "constraint.\n\n" | ||
| 31 | "The rigid impulse model throught acceleration-base holonomic " | ||
| 32 | "constraint of the impulse frame placement. It assumes that calc " | ||
| 33 | "has been run first.\n" | ||
| 34 | ":param data: cost data\n" | ||
| 35 | ":param x: state point (dim. state.nx)") | ||
| 36 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
80 | .def("updateForce", &Model::updateForce, |
| 37 | bp::args("self", "data", "force"), | ||
| 38 | "Convert the force into a stack of spatial forces.\n\n" | ||
| 39 | ":param data: cost data\n" | ||
| 40 | ":param force: force vector (dimension 3)") | ||
| 41 |
3/6✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
|
80 | .def("createData", &Model::createData, |
| 42 | 40 | bp::with_custodian_and_ward_postcall<0, 2>(), | |
| 43 | bp::args("self", "data"), | ||
| 44 | "Create the 3D impulse data.\n\n" | ||
| 45 | "Each impulse model has its own data that needs to be allocated. " | ||
| 46 | "This function returns the allocated data for a predefined cost.\n" | ||
| 47 | ":param data: Pinocchio data\n" | ||
| 48 | ":return impulse data."); | ||
| 49 | 40 | } | |
| 50 | }; | ||
| 51 | |||
| 52 | template <typename Data> | ||
| 53 | struct ImpulseData3DVisitor | ||
| 54 | : public bp::def_visitor<ImpulseData3DVisitor<Data>> { | ||
| 55 | template <class PyClass> | ||
| 56 | 40 | void visit(PyClass& cl) const { | |
| 57 |
3/6✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
|
40 | cl.add_property( |
| 58 | "f_local", | ||
| 59 | 40 | bp::make_getter(&Data::f_local, bp::return_internal_reference<>()), | |
| 60 | bp::make_setter(&Data::f_local), | ||
| 61 | "spatial contact force in local coordinates") | ||
| 62 |
3/6✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
|
80 | .add_property("dv0_local_dq", |
| 63 | bp::make_getter(&Data::dv0_local_dq, | ||
| 64 | 40 | bp::return_internal_reference<>()), | |
| 65 | bp::make_setter(&Data::dv0_local_dq), | ||
| 66 | "Jacobian of the desired local contact velocity") | ||
| 67 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .add_property( |
| 68 | "fJf", | ||
| 69 | 40 | bp::make_getter(&Data::fJf, bp::return_internal_reference<>()), | |
| 70 | "local Jacobian of the impulse frame") | ||
| 71 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .add_property("v_partial_dq", |
| 72 | bp::make_getter(&Data::v_partial_dq, | ||
| 73 | 40 | bp::return_internal_reference<>()), | |
| 74 | "Jacobian of the spatial body velocity") | ||
| 75 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .add_property("v_partial_dv", |
| 76 | bp::make_getter(&Data::v_partial_dv, | ||
| 77 | 40 | bp::return_internal_reference<>()), | |
| 78 | "Jacobian of the spatial body velocity"); | ||
| 79 | 40 | } | |
| 80 | }; | ||
| 81 | |||
| 82 | #define CROCODDYL_IMPULSE_MODEL_3D_PYTHON_BINDINGS(Scalar) \ | ||
| 83 | typedef ImpulseModel3DTpl<Scalar> Model; \ | ||
| 84 | typedef ImpulseModelAbstractTpl<Scalar> ModelBase; \ | ||
| 85 | typedef Model::StateMultibody State; \ | ||
| 86 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 87 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
| 88 | "ImpulseModel3D", \ | ||
| 89 | "Rigid 3D impulse model.\n\n" \ | ||
| 90 | "It defines a rigid 3D impulse models (point impulse) based on " \ | ||
| 91 | "acceleration-based holonomic constraints. The calc and calcDiff " \ | ||
| 92 | "functions compute the impulse Jacobian and drift (holonomic " \ | ||
| 93 | "constraint) or the derivatives of the holonomic constraint, " \ | ||
| 94 | "respectively.", \ | ||
| 95 | bp::init<std::shared_ptr<State>, std::size_t, \ | ||
| 96 | bp::optional<pinocchio::ReferenceFrame>>( \ | ||
| 97 | bp::args("self", "state", "frame", "type"), \ | ||
| 98 | "Initialize the 3D impulse model.\n\n" \ | ||
| 99 | ":param state: state of the multibody system\n" \ | ||
| 100 | ":param type: type of impulse (default pinocchio.LOCAL)\n" \ | ||
| 101 | ":param frame: reference frame id")) \ | ||
| 102 | .def(ImpulseModel3DVisitor<Model>()) \ | ||
| 103 | .def(CastVisitor<Model>()) \ | ||
| 104 | .def(PrintableVisitor<Model>()) \ | ||
| 105 | .def(CopyableVisitor<Model>()); | ||
| 106 | |||
| 107 | #define CROCODDYL_IMPULSE_DATA_3D_PYTHON_BINDINGS(Scalar) \ | ||
| 108 | typedef ImpulseData3DTpl<Scalar> Data; \ | ||
| 109 | typedef ImpulseDataAbstractTpl<Scalar> DataBase; \ | ||
| 110 | typedef ImpulseModel3DTpl<Scalar> Model; \ | ||
| 111 | typedef pinocchio::DataTpl<Scalar> PinocchioData; \ | ||
| 112 | bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ | ||
| 113 | bp::class_<Data, bp::bases<DataBase>>( \ | ||
| 114 | "ImpulseData3D", "Data for 3D impulse.\n\n", \ | ||
| 115 | bp::init<Model*, PinocchioData*>( \ | ||
| 116 | bp::args("self", "model", "data"), \ | ||
| 117 | "Create 3D impulse data.\n\n" \ | ||
| 118 | ":param model: 3D impulse model\n" \ | ||
| 119 | ":param data: Pinocchio data")[bp::with_custodian_and_ward< \ | ||
| 120 | 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \ | ||
| 121 | .def(ImpulseData3DVisitor<Data>()) \ | ||
| 122 | .def(CopyableVisitor<Data>()); | ||
| 123 | |||
| 124 | 10 | void exposeImpulse3D() { | |
| 125 |
17/34✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 10 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 10 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 10 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 10 times.
✗ Branch 31 not taken.
✓ Branch 35 taken 10 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 10 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 10 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 10 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 10 times.
✗ Branch 48 not taken.
✓ Branch 50 taken 10 times.
✗ Branch 51 not taken.
✓ Branch 53 taken 10 times.
✗ Branch 54 not taken.
✓ Branch 56 taken 10 times.
✗ Branch 57 not taken.
|
20 | CROCODDYL_PYTHON_SCALARS(CROCODDYL_IMPULSE_MODEL_3D_PYTHON_BINDINGS) |
| 126 |
15/30✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 10 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 10 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 10 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 10 times.
✗ Branch 28 not taken.
✓ Branch 32 taken 10 times.
✗ Branch 33 not taken.
✓ Branch 35 taken 10 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 10 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 10 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 10 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 10 times.
✗ Branch 48 not taken.
✓ Branch 50 taken 10 times.
✗ Branch 51 not taken.
|
20 | CROCODDYL_PYTHON_SCALARS(CROCODDYL_IMPULSE_DATA_3D_PYTHON_BINDINGS) |
| 127 | 10 | } | |
| 128 | |||
| 129 | } // namespace python | ||
| 130 | } // namespace crocoddyl | ||
| 131 |