Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/core/numdiff/action.cpp |
Date: | 2025-01-30 11:01:55 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 50 | 50 | 100.0% |
Branches: | 36 | 72 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-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/core/numdiff/action.hpp" | ||
11 | |||
12 | #include "python/crocoddyl/core/action-base.hpp" | ||
13 | #include "python/crocoddyl/core/core.hpp" | ||
14 | #include "python/crocoddyl/utils/copyable.hpp" | ||
15 | |||
16 | namespace crocoddyl { | ||
17 | namespace python { | ||
18 | |||
19 | 10 | void exposeActionNumDiff() { | |
20 | 10 | bp::register_ptr_to_python<std::shared_ptr<ActionModelNumDiff> >(); | |
21 | |||
22 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ActionModelNumDiff, bp::bases<ActionModelAbstract> >( |
23 | "ActionModelNumDiff", | ||
24 | "Abstract class for computing calcDiff by using numerical " | ||
25 | "differentiation.\n\n", | ||
26 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<std::shared_ptr<ActionModelAbstract>, bp::optional<bool> >( |
27 | 20 | bp::args("self", "model", "gaussApprox"), | |
28 | "Initialize the action model NumDiff.\n\n" | ||
29 | ":param model: action model where we compute the derivatives through " | ||
30 | "NumDiff\n" | ||
31 | ":param gaussApprox: compute the Hessian using Gauss approximation " | ||
32 | "(default False)")) | ||
33 | .def<void (ActionModelNumDiff::*)( | ||
34 | const std::shared_ptr<ActionDataAbstract>&, | ||
35 | const Eigen::Ref<const Eigen::VectorXd>&, | ||
36 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
37 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | "calc", &ActionModelNumDiff::calc, bp::args("self", "data", "x", "u"), |
38 | "Compute the next state and cost value.\n\n" | ||
39 | "The system evolution is described in model.\n" | ||
40 | ":param data: NumDiff action data\n" | ||
41 | ":param x: state point (dim. state.nx)\n" | ||
42 | ":param u: control input (dim. nu)") | ||
43 | .def<void (ActionModelNumDiff::*)( | ||
44 | const std::shared_ptr<ActionDataAbstract>&, | ||
45 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
46 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | "calc", &ActionModelAbstract::calc, bp::args("self", "data", "x")) |
47 | .def<void (ActionModelNumDiff::*)( | ||
48 | const std::shared_ptr<ActionDataAbstract>&, | ||
49 | const Eigen::Ref<const Eigen::VectorXd>&, | ||
50 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
51 | "calcDiff", &ActionModelNumDiff::calcDiff, | ||
52 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
53 | "Compute the derivatives of the dynamics and cost functions.\n\n" | ||
54 | "It computes the Jacobian and Hessian using numerical " | ||
55 | "differentiation.\n" | ||
56 | "It assumes that calc has been run first.\n" | ||
57 | ":param data: NumDiff action data\n" | ||
58 | ":param x: state point (dim. state.nx)\n" | ||
59 | ":param u: control input (dim. nu)") | ||
60 | .def<void (ActionModelNumDiff::*)( | ||
61 | const std::shared_ptr<ActionDataAbstract>&, | ||
62 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
63 | "calcDiff", &ActionModelAbstract::calcDiff, | ||
64 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x")) |
65 |
3/6✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
|
20 | .def("createData", &ActionModelNumDiff::createData, bp::args("self"), |
66 | "Create the action data.\n\n" | ||
67 | "Each action model (AM) has its own data that needs to be " | ||
68 | "allocated.\n" | ||
69 | "This function returns the allocated data for a predefined AM.\n" | ||
70 | ":return AM data.") | ||
71 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
72 | "model", | ||
73 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ActionModelNumDiff::get_model, |
74 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
75 | "action model") | ||
76 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
77 | "disturbance", | ||
78 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&ActionModelNumDiff::get_disturbance), |
79 | &ActionModelNumDiff::set_disturbance, | ||
80 | "disturbance constant used in the numerical differentiation") | ||
81 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
82 | "withGaussApprox", | ||
83 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ActionModelNumDiff::get_with_gauss_approx, |
84 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
85 | "Gauss approximation for computing the Hessians") | ||
86 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ActionModelNumDiff>()); |
87 | |||
88 | 10 | bp::register_ptr_to_python<std::shared_ptr<ActionDataNumDiff> >(); | |
89 | |||
90 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ActionDataNumDiff, bp::bases<ActionDataAbstract> >( |
91 | "ActionDataNumDiff", "Numerical differentiation action data.", | ||
92 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ActionModelNumDiff*>( |
93 | 20 | bp::args("self", "model"), | |
94 | "Create numerical differentiation action data.\n\n" | ||
95 | ":param model: numdiff action model")) | ||
96 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("Rx", |
97 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActionDataNumDiff::Rx, |
98 | 10 | bp::return_internal_reference<>()), | |
99 | "Jacobian of the cost residual.") | ||
100 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("Ru", |
101 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActionDataNumDiff::Ru, |
102 | 10 | bp::return_internal_reference<>()), | |
103 | "Jacobian of the cost residual.") | ||
104 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("dx", |
105 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActionDataNumDiff::dx, |
106 | 10 | bp::return_internal_reference<>()), | |
107 | "state disturbance.") | ||
108 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("du", |
109 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActionDataNumDiff::du, |
110 | 10 | bp::return_internal_reference<>()), | |
111 | "control disturbance.") | ||
112 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
113 | "data_0", | ||
114 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActionDataNumDiff::data_0, |
115 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
116 | "data that contains the final results") | ||
117 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
118 | "data_x", | ||
119 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActionDataNumDiff::data_x, |
120 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
121 | "temporary data associated with the state variation") | ||
122 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
123 | "data_u", | ||
124 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActionDataNumDiff::data_u, |
125 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
126 | "temporary data associated with the control variation") | ||
127 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ActionDataNumDiff>()); |
128 | 10 | } | |
129 | |||
130 | } // namespace python | ||
131 | } // namespace crocoddyl | ||
132 |