Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/multibody/contacts/contact-3d.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 60 | 67 | 89.6% |
Branches: | 49 | 98 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-2023, 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/contacts/contact-3d.hpp" | ||
11 | |||
12 | #include "python/crocoddyl/multibody/multibody.hpp" | ||
13 | #include "python/crocoddyl/utils/copyable.hpp" | ||
14 | |||
15 | namespace crocoddyl { | ||
16 | namespace python { | ||
17 | |||
18 | 10 | void exposeContact3D() { | |
19 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ContactModel3D> >(); | |
20 | |||
21 | #pragma GCC diagnostic push // TODO: Remove once the deprecated FrameXX has | ||
22 | // been removed in a future release | ||
23 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | ||
24 | |||
25 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ContactModel3D, bp::bases<ContactModelAbstract> >( |
26 | "ContactModel3D", | ||
27 | "Rigid 3D contact model.\n\n" | ||
28 | "It defines a rigid 3D contact models (point contact) based on " | ||
29 | "acceleration-based holonomic constraints.\n" | ||
30 | "The calc and calcDiff functions compute the contact Jacobian and drift " | ||
31 | "(holonomic constraint) or\n" | ||
32 | "the derivatives of the holonomic constraint, respectively.", | ||
33 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
34 | Eigen::Vector3d, pinocchio::ReferenceFrame, | ||
35 | bp::optional<std::size_t, Eigen::Vector2d> >( | ||
36 | 20 | bp::args("self", "state", "id", "xref", "type", "nu", "gains"), | |
37 | "Initialize the contact model.\n\n" | ||
38 | ":param state: state of the multibody system\n" | ||
39 | ":param id: reference frame id of the contact\n" | ||
40 | ":param xref: contact position used for the Baumgarte stabilization\n" | ||
41 | ":param type: type of contact\n" | ||
42 | ":param nu: dimension of control vector (default state.nv)\n" | ||
43 | ":param gains: gains of the contact model (default " | ||
44 | "np.array([0.,0.]))")) | ||
45 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def(bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
46 | Eigen::Vector3d, pinocchio::ReferenceFrame, | ||
47 | bp::optional<Eigen::Vector2d> >( | ||
48 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "state", "id", "xref", "type", "gains"), |
49 | "Initialize the contact model.\n\n" | ||
50 | ":param state: state of the multibody system\n" | ||
51 | ":param id: reference frame id of the contact\n" | ||
52 | ":param xref: contact position used for the Baumgarte stabilization\n" | ||
53 | ":param type: type of contact\n" | ||
54 | ":param gains: gains of the contact model (default " | ||
55 | "np.matrix([0.,0.]))")) | ||
56 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("calc", &ContactModel3D::calc, bp::args("self", "data", "x"), |
57 | "Compute the 3d contact Jacobian and drift.\n\n" | ||
58 | "The rigid contact model throught acceleration-base holonomic " | ||
59 | "constraint\n" | ||
60 | "of the contact frame placement.\n" | ||
61 | ":param data: contact data\n" | ||
62 | ":param x: state point (dim. state.nx)") | ||
63 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("calcDiff", &ContactModel3D::calcDiff, bp::args("self", "data", "x"), |
64 | "Compute the derivatives of the 3d contact holonomic constraint.\n\n" | ||
65 | "The rigid contact model throught acceleration-base holonomic " | ||
66 | "constraint\n" | ||
67 | "of the contact frame placement.\n" | ||
68 | "It assumes that calc has been run first.\n" | ||
69 | ":param data: cost data\n" | ||
70 | ":param x: state point (dim. state.nx)") | ||
71 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("updateForce", &ContactModel3D::updateForce, |
72 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "force"), |
73 | "Convert the force into a stack of spatial forces.\n\n" | ||
74 | ":param data: cost data\n" | ||
75 | ":param force: force vector (dimension 3)") | ||
76 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("createData", &ContactModel3D::createData, |
77 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
78 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data"), |
79 | "Create the 3D contact data.\n\n" | ||
80 | "Each contact model has its own data that needs to be allocated. " | ||
81 | "This function\n" | ||
82 | "returns the allocated data for a predefined cost.\n" | ||
83 | ":param data: Pinocchio data\n" | ||
84 | ":return contact data.") | ||
85 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("reference", |
86 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ContactModel3D::get_reference, |
87 | 10 | bp::return_internal_reference<>()), | |
88 | &ContactModel3D::set_reference, | ||
89 | "reference contact translation") | ||
90 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
91 | "gains", | ||
92 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ContactModel3D::get_gains, |
93 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
94 | "contact gains") | ||
95 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ContactModel3D>()); |
96 | |||
97 | #pragma GCC diagnostic pop | ||
98 | |||
99 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ContactData3D> >(); | |
100 | |||
101 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ContactData3D, bp::bases<ContactDataAbstract> >( |
102 | "ContactData3D", "Data for 3D contact.\n\n", | ||
103 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ContactModel3D*, pinocchio::Data*>( |
104 | 10 | bp::args("self", "model", "data"), | |
105 | "Create 3D contact data.\n\n" | ||
106 | ":param model: 3D contact model\n" | ||
107 | ✗ | ":param data: Pinocchio data")[bp::with_custodian_and_ward< | |
108 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | 1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
109 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
110 | "v", | ||
111 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData3D::v, |
112 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
113 | "spatial velocity of the contact body") | ||
114 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("a0_local", |
115 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData3D::a0_local, |
116 | ✗ | bp::return_internal_reference<>()), | |
117 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ContactData3D::a0_local), |
118 | "desired local contact acceleration") | ||
119 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
120 | "dp", | ||
121 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData3D::dp, |
122 | ✗ | bp::return_internal_reference<>()), | |
123 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ContactData3D::dp), |
124 | "Translation error computed for the Baumgarte regularization term") | ||
125 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("dp_local", |
126 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData3D::dp_local, |
127 | ✗ | bp::return_internal_reference<>()), | |
128 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ContactData3D::dp_local), |
129 | "local translation error computed for the Baumgarte " | ||
130 | "regularization term") | ||
131 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("f_local", |
132 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData3D::f_local, |
133 | ✗ | bp::return_internal_reference<>()), | |
134 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ContactData3D::f_local), |
135 | "spatial contact force in local coordinates") | ||
136 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("da0_local_dx", |
137 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData3D::da0_local_dx, |
138 | ✗ | bp::return_internal_reference<>()), | |
139 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ContactData3D::da0_local_dx), |
140 | "Jacobian of the desired local contact acceleration") | ||
141 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("fJf", |
142 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData3D::fJf, |
143 | 10 | bp::return_internal_reference<>()), | |
144 | "local Jacobian of the contact frame") | ||
145 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("v_partial_dq", |
146 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData3D::v_partial_dq, |
147 | 10 | bp::return_internal_reference<>()), | |
148 | "Jacobian of the spatial body velocity") | ||
149 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("a_partial_dq", |
150 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData3D::a_partial_dq, |
151 | 10 | bp::return_internal_reference<>()), | |
152 | "Jacobian of the spatial body acceleration") | ||
153 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("a_partial_dv", |
154 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData3D::a_partial_dv, |
155 | 10 | bp::return_internal_reference<>()), | |
156 | "Jacobian of the spatial body acceleration") | ||
157 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("a_partial_da", |
158 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData3D::a_partial_da, |
159 | 10 | bp::return_internal_reference<>()), | |
160 | "Jacobian of the spatial body acceleration") | ||
161 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ContactData3D>()); |
162 | 10 | } | |
163 | |||
164 | } // namespace python | ||
165 | } // namespace crocoddyl | ||
166 |