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