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/core/actuation-base.hpp" |
12 |
|
|
|
13 |
|
|
#include "python/crocoddyl/core/core.hpp" |
14 |
|
|
|
15 |
|
|
namespace crocoddyl { |
16 |
|
|
namespace python { |
17 |
|
|
|
18 |
|
|
template <typename Model> |
19 |
|
|
struct ActuationModelAbstractVisitor |
20 |
|
|
: public bp::def_visitor<ActuationModelAbstractVisitor<Model>> { |
21 |
|
|
typedef typename Model::Scalar Scalar; |
22 |
|
|
typedef typename Model::ActuationModel ActuationModel; |
23 |
|
|
typedef typename Model::ActuationData ActuationData; |
24 |
|
|
typedef typename Model::VectorXs VectorXs; |
25 |
|
|
template <class PyClass> |
26 |
|
✗ |
void visit(PyClass& cl) const { |
27 |
|
✗ |
cl.def("calc", pure_virtual(&Model::calc), |
28 |
|
|
bp::args("self", "data", "x", "u"), |
29 |
|
|
"Compute the actuation signal and actuation set from the " |
30 |
|
|
"joint-torque input u.\n\n" |
31 |
|
|
"It describes the time-continuos evolution of the actuation model.\n" |
32 |
|
|
":param data: actuation data\n" |
33 |
|
|
":param x: state point (dim. state.nx)\n" |
34 |
|
|
":param u: joint-torque input (dim. nu)") |
35 |
|
✗ |
.def("calc", |
36 |
|
|
static_cast<void (ActuationModel::*)( |
37 |
|
|
const std::shared_ptr<ActuationData>&, |
38 |
|
|
const Eigen::Ref<const VectorXs>&)>(&ActuationModel::calc), |
39 |
|
|
bp::args("self", "data", "x"), |
40 |
|
|
"Ignore the computation of the actuation signal and actuation " |
41 |
|
|
"set.\n\n" |
42 |
|
|
"It does not update the actuation signal as this function is used " |
43 |
|
|
"in " |
44 |
|
|
"the\n" |
45 |
|
|
"terminal nodes of an optimal control problem.\n" |
46 |
|
|
":param data: actuation data\n" |
47 |
|
|
":param x: state point (dim. state.nx)") |
48 |
|
✗ |
.def("calcDiff", pure_virtual(&Model::calcDiff), |
49 |
|
|
bp::args("self", "data", "x", "u"), |
50 |
|
|
"Compute the Jacobians of the actuation model.\n\n" |
51 |
|
|
"It computes the partial derivatives of the actuation model which " |
52 |
|
|
"is\n" |
53 |
|
|
"describes in continouos time.\n" |
54 |
|
|
":param data: actuation data\n" |
55 |
|
|
":param x: state point (dim. state.nx)\n" |
56 |
|
|
":param u: joint-torque input (dim. nu)") |
57 |
|
✗ |
.def("calcDiff", |
58 |
|
|
static_cast<void (ActuationModel::*)( |
59 |
|
|
const std::shared_ptr<ActuationData>&, |
60 |
|
|
const Eigen::Ref<const VectorXs>&)>(&ActuationModel::calc), |
61 |
|
|
bp::args("self", "data", "x"), |
62 |
|
|
"Ignore the computation of the Jacobians of the actuation " |
63 |
|
|
"function.\n\n" |
64 |
|
|
"It does not update the Jacobians of the actuation function as " |
65 |
|
|
"this " |
66 |
|
|
"function\n" |
67 |
|
|
"is used in the terminal nodes of an optimal control problem.\n" |
68 |
|
|
":param data: actuation data\n" |
69 |
|
|
":param x: state point (dim. state.nx)") |
70 |
|
✗ |
.def("commands", pure_virtual(&Model::commands), |
71 |
|
|
bp::args("self", "data", "x", "tau"), |
72 |
|
|
"Compute the joint-torque commands from the generalized " |
73 |
|
|
"torques.\n\n" |
74 |
|
|
"It stores the results in data.u.\n" |
75 |
|
|
":param data: actuation data\n" |
76 |
|
|
":param x: state point (dim. state.nx)\n" |
77 |
|
|
":param tau: generalized torques (dim state.nv)") |
78 |
|
✗ |
.def("torqueTransform", &Model::torqueTransform, |
79 |
|
|
&Model::default_torqueTransform, |
80 |
|
|
bp::args("self", "data", "x", "u"), |
81 |
|
|
"Compute the torque transform from generalized torques to " |
82 |
|
|
"joint-torque inputs.\n\n" |
83 |
|
|
"It stores the results in data.Mtau.\n" |
84 |
|
|
":param data: actuation data\n" |
85 |
|
|
":param x: state point (dim. state.nx)\n" |
86 |
|
|
":param u: joint-torque input (dim nu)") |
87 |
|
✗ |
.def("createData", &Model::createData, &Model::default_createData, |
88 |
|
|
bp::args("self"), |
89 |
|
|
"Create the actuation data.\n\n" |
90 |
|
|
"Each actuation model (AM) has its own data that needs to be " |
91 |
|
|
"allocated.\n" |
92 |
|
|
"This function returns the allocated data for a predefined AM.\n" |
93 |
|
|
":return AM data.") |
94 |
|
✗ |
.add_property("nu", bp::make_function(&Model::get_nu), |
95 |
|
|
"dimension of joint-torque vector") |
96 |
|
✗ |
.add_property( |
97 |
|
|
"state", |
98 |
|
|
bp::make_function(&Model::get_state, |
99 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
100 |
|
|
"state"); |
101 |
|
|
} |
102 |
|
|
}; |
103 |
|
|
|
104 |
|
|
template <typename Data> |
105 |
|
|
struct ActuationDataAbstractVisitor |
106 |
|
|
: public bp::def_visitor<ActuationDataAbstractVisitor<Data>> { |
107 |
|
|
typedef typename Data::Scalar Scalar; |
108 |
|
|
template <class PyClass> |
109 |
|
✗ |
void visit(PyClass& cl) const { |
110 |
|
✗ |
cl.add_property( |
111 |
|
✗ |
"tau", bp::make_getter(&Data::tau, bp::return_internal_reference<>()), |
112 |
|
|
bp::make_setter(&Data::tau), "generalized torques") |
113 |
|
✗ |
.add_property( |
114 |
|
✗ |
"u", bp::make_getter(&Data::u, bp::return_internal_reference<>()), |
115 |
|
|
bp::make_setter(&Data::u), "joint-torque inputs") |
116 |
|
✗ |
.add_property( |
117 |
|
|
"dtau_dx", |
118 |
|
✗ |
bp::make_getter(&Data::dtau_dx, bp::return_internal_reference<>()), |
119 |
|
|
bp::make_setter(&Data::dtau_dx), |
120 |
|
|
"partial derivatives of the actuation model w.r.t. the state point") |
121 |
|
✗ |
.add_property( |
122 |
|
|
"dtau_du", |
123 |
|
✗ |
bp::make_getter(&Data::dtau_du, bp::return_internal_reference<>()), |
124 |
|
|
bp::make_setter(&Data::dtau_du), |
125 |
|
|
"partial derivatives of the actuation model w.r.t. the " |
126 |
|
|
"joint-torque input") |
127 |
|
✗ |
.add_property( |
128 |
|
|
"Mtau", |
129 |
|
✗ |
bp::make_getter(&Data::Mtau, bp::return_internal_reference<>()), |
130 |
|
|
bp::make_setter(&Data::Mtau), |
131 |
|
|
"torque transform from generalized torques to joint-torque input") |
132 |
|
✗ |
.add_property( |
133 |
|
|
"tau_set", |
134 |
|
|
bp::make_getter(&Data::tau_set, |
135 |
|
✗ |
bp::return_value_policy<bp::return_by_value>()), |
136 |
|
|
bp::make_setter(&Data::tau_set), "actuation set"); |
137 |
|
|
} |
138 |
|
|
}; |
139 |
|
|
|
140 |
|
|
#define CROCODDYL_ACTUATION_MODEL_ABSTRACT_PYTHON_BINDINGS(Scalar) \ |
141 |
|
|
typedef ActuationModelAbstractTpl<Scalar> Model; \ |
142 |
|
|
typedef ActuationModelAbstractTpl_wrap<Scalar> Model_wrap; \ |
143 |
|
|
typedef StateAbstractTpl<Scalar> State; \ |
144 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ |
145 |
|
|
bp::class_<Model_wrap, boost::noncopyable>( \ |
146 |
|
|
"ActuationModelAbstract", \ |
147 |
|
|
"Abstract class for actuation-mapping models.\n\n" \ |
148 |
|
|
"An actuation model is a function that maps state x and joint-torque " \ |
149 |
|
|
"inputs u into generalized torques tau, where tau is also named as the " \ |
150 |
|
|
"actuation signal of our system. The computation of the actuation " \ |
151 |
|
|
"signal and its partial derivatives are mainly carried out inside " \ |
152 |
|
|
"calc() and calcDiff(), respectively.", \ |
153 |
|
|
bp::init<std::shared_ptr<State>, std::size_t>( \ |
154 |
|
|
bp::args("self", "state", "nu"), \ |
155 |
|
|
"Initialize the actuation model.\n\n" \ |
156 |
|
|
":param state: state description,\n" \ |
157 |
|
|
":param nu: dimension of the joint-torque input")) \ |
158 |
|
|
.def(ActuationModelAbstractVisitor<Model_wrap>()) \ |
159 |
|
|
.def(PrintableVisitor<Model_wrap>()) \ |
160 |
|
|
.def(CopyableVisitor<Model_wrap>()); |
161 |
|
|
|
162 |
|
|
#define CROCODDYL_ACTUATION_DATA_ABSTRACT_PYTHON_BINDINGS(Scalar) \ |
163 |
|
|
typedef ActuationDataAbstractTpl<Scalar> Data; \ |
164 |
|
|
typedef ActuationModelAbstractTpl<Scalar> Model; \ |
165 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ |
166 |
|
|
bp::class_<Data>( \ |
167 |
|
|
"ActuationDataAbstract", \ |
168 |
|
|
"Abstract class for actuation datas.\n\n" \ |
169 |
|
|
"An actuation data contains all the required information for " \ |
170 |
|
|
"processing an user-defined actuation model. The actuation data " \ |
171 |
|
|
"typically is allocated onces by running model.createData().", \ |
172 |
|
|
bp::init<Model*>( \ |
173 |
|
|
bp::args("self", "model"), \ |
174 |
|
|
"Create common data shared between actuation models.\n\n" \ |
175 |
|
|
"The actuation data uses the model in order to first process it.\n" \ |
176 |
|
|
":param model: actuation model")) \ |
177 |
|
|
.def(ActuationDataAbstractVisitor<Data>()) \ |
178 |
|
|
.def(CopyableVisitor<Data>()); |
179 |
|
|
|
180 |
|
✗ |
void exposeActuationAbstract() { |
181 |
|
✗ |
CROCODDYL_ACTUATION_MODEL_ABSTRACT_PYTHON_BINDINGS(float) |
182 |
|
✗ |
CROCODDYL_ACTUATION_DATA_ABSTRACT_PYTHON_BINDINGS(float) |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
} // namespace python |
186 |
|
|
} // namespace crocoddyl |
187 |
|
|
|