1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2020-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-2d.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 exposeContact2D() { |
19 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ContactModel2D> >(); |
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_<ContactModel2D, bp::bases<ContactModelAbstract> >( |
26 |
|
|
"ContactModel2D", |
27 |
|
|
"Rigid 2D contact model.\n\n" |
28 |
|
|
"It defines a rigid 2D contact models (point contact) based on " |
29 |
|
|
"acceleration-based holonomic constraints, in x,z " |
30 |
|
|
"directions.\n" |
31 |
|
|
"The calc and calcDiff functions compute the contact Jacobian and drift " |
32 |
|
|
"(holonomic constraint) or\n" |
33 |
|
|
"the derivatives of the holonomic constraint, respectively.", |
34 |
✓✗ |
10 |
bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
35 |
|
|
Eigen::Vector2d, std::size_t, bp::optional<Eigen::Vector2d> >( |
36 |
|
20 |
bp::args("self", "state", "id", "xref", "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 nu: dimension of control vector\n" |
42 |
|
|
":param gains: gains of the contact model (default " |
43 |
|
|
"np.matrix([0.,0.]))")) |
44 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
45 |
|
|
Eigen::Vector2d, bp::optional<Eigen::Vector2d> >( |
46 |
✓✗ |
20 |
bp::args("self", "state", "id", "xref", "gains"), |
47 |
|
|
"Initialize the contact model.\n\n" |
48 |
|
|
":param state: state of the multibody system\n" |
49 |
|
|
":param id: reference frame id of the contact\n" |
50 |
|
|
":param xref: contact position used for the Baumgarte stabilization\n" |
51 |
|
|
":param gains: gains of the contact model (default " |
52 |
✓✗ |
10 |
"np.matrix([0.,0.]))")) |
53 |
✓✗ |
20 |
.def("calc", &ContactModel2D::calc, bp::args("self", "data", "x"), |
54 |
|
|
"Compute the 2D contact Jacobian and drift.\n\n" |
55 |
|
|
"The rigid contact model throught acceleration-base holonomic " |
56 |
|
|
"constraint\n" |
57 |
|
|
"of the contact frame placement.\n" |
58 |
|
|
":param data: contact data\n" |
59 |
✓✗ |
10 |
":param x: state point (dim. state.nx)") |
60 |
✓✗ |
20 |
.def("calcDiff", &ContactModel2D::calcDiff, bp::args("self", "data", "x"), |
61 |
|
|
"Compute the derivatives of the 2D contact holonomic constraint.\n\n" |
62 |
|
|
"The rigid contact model throught acceleration-base holonomic " |
63 |
|
|
"constraint\n" |
64 |
|
|
"of the contact frame placement.\n" |
65 |
|
|
"It assumes that calc has been run first.\n" |
66 |
|
|
":param data: cost data\n" |
67 |
✓✗ |
10 |
":param x: state point (dim. state.nx)") |
68 |
|
|
.def("updateForce", &ContactModel2D::updateForce, |
69 |
✓✗ |
20 |
bp::args("self", "data", "force"), |
70 |
|
|
"Convert the force into a stack of spatial forces.\n\n" |
71 |
|
|
":param data: cost data\n" |
72 |
✓✗ |
10 |
":param force: force vector (dimension 2)") |
73 |
|
|
.def("createData", &ContactModel2D::createData, |
74 |
|
|
bp::with_custodian_and_ward_postcall<0, 2>(), |
75 |
✓✗ |
20 |
bp::args("self", "data"), |
76 |
|
|
"Create the 2D contact data.\n\n" |
77 |
|
|
"Each contact model has its own data that needs to be allocated. " |
78 |
|
|
"This function\n" |
79 |
|
|
"returns the allocated data for a predefined cost.\n" |
80 |
|
|
":param data: Pinocchio data\n" |
81 |
✓✗ |
10 |
":return contact data.") |
82 |
|
|
.add_property("reference", |
83 |
|
|
bp::make_function(&ContactModel2D::get_reference, |
84 |
|
10 |
bp::return_internal_reference<>()), |
85 |
|
|
&ContactModel2D::set_reference, |
86 |
✓✗✓✗
|
10 |
"reference contact translation") |
87 |
|
|
.add_property( |
88 |
|
|
"gains", |
89 |
✓✗ |
10 |
bp::make_function(&ContactModel2D::get_gains, |
90 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
91 |
✓✗ |
10 |
"contact gains") |
92 |
✓✗ |
10 |
.def(CopyableVisitor<ContactModel2D>()); |
93 |
|
|
|
94 |
|
|
#pragma GCC diagnostic pop |
95 |
|
|
|
96 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ContactData2D> >(); |
97 |
|
|
|
98 |
✓✗ |
10 |
bp::class_<ContactData2D, bp::bases<ContactDataAbstract> >( |
99 |
|
|
"ContactData2D", "Data for 2D contact.\n\n", |
100 |
✓✗ |
10 |
bp::init<ContactModel2D*, pinocchio::Data*>( |
101 |
✓✗ |
10 |
bp::args("self", "model", "data"), |
102 |
|
|
"Create 2D contact data.\n\n" |
103 |
|
|
":param model: 2D contact model\n" |
104 |
|
10 |
":param data: Pinocchio data")[bp::with_custodian_and_ward< |
105 |
✓✗ |
20 |
1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
106 |
|
|
.add_property( |
107 |
|
|
"v", |
108 |
✓✗ |
10 |
bp::make_getter(&ContactData2D::v, |
109 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
110 |
✓✗ |
10 |
"spatial velocity of the contact body") |
111 |
|
|
.add_property( |
112 |
|
|
"a", |
113 |
✓✗ |
10 |
bp::make_getter(&ContactData2D::a, |
114 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
115 |
✓✗ |
10 |
"spatial acceleration of the contact body") |
116 |
|
|
.add_property("fJf", |
117 |
✓✗ |
10 |
bp::make_getter(&ContactData2D::fJf, |
118 |
|
10 |
bp::return_internal_reference<>()), |
119 |
✓✗ |
10 |
"local Jacobian of the contact frame") |
120 |
|
|
.add_property("v_partial_dq", |
121 |
✓✗ |
10 |
bp::make_getter(&ContactData2D::v_partial_dq, |
122 |
|
10 |
bp::return_internal_reference<>()), |
123 |
✓✗ |
10 |
"Jacobian of the spatial body velocity") |
124 |
|
|
.add_property("a_partial_dq", |
125 |
✓✗ |
10 |
bp::make_getter(&ContactData2D::a_partial_dq, |
126 |
|
10 |
bp::return_internal_reference<>()), |
127 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
128 |
|
|
.add_property("a_partial_dv", |
129 |
✓✗ |
10 |
bp::make_getter(&ContactData2D::a_partial_dv, |
130 |
|
10 |
bp::return_internal_reference<>()), |
131 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
132 |
|
|
.add_property("a_partial_da", |
133 |
✓✗ |
10 |
bp::make_getter(&ContactData2D::a_partial_da, |
134 |
|
10 |
bp::return_internal_reference<>()), |
135 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
136 |
|
|
.add_property( |
137 |
|
|
"oRf", |
138 |
✓✗ |
10 |
bp::make_getter(&ContactData2D::oRf, |
139 |
|
10 |
bp::return_internal_reference<>()), |
140 |
✓✗ |
10 |
"Rotation matrix of the contact body expressed in the world frame") |
141 |
✓✗ |
10 |
.def(CopyableVisitor<ContactData2D>()); |
142 |
|
10 |
} |
143 |
|
|
|
144 |
|
|
} // namespace python |
145 |
|
|
} // namespace crocoddyl |