Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/multibody/residuals/contact-cop-position.cpp |
Date: | 2025-03-26 19:23:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 22 | 23 | 95.7% |
Branches: | 56 | 112 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2020-2025, University of Duisburg-Essen, University of | ||
5 | // Edinburgh, | ||
6 | // Heriot-Watt University | ||
7 | // Copyright note valid unless otherwise stated in individual files. | ||
8 | // All rights reserved. | ||
9 | /////////////////////////////////////////////////////////////////////////////// | ||
10 | |||
11 | #include "crocoddyl/multibody/residuals/contact-cop-position.hpp" | ||
12 | |||
13 | #include "python/crocoddyl/multibody/multibody.hpp" | ||
14 | #include "python/crocoddyl/utils/deprecate.hpp" | ||
15 | |||
16 | namespace crocoddyl { | ||
17 | namespace python { | ||
18 | |||
19 | template <typename Model> | ||
20 | struct ResidualModelContactCoPPositionVisitor | ||
21 | : public bp::def_visitor<ResidualModelContactCoPPositionVisitor<Model>> { | ||
22 | typedef typename Model::ResidualDataAbstract Data; | ||
23 | typedef typename Model::StateMultibody State; | ||
24 | typedef typename Model::VectorXs VectorXs; | ||
25 | typedef typename Model::CoPSupport Support; | ||
26 | template <class PyClass> | ||
27 | 40 | void visit(PyClass& cl) const { | |
28 |
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>, pinocchio::FrameIndex, Support>( |
29 | bp::args("self", "state", "id", "cref"), | ||
30 | "Initialize the contact CoP position residual model.\n\n" | ||
31 | "The default nu is obtained from state.nv. Note that this " | ||
32 | "constructor can be used for forward-dynamics\n" | ||
33 | "cases only.\n" | ||
34 | ":param state: state of the multibody system\n" | ||
35 | ":param id: reference frame id\n" | ||
36 | ":param cref: support region of the CoP")) | ||
37 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
80 | .def( |
38 | "calc", | ||
39 | static_cast<void (Model::*)( | ||
40 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
41 | const Eigen::Ref<const VectorXs>&)>(&Model::calc), | ||
42 | bp::args("self", "data", "x", "u"), | ||
43 | "Compute the contact CoP position residual.\n\n" | ||
44 | ":param data: residual data\n" | ||
45 | ":param x: state point (dim. state.nx)\n" | ||
46 | ":param u: control input (dim. nu)") | ||
47 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
80 | .def("calc", |
48 | static_cast<void (Model::*)(const std::shared_ptr<Data>&, | ||
49 | const Eigen::Ref<const VectorXs>&)>( | ||
50 | &Model::calc), | ||
51 | bp::args("self", "data", "x")) | ||
52 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
80 | .def( |
53 | "calcDiff", | ||
54 | static_cast<void (Model::*)( | ||
55 | const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, | ||
56 | const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), | ||
57 | bp::args("self", "data", "x", "u"), | ||
58 | "Compute the derivatives of the contact CoP position residual.\n\n" | ||
59 | "It assumes that calc has been run first.\n" | ||
60 | ":param data: action data\n" | ||
61 | ":param x: state point (dim. state.nx)\n" | ||
62 | ":param u: control input (dim. nu)\n") | ||
63 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
80 | .def("calcDiff", |
64 | static_cast<void (Model::*)(const std::shared_ptr<Data>&, | ||
65 | const Eigen::Ref<const VectorXs>&)>( | ||
66 | &Model::calcDiff), | ||
67 | bp::args("self", "data", "x")) | ||
68 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
80 | .def("createData", &Model::createData, |
69 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
70 | bp::args("self", "data"), | ||
71 | "Create the contact CoP position residual data.\n\n" | ||
72 | "Each residual model has its own data that needs to be allocated. " | ||
73 | "This function\n" | ||
74 | "returns the allocated data for the CoP position residual.\n" | ||
75 | ":param data: shared data\n" | ||
76 | ":return residual data.") | ||
77 |
4/8✓ 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.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
|
120 | .add_property( |
78 | "id", bp::make_function(&Model::get_id), | ||
79 | bp::make_function(&Model::set_id, | ||
80 |
2/4✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
|
80 | deprecated<>("Deprecated. Do not use set_id, " |
81 | "instead create a new model")), | ||
82 | "reference frame id") | ||
83 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .add_property("reference", |
84 | bp::make_function( | ||
85 | &Model::get_reference, | ||
86 | 40 | bp::return_value_policy<bp::copy_const_reference>()), | |
87 | &Model::set_reference, | ||
88 | "reference support region of the CoP"); | ||
89 | 40 | } | |
90 | }; | ||
91 | |||
92 | template <typename Data> | ||
93 | struct ResidualDataContactCoPPositionVisitor | ||
94 | : public bp::def_visitor<ResidualDataContactCoPPositionVisitor<Data>> { | ||
95 | template <class PyClass> | ||
96 | 40 | void visit(PyClass& cl) const { | |
97 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | cl.add_property( |
98 | "pinocchio", | ||
99 | 40 | bp::make_getter(&Data::pinocchio, bp::return_internal_reference<>()), | |
100 | "pinocchio data") | ||
101 |
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( |
102 | "contact", | ||
103 | bp::make_getter(&Data::contact, | ||
104 | 40 | bp::return_value_policy<bp::return_by_value>()), | |
105 | bp::make_setter(&Data::contact), | ||
106 | "contact data associated with the current residual"); | ||
107 | 40 | } | |
108 | }; | ||
109 | |||
110 | #define CROCODDYL_RESIDUAL_MODEL_CONTACT_COP_POSITION_PYTHON_BINDINGS(Scalar) \ | ||
111 | typedef ResidualModelContactCoPPositionTpl<Scalar> Model; \ | ||
112 | typedef ResidualModelAbstractTpl<Scalar> ModelBase; \ | ||
113 | typedef typename Model::StateMultibody State; \ | ||
114 | typedef typename Model::CoPSupport Support; \ | ||
115 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
116 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
117 | "ResidualModelContactCoPPosition", \ | ||
118 | bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, Support, \ | ||
119 | std::size_t, bp::optional<bool>>( \ | ||
120 | bp::args("self", "state", "id", "cref", "nu", "fwddyn"), \ | ||
121 | "Initialize the contact CoP position residual model.\n\n" \ | ||
122 | ":param state: state of the multibody system\n" \ | ||
123 | ":param id: reference frame id\n" \ | ||
124 | ":param cref: support region of the CoP\n" \ | ||
125 | ":param nu: dimension of control vector\n" \ | ||
126 | ":param fwddyn: indicate if we have a forward dynamics problem " \ | ||
127 | "(True) or inverse dynamics problem (False) (default True)")) \ | ||
128 | .def(ResidualModelContactCoPPositionVisitor<Model>()) \ | ||
129 | .def(CastVisitor<Model>()) \ | ||
130 | .def(PrintableVisitor<Model>()) \ | ||
131 | .def(CopyableVisitor<Model>()); | ||
132 | |||
133 | #define CROCODDYL_RESIDUAL_DATA_CONTACT_COP_POSITION_PYTHON_BINDINGS(Scalar) \ | ||
134 | typedef ResidualDataContactCoPPositionTpl<Scalar> Data; \ | ||
135 | typedef ResidualDataAbstractTpl<Scalar> DataBase; \ | ||
136 | typedef ResidualModelContactCoPPositionTpl<Scalar> Model; \ | ||
137 | typedef Model::DataCollectorAbstract DataCollector; \ | ||
138 | bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ | ||
139 | bp::class_<Data, bp::bases<DataBase>>( \ | ||
140 | "ResidualDataContactCoPPosition", \ | ||
141 | "Data for contact CoP position residual.\n\n", \ | ||
142 | bp::init<Model*, DataCollector*>( \ | ||
143 | bp::args("self", "model", "data"), \ | ||
144 | "Create contact CoP position residual data.\n\n" \ | ||
145 | ":param model: contact CoP position residual model\n" \ | ||
146 | ":param data: shared data")[bp::with_custodian_and_ward< \ | ||
147 | 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \ | ||
148 | .def(ResidualDataContactCoPPositionVisitor<Data>()) \ | ||
149 | .def(CopyableVisitor<Data>()); | ||
150 | |||
151 | 10 | void exposeResidualContactCoPPosition() { | |
152 |
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( |
153 | CROCODDYL_RESIDUAL_MODEL_CONTACT_COP_POSITION_PYTHON_BINDINGS) | ||
154 |
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( |
155 | CROCODDYL_RESIDUAL_DATA_CONTACT_COP_POSITION_PYTHON_BINDINGS) | ||
156 | 10 | } | |
157 | |||
158 | } // namespace python | ||
159 | } // namespace crocoddyl | ||
160 |