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 |
✓✗ |
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 |
✓✗ |
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 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
46 |
|
|
Eigen::Vector3d, pinocchio::ReferenceFrame, |
47 |
|
|
bp::optional<Eigen::Vector2d> >( |
48 |
✓✗ |
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 |
✓✗ |
10 |
"np.matrix([0.,0.]))")) |
56 |
✓✗ |
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 |
✓✗ |
10 |
":param x: state point (dim. state.nx)") |
63 |
✓✗ |
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 |
✓✗ |
10 |
":param x: state point (dim. state.nx)") |
71 |
|
|
.def("updateForce", &ContactModel3D::updateForce, |
72 |
✓✗ |
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 |
✓✗ |
10 |
":param force: force vector (dimension 3)") |
76 |
|
|
.def("createData", &ContactModel3D::createData, |
77 |
|
|
bp::with_custodian_and_ward_postcall<0, 2>(), |
78 |
✓✗ |
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 |
✓✗ |
10 |
":return contact data.") |
85 |
|
|
.add_property("reference", |
86 |
|
|
bp::make_function(&ContactModel3D::get_reference, |
87 |
|
10 |
bp::return_internal_reference<>()), |
88 |
|
|
&ContactModel3D::set_reference, |
89 |
✓✗✓✗
|
10 |
"reference contact translation") |
90 |
|
|
.add_property( |
91 |
|
|
"gains", |
92 |
✓✗ |
10 |
bp::make_function(&ContactModel3D::get_gains, |
93 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
94 |
✓✗ |
10 |
"contact gains") |
95 |
✓✗ |
10 |
.def(CopyableVisitor<ContactModel3D>()); |
96 |
|
|
|
97 |
|
|
#pragma GCC diagnostic pop |
98 |
|
|
|
99 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ContactData3D> >(); |
100 |
|
|
|
101 |
✓✗ |
10 |
bp::class_<ContactData3D, bp::bases<ContactDataAbstract> >( |
102 |
|
|
"ContactData3D", "Data for 3D contact.\n\n", |
103 |
✓✗ |
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 |
|
10 |
":param data: Pinocchio data")[bp::with_custodian_and_ward< |
108 |
✓✗ |
20 |
1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
109 |
|
|
.add_property( |
110 |
|
|
"v", |
111 |
✓✗ |
10 |
bp::make_getter(&ContactData3D::v, |
112 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
113 |
✓✗ |
10 |
"spatial velocity of the contact body") |
114 |
|
|
.add_property("a0_local", |
115 |
✓✗ |
10 |
bp::make_getter(&ContactData3D::a0_local, |
116 |
|
|
bp::return_internal_reference<>()), |
117 |
✓✗ |
20 |
bp::make_setter(&ContactData3D::a0_local), |
118 |
✓✗ |
10 |
"desired local contact acceleration") |
119 |
|
|
.add_property( |
120 |
|
|
"dp", |
121 |
✓✗ |
10 |
bp::make_getter(&ContactData3D::dp, |
122 |
|
|
bp::return_internal_reference<>()), |
123 |
✓✗ |
20 |
bp::make_setter(&ContactData3D::dp), |
124 |
✓✗ |
10 |
"Translation error computed for the Baumgarte regularization term") |
125 |
|
|
.add_property("dp_local", |
126 |
✓✗ |
10 |
bp::make_getter(&ContactData3D::dp_local, |
127 |
|
|
bp::return_internal_reference<>()), |
128 |
✓✗ |
20 |
bp::make_setter(&ContactData3D::dp_local), |
129 |
|
|
"local translation error computed for the Baumgarte " |
130 |
✓✗ |
10 |
"regularization term") |
131 |
|
|
.add_property("f_local", |
132 |
✓✗ |
10 |
bp::make_getter(&ContactData3D::f_local, |
133 |
|
|
bp::return_internal_reference<>()), |
134 |
✓✗ |
20 |
bp::make_setter(&ContactData3D::f_local), |
135 |
✓✗ |
10 |
"spatial contact force in local coordinates") |
136 |
|
|
.add_property("da0_local_dx", |
137 |
✓✗ |
10 |
bp::make_getter(&ContactData3D::da0_local_dx, |
138 |
|
|
bp::return_internal_reference<>()), |
139 |
✓✗ |
20 |
bp::make_setter(&ContactData3D::da0_local_dx), |
140 |
✓✗ |
10 |
"Jacobian of the desired local contact acceleration") |
141 |
|
|
.add_property("fJf", |
142 |
✓✗ |
10 |
bp::make_getter(&ContactData3D::fJf, |
143 |
|
10 |
bp::return_internal_reference<>()), |
144 |
✓✗ |
10 |
"local Jacobian of the contact frame") |
145 |
|
|
.add_property("v_partial_dq", |
146 |
✓✗ |
10 |
bp::make_getter(&ContactData3D::v_partial_dq, |
147 |
|
10 |
bp::return_internal_reference<>()), |
148 |
✓✗ |
10 |
"Jacobian of the spatial body velocity") |
149 |
|
|
.add_property("a_partial_dq", |
150 |
✓✗ |
10 |
bp::make_getter(&ContactData3D::a_partial_dq, |
151 |
|
10 |
bp::return_internal_reference<>()), |
152 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
153 |
|
|
.add_property("a_partial_dv", |
154 |
✓✗ |
10 |
bp::make_getter(&ContactData3D::a_partial_dv, |
155 |
|
10 |
bp::return_internal_reference<>()), |
156 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
157 |
|
|
.add_property("a_partial_da", |
158 |
✓✗ |
10 |
bp::make_getter(&ContactData3D::a_partial_da, |
159 |
|
10 |
bp::return_internal_reference<>()), |
160 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
161 |
✓✗ |
10 |
.def(CopyableVisitor<ContactData3D>()); |
162 |
|
10 |
} |
163 |
|
|
|
164 |
|
|
} // namespace python |
165 |
|
|
} // namespace crocoddyl |