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