Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/multibody/residuals/control-gravity.cpp |
Date: | 2025-02-24 23:41:29 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 30 | 32 | 93.8% |
Branches: | 24 | 48 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
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<std::shared_ptr<ResidualModelControlGrav> >(); | |
20 | |||
21 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<std::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 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def(bp::init<std::shared_ptr<StateMultibody> >( |
32 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":param state: state description")) | ||
36 | .def<void (ResidualModelControlGrav::*)( | ||
37 | const std::shared_ptr<ResidualDataAbstract> &, | ||
38 | const Eigen::Ref<const Eigen::VectorXd> &, | ||
39 | 20 | const Eigen::Ref<const Eigen::VectorXd> &)>( | |
40 | "calc", &ResidualModelControlGrav::calc, | ||
41 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":param u: control input (dim. nu)") | ||
46 | .def<void (ResidualModelControlGrav::*)( | ||
47 | const std::shared_ptr<ResidualDataAbstract> &, | ||
48 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd> &)>( |
49 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | "calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x")) |
50 | .def<void (ResidualModelControlGrav::*)( | ||
51 | const std::shared_ptr<ResidualDataAbstract> &, | ||
52 | const Eigen::Ref<const Eigen::VectorXd> &, | ||
53 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd> &)>( |
54 | "calcDiff", &ResidualModelControlGrav::calcDiff, | ||
55 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":param u: control input (dim. nu)") | ||
60 | .def<void (ResidualModelControlGrav::*)( | ||
61 | const std::shared_ptr<ResidualDataAbstract> &, | ||
62 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd> &)>( |
63 | "calcDiff", &ResidualModelAbstract::calcDiff, | ||
64 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x")) |
65 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("createData", &ResidualModelControlGrav::createData, |
66 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
67 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ":return residual data.") | ||
75 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ResidualModelControlGrav>()); |
76 | |||
77 | 10 | bp::register_ptr_to_python<std::shared_ptr<ResidualDataControlGrav> >(); | |
78 | |||
79 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ResidualDataControlGrav, bp::bases<ResidualDataAbstract> >( |
80 | "ResidualDataControlGrav", "Data for control gravity residual.\n\n", | ||
81 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
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 | ✗ | ":param data: shared data")[bp::with_custodian_and_ward< | |
86 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | 1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
87 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("pinocchio", |
88 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_getter(&ResidualDataControlGrav::pinocchio), |
89 | "Pinocchio data used for internal computations") | ||
90 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("actuation", |
91 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ResidualDataControlGrav::actuation, |
92 | 10 | bp::return_internal_reference<>()), | |
93 | "actuation model") | ||
94 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ResidualDataControlGrav>()); |
95 | 10 | } | |
96 | |||
97 | } // namespace python | ||
98 | } // namespace crocoddyl | ||
99 |