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/residuals/control-gravity.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 exposeResidualControlGrav() { |
19 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ResidualModelControlGrav> >(); |
20 |
|
|
|
21 |
✓✗ |
10 |
bp::class_<ResidualModelControlGrav, bp::bases<ResidualModelAbstract> >( |
22 |
|
|
"ResidualModelControlGrav", |
23 |
|
|
"This residual function is defined as r = a(u) - g(q), where a(u)\n" |
24 |
|
|
"is the actuated torque; and q, g(q) are the generalized position\n" |
25 |
|
|
"and gravity vector, respectively.", |
26 |
✓✗ |
10 |
bp::init<boost::shared_ptr<StateMultibody>, std::size_t>( |
27 |
|
20 |
bp::args("self", "state", "nu"), |
28 |
|
|
"Initialize the control-gravity residual model.\n\n" |
29 |
|
|
":param state: state description\n" |
30 |
|
|
":param nu: dimension of the control vector")) |
31 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateMultibody> >( |
32 |
✓✗ |
20 |
bp::args("self", "state"), |
33 |
|
|
"Initialize the control-gravity residual model.\n\n" |
34 |
|
|
"The default nu is obtained from state.nv.\n" |
35 |
✓✗ |
10 |
":param state: state description")) |
36 |
|
|
.def<void (ResidualModelControlGrav::*)( |
37 |
|
|
const boost::shared_ptr<ResidualDataAbstract> &, |
38 |
|
|
const Eigen::Ref<const Eigen::VectorXd> &, |
39 |
|
|
const Eigen::Ref<const Eigen::VectorXd> &)>( |
40 |
|
|
"calc", &ResidualModelControlGrav::calc, |
41 |
✓✗ |
20 |
bp::args("self", "data", "x", "u"), |
42 |
|
|
"Compute the control residual.\n\n" |
43 |
|
|
":param data: residual data\n" |
44 |
|
|
":param x: state point (dim. state.nx)\n" |
45 |
|
20 |
":param u: control input (dim. nu)") |
46 |
|
|
.def<void (ResidualModelControlGrav::*)( |
47 |
|
|
const boost::shared_ptr<ResidualDataAbstract> &, |
48 |
|
|
const Eigen::Ref<const Eigen::VectorXd> &)>( |
49 |
✓✗✓✗
|
20 |
"calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x")) |
50 |
|
|
.def<void (ResidualModelControlGrav::*)( |
51 |
|
|
const boost::shared_ptr<ResidualDataAbstract> &, |
52 |
|
|
const Eigen::Ref<const Eigen::VectorXd> &, |
53 |
|
|
const Eigen::Ref<const Eigen::VectorXd> &)>( |
54 |
|
|
"calcDiff", &ResidualModelControlGrav::calcDiff, |
55 |
✓✗ |
20 |
bp::args("self", "data", "x", "u"), |
56 |
|
|
"Compute the derivatives of the control residual.\n\n" |
57 |
|
|
":param data: action data\n" |
58 |
|
|
":param x: state point (dim. state.nx)\n" |
59 |
✓✗ |
10 |
":param u: control input (dim. nu)") |
60 |
|
|
.def<void (ResidualModelControlGrav::*)( |
61 |
|
|
const boost::shared_ptr<ResidualDataAbstract> &, |
62 |
|
|
const Eigen::Ref<const Eigen::VectorXd> &)>( |
63 |
|
|
"calcDiff", &ResidualModelAbstract::calcDiff, |
64 |
✓✗✓✗
|
20 |
bp::args("self", "data", "x")) |
65 |
|
|
.def("createData", &ResidualModelControlGrav::createData, |
66 |
|
|
bp::with_custodian_and_ward_postcall<0, 2>(), |
67 |
✓✗ |
20 |
bp::args("self", "data"), |
68 |
|
|
"Create the control residual data.\n\n" |
69 |
|
|
"Each residual model has its own data that needs to be allocated. " |
70 |
|
|
"This " |
71 |
|
|
"function\n" |
72 |
|
|
"returns the allocated data for the control gravity residual.\n" |
73 |
|
|
":param data: shared data\n" |
74 |
✓✗✓✗
|
20 |
":return residual data.") |
75 |
✓✗ |
10 |
.def(CopyableVisitor<ResidualModelControlGrav>()); |
76 |
|
|
|
77 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ResidualDataControlGrav> >(); |
78 |
|
|
|
79 |
✓✗ |
10 |
bp::class_<ResidualDataControlGrav, bp::bases<ResidualDataAbstract> >( |
80 |
|
|
"ResidualDataControlGrav", "Data for control gravity residual.\n\n", |
81 |
✓✗ |
10 |
bp::init<ResidualModelControlGrav *, DataCollectorAbstract *>( |
82 |
✓✗ |
10 |
bp::args("self", "model", "data"), |
83 |
|
|
"Create control gravity residual data.\n\n" |
84 |
|
|
":param model: control gravity residual model\n" |
85 |
|
10 |
":param data: shared data")[bp::with_custodian_and_ward< |
86 |
✓✗ |
20 |
1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
87 |
|
|
.add_property("pinocchio", |
88 |
✓✗ |
20 |
bp::make_getter(&ResidualDataControlGrav::pinocchio), |
89 |
✓✗ |
10 |
"Pinocchio data used for internal computations") |
90 |
|
|
.add_property("actuation", |
91 |
✓✗ |
10 |
bp::make_getter(&ResidualDataControlGrav::actuation, |
92 |
|
10 |
bp::return_internal_reference<>()), |
93 |
✓✗ |
10 |
"actuation model") |
94 |
✓✗ |
10 |
.def(CopyableVisitor<ResidualDataControlGrav>()); |
95 |
|
10 |
} |
96 |
|
|
|
97 |
|
|
} // namespace python |
98 |
|
|
} // namespace crocoddyl |