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