Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/core/actuation-base.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 49 | 55 | 89.1% |
Branches: | 44 | 88 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-2024, 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 "python/crocoddyl/core/actuation-base.hpp" | ||
11 | |||
12 | #include "python/crocoddyl/core/core.hpp" | ||
13 | #include "python/crocoddyl/utils/copyable.hpp" | ||
14 | |||
15 | namespace crocoddyl { | ||
16 | namespace python { | ||
17 | |||
18 | 10 | void exposeActuationAbstract() { | |
19 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ActuationModelAbstract> >(); | |
20 | |||
21 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ActuationModelAbstract_wrap, boost::noncopyable>( |
22 | "ActuationModelAbstract", | ||
23 | "Abstract class for actuation-mapping models.\n\n" | ||
24 | "An actuation model is a function that maps state x and joint-torque " | ||
25 | "inputs u into generalized\n" | ||
26 | "torques tau, where tau is also named as the actuation signal of our " | ||
27 | "system.\n" | ||
28 | "The computation of the actuation signal and its partial derivatives are " | ||
29 | "mainly carried out\n" | ||
30 | "inside calc() and calcDiff(), respectively.", | ||
31 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<boost::shared_ptr<StateAbstract>, std::size_t>( |
32 | 20 | bp::args("self", "state", "nu"), | |
33 | "Initialize the actuation model.\n\n" | ||
34 | ":param state: state description,\n" | ||
35 | ":param nu: dimension of the joint-torque input")) | ||
36 |
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(&ActuationModelAbstract_wrap::calc), |
37 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
38 | "Compute the actuation signal and actuation set from the " | ||
39 | "joint-torque input u.\n\n" | ||
40 | "It describes the time-continuos evolution of the actuation model.\n" | ||
41 | ":param data: actuation data\n" | ||
42 | ":param x: state point (dim. state.nx)\n" | ||
43 | ":param u: joint-torque input (dim. nu)") | ||
44 | .def<void (ActuationModelAbstract::*)( | ||
45 | const boost::shared_ptr<ActuationDataAbstract>&, | ||
46 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
47 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | "calc", &ActuationModelAbstract::calc, bp::args("self", "data", "x"), |
48 | "Ignore the computation of the actuation signal and actuation " | ||
49 | "set.\n\n" | ||
50 | "It does not update the actuation signal as this function is used in " | ||
51 | "the\n" | ||
52 | "terminal nodes of an optimal control problem.\n" | ||
53 | ":param data: actuation data\n" | ||
54 | ":param x: state point (dim. state.nx)") | ||
55 |
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", pure_virtual(&ActuationModelAbstract_wrap::calcDiff), |
56 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
57 | "Compute the Jacobians of the actuation model.\n\n" | ||
58 | "It computes the partial derivatives of the actuation model which " | ||
59 | "is\n" | ||
60 | "describes in continouos time.\n" | ||
61 | ":param data: actuation data\n" | ||
62 | ":param x: state point (dim. state.nx)\n" | ||
63 | ":param u: joint-torque input (dim. nu)") | ||
64 | .def<void (ActuationModelAbstract::*)( | ||
65 | const boost::shared_ptr<ActuationDataAbstract>&, | ||
66 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
67 | "calcDiff", &ActuationModelAbstract::calcDiff, | ||
68 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x"), |
69 | "Ignore the computation of the Jacobians of the actuation " | ||
70 | "function.\n\n" | ||
71 | "It does not update the Jacobians of the actuation function as this " | ||
72 | "function\n" | ||
73 | "is used in the terminal nodes of an optimal control problem.\n" | ||
74 | ":param data: actuation data\n" | ||
75 | ":param x: state point (dim. state.nx)") | ||
76 |
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("commands", pure_virtual(&ActuationModelAbstract_wrap::commands), |
77 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "tau"), |
78 | "Compute the joint-torque commands from the generalized torques.\n\n" | ||
79 | "It stores the results in data.u.\n" | ||
80 | ":param data: actuation data\n" | ||
81 | ":param x: state point (dim. state.nx)\n" | ||
82 | ":param tau: generalized torques (dim state.nv)") | ||
83 | 20 | .def("torqueTransform", &ActuationModelAbstract_wrap::torqueTransform, | |
84 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | &ActuationModelAbstract_wrap::default_torqueTransform, |
85 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
86 | "Compute the torque transform from generalized torques to " | ||
87 | "joint-torque inputs.\n\n" | ||
88 | "It stores the results in data.Mtau.\n" | ||
89 | ":param data: actuation data\n" | ||
90 | ":param x: state point (dim. state.nx)\n" | ||
91 | ":param u: joint-torque input (dim nu)") | ||
92 | 20 | .def("createData", &ActuationModelAbstract_wrap::createData, | |
93 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | &ActuationModelAbstract_wrap::default_createData, bp::args("self"), |
94 | "Create the actuation data.\n\n" | ||
95 | "Each actuation model (AM) has its own data that needs to be " | ||
96 | "allocated.\n" | ||
97 | "This function returns the allocated data for a predefined AM.\n" | ||
98 | ":return AM data.") | ||
99 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("nu", |
100 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&ActuationModelAbstract_wrap::get_nu), |
101 | "dimension of joint-torque vector") | ||
102 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
103 | "state", | ||
104 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&ActuationModelAbstract_wrap::get_state, |
105 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
106 | "state"); | ||
107 | |||
108 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ActuationDataAbstract> >(); | |
109 | |||
110 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ActuationDataAbstract>( |
111 | "ActuationDataAbstract", | ||
112 | "Abstract class for actuation datas.\n\n" | ||
113 | "An actuation data contains all the required information for processing " | ||
114 | "an user-defined \n" | ||
115 | "actuation model. The actuation data typically is allocated onces by " | ||
116 | "running model.createData().", | ||
117 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ActuationModelAbstract*>( |
118 | 20 | bp::args("self", "model"), | |
119 | "Create common data shared between actuation models.\n\n" | ||
120 | "The actuation data uses the model in order to first process it.\n" | ||
121 | ":param model: actuation model")) | ||
122 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("tau", |
123 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActuationDataAbstract::tau, |
124 | ✗ | bp::return_internal_reference<>()), | |
125 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ActuationDataAbstract::tau), |
126 | "generalized torques") | ||
127 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("u", |
128 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActuationDataAbstract::u, |
129 | ✗ | bp::return_internal_reference<>()), | |
130 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ActuationDataAbstract::u), |
131 | "joint-torque inputs") | ||
132 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
133 | "dtau_dx", | ||
134 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActuationDataAbstract::dtau_dx, |
135 | ✗ | bp::return_internal_reference<>()), | |
136 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ActuationDataAbstract::dtau_dx), |
137 | "partial derivatives of the actuation model w.r.t. the state point") | ||
138 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("dtau_du", |
139 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActuationDataAbstract::dtau_du, |
140 | ✗ | bp::return_internal_reference<>()), | |
141 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ActuationDataAbstract::dtau_du), |
142 | "partial derivatives of the actuation model w.r.t. the " | ||
143 | "joint-torque input") | ||
144 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
145 | "Mtau", | ||
146 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActuationDataAbstract::Mtau, |
147 | ✗ | bp::return_internal_reference<>()), | |
148 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ActuationDataAbstract::Mtau), |
149 | "torque transform from generalized torques to joint-torque input") | ||
150 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
151 | "tau_set", | ||
152 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActuationDataAbstract::tau_set, |
153 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
154 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&ActuationDataAbstract::tau_set), "actuation set") |
155 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ActuationDataAbstract>()); |
156 | 10 | } | |
157 | |||
158 | } // namespace python | ||
159 | } // namespace crocoddyl | ||
160 |