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/multibody/residuals/state.hpp" |
10 |
|
|
|
11 |
|
|
#include "python/crocoddyl/multibody/multibody.hpp" |
12 |
|
|
#include "python/crocoddyl/utils/copyable.hpp" |
13 |
|
|
|
14 |
|
|
namespace crocoddyl { |
15 |
|
|
namespace python { |
16 |
|
|
|
17 |
|
10 |
void exposeResidualState() { |
18 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ResidualModelState> >(); |
19 |
|
|
|
20 |
✓✗ |
10 |
bp::class_<ResidualModelState, bp::bases<ResidualModelAbstract> >( |
21 |
|
|
"ResidualModelState", |
22 |
|
|
"This cost function defines a residual vector as r = x - xref, with x " |
23 |
|
|
"and xref as the current and reference\n" |
24 |
|
|
"state, respectively.", |
25 |
✓✗ |
10 |
bp::init<boost::shared_ptr<StateAbstract>, Eigen::VectorXd, std::size_t>( |
26 |
|
20 |
bp::args("self", "state", "xref", "nu"), |
27 |
|
|
"Initialize the state cost model.\n\n" |
28 |
|
|
":param state: state description\n" |
29 |
|
|
":param xref: reference state (default state.zero())\n" |
30 |
|
|
":param nu: dimension of control vector")) |
31 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateAbstract>, Eigen::VectorXd>( |
32 |
✓✗ |
20 |
bp::args("self", "state", "xref"), |
33 |
|
|
"Initialize the state cost model.\n\n" |
34 |
|
|
"The default nu value is obtained from state.nv.\n" |
35 |
|
|
":param state: state description\n" |
36 |
✓✗ |
10 |
":param xref: reference state")) |
37 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateAbstract>, std::size_t>( |
38 |
✓✗ |
20 |
bp::args("self", "state", "nu"), |
39 |
|
|
"Initialize the state cost model.\n\n" |
40 |
|
|
"The default reference state is obtained from state.zero().\n" |
41 |
|
|
":param state: state description\n" |
42 |
✓✗ |
10 |
":param nu: dimension of control vector")) |
43 |
✓✗ |
10 |
.def(bp::init<boost::shared_ptr<StateAbstract> >( |
44 |
✓✗ |
20 |
bp::args("self", "state"), |
45 |
|
|
"Initialize the state cost model.\n\n" |
46 |
|
|
"The default reference state is obtained from state.zero(), and nu " |
47 |
|
|
"from state.nv.\n" |
48 |
✓✗ |
10 |
":param state: state description")) |
49 |
|
|
.def<void (ResidualModelState::*)( |
50 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
51 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
52 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
53 |
✓✗ |
20 |
"calc", &ResidualModelState::calc, bp::args("self", "data", "x", "u"), |
54 |
|
|
"Compute the state cost.\n\n" |
55 |
|
|
":param data: cost data\n" |
56 |
|
|
":param x: state point (dim. state.nx)\n" |
57 |
✓✗ |
10 |
":param u: control input (dim. nu)") |
58 |
|
|
.def<void (ResidualModelState::*)( |
59 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
60 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
61 |
✓✗ |
20 |
"calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x")) |
62 |
|
|
.def<void (ResidualModelState::*)( |
63 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
64 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&, |
65 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
66 |
|
|
"calcDiff", &ResidualModelState::calcDiff, |
67 |
✓✗ |
20 |
bp::args("self", "data", "x", "u"), |
68 |
|
|
"Compute the derivatives of the state cost.\n\n" |
69 |
|
|
"It assumes that calc has been run first.\n" |
70 |
|
|
":param data: action data\n" |
71 |
|
|
":param x: state point (dim. state.nx)\n" |
72 |
✓✗✓✗
|
20 |
":param u: control input (dim. nu)") |
73 |
|
|
.def<void (ResidualModelState::*)( |
74 |
|
|
const boost::shared_ptr<ResidualDataAbstract>&, |
75 |
|
|
const Eigen::Ref<const Eigen::VectorXd>&)>( |
76 |
|
|
"calcDiff", &ResidualModelAbstract::calcDiff, |
77 |
✓✗ |
20 |
bp::args("self", "data", "x")) |
78 |
|
|
.def("createData", &ResidualModelState::createData, |
79 |
|
|
bp::with_custodian_and_ward_postcall<0, 2>(), |
80 |
✓✗ |
20 |
bp::args("self", "data"), |
81 |
|
|
"Create the stae residual data.\n\n" |
82 |
|
|
"Each residual model has its own data that needs to be allocated. " |
83 |
|
|
"This function\n" |
84 |
|
|
"returns the allocated data for the control residual.\n" |
85 |
|
|
":param data: shared data\n" |
86 |
✓✗✓✗
|
20 |
":return residual data.") |
87 |
|
|
.add_property("reference", |
88 |
|
|
bp::make_function(&ResidualModelState::get_reference, |
89 |
|
10 |
bp::return_internal_reference<>()), |
90 |
✓✗✓✗
|
10 |
&ResidualModelState::set_reference, "reference state") |
91 |
✓✗ |
10 |
.def(CopyableVisitor<ResidualModelState>()); |
92 |
|
10 |
} |
93 |
|
|
|
94 |
|
|
} // namespace python |
95 |
|
|
} // namespace crocoddyl |