Line |
Branch |
Exec |
Source |
1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh, CTU, INRIA, |
5 |
|
|
// University of Oxford, 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/actions/contact-fwddyn.hpp" |
12 |
|
|
|
13 |
|
|
#include "python/crocoddyl/core/diff-action-base.hpp" |
14 |
|
|
#include "python/crocoddyl/multibody/multibody.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
|
template <typename Model> |
20 |
|
|
struct DifferentialActionModelContactFwdDynamicsVisitor |
21 |
|
|
: public bp::def_visitor< |
22 |
|
|
DifferentialActionModelContactFwdDynamicsVisitor<Model>> { |
23 |
|
|
typedef typename Model::Scalar Scalar; |
24 |
|
|
typedef typename Model::DifferentialActionDataAbstract Data; |
25 |
|
|
typedef typename Model::StateMultibody State; |
26 |
|
|
typedef typename Model::ActuationModelAbstract Actuation; |
27 |
|
|
typedef typename Model::ContactModelMultiple Contacts; |
28 |
|
|
typedef typename Model::CostModelSum Costs; |
29 |
|
|
typedef typename Model::ConstraintModelManager Constraints; |
30 |
|
|
typedef typename Model::VectorXs VectorXs; |
31 |
|
|
template <class PyClass> |
32 |
|
✗ |
void visit(PyClass& cl) const { |
33 |
|
|
cl |
34 |
|
✗ |
.def(bp::init<std::shared_ptr<State>, std::shared_ptr<Actuation>, |
35 |
|
|
std::shared_ptr<Contacts>, std::shared_ptr<Costs>, |
36 |
|
|
std::shared_ptr<Constraints>, bp::optional<Scalar, bool>>( |
37 |
|
|
bp::args("self", "state", "actuation", "contacts", "costs", |
38 |
|
|
"constraints", "inv_damping", "enable_force"), |
39 |
|
|
"Initialize the constrained forward-dynamics action model.\n\n" |
40 |
|
|
"The damping factor is needed when the contact Jacobian is not " |
41 |
|
|
"full-rank. Otherwise, a good damping factor could be 1e-12. In " |
42 |
|
|
"addition, if you have cost based on forces, you need to enable " |
43 |
|
|
"the computation of the force Jacobians (i.e. enable_force=True).\n" |
44 |
|
|
":param state: multibody state\n" |
45 |
|
|
":param actuation: actuation model\n" |
46 |
|
|
":param contacts: multiple contact model\n" |
47 |
|
|
":param costs: stack of cost functions\n" |
48 |
|
|
":param constraints: stack of constraint functions\n" |
49 |
|
|
":param inv_damping: Damping factor for cholesky decomposition of " |
50 |
|
|
"JMinvJt (default 0.)\n" |
51 |
|
|
":param enable_force: Enable the computation of force Jacobians " |
52 |
|
|
"(default False)")) |
53 |
|
✗ |
.def( |
54 |
|
|
"calc", |
55 |
|
|
static_cast<void (Model::*)( |
56 |
|
|
const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, |
57 |
|
|
const Eigen::Ref<const VectorXs>&)>(&Model::calc), |
58 |
|
|
bp::args("self", "data", "x", "u"), |
59 |
|
|
"Compute the next state and cost value.\n\n" |
60 |
|
|
"It describes the time-continuous evolution of the multibody " |
61 |
|
|
"system with contact. The contacts are modelled as holonomic " |
62 |
|
|
"constraints. Additionally it computes the cost value associated " |
63 |
|
|
"to this state and control pair.\n" |
64 |
|
|
":param data: contact forward-dynamics action data\n" |
65 |
|
|
":param x: time-continuous state vector\n" |
66 |
|
|
":param u: time-continuous control input") |
67 |
|
✗ |
.def("calc", |
68 |
|
|
static_cast<void (Model::*)(const std::shared_ptr<Data>&, |
69 |
|
|
const Eigen::Ref<const VectorXs>&)>( |
70 |
|
|
&Model::calc), |
71 |
|
|
bp::args("self", "data", "x")) |
72 |
|
✗ |
.def( |
73 |
|
|
"calcDiff", |
74 |
|
|
static_cast<void (Model::*)( |
75 |
|
|
const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&, |
76 |
|
|
const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff), |
77 |
|
|
bp::args("self", "data", "x", "u"), |
78 |
|
|
"Compute the derivatives of the differential multibody system and " |
79 |
|
|
"its cost functions.\n\n" |
80 |
|
|
"It computes the partial derivatives of the differential multibody " |
81 |
|
|
"system and the cost function. It assumes that calc has been run " |
82 |
|
|
"first. This function builds a quadratic approximation of the " |
83 |
|
|
"action model (i.e. dynamical system and cost function).\n" |
84 |
|
|
":param data: contact forward-dynamics action data\n" |
85 |
|
|
":param x: time-continuous state vector\n" |
86 |
|
|
":param u: time-continuous control input\n") |
87 |
|
✗ |
.def("calcDiff", |
88 |
|
|
static_cast<void (Model::*)(const std::shared_ptr<Data>&, |
89 |
|
|
const Eigen::Ref<const VectorXs>&)>( |
90 |
|
|
&Model::calcDiff), |
91 |
|
|
bp::args("self", "data", "x")) |
92 |
|
✗ |
.def("createData", &Model::createData, bp::args("self"), |
93 |
|
|
"Create the contact forward dynamics differential action data.") |
94 |
|
✗ |
.add_property("pinocchio", |
95 |
|
|
bp::make_function(&Model::get_pinocchio, |
96 |
|
✗ |
bp::return_internal_reference<>()), |
97 |
|
|
"multibody model (i.e. pinocchio model)") |
98 |
|
✗ |
.add_property( |
99 |
|
|
"actuation", |
100 |
|
|
bp::make_function(&Model::get_actuation, |
101 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
102 |
|
|
"actuation model") |
103 |
|
✗ |
.add_property( |
104 |
|
|
"contacts", |
105 |
|
|
bp::make_function(&Model::get_contacts, |
106 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
107 |
|
|
"multiple contact model") |
108 |
|
✗ |
.add_property( |
109 |
|
|
"costs", |
110 |
|
|
bp::make_function(&Model::get_costs, |
111 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
112 |
|
|
"total cost model") |
113 |
|
✗ |
.add_property( |
114 |
|
|
"constraints", |
115 |
|
|
bp::make_function(&Model::get_constraints, |
116 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
117 |
|
|
"constraint model manager") |
118 |
|
✗ |
.add_property( |
119 |
|
|
"armature", |
120 |
|
|
bp::make_function(&Model::get_armature, |
121 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
122 |
|
|
bp::make_function(&Model::set_armature), |
123 |
|
|
"set an armature mechanism in the joints") |
124 |
|
✗ |
.add_property("JMinvJt_damping", |
125 |
|
|
bp::make_function(&Model::get_damping_factor), |
126 |
|
|
bp::make_function(&Model::set_damping_factor), |
127 |
|
|
"Damping factor for cholesky decomposition of JMinvJt"); |
128 |
|
|
} |
129 |
|
|
}; |
130 |
|
|
|
131 |
|
|
template <typename Data> |
132 |
|
|
struct DifferentialActionDataContactFwdDynamicsVisitor |
133 |
|
|
: public bp::def_visitor< |
134 |
|
|
DifferentialActionDataContactFwdDynamicsVisitor<Data>> { |
135 |
|
|
template <class PyClass> |
136 |
|
✗ |
void visit(PyClass& cl) const { |
137 |
|
✗ |
cl.add_property( |
138 |
|
|
"pinocchio", |
139 |
|
✗ |
bp::make_getter(&Data::pinocchio, bp::return_internal_reference<>()), |
140 |
|
|
"pinocchio data") |
141 |
|
✗ |
.add_property("multibody", |
142 |
|
|
bp::make_getter(&Data::multibody, |
143 |
|
✗ |
bp::return_internal_reference<>()), |
144 |
|
|
"multibody data") |
145 |
|
✗ |
.add_property( |
146 |
|
|
"costs", |
147 |
|
|
bp::make_getter(&Data::costs, |
148 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
149 |
|
|
"total cost data") |
150 |
|
✗ |
.add_property( |
151 |
|
|
"constraints", |
152 |
|
|
bp::make_getter(&Data::constraints, |
153 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
154 |
|
|
"constraint data") |
155 |
|
✗ |
.add_property( |
156 |
|
|
"Kinv", |
157 |
|
✗ |
bp::make_getter(&Data::Kinv, bp::return_internal_reference<>()), |
158 |
|
|
"inverse of the KKT matrix") |
159 |
|
✗ |
.add_property( |
160 |
|
|
"df_dx", |
161 |
|
✗ |
bp::make_getter(&Data::df_dx, bp::return_internal_reference<>()), |
162 |
|
|
"Jacobian of the contact force") |
163 |
|
✗ |
.add_property( |
164 |
|
|
"df_du", |
165 |
|
✗ |
bp::make_getter(&Data::df_du, bp::return_internal_reference<>()), |
166 |
|
|
"Jacobian of the contact force"); |
167 |
|
|
} |
168 |
|
|
}; |
169 |
|
|
|
170 |
|
|
#define CROCODDYL_ACTION_MODEL_CONTACT_FWDDYN_PYTHON_BINDINGS(Scalar) \ |
171 |
|
|
typedef DifferentialActionModelContactFwdDynamicsTpl<Scalar> Model; \ |
172 |
|
|
typedef DifferentialActionModelAbstractTpl<Scalar> ModelBase; \ |
173 |
|
|
typedef typename Model::StateMultibody State; \ |
174 |
|
|
typedef typename Model::ActuationModelAbstract Actuation; \ |
175 |
|
|
typedef typename Model::ContactModelMultiple Contacts; \ |
176 |
|
|
typedef typename Model::CostModelSum Costs; \ |
177 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ |
178 |
|
|
bp::class_<Model, bp::bases<ModelBase>>( \ |
179 |
|
|
"DifferentialActionModelContactFwdDynamics", \ |
180 |
|
|
"Differential action model for contact forward dynamics in multibody " \ |
181 |
|
|
"systems.\n\n" \ |
182 |
|
|
"The contact is modelled as holonomic constraits in the contact frame. " \ |
183 |
|
|
"There is also a custom implementation in case of system with " \ |
184 |
|
|
"armatures. If you want to include the armature, you need to use " \ |
185 |
|
|
"set_armature(). On the other hand, the stack of cost functions are " \ |
186 |
|
|
"implemented in CostModelSum().", \ |
187 |
|
|
bp::init<std::shared_ptr<State>, std::shared_ptr<Actuation>, \ |
188 |
|
|
std::shared_ptr<Contacts>, std::shared_ptr<Costs>, \ |
189 |
|
|
bp::optional<Scalar, bool>>( \ |
190 |
|
|
bp::args("self", "state", "actuation", "contacts", "costs", \ |
191 |
|
|
"inv_damping", "enable_force"), \ |
192 |
|
|
"Initialize the constrained forward-dynamics action model.\n\n" \ |
193 |
|
|
"The damping factor is needed when the contact Jacobian is not " \ |
194 |
|
|
"full-rank. Otherwise, a good damping factor could be 1e-12. In " \ |
195 |
|
|
"addition, if you have cost based on forces, you need to enable " \ |
196 |
|
|
"the computation of the force Jacobians (i.e., " \ |
197 |
|
|
"enable_force=True).\n" \ |
198 |
|
|
":param state: multibody state\n" \ |
199 |
|
|
":param actuation: actuation model\n" \ |
200 |
|
|
":param contacts: multiple contact model\n" \ |
201 |
|
|
":param costs: stack of cost functions\n" \ |
202 |
|
|
":param inv_damping: Damping factor for cholesky decomposition of " \ |
203 |
|
|
"JMinvJt (default 0.)\n" \ |
204 |
|
|
":param enable_force: Enable the computation of force Jacobians " \ |
205 |
|
|
"(default False)")) \ |
206 |
|
|
.def(DifferentialActionModelContactFwdDynamicsVisitor<Model>()) \ |
207 |
|
|
.def(CastVisitor<Model>()) \ |
208 |
|
|
.def(PrintableVisitor<Model>()) \ |
209 |
|
|
.def(CopyableVisitor<Model>()); |
210 |
|
|
|
211 |
|
|
#define CROCODDYL_ACTION_DATA_CONTACT_FWDDYN_PYTHON_BINDINGS(Scalar) \ |
212 |
|
|
typedef DifferentialActionDataContactFwdDynamicsTpl<Scalar> Data; \ |
213 |
|
|
typedef DifferentialActionDataAbstractTpl<Scalar> DataBase; \ |
214 |
|
|
typedef DifferentialActionModelContactFwdDynamicsTpl<Scalar> Model; \ |
215 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ |
216 |
|
|
bp::class_<Data, bp::bases<DataBase>>( \ |
217 |
|
|
"DifferentialActionDataContactFwdDynamics", \ |
218 |
|
|
"Action data for the contact forward dynamics system.", \ |
219 |
|
|
bp::init<Model*>(bp::args("self", "model"), \ |
220 |
|
|
"Create contact forward-dynamics action data.\n\n" \ |
221 |
|
|
":param model: contact forward-dynamics action model")) \ |
222 |
|
|
.def(DifferentialActionDataContactFwdDynamicsVisitor<Data>()) \ |
223 |
|
|
.def(CopyableVisitor<Data>()); |
224 |
|
|
|
225 |
|
✗ |
void exposeDifferentialActionContactFwdDynamics() { |
226 |
|
✗ |
CROCODDYL_ACTION_MODEL_CONTACT_FWDDYN_PYTHON_BINDINGS(double) |
227 |
|
✗ |
CROCODDYL_ACTION_DATA_CONTACT_FWDDYN_PYTHON_BINDINGS(double) |
228 |
|
|
} |
229 |
|
|
|
230 |
|
|
} // namespace python |
231 |
|
|
} // namespace crocoddyl |
232 |
|
|
|