Line |
Branch |
Exec |
Source |
1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2020-2025, 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 |
|
|
// Auto-generated file for double |
11 |
|
|
#include "crocoddyl/multibody/contacts/contact-2d.hpp" |
12 |
|
|
|
13 |
|
|
#include "python/crocoddyl/multibody/multibody.hpp" |
14 |
|
|
|
15 |
|
|
namespace crocoddyl { |
16 |
|
|
namespace python { |
17 |
|
|
|
18 |
|
|
template <typename Model> |
19 |
|
|
struct ContactModel2DVisitor |
20 |
|
|
: public bp::def_visitor<ContactModel2DVisitor<Model>> { |
21 |
|
|
typedef typename Model::StateMultibody State; |
22 |
|
|
typedef typename Model::Vector2s Vector2s; |
23 |
|
|
template <class PyClass> |
24 |
|
✗ |
void visit(PyClass& cl) const { |
25 |
|
✗ |
cl.def(bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, Vector2s, |
26 |
|
|
bp::optional<Vector2s>>( |
27 |
|
|
bp::args("self", "state", "id", "xref", "gains"), |
28 |
|
|
"Initialize the contact model.\n\n" |
29 |
|
|
":param state: state of the multibody system\n" |
30 |
|
|
":param id: reference frame id of the contact\n" |
31 |
|
|
":param xref: contact position used for the Baumgarte " |
32 |
|
|
"stabilization\n" |
33 |
|
|
":param gains: gains of the contact model (default " |
34 |
|
|
"np.matrix([0.,0.]))")) |
35 |
|
✗ |
.def("calc", &Model::calc, bp::args("self", "data", "x"), |
36 |
|
|
"Compute the 2D contact Jacobian and drift.\n\n" |
37 |
|
|
"The rigid contact model throught acceleration-base holonomic " |
38 |
|
|
"constraint of the contact frame placement.\n" |
39 |
|
|
":param data: contact data\n" |
40 |
|
|
":param x: state point (dim. state.nx)") |
41 |
|
✗ |
.def("calcDiff", &Model::calcDiff, bp::args("self", "data", "x"), |
42 |
|
|
"Compute the derivatives of the 2D contact holonomic " |
43 |
|
|
"constraint.\n\n" |
44 |
|
|
"The rigid contact model throught acceleration-base holonomic " |
45 |
|
|
"constraint of the contact frame placement. It assumes that calc " |
46 |
|
|
"has been run first.\n" |
47 |
|
|
":param data: cost data\n" |
48 |
|
|
":param x: state point (dim. state.nx)") |
49 |
|
✗ |
.def("updateForce", &Model::updateForce, |
50 |
|
|
bp::args("self", "data", "force"), |
51 |
|
|
"Convert the force into a stack of spatial forces.\n\n" |
52 |
|
|
":param data: cost data\n" |
53 |
|
|
":param force: force vector (dimension 2)") |
54 |
|
✗ |
.def("createData", &Model::createData, |
55 |
|
✗ |
bp::with_custodian_and_ward_postcall<0, 2>(), |
56 |
|
|
bp::args("self", "data"), |
57 |
|
|
"Create the 2D contact data.\n\n" |
58 |
|
|
"Each contact model has its own data that needs to be allocated. " |
59 |
|
|
"This function returns the allocated data for a predefined cost.\n" |
60 |
|
|
":param data: Pinocchio data\n" |
61 |
|
|
":return contact data.") |
62 |
|
✗ |
.add_property("reference", |
63 |
|
|
bp::make_function(&Model::get_reference, |
64 |
|
✗ |
bp::return_internal_reference<>()), |
65 |
|
|
&Model::set_reference, "reference contact translation") |
66 |
|
✗ |
.add_property( |
67 |
|
|
"gains", |
68 |
|
|
bp::make_function(&Model::get_gains, |
69 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
70 |
|
|
"contact gains"); |
71 |
|
|
} |
72 |
|
|
}; |
73 |
|
|
|
74 |
|
|
template <typename Data> |
75 |
|
|
struct ContactData2DVisitor |
76 |
|
|
: public bp::def_visitor<ContactData2DVisitor<Data>> { |
77 |
|
|
template <class PyClass> |
78 |
|
✗ |
void visit(PyClass& cl) const { |
79 |
|
✗ |
cl.add_property( |
80 |
|
|
"v", |
81 |
|
|
bp::make_getter(&Data::v, |
82 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
83 |
|
|
"spatial velocity of the contact body") |
84 |
|
✗ |
.add_property( |
85 |
|
|
"a", |
86 |
|
|
bp::make_getter(&Data::a, |
87 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
88 |
|
|
"spatial acceleration of the contact body") |
89 |
|
✗ |
.add_property( |
90 |
|
|
"fJf", |
91 |
|
✗ |
bp::make_getter(&Data::fJf, bp::return_internal_reference<>()), |
92 |
|
|
"local Jacobian of the contact frame") |
93 |
|
✗ |
.add_property("v_partial_dq", |
94 |
|
|
bp::make_getter(&Data::v_partial_dq, |
95 |
|
✗ |
bp::return_internal_reference<>()), |
96 |
|
|
"Jacobian of the spatial body velocity") |
97 |
|
✗ |
.add_property("a_partial_dq", |
98 |
|
|
bp::make_getter(&Data::a_partial_dq, |
99 |
|
✗ |
bp::return_internal_reference<>()), |
100 |
|
|
"Jacobian of the spatial body acceleration") |
101 |
|
✗ |
.add_property("a_partial_dv", |
102 |
|
|
bp::make_getter(&Data::a_partial_dv, |
103 |
|
✗ |
bp::return_internal_reference<>()), |
104 |
|
|
"Jacobian of the spatial body acceleration") |
105 |
|
✗ |
.add_property("a_partial_da", |
106 |
|
|
bp::make_getter(&Data::a_partial_da, |
107 |
|
✗ |
bp::return_internal_reference<>()), |
108 |
|
|
"Jacobian of the spatial body acceleration") |
109 |
|
✗ |
.add_property( |
110 |
|
|
"oRf", |
111 |
|
✗ |
bp::make_getter(&Data::oRf, bp::return_internal_reference<>()), |
112 |
|
|
"Rotation matrix of the contact body expressed in the world frame"); |
113 |
|
|
} |
114 |
|
|
}; |
115 |
|
|
|
116 |
|
|
#define CROCODDYL_CONTACT_MODEL_2D_PYTHON_BINDINGS(Scalar) \ |
117 |
|
|
typedef ContactModel2DTpl<Scalar> Model; \ |
118 |
|
|
typedef ContactModelAbstractTpl<Scalar> ModelBase; \ |
119 |
|
|
typedef Model::StateMultibody State; \ |
120 |
|
|
typedef Model::Vector2s Vector2s; \ |
121 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ |
122 |
|
|
bp::class_<Model, bp::bases<ModelBase>>( \ |
123 |
|
|
"ContactModel2D", \ |
124 |
|
|
"Rigid 2D contact model.\n\n" \ |
125 |
|
|
"It defines a rigid 2D contact models (point contact) based on " \ |
126 |
|
|
"acceleration-based holonomic constraints, in x,z directions. The calc " \ |
127 |
|
|
"and calcDiff functions compute the contact Jacobian and drift " \ |
128 |
|
|
"(holonomic constraint) or the derivatives of the holonomic " \ |
129 |
|
|
"constraint, respectively.", \ |
130 |
|
|
bp::init<std::shared_ptr<State>, pinocchio::FrameIndex, Vector2s, \ |
131 |
|
|
std::size_t, bp::optional<Vector2s>>( \ |
132 |
|
|
bp::args("self", "state", "id", "xref", "nu", "gains"), \ |
133 |
|
|
"Initialize the contact model.\n\n" \ |
134 |
|
|
":param state: state of the multibody system\n" \ |
135 |
|
|
":param id: reference frame id of the contact\n" \ |
136 |
|
|
":param xref: contact position used for the Baumgarte " \ |
137 |
|
|
"stabilization\n" \ |
138 |
|
|
":param nu: dimension of control vector\n" \ |
139 |
|
|
":param gains: gains of the contact model (default " \ |
140 |
|
|
"np.matrix([0.,0.]))")) \ |
141 |
|
|
.def(ContactModel2DVisitor<Model>()) \ |
142 |
|
|
.def(CastVisitor<Model>()) \ |
143 |
|
|
.def(PrintableVisitor<Model>()) \ |
144 |
|
|
.def(CopyableVisitor<Model>()); |
145 |
|
|
|
146 |
|
|
#define CROCODDYL_CONTACT_DATA_2D_PYTHON_BINDINGS(Scalar) \ |
147 |
|
|
typedef ContactData2DTpl<Scalar> Data; \ |
148 |
|
|
typedef ContactDataAbstractTpl<Scalar> DataBase; \ |
149 |
|
|
typedef ContactModel2DTpl<Scalar> Model; \ |
150 |
|
|
typedef pinocchio::DataTpl<Scalar> PinocchioData; \ |
151 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ |
152 |
|
|
bp::class_<Data, bp::bases<DataBase>>( \ |
153 |
|
|
"ContactData2D", "Data for 2D contact.\n\n", \ |
154 |
|
|
bp::init<Model*, PinocchioData*>( \ |
155 |
|
|
bp::args("self", "model", "data"), \ |
156 |
|
|
"Create 2D contact data.\n\n" \ |
157 |
|
|
":param model: 2D contact model\n" \ |
158 |
|
|
":param data: Pinocchio data")[bp::with_custodian_and_ward< \ |
159 |
|
|
1, 2, bp::with_custodian_and_ward<1, 3>>()]) \ |
160 |
|
|
.def(ContactData2DVisitor<Data>()) \ |
161 |
|
|
.def(CopyableVisitor<Data>()); |
162 |
|
|
|
163 |
|
✗ |
void exposeContact2D() { |
164 |
|
|
#pragma GCC diagnostic push // TODO: Remove once the deprecated FrameXX has |
165 |
|
|
// been removed in a future release |
166 |
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
167 |
|
|
|
168 |
|
✗ |
CROCODDYL_CONTACT_MODEL_2D_PYTHON_BINDINGS(double) |
169 |
|
|
|
170 |
|
|
#pragma GCC diagnostic pop |
171 |
|
|
|
172 |
|
✗ |
CROCODDYL_CONTACT_DATA_2D_PYTHON_BINDINGS(double) |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
} // namespace python |
176 |
|
|
} // namespace crocoddyl |
177 |
|
|
|