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