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-1d.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 exposeContact1D() { |
19 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ContactModel1D> >(); |
20 |
|
|
|
21 |
✓✗ |
10 |
bp::class_<ContactModel1D, bp::bases<ContactModelAbstract> >( |
22 |
|
|
"ContactModel1D", |
23 |
|
|
"Rigid 1D contact model.\n\n" |
24 |
|
|
"It defines a rigid 1D contact model (point contact) based on " |
25 |
|
|
"acceleration-based holonomic constraints, in the " |
26 |
|
|
"z " |
27 |
|
|
"direction.\n" |
28 |
|
|
"The calc and calcDiff functions compute the contact Jacobian and drift " |
29 |
|
|
"(holonomic constraint) or\n" |
30 |
|
|
"the derivatives of the holonomic constraint, respectively.", |
31 |
✓✗ |
10 |
bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, double, |
32 |
|
|
pinocchio::ReferenceFrame, Eigen::Matrix3d, std::size_t, |
33 |
|
|
bp::optional<Eigen::Vector2d> >( |
34 |
|
20 |
bp::args("self", "state", "id", "xref", "type", "rotation", "nu", |
35 |
|
|
"gains"), |
36 |
|
|
"Initialize the contact model.\n\n" |
37 |
|
|
":param state: state of the multibody system\n" |
38 |
|
|
":param id: reference frame id of the contact\n" |
39 |
|
|
":param xref: contact position used for the Baumgarte stabilization\n" |
40 |
|
|
":param type: type of contact\n" |
41 |
|
|
":param rotation: rotation of the reference frame's z axis" |
42 |
|
|
":param nu: dimension of control vector\n" |
43 |
|
|
":param gains: gains of the contact model (default " |
44 |
|
|
"np.matrix([0.,0.]))")) |
45 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateMultibody>, pinocchio::FrameIndex, |
46 |
|
|
double, pinocchio::ReferenceFrame, |
47 |
|
|
bp::optional<Eigen::Vector2d> >( |
48 |
✓✗ |
20 |
bp::args("self", "state", "id", "xref", "type", "gains"), |
49 |
|
|
"Initialize the contact model.\n\n" |
50 |
|
|
":param state: state of the multibody system\n" |
51 |
|
|
":param id: reference frame id of the contact\n" |
52 |
|
|
":param xref: contact position used for the Baumgarte stabilization\n" |
53 |
|
|
":param type: type of contact\n" |
54 |
|
|
":param gains: gains of the contact model (default " |
55 |
✓✗ |
10 |
"np.matrix([0.,0.]))")) |
56 |
✓✗ |
20 |
.def("calc", &ContactModel1D::calc, bp::args("self", "data", "x"), |
57 |
|
|
"Compute the 1D contact Jacobian and drift.\n\n" |
58 |
|
|
"The rigid contact model throught acceleration-base holonomic " |
59 |
|
|
"constraint\n" |
60 |
|
|
"of the contact frame placement.\n" |
61 |
|
|
":param data: contact data\n" |
62 |
✓✗ |
10 |
":param x: state point (dim. state.nx)") |
63 |
✓✗ |
20 |
.def("calcDiff", &ContactModel1D::calcDiff, bp::args("self", "data", "x"), |
64 |
|
|
"Compute the derivatives of the 1D contact holonomic constraint.\n\n" |
65 |
|
|
"The rigid contact model throught acceleration-base holonomic " |
66 |
|
|
"constraint\n" |
67 |
|
|
"of the contact frame placement.\n" |
68 |
|
|
"It assumes that calc has been run first.\n" |
69 |
|
|
":param data: cost data\n" |
70 |
✓✗ |
10 |
":param x: state point (dim. state.nx)") |
71 |
|
|
.def("updateForce", &ContactModel1D::updateForce, |
72 |
✓✗ |
20 |
bp::args("self", "data", "force"), |
73 |
|
|
"Convert the force into a stack of spatial forces.\n\n" |
74 |
|
|
":param data: cost data\n" |
75 |
✓✗ |
10 |
":param force: force vector (dimension 1)") |
76 |
|
|
.def("createData", &ContactModel1D::createData, |
77 |
|
|
bp::with_custodian_and_ward_postcall<0, 2>(), |
78 |
✓✗ |
20 |
bp::args("self", "data"), |
79 |
|
|
"Create the 1D contact data.\n\n" |
80 |
|
|
"Each contact model has its own data that needs to be allocated. " |
81 |
|
|
"This function\n" |
82 |
|
|
"returns the allocated data for a predefined cost.\n" |
83 |
|
|
":param data: Pinocchio data\n" |
84 |
✓✗ |
10 |
":return contact data.") |
85 |
|
|
.add_property( |
86 |
|
|
"reference", |
87 |
|
|
bp::make_function(&ContactModel1D::get_reference, |
88 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
89 |
✓✗✓✗
|
10 |
&ContactModel1D::set_reference, "reference contact translation") |
90 |
|
|
.add_property("Raxis", |
91 |
|
|
bp::make_function(&ContactModel1D::get_axis_rotation, |
92 |
|
10 |
bp::return_internal_reference<>()), |
93 |
|
|
&ContactModel1D::set_axis_rotation, |
94 |
✓✗✓✗
|
10 |
"rotation of the reference frame's z axis") |
95 |
|
|
.add_property( |
96 |
|
|
"gains", |
97 |
✓✗ |
10 |
bp::make_function(&ContactModel1D::get_gains, |
98 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
99 |
✓✗ |
10 |
"contact gains") |
100 |
✓✗ |
10 |
.def(CopyableVisitor<ContactModel1D>()); |
101 |
|
|
|
102 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ContactData1D> >(); |
103 |
|
|
|
104 |
✓✗ |
10 |
bp::class_<ContactData1D, bp::bases<ContactDataAbstract> >( |
105 |
|
|
"ContactData1D", "Data for 1D contact.\n\n", |
106 |
✓✗ |
10 |
bp::init<ContactModel1D*, pinocchio::Data*>( |
107 |
✓✗ |
10 |
bp::args("self", "model", "data"), |
108 |
|
|
"Create 1D contact data.\n\n" |
109 |
|
|
":param model: 1D 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( |
113 |
|
|
"v", |
114 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::v, |
115 |
|
10 |
bp::return_value_policy<bp::return_by_value>()), |
116 |
✓✗ |
10 |
"spatial velocity of the contact body") |
117 |
|
|
.add_property("a0_local", |
118 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::a0_local, |
119 |
|
|
bp::return_internal_reference<>()), |
120 |
✓✗ |
20 |
bp::make_setter(&ContactData1D::a0_local), |
121 |
✓✗ |
10 |
"desired local contact acceleration") |
122 |
|
|
.add_property("a0_skew", |
123 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::a0_skew, |
124 |
|
|
bp::return_internal_reference<>()), |
125 |
✓✗ |
20 |
bp::make_setter(&ContactData1D::a0_skew), |
126 |
✓✗ |
10 |
"contact acceleration skew (local)") |
127 |
|
|
.add_property("a0_world_skew", |
128 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::a0_world_skew, |
129 |
|
|
bp::return_internal_reference<>()), |
130 |
✓✗ |
20 |
bp::make_setter(&ContactData1D::a0_world_skew), |
131 |
✓✗ |
10 |
"contact acceleration skew (world)") |
132 |
|
|
.add_property( |
133 |
|
|
"dp", |
134 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::dp, |
135 |
|
|
bp::return_internal_reference<>()), |
136 |
✓✗ |
20 |
bp::make_setter(&ContactData1D::dp), |
137 |
✓✗ |
10 |
"Translation error computed for the Baumgarte regularization term") |
138 |
|
|
.add_property("dp_local", |
139 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::dp_local, |
140 |
|
|
bp::return_internal_reference<>()), |
141 |
✓✗ |
20 |
bp::make_setter(&ContactData1D::dp_local), |
142 |
|
|
"local translation error computed for the Baumgarte " |
143 |
✓✗ |
10 |
"regularization term") |
144 |
|
|
.add_property("f_local", |
145 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::f_local, |
146 |
|
|
bp::return_internal_reference<>()), |
147 |
✓✗ |
20 |
bp::make_setter(&ContactData1D::f_local), |
148 |
✓✗ |
10 |
"spatial contact force in local coordinates") |
149 |
|
|
.add_property("da0_local_dx", |
150 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::da0_local_dx, |
151 |
|
|
bp::return_internal_reference<>()), |
152 |
✓✗ |
20 |
bp::make_setter(&ContactData1D::da0_local_dx), |
153 |
✓✗ |
10 |
"Jacobian of the desired local contact acceleration") |
154 |
|
|
.add_property("fJf", |
155 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::fJf, |
156 |
|
10 |
bp::return_internal_reference<>()), |
157 |
✓✗ |
10 |
"local Jacobian of the contact frame") |
158 |
|
|
.add_property("v_partial_dq", |
159 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::v_partial_dq, |
160 |
|
10 |
bp::return_internal_reference<>()), |
161 |
✓✗ |
10 |
"Jacobian of the spatial body velocity") |
162 |
|
|
.add_property("a_partial_dq", |
163 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::a_partial_dq, |
164 |
|
10 |
bp::return_internal_reference<>()), |
165 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
166 |
|
|
.add_property("a_partial_dv", |
167 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::a_partial_dv, |
168 |
|
10 |
bp::return_internal_reference<>()), |
169 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
170 |
|
|
.add_property("a_partial_da", |
171 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::a_partial_da, |
172 |
|
10 |
bp::return_internal_reference<>()), |
173 |
✓✗ |
10 |
"Jacobian of the spatial body acceleration") |
174 |
|
|
.add_property( |
175 |
|
|
"oRf", |
176 |
✓✗ |
10 |
bp::make_getter(&ContactData1D::oRf, |
177 |
|
10 |
bp::return_internal_reference<>()), |
178 |
✓✗ |
10 |
"Rotation matrix of the contact body expressed in the world frame") |
179 |
✓✗ |
10 |
.def(CopyableVisitor<ContactData1D>()); |
180 |
|
10 |
} |
181 |
|
|
|
182 |
|
|
} // namespace python |
183 |
|
|
} // namespace crocoddyl |