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