Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/multibody/contacts/contact-6d.cpp |
Date: | 2025-01-30 11:01:55 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 48 | 50 | 96.0% |
Branches: | 36 | 72 | 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-6d.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 exposeContact6D() { | |
19 | 10 | bp::register_ptr_to_python<std::shared_ptr<ContactModel6D> >(); | |
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_<ContactModel6D, bp::bases<ContactModelAbstract> >( |
26 | "ContactModel6D", | ||
27 | "Rigid 6D contact model.\n\n" | ||
28 | "It defines a rigid 6D contact models based on acceleration-based " | ||
29 | "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<std::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
34 | pinocchio::SE3, pinocchio::ReferenceFrame, std::size_t, | ||
35 | bp::optional<Eigen::Vector2d> >( | ||
36 | 20 | bp::args("self", "state", "id", "pref", "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 pref: contact placement used for the Baumgarte " | ||
41 | "stabilization\n" | ||
42 | ":param type: type of contact\n" | ||
43 | ":param nu: dimension of control vector\n" | ||
44 | ":param gains: gains of the contact model (default " | ||
45 | "np.matrix([0.,0.]))")) | ||
46 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def(bp::init<std::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
47 | pinocchio::SE3, pinocchio::ReferenceFrame, | ||
48 | bp::optional<Eigen::Vector2d> >( | ||
49 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "state", "id", "pref", "type", "gains"), |
50 | "Initialize the contact model.\n\n" | ||
51 | ":param state: state of the multibody system\n" | ||
52 | ":param id: reference frame id of the contact\n" | ||
53 | ":param pref: contact placement used for the Baumgarte " | ||
54 | "stabilization\n" | ||
55 | ":param type: type of contact\n" | ||
56 | ":param gains: gains of the contact model (default " | ||
57 | "np.matrix([0.,0.]))")) | ||
58 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("calc", &ContactModel6D::calc, bp::args("self", "data", "x"), |
59 | "Compute the 6D contact Jacobian and drift.\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 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("calcDiff", &ContactModel6D::calcDiff, bp::args("self", "data", "x"), |
66 | "Compute the derivatives of the 6D 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: cost data\n" | ||
72 | ":param x: state point (dim. state.nx)") | ||
73 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("updateForce", &ContactModel6D::updateForce, |
74 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "force"), |
75 | "Convert the Lagrangian into a stack of spatial forces.\n\n" | ||
76 | ":param data: cost data\n" | ||
77 | ":param force: force vector (dimension 6)") | ||
78 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("createData", &ContactModel6D::createData, |
79 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
80 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data"), |
81 | "Create the 6D contact data.\n\n" | ||
82 | "Each contact model has its own data that needs to be allocated. " | ||
83 | "This function\n" | ||
84 | "returns the allocated data for a predefined cost.\n" | ||
85 | ":param data: Pinocchio data\n" | ||
86 | ":return contact data.") | ||
87 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("reference", |
88 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ContactModel6D::get_reference, |
89 | 10 | bp::return_internal_reference<>()), | |
90 | &ContactModel6D::set_reference, | ||
91 | "reference contact placement") | ||
92 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
93 | "gains", | ||
94 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ContactModel6D::get_gains, |
95 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
96 | "contact gains") | ||
97 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ContactModel6D>()); |
98 | |||
99 | #pragma GCC diagnostic pop | ||
100 | |||
101 | 10 | bp::register_ptr_to_python<std::shared_ptr<ContactData6D> >(); | |
102 | |||
103 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ContactData6D, bp::bases<ContactDataAbstract> >( |
104 | "ContactData6D", "Data for 6D contact.\n\n", | ||
105 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ContactModel6D*, pinocchio::Data*>( |
106 | 10 | bp::args("self", "model", "data"), | |
107 | "Create 6D contact data.\n\n" | ||
108 | ":param model: 6D contact model\n" | ||
109 | ✗ | ":param data: Pinocchio data")[bp::with_custodian_and_ward< | |
110 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | 1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
111 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
112 | "rMf", | ||
113 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData6D::jMf, |
114 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
115 | "error frame placement of the contact frame") | ||
116 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
117 | "v", | ||
118 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData6D::v, |
119 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
120 | "spatial velocity of the contact body") | ||
121 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
122 | "a0_local", | ||
123 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData6D::a0_local, |
124 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
125 | "desired local contact acceleration") | ||
126 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("v_partial_dq", |
127 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData6D::v_partial_dq, |
128 | 10 | bp::return_internal_reference<>()), | |
129 | "Jacobian of the spatial body velocity") | ||
130 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("a_partial_dq", |
131 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData6D::a_partial_dq, |
132 | 10 | bp::return_internal_reference<>()), | |
133 | "Jacobian of the spatial body acceleration") | ||
134 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("a_partial_dv", |
135 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData6D::a_partial_dv, |
136 | 10 | bp::return_internal_reference<>()), | |
137 | "Jacobian of the spatial body acceleration") | ||
138 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("a_partial_da", |
139 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ContactData6D::a_partial_da, |
140 | 10 | bp::return_internal_reference<>()), | |
141 | "Jacobian of the spatial body acceleration") | ||
142 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ContactData6D>()); |
143 | 10 | } | |
144 | |||
145 | } // namespace python | ||
146 | } // namespace crocoddyl | ||
147 |