| Directory: | ./ |
|---|---|
| File: | bindings/python/crocoddyl/core/residuals/joint-acceleration.cpp |
| Date: | 2025-03-26 19:23:43 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 15 | 16 | 93.8% |
| Branches: | 37 | 74 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2022-2023, Heriot-Watt University | ||
| 5 | // Copyright note valid unless otherwise stated in individual files. | ||
| 6 | // All rights reserved. | ||
| 7 | /////////////////////////////////////////////////////////////////////////////// | ||
| 8 | |||
| 9 | #include "crocoddyl/core/residuals/joint-acceleration.hpp" | ||
| 10 | |||
| 11 | #include "python/crocoddyl/core/core.hpp" | ||
| 12 | |||
| 13 | namespace crocoddyl { | ||
| 14 | namespace python { | ||
| 15 | |||
| 16 | template <typename Model> | ||
| 17 | struct ResidualModelJointAccelerationVisitor | ||
| 18 | : public bp::def_visitor<ResidualModelJointAccelerationVisitor<Model>> { | ||
| 19 | typedef typename Model::ResidualDataAbstract Data; | ||
| 20 | typedef typename Model::Base ModelBase; | ||
| 21 | typedef typename Model::StateAbstract State; | ||
| 22 | typedef typename Model::VectorXs VectorXs; | ||
| 23 | template <class PyClass> | ||
| 24 | 40 | void visit(PyClass& cl) const { | |
| 25 |
2/4✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
|
40 | cl.def(bp::init<std::shared_ptr<State>, VectorXs>( |
| 26 | bp::args("self", "state", "aref"), | ||
| 27 | "Initialize the joint-acceleration residual model.\n\n" | ||
| 28 | "The default nu value is obtained from state.nv.\n" | ||
| 29 | ":param state: state description\n" | ||
| 30 | ":param aref: reference joint acceleration")) | ||
| 31 |
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(bp::init<std::shared_ptr<State>, std::size_t>( |
| 32 | bp::args("self", "state", "nu"), | ||
| 33 | "Initialize the joint-acceleration residual model.\n\n" | ||
| 34 | "The default reference joint-acceleration is obtained from " | ||
| 35 | "np.zero(actuation.nu).\n" | ||
| 36 | ":param state: state description\n" | ||
| 37 | ":param nu: dimension of the control vector")) | ||
| 38 |
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(bp::init<std::shared_ptr<State>>( |
| 39 | bp::args("self", "state"), | ||
| 40 | "Initialize the joint-acceleration residual model.\n\n" | ||
| 41 | "The default reference joint-acceleration is obtained from " | ||
| 42 | "np.zero(actuation.nu). The default nu value is obtained from " | ||
| 43 | "state.nv.\n" | ||
| 44 | ":param state: state description")) | ||
| 45 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
80 | .def( |
| 46 | "calc", | ||
| 47 | static_cast<void (Model::*)( | ||
| 48 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 49 | const Eigen::Ref<const VectorXs>&)>(&Model::calc), | ||
| 50 | bp::args("self", "data", "x", "u"), | ||
| 51 | "Compute the joint-acceleration residual.\n\n" | ||
| 52 | ":param data: residual data\n" | ||
| 53 | ":param x: state point (dim. state.nx)\n" | ||
| 54 | ":param u: control input (dim. nu)") | ||
| 55 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
80 | .def("calc", |
| 56 | static_cast<void (Model::*)(const std::shared_ptr<Data>&, | ||
| 57 | const Eigen::Ref<const VectorXs>&)>( | ||
| 58 | &Model::calc), | ||
| 59 | bp::args("self", "data", "x")) | ||
| 60 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
80 | .def( |
| 61 | "calcDiff", | ||
| 62 | static_cast<void (Model::*)( | ||
| 63 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
| 64 | const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), | ||
| 65 | bp::args("self", "data", "x", "u"), | ||
| 66 | "Compute the Jacobians of the joint-acceleration residual.\n\n" | ||
| 67 | "It assumes that calc has been run first.\n" | ||
| 68 | ":param data: residual data\n" | ||
| 69 | ":param x: state point (dim. state.nx)\n" | ||
| 70 | ":param u: control input (dim. nu)") | ||
| 71 |
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( |
| 72 | "calcDiff", | ||
| 73 | static_cast<void (ModelBase::*)(const std::shared_ptr<Data>&, | ||
| 74 | const Eigen::Ref<const VectorXs>&)>( | ||
| 75 | &ModelBase::calcDiff), | ||
| 76 | bp::args("self", "data", "x")) | ||
| 77 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
80 | .def("createData", &Model::createData, |
| 78 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
| 79 | bp::args("self", "data"), | ||
| 80 | "Create the joint-acceleration residual data.\n\n" | ||
| 81 | "Each residual model has its own data that needs to be allocated. " | ||
| 82 | "This function\n" | ||
| 83 | "returns the allocated data for the joint-acceleration residual.\n" | ||
| 84 | ":param data: shared data\n" | ||
| 85 | ":return residual data.") | ||
| 86 |
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 | .add_property("reference", |
| 87 | bp::make_function(&Model::get_reference, | ||
| 88 | 40 | bp::return_internal_reference<>()), | |
| 89 | &Model::set_reference, "reference joint acceleration"); | ||
| 90 | 40 | } | |
| 91 | }; | ||
| 92 | |||
| 93 | #define CROCODDYL_RESIDUAL_MODEL_JOINTACC_PYTHON_BINDINGS(Scalar) \ | ||
| 94 | typedef ResidualModelJointAccelerationTpl<Scalar> Model; \ | ||
| 95 | typedef ResidualModelAbstractTpl<Scalar> ModelBase; \ | ||
| 96 | typedef typename ModelBase::StateAbstract State; \ | ||
| 97 | typedef typename ModelBase::VectorXs VectorXs; \ | ||
| 98 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 99 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
| 100 | "ResidualModelJointAcceleration", \ | ||
| 101 | "This residual function defines a residual vector as r = a - aref, " \ | ||
| 102 | "with a and aref as the current and reference joint acceleration " \ | ||
| 103 | "(i.e., generalized acceleration), respectively.", \ | ||
| 104 | bp::init<std::shared_ptr<State>, VectorXs, std::size_t>( \ | ||
| 105 | bp::args("self", "state", "aref", "nu"), \ | ||
| 106 | "Initialize the joint-acceleration residual model.\n\n" \ | ||
| 107 | ":param state: state description\n" \ | ||
| 108 | ":param aref: reference joint acceleration\n" \ | ||
| 109 | ":param nu: dimension of the control vector")) \ | ||
| 110 | .def(ResidualModelJointAccelerationVisitor<Model>()) \ | ||
| 111 | .def(CastVisitor<Model>()) \ | ||
| 112 | .def(PrintableVisitor<Model>()) \ | ||
| 113 | .def(CopyableVisitor<Model>()); | ||
| 114 | |||
| 115 | 10 | void exposeResidualJointAcceleration() { | |
| 116 |
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_RESIDUAL_MODEL_JOINTACC_PYTHON_BINDINGS) |
| 117 | 10 | } | |
| 118 | |||
| 119 | } // namespace python | ||
| 120 | } // namespace crocoddyl | ||
| 121 |