Line |
Branch |
Exec |
Source |
1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-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 float |
11 |
|
|
#include "python/crocoddyl/multibody/contact-base.hpp" |
12 |
|
|
|
13 |
|
|
#include "python/crocoddyl/multibody/multibody.hpp" |
14 |
|
|
|
15 |
|
|
namespace crocoddyl { |
16 |
|
|
namespace python { |
17 |
|
|
|
18 |
|
|
template <typename Model> |
19 |
|
|
struct ContactModelAbstractVisitor |
20 |
|
|
: public bp::def_visitor<ContactModelAbstractVisitor<Model>> { |
21 |
|
|
template <class PyClass> |
22 |
|
✗ |
void visit(PyClass& cl) const { |
23 |
|
✗ |
cl.def("calc", pure_virtual(&Model::calc), bp::args("self", "data", "x"), |
24 |
|
|
"Compute the contact Jacobian and drift.\n\n" |
25 |
|
|
"The rigid contact model throught acceleration-base holonomic " |
26 |
|
|
"constraint of the contact frame placement.\n" |
27 |
|
|
":param data: contact data\n" |
28 |
|
|
":param x: state point (dim. state.nx)") |
29 |
|
✗ |
.def("calcDiff", pure_virtual(&Model::calcDiff), |
30 |
|
|
bp::args("self", "data", "x"), |
31 |
|
|
"Compute the derivatives of contact holonomic constraint.\n\n" |
32 |
|
|
"The rigid contact model throught acceleration-base holonomic " |
33 |
|
|
"constraint of the contact frame placement. It assumes that calc " |
34 |
|
|
"has been run first.\n" |
35 |
|
|
":param data: contact data\n" |
36 |
|
|
":param x: state point (dim. state.nx)") |
37 |
|
✗ |
.def("updateForce", pure_virtual(&Model::updateForce), |
38 |
|
|
bp::args("self", "data", "force"), |
39 |
|
|
"Convert the force into a stack of spatial forces.\n\n" |
40 |
|
|
":param data: contact data\n" |
41 |
|
|
":param force: force vector (dimension nc)") |
42 |
|
✗ |
.def("updateForceDiff", &Model::updateForceDiff, |
43 |
|
|
bp::args("self", "data", "df_dx", "df_du"), |
44 |
|
|
"Update the Jacobians of the force.\n\n" |
45 |
|
|
":param data: contact data\n" |
46 |
|
|
":param df_dx: Jacobian of the force with respect to the state\n" |
47 |
|
|
":param df_du: Jacobian of the force with respect to the control") |
48 |
|
✗ |
.def("setZeroForce", &Model::setZeroForce, bp::args("self", "data"), |
49 |
|
|
"Set zero the spatial force.\n\n" |
50 |
|
|
":param data: contact data") |
51 |
|
✗ |
.def("setZeroForceDiff", &Model::setZeroForceDiff, |
52 |
|
|
bp::args("self", "data"), |
53 |
|
|
"Set zero the derivatives of the spatial force.\n\n" |
54 |
|
|
":param data: contact data") |
55 |
|
✗ |
.def("createData", &Model::createData, |
56 |
|
✗ |
bp::with_custodian_and_ward_postcall<0, 2>(), |
57 |
|
|
bp::args("self", "data"), |
58 |
|
|
"Create the contact data.\n\n" |
59 |
|
|
"Each contact model has its own data that needs to be allocated. " |
60 |
|
|
"This function returns the allocated data for a predefined " |
61 |
|
|
"contact.\n" |
62 |
|
|
":param data: Pinocchio data\n" |
63 |
|
|
":return contact data.") |
64 |
|
✗ |
.def("createData", &Model::default_createData, |
65 |
|
✗ |
bp::with_custodian_and_ward_postcall<0, 2>()) |
66 |
|
✗ |
.add_property( |
67 |
|
|
"state", |
68 |
|
|
bp::make_function(&Model::get_state, |
69 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
70 |
|
|
"state of the multibody system") |
71 |
|
✗ |
.add_property("nc", bp::make_function(&Model::get_nc), |
72 |
|
|
"dimension of contact") |
73 |
|
✗ |
.add_property("nu", bp::make_function(&Model::get_nu), |
74 |
|
|
"dimension of control") |
75 |
|
✗ |
.add_property("id", &Model::get_id, &Model::set_id, |
76 |
|
|
"reference frame id") |
77 |
|
✗ |
.add_property("type", bp::make_function(&Model::get_type), |
78 |
|
|
&Model::set_type, "type of contact"); |
79 |
|
|
} |
80 |
|
|
}; |
81 |
|
|
|
82 |
|
|
template <typename Data> |
83 |
|
|
struct ContactDataAbstractVisitor |
84 |
|
|
: public bp::def_visitor<ContactDataAbstractVisitor<Data>> { |
85 |
|
|
template <class PyClass> |
86 |
|
✗ |
void visit(PyClass& cl) const { |
87 |
|
✗ |
cl.add_property( |
88 |
|
✗ |
"fXj", bp::make_getter(&Data::fXj, bp::return_internal_reference<>()), |
89 |
|
|
bp::make_setter(&Data::fXj), |
90 |
|
|
"action matrix from contact to local frames") |
91 |
|
✗ |
.add_property( |
92 |
|
✗ |
"a0", bp::make_getter(&Data::a0, bp::return_internal_reference<>()), |
93 |
|
|
bp::make_setter(&Data::a0), "desired contact acceleration") |
94 |
|
✗ |
.add_property( |
95 |
|
|
"da0_dx", |
96 |
|
✗ |
bp::make_getter(&Data::da0_dx, bp::return_internal_reference<>()), |
97 |
|
|
bp::make_setter(&Data::da0_dx), |
98 |
|
|
"Jacobian of the desired contact acceleration") |
99 |
|
✗ |
.add_property( |
100 |
|
|
"dtau_dq", |
101 |
|
✗ |
bp::make_getter(&Data::dtau_dq, bp::return_internal_reference<>()), |
102 |
|
|
bp::make_setter(&Data::dtau_dq), "Force contribution to dtau_dq"); |
103 |
|
|
} |
104 |
|
|
}; |
105 |
|
|
|
106 |
|
|
#define CROCODDYL_CONTACT_MODEL_ABSTRACT_PYTHON_BINDINGS(Scalar) \ |
107 |
|
|
typedef ContactModelAbstractTpl<Scalar> Model; \ |
108 |
|
|
typedef ContactModelAbstractTpl_wrap<Scalar> Model_wrap; \ |
109 |
|
|
typedef Model::StateMultibody State; \ |
110 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ |
111 |
|
|
bp::class_<Model_wrap, boost::noncopyable>( \ |
112 |
|
|
"ContactModelAbstract", \ |
113 |
|
|
"Abstract rigid contact model.\n\n" \ |
114 |
|
|
"It defines a template for rigid contact models based on " \ |
115 |
|
|
"acceleration-based holonomic constraints. The calc and calcDiff " \ |
116 |
|
|
"functions compute the contact Jacobian and drift (holonomic " \ |
117 |
|
|
"constraint) or the derivatives of the holonomic constraint, " \ |
118 |
|
|
"respectively.", \ |
119 |
|
|
bp::init<std::shared_ptr<State>, pinocchio::ReferenceFrame, std::size_t, \ |
120 |
|
|
bp::optional<std::size_t>>( \ |
121 |
|
|
bp::args("self", "state", "type", "nc", "nu"), \ |
122 |
|
|
"Initialize the contact model.\n\n" \ |
123 |
|
|
":param state: state of the multibody system\n" \ |
124 |
|
|
":param type: type of contact\n" \ |
125 |
|
|
":param nc: dimension of contact model\n" \ |
126 |
|
|
":param nu: dimension of the control vector (default state.nv)")) \ |
127 |
|
|
.def(ContactModelAbstractVisitor<Model_wrap>()) \ |
128 |
|
|
.def(PrintableVisitor<Model_wrap>()) \ |
129 |
|
|
.def(CopyableVisitor<Model_wrap>()); |
130 |
|
|
|
131 |
|
|
#define CROCODDYL_CONTACT_DATA_ABSTRACT_PYTHON_BINDINGS(Scalar) \ |
132 |
|
|
typedef ContactDataAbstractTpl<Scalar> Data; \ |
133 |
|
|
typedef ContactModelAbstractTpl<Scalar> Model; \ |
134 |
|
|
typedef ForceDataAbstractTpl<Scalar> ForceData; \ |
135 |
|
|
typedef pinocchio::DataTpl<Scalar> PinocchioData; \ |
136 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ |
137 |
|
|
bp::class_<Data, bp::bases<ForceData>>( \ |
138 |
|
|
"ContactDataAbstract", "Abstract class for contact datas.\n\n", \ |
139 |
|
|
bp::init<Model*, PinocchioData*>( \ |
140 |
|
|
bp::args("self", "model", "data"), \ |
141 |
|
|
"Create common data shared between contact models.\n\n" \ |
142 |
|
|
":param model: contact model\n" \ |
143 |
|
|
":param data: Pinocchio data")[bp::with_custodian_and_ward< \ |
144 |
|
|
1, 2, bp::with_custodian_and_ward<1, 3>>()]) \ |
145 |
|
|
.def(ContactDataAbstractVisitor<Data>()) \ |
146 |
|
|
.def(CopyableVisitor<Data>()); |
147 |
|
|
|
148 |
|
✗ |
void exposeContactAbstract() { |
149 |
|
✗ |
CROCODDYL_CONTACT_MODEL_ABSTRACT_PYTHON_BINDINGS(float) |
150 |
|
✗ |
CROCODDYL_CONTACT_DATA_ABSTRACT_PYTHON_BINDINGS(float) |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
} // namespace python |
154 |
|
|
} // namespace crocoddyl |
155 |
|
|
|