Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/multibody/residuals/state.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 26 | 27 | 96.3% |
Branches: | 24 | 48 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
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 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def(bp::init<boost::shared_ptr<StateAbstract>, Eigen::VectorXd>( |
32 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":param xref: reference state")) | ||
37 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def(bp::init<boost::shared_ptr<StateAbstract>, std::size_t>( |
38 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":param nu: dimension of control vector")) | ||
43 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def(bp::init<boost::shared_ptr<StateAbstract> >( |
44 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":param state: state description")) | ||
49 | .def<void (ResidualModelState::*)( | ||
50 | const boost::shared_ptr<ResidualDataAbstract>&, | ||
51 | const Eigen::Ref<const Eigen::VectorXd>&, | ||
52 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
53 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":param u: control input (dim. nu)") | ||
58 | .def<void (ResidualModelState::*)( | ||
59 | const boost::shared_ptr<ResidualDataAbstract>&, | ||
60 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
61 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
66 | "calcDiff", &ResidualModelState::calcDiff, | ||
67 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":param u: control input (dim. nu)") | ||
73 | .def<void (ResidualModelState::*)( | ||
74 | const boost::shared_ptr<ResidualDataAbstract>&, | ||
75 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
76 | "calcDiff", &ResidualModelAbstract::calcDiff, | ||
77 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x")) |
78 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("createData", &ResidualModelState::createData, |
79 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
80 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":return residual data.") | ||
87 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("reference", |
88 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ResidualModelState::get_reference, |
89 | 10 | bp::return_internal_reference<>()), | |
90 | &ResidualModelState::set_reference, "reference state") | ||
91 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ResidualModelState>()); |
92 | 10 | } | |
93 | |||
94 | } // namespace python | ||
95 | } // namespace crocoddyl | ||
96 |