GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/contacts/multiple-contacts-double.cpp
Date: 2025-04-18 16:41:15
Exec Total Coverage
Lines: 0 51 0.0%
Branches: 0 174 0.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh,
5 // University of Oxford, Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // Auto-generated file for double
11 #include "crocoddyl/multibody/contacts/multiple-contacts.hpp"
12
13 #include "python/crocoddyl/multibody/multibody.hpp"
14 #include "python/crocoddyl/utils/map-converter.hpp"
15 #include "python/crocoddyl/utils/set-converter.hpp"
16
17 namespace crocoddyl {
18 namespace python {
19
20 template <typename Model>
21 struct ContactItemVisitor : public bp::def_visitor<ContactItemVisitor<Model>> {
22 template <class PyClass>
23 void visit(PyClass& cl) const {
24 cl.def_readwrite("name", &Model::name, "contact name")
25 .add_property(
26 "contact",
27 bp::make_getter(&Model::contact,
28 bp::return_value_policy<bp::return_by_value>()),
29 "contact model")
30 .def_readwrite("active", &Model::active, "contact status");
31 }
32 };
33
34 template <typename Model>
35 struct ContactModelMultipleVisitor
36 : public bp::def_visitor<ContactModelMultipleVisitor<Model>> {
37 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(ContactModelMultiple_addContact_wrap,
38 Model::addContact, 2, 3)
39 template <class PyClass>
40 void visit(PyClass& cl) const {
41 cl.def(
42 "addContact", &Model::addContact,
43 ContactModelMultiple_addContact_wrap(
44 bp::args("self", "name", "contact", "active"),
45 "Add a contact item.\n\n"
46 ":param name: contact name\n"
47 ":param contact: contact model\n"
48 ":param active: True if the contact is activated (default true)"))
49 .def("removeContact", &Model::removeContact, bp::args("self", "name"),
50 "Remove a contact item.\n\n"
51 ":param name: contact name")
52 .def("changeContactStatus", &Model::changeContactStatus,
53 bp::args("self", "name", "active"),
54 "Change the contact status.\n\n"
55 ":param name: contact name\n"
56 ":param active: contact status (true for active and false for "
57 "inactive)")
58 .def("calc", &Model::calc, bp::args("self", "data", "x"),
59 "Compute the contact Jacobian and contact acceleration.\n\n"
60 "The rigid contact model throught acceleration-base holonomic "
61 "constraint\n"
62 "of the contact frame placement.\n"
63 ":param data: contact data\n"
64 ":param x: state point (dim. state.nx)")
65 .def("calcDiff", &Model::calcDiff, bp::args("self", "data", "x"),
66 "Compute the derivatives of the contact holonomic constraint.\n\n"
67 "The rigid contact model throught acceleration-base holonomic "
68 "constraint\n"
69 "of the contact frame placement.\n"
70 "It assumes that calc has been run first.\n"
71 ":param data: contact data\n"
72 ":param x: state point (dim. state.nx)")
73 .def("updateAcceleration", &Model::updateAcceleration,
74 bp::args("self", "data", "dv"),
75 "Update the constrained system acceleration.\n\n"
76 ":param data: contact data\n"
77 ":param dv: constrained acceleration (dimension nv)")
78 .def("updateForce", &Model::updateForce,
79 bp::args("self", "data", "force"),
80 "Update the spatial force in frame coordinate.\n\n"
81 ":param data: contact data\n"
82 ":param force: force vector (dimension nc)")
83 .def(
84 "updateAccelerationDiff", &Model::updateAccelerationDiff,
85 bp::args("self", "data", "ddv_dx"),
86 "Update the Jacobian of the constrained system acceleration.\n\n"
87 ":param data: contact data\n"
88 ":param ddv_dx: Jacobian of the system acceleration in generalized "
89 "coordinates (dimension nv*ndx)")
90 .def("updateForceDiff", &Model::updateForceDiff,
91 bp::args("self", "data", "df_dx", "df_du"),
92 "Update the Jacobians of the spatial force defined in frame "
93 "coordinates.\n\n"
94 ":param data: contact data\n"
95 ":param df_dx: Jacobian of the force with respect to the state "
96 "(dimension nc*ndx)\n"
97 ":param df_du: Jacobian of the force with respect to the control "
98 "(dimension nc*nu)")
99 .def("updateRneaDiff", &Model::updateRneaDiff,
100 bp::args("self", "data", "pinocchio"),
101 "Update the RNEA derivative dtau_dq by by adding the skew term "
102 "(necessary for contacts expressed in\n"
103 "LOCAL_WORLD_ALIGNED / WORLD).\n\n"
104 ":param data: contact data\n"
105 ":param pinocchio: Pinocchio data")
106 .def("createData", &Model::createData,
107 bp::with_custodian_and_ward_postcall<0, 2>(),
108 bp::args("self", "data"),
109 "Create the total contact data.\n\n"
110 ":param data: Pinocchio data\n"
111 ":return total contact data.")
112 .add_property(
113 "contacts",
114 bp::make_function(&Model::get_contacts,
115 bp::return_value_policy<bp::return_by_value>()),
116 "stack of contacts")
117 .add_property(
118 "state",
119 bp::make_function(&Model::get_state,
120 bp::return_value_policy<bp::return_by_value>()),
121 "state of the multibody system")
122 .add_property("nc", bp::make_function(&Model::get_nc),
123 "dimension of the active contact vector")
124 .add_property("nc_total", bp::make_function(&Model::get_nc_total),
125 "dimension of the total contact vector")
126 .add_property("nu", bp::make_function(&Model::get_nu),
127 "dimension of control vector")
128 .add_property(
129 "active_set",
130 bp::make_function(&Model::get_active_set,
131 bp::return_value_policy<bp::return_by_value>()),
132 "names of the active set of contact items")
133 .add_property(
134 "inactive_set",
135 bp::make_function(&Model::get_inactive_set,
136 bp::return_value_policy<bp::return_by_value>()),
137 "names of the inactive set of contact items")
138 .def("getContactStatus", &Model::getContactStatus,
139 bp::args("self", "name"),
140 "Return the contact status of a given contact name.\n\n"
141 ":param name: contact name")
142 .add_property(
143 "computeAllContacts",
144 bp::make_function(&Model::getComputeAllContacts),
145 bp::make_function(&Model::setComputeAllContacts),
146 "type of contact computation (True for all contacts and False for "
147 "active contacts)");
148 }
149 };
150
151 template <typename Data>
152 struct ContactDataMultipleVisitor
153 : public bp::def_visitor<ContactDataMultipleVisitor<Data>> {
154 template <class PyClass>
155 void visit(PyClass& cl) const {
156 cl.add_property(
157 "Jc", bp::make_getter(&Data::Jc, bp::return_internal_reference<>()),
158 bp::make_setter(&Data::Jc),
159 "contact Jacobian in frame coordinate (memory defined for "
160 "active and inactive contacts)")
161 .add_property(
162 "a0", bp::make_getter(&Data::a0, bp::return_internal_reference<>()),
163 bp::make_setter(&Data::a0),
164 "desired spatial contact acceleration in frame coordinate "
165 "(memory defined for active and inactive contacts)")
166 .add_property(
167 "da0_dx",
168 bp::make_getter(&Data::da0_dx, bp::return_internal_reference<>()),
169 bp::make_setter(&Data::da0_dx),
170 "Jacobian of the desired spatial contact acceleration in "
171 "frame coordinate (memory defined for active and "
172 "inactive contacts)")
173 .add_property(
174 "dv", bp::make_getter(&Data::dv, bp::return_internal_reference<>()),
175 bp::make_setter(&Data::dv),
176 "constrained system acceleration in generalized coordinates")
177 .add_property(
178 "ddv_dx",
179 bp::make_getter(&Data::ddv_dx, bp::return_internal_reference<>()),
180 bp::make_setter(&Data::ddv_dx),
181 "Jacobian of the constrained system acceleration in "
182 "generalized coordinates")
183 .add_property(
184 "contacts",
185 bp::make_getter(&Data::contacts,
186 bp::return_value_policy<bp::return_by_value>()),
187 "stack of contacts data")
188 .def_readwrite("fext", &Data::fext,
189 "external spatial forces in join coordinates");
190 }
191 };
192
193 #define CROCODDYL_CONTACT_ITEM_PYTHON_BINDINGS(Scalar) \
194 typedef ContactItemTpl<Scalar> Item; \
195 typedef Item::ContactModelAbstract ContactModel; \
196 typedef std::shared_ptr<Item> ContactItemPtr; \
197 StdMapPythonVisitor< \
198 std::string, ContactItemPtr, std::less<std::string>, \
199 std::allocator<std::pair<const std::string, ContactItemPtr>>, \
200 true>::expose("StdMap_ContactItem"); \
201 typedef ContactDataAbstractTpl<Scalar> ContactData; \
202 typedef std::shared_ptr<ContactData> ContactDataPtr; \
203 StdMapPythonVisitor< \
204 std::string, ContactDataPtr, std::less<std::string>, \
205 std::allocator<std::pair<const std::string, ContactDataPtr>>, \
206 true>::expose("StdMap_ContactData"); \
207 bp::register_ptr_to_python<std::shared_ptr<Item>>(); \
208 bp::class_<Item>( \
209 "ContactItem", "Describe a contact item.\n\n", \
210 bp::init<std::string, std::shared_ptr<ContactModel>, \
211 bp::optional<bool>>( \
212 bp::args("self", "name", "contact", "active"), \
213 "Initialize the contact item.\n\n" \
214 ":param name: contact name\n" \
215 ":param contact: contact model\n" \
216 ":param active: True if the contact is activated (default true)")) \
217 .def(ContactItemVisitor<Item>()) \
218 .def(CastVisitor<Item>()) \
219 .def(PrintableVisitor<Item>()) \
220 .def(CopyableVisitor<Item>());
221
222 #define CROCODDYL_CONTACT_MODEL_MULTIPLE_PYTHON_BINDINGS(Scalar) \
223 typedef ContactModelMultipleTpl<Scalar> Model; \
224 typedef Model::StateMultibody State; \
225 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
226 bp::class_<Model>( \
227 "ContactModelMultiple", \
228 bp::init<std::shared_ptr<State>, bp::optional<std::size_t>>( \
229 bp::args("self", "state", "nu"), \
230 "Initialize the multiple contact model.\n\n" \
231 ":param state: state of the multibody system\n" \
232 ":param nu: dimension of control vector")) \
233 .def(ContactModelMultipleVisitor<Model>()) \
234 .def(CastVisitor<Model>()) \
235 .def(PrintableVisitor<Model>()) \
236 .def(CopyableVisitor<Model>());
237
238 #define CROCODDYL_CONTACT_DATA_MULTIPLE_PYTHON_BINDINGS(Scalar) \
239 typedef ContactDataMultipleTpl<Scalar> Data; \
240 typedef ContactModelMultipleTpl<Scalar> Model; \
241 typedef pinocchio::DataTpl<Scalar> PinocchioData; \
242 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
243 bp::class_<Data>( \
244 "ContactDataMultiple", "Data class for multiple contacts.\n\n", \
245 bp::init<Model*, PinocchioData*>( \
246 bp::args("self", "model", "data"), \
247 "Create multicontact data.\n\n" \
248 ":param model: multicontact model\n" \
249 ":param data: Pinocchio data")[bp::with_custodian_and_ward< \
250 1, 2, bp::with_custodian_and_ward<1, 3>>()]) \
251 .def(ContactDataMultipleVisitor<Data>()) \
252 .def(CopyableVisitor<Data>());
253
254 void exposeContactMultiple() {
255 CROCODDYL_CONTACT_ITEM_PYTHON_BINDINGS(double)
256 CROCODDYL_CONTACT_MODEL_MULTIPLE_PYTHON_BINDINGS(double)
257 CROCODDYL_CONTACT_DATA_MULTIPLE_PYTHON_BINDINGS(double)
258 }
259
260 } // namespace python
261 } // namespace crocoddyl
262