1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2021-2023, University of Edinburgh, Heriot-Watt University |
5 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
6 |
|
|
// All rights reserved. |
7 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
8 |
|
|
|
9 |
|
|
#include "crocoddyl/core/residuals/control.hpp" |
10 |
|
|
|
11 |
|
|
#include "python/crocoddyl/core/core.hpp" |
12 |
|
|
#include "python/crocoddyl/utils/copyable.hpp" |
13 |
|
|
|
14 |
|
|
namespace crocoddyl { |
15 |
|
|
namespace python { |
16 |
|
|
|
17 |
|
10 |
void exposeResidualControl() { |
18 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ResidualModelControl> >(); |
19 |
|
|
|
20 |
✓✗ |
10 |
bp::class_<ResidualModelControl, bp::bases<ResidualModelAbstract> >( |
21 |
|
|
"ResidualModelControl", |
22 |
|
|
"This residual function defines a residual vector as r = u - uref, with " |
23 |
|
|
"u and uref as the current and " |
24 |
|
|
"reference\n" |
25 |
|
|
"control, respectively.", |
26 |
✓✗ |
10 |
bp::init<boost::shared_ptr<StateAbstract>, Eigen::VectorXd>( |
27 |
|
20 |
bp::args("self", "state", "uref"), |
28 |
|
|
"Initialize the control residual model.\n\n" |
29 |
|
|
":param state: state description\n" |
30 |
|
|
":param uref: reference control")) |
31 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateAbstract>, std::size_t>( |
32 |
✓✗ |
20 |
bp::args("self", "state", "nu"), |
33 |
|
|
"Initialize the control residual model.\n\n" |
34 |
|
|
"The default reference control is obtained from np.zero(nu).\n" |
35 |
|
|
":param state: state description\n" |
36 |
✓✗ |
10 |
":param nu: dimension of the control vector")) |
37 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateAbstract> >( |
38 |
✓✗ |
20 |
bp::args("self", "state"), |
39 |
|
|
"Initialize the control residual model.\n\n" |
40 |
|
|
"The default reference control is obtained from np.zero(nu).\n" |
41 |
✓✗ |
10 |
":param state: state description")) |
42 |
|
|
.def<void (ResidualModelControl::*)( |
43 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
44 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
45 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
46 |
|
|
"calc", &ResidualModelControl::calc, |
47 |
✓✗ |
20 |
bp::args("self", "data", "x", "u"), |
48 |
|
|
"Compute the control residual.\n\n" |
49 |
|
|
":param data: residual data\n" |
50 |
|
|
":param x: state point (dim. state.nx)\n" |
51 |
|
20 |
":param u: control input (dim. nu)") |
52 |
|
|
.def<void (ResidualModelControl::*)( |
53 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
54 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
55 |
✓✗✓✗
|
20 |
"calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x")) |
56 |
|
|
.def<void (ResidualModelControl::*)( |
57 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
58 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
59 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
60 |
|
|
"calcDiff", &ResidualModelControl::calcDiff, |
61 |
✓✗ |
20 |
bp::args("self", "data", "x", "u"), |
62 |
|
|
"Compute the Jacobians of the control residual.\n\n" |
63 |
|
|
"It assumes that calc has been run first.\n" |
64 |
|
|
":param data: action data\n" |
65 |
|
|
":param x: state point (dim. state.nx)\n" |
66 |
✓✗✓✗
|
20 |
":param u: control input (dim. nu)") |
67 |
|
|
.def<void (ResidualModelControl::*)( |
68 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
69 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
70 |
|
|
"calcDiff", &ResidualModelAbstract::calcDiff, |
71 |
✓✗ |
20 |
bp::args("self", "data", "x")) |
72 |
|
|
.def("createData", &ResidualModelControl::createData, |
73 |
|
|
bp::with_custodian_and_ward_postcall<0, 2>(), |
74 |
✓✗ |
20 |
bp::args("self", "data"), |
75 |
|
|
"Create the control residual data.\n\n" |
76 |
|
|
"Each residual model has its own data that needs to be allocated. " |
77 |
|
|
"This function\n" |
78 |
|
|
"returns the allocated data for the control residual.\n" |
79 |
|
|
":param data: shared data\n" |
80 |
✓✗✓✗
|
20 |
":return residual data.") |
81 |
|
|
.add_property("reference", |
82 |
|
|
bp::make_function(&ResidualModelControl::get_reference, |
83 |
|
10 |
bp::return_internal_reference<>()), |
84 |
|
|
&ResidualModelControl::set_reference, |
85 |
✓✗✓✗
|
10 |
"reference control vector") |
86 |
✓✗ |
10 |
.def(CopyableVisitor<ResidualModelControl>()); |
87 |
|
10 |
} |
88 |
|
|
|
89 |
|
|
} // namespace python |
90 |
|
|
} // namespace crocoddyl |