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<boost::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 |
✓✗ |
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 |
✓✗ |
10 |
bp::init<boost::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 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
47 |
|
|
pinocchio::SE3, pinocchio::ReferenceFrame, |
48 |
|
|
bp::optional<Eigen::Vector2d> >( |
49 |
✓✗ |
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 |
✓✗ |
10 |
"np.matrix([0.,0.]))")) |
58 |
✓✗ |
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 |
✓✗ |
10 |
":param x: state point (dim. state.nx)") |
65 |
✓✗ |
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 |
✓✗ |
10 |
":param x: state point (dim. state.nx)") |
73 |
|
|
.def("updateForce", &ContactModel6D::updateForce, |
74 |
✓✗ |
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 |
✓✗ |
10 |
":param force: force vector (dimension 6)") |
78 |
|
|
.def("createData", &ContactModel6D::createData, |
79 |
|
|
bp::with_custodian_and_ward_postcall<0, 2>(), |
80 |
✓✗ |
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 |
✓✗ |
10 |
":return contact data.") |
87 |
|
|
.add_property("reference", |
88 |
|
|
bp::make_function(&ContactModel6D::get_reference, |
89 |
|
10 |
bp::return_internal_reference<>()), |
90 |
|
|
&ContactModel6D::set_reference, |
91 |
✓✗✓✗
|
10 |
"reference contact placement") |
92 |
|
|
.add_property( |
93 |
|
|
"gains", |
94 |
✓✗ |
10 |
bp::make_function(&ContactModel6D::get_gains, |
95 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
96 |
✓✗ |
10 |
"contact gains") |
97 |
✓✗ |
10 |
.def(CopyableVisitor<ContactModel6D>()); |
98 |
|
|
|
99 |
|
|
#pragma GCC diagnostic pop |
100 |
|
|
|
101 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ContactData6D> >(); |
102 |
|
|
|
103 |
✓✗ |
10 |
bp::class_<ContactData6D, bp::bases<ContactDataAbstract> >( |
104 |
|
|
"ContactData6D", "Data for 6D contact.\n\n", |
105 |
✓✗ |
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 |
|
10 |
":param data: Pinocchio data")[bp::with_custodian_and_ward< |
110 |
✓✗ |
20 |
1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
111 |
|
|
.add_property( |
112 |
|
|
"rMf", |
113 |
✓✗ |
10 |
bp::make_getter(&ContactData6D::jMf, |
114 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
115 |
✓✗ |
10 |
"error frame placement of the contact frame") |
116 |
|
|
.add_property( |
117 |
|
|
"v", |
118 |
✓✗ |
10 |
bp::make_getter(&ContactData6D::v, |
119 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
120 |
✓✗ |
10 |
"spatial velocity of the contact body") |
121 |
|
|
.add_property( |
122 |
|
|
"a0_local", |
123 |
✓✗ |
10 |
bp::make_getter(&ContactData6D::a0_local, |
124 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
125 |
✓✗ |
10 |
"desired local contact acceleration") |
126 |
|
|
.add_property("v_partial_dq", |
127 |
✓✗ |
10 |
bp::make_getter(&ContactData6D::v_partial_dq, |
128 |
|
10 |
bp::return_internal_reference<>()), |
129 |
✓✗ |
10 |
"Jacobian of the spatial body velocity") |
130 |
|
|
.add_property("a_partial_dq", |
131 |
✓✗ |
10 |
bp::make_getter(&ContactData6D::a_partial_dq, |
132 |
|
10 |
bp::return_internal_reference<>()), |
133 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
134 |
|
|
.add_property("a_partial_dv", |
135 |
✓✗ |
10 |
bp::make_getter(&ContactData6D::a_partial_dv, |
136 |
|
10 |
bp::return_internal_reference<>()), |
137 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
138 |
|
|
.add_property("a_partial_da", |
139 |
✓✗ |
10 |
bp::make_getter(&ContactData6D::a_partial_da, |
140 |
|
10 |
bp::return_internal_reference<>()), |
141 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
142 |
✓✗ |
10 |
.def(CopyableVisitor<ContactData6D>()); |
143 |
|
10 |
} |
144 |
|
|
|
145 |
|
|
} // namespace python |
146 |
|
|
} // namespace crocoddyl |