Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/core/integ-action-base.cpp |
Date: | 2025-02-24 23:41:29 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 34 | 34 | 100.0% |
Branches: | 27 | 54 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2021-2023, LAAS-CNRS, University of Edinburgh, | ||
5 | // University of Oxford, University of Trento, | ||
6 | // Heriot-Watt University | ||
7 | // Copyright note valid unless otherwise stated in individual files. | ||
8 | // All rights reserved. | ||
9 | /////////////////////////////////////////////////////////////////////////////// | ||
10 | |||
11 | #include "python/crocoddyl/core/integ-action-base.hpp" | ||
12 | |||
13 | #include "python/crocoddyl/utils/copyable.hpp" | ||
14 | #include "python/crocoddyl/utils/printable.hpp" | ||
15 | |||
16 | namespace crocoddyl { | ||
17 | namespace python { | ||
18 | |||
19 | 10 | void exposeIntegratedActionAbstract() { | |
20 | 10 | bp::register_ptr_to_python<std::shared_ptr<IntegratedActionModelAbstract> >(); | |
21 | |||
22 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<IntegratedActionModelAbstract_wrap, boost::noncopyable, |
23 | bp::bases<ActionModelAbstract> >( | ||
24 | "IntegratedActionModelAbstract", | ||
25 | "Abstract class for integrated action models.\n\n" | ||
26 | "In Crocoddyl, an integrated action model transforms a differential " | ||
27 | "action model in a (discrete) action " | ||
28 | "model.\n", | ||
29 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<std::shared_ptr<DifferentialActionModelAbstract>, |
30 | bp::optional<double, bool> >( | ||
31 | 20 | bp::args("self", "diffModel", "timeStep", "withCostResidual"), | |
32 | "Initialize the integrated-action model.\n\n" | ||
33 | "You can also integrate autonomous systems (i.e., when diffModel.nu " | ||
34 | "is equals to 0).\n" | ||
35 | ":param diffModel: differential action model\n" | ||
36 | ":param timestep: integration time step (default 1e-3)\n" | ||
37 | ":param withCostResidual: includes the cost residuals and " | ||
38 | "derivatives (default True).")) | ||
39 |
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<DifferentialActionModelAbstract>, |
40 | std::shared_ptr<ControlParametrizationModelAbstract>, | ||
41 | bp::optional<double, bool> >( | ||
42 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "diffModel", "control", "stepTime", |
43 | "withCostResidual"), | ||
44 | "Initialize the integrated-action integrator.\n\n" | ||
45 | "You can also integrate autonomous systems (i.e., when diffModel.nu " | ||
46 | "is equals to 0).\n" | ||
47 | ":param model: differential action model\n" | ||
48 | ":param control: the control parametrization\n" | ||
49 | ":param stepTime: step time (default 1e-3)\n" | ||
50 | ":param withCostResidual: includes the cost residuals and " | ||
51 | "derivatives (default True).")) | ||
52 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("calc", pure_virtual(&IntegratedActionModelAbstract_wrap::calc), |
53 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
54 | "Compute the next state and cost value.\n\n" | ||
55 | "It describes the time-discrete evolution of our dynamical system\n" | ||
56 | "in which we obtain the next state. Additionally it computes the\n" | ||
57 | "cost value associated to this discrete state and control pair.\n" | ||
58 | ":param data: integrated-action data\n" | ||
59 | ":param x: state point (dim. state.nx)\n" | ||
60 | ":param u: control input (dim. nu)") | ||
61 | .def<void (IntegratedActionModelAbstract::*)( | ||
62 | const std::shared_ptr<ActionDataAbstract>&, | ||
63 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
64 | "calc", &IntegratedActionModelAbstract::calc, | ||
65 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x")) |
66 |
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("calcDiff", |
67 | pure_virtual(&IntegratedActionModelAbstract_wrap::calcDiff), | ||
68 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
69 | "Compute the derivatives of the dynamics and cost functions.\n\n" | ||
70 | "It computes the partial derivatives of the dynamical system and " | ||
71 | "the\n" | ||
72 | "cost function. It assumes that calc has been run first.\n" | ||
73 | "This function builds a quadratic approximation of the\n" | ||
74 | "action model (i.e. linear dynamics and quadratic cost).\n" | ||
75 | ":param data: integrated-action data\n" | ||
76 | ":param x: state point (dim. state.nx)\n" | ||
77 | ":param u: control input (dim. nu)") | ||
78 | .def<void (IntegratedActionModelAbstract::*)( | ||
79 | const std::shared_ptr<ActionDataAbstract>&, | ||
80 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
81 | "calcDiff", &IntegratedActionModelAbstract::calcDiff, | ||
82 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x")) |
83 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("createData", &IntegratedActionModelAbstract_wrap::createData, |
84 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | &IntegratedActionModelAbstract_wrap::default_createData, |
85 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self"), |
86 | "Create the integrated-action data.\n\n" | ||
87 | "Each integrated-action model (IAM) has its own data that needs to " | ||
88 | "be allocated.\n" | ||
89 | "This function returns the allocated data for a predefined IAM.\n" | ||
90 | ":return integrated-action data.") | ||
91 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("differential", |
92 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function( |
93 | &IntegratedActionModelAbstract_wrap::get_differential, | ||
94 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
95 | "differential action model") | ||
96 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
97 | "control", | ||
98 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&IntegratedActionModelAbstract_wrap::get_control, |
99 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
100 | "control parametrization model") | ||
101 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
102 | "dt", | ||
103 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&IntegratedActionModelAbstract::get_dt, |
104 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
105 | &IntegratedActionModelAbstract::set_dt, "step time") | ||
106 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(PrintableVisitor<IntegratedActionModelAbstract>()); |
107 | |||
108 | 10 | bp::register_ptr_to_python<std::shared_ptr<IntegratedActionDataAbstract> >(); | |
109 | |||
110 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<IntegratedActionDataAbstract, bp::bases<ActionDataAbstract> >( |
111 | "IntegratedActionDataAbstract", | ||
112 | "Abstract class for integrated-action data.\n\n" | ||
113 | "In Crocoddyl, an action data contains all the required information for " | ||
114 | "processing an\n" | ||
115 | "user-defined action model. The action data typically is allocated onces " | ||
116 | "by running\n" | ||
117 | "model.createData() and contains the first- and second- order " | ||
118 | "derivatives of the dynamics\n" | ||
119 | "and cost function, respectively.", | ||
120 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<IntegratedActionModelAbstract*>( |
121 | 20 | bp::args("self", "model"), | |
122 | "Create common data shared between integrated-action models.\n\n" | ||
123 | "The integrated-action data uses its model in order to first process " | ||
124 | "it.\n" | ||
125 | ":param model: integrated-action model")) | ||
126 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<IntegratedActionDataAbstract>()); |
127 | 10 | } | |
128 | |||
129 | } // namespace python | ||
130 | } // namespace crocoddyl | ||
131 |