GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/actions/free-invdyn.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 67 70 95.7%
Branches: 63 126 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2023, University of Edinburgh, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "crocoddyl/multibody/actions/free-invdyn.hpp"
10
11 #include "python/crocoddyl/core/diff-action-base.hpp"
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 exposeDifferentialActionFreeInvDynamics() {
19
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.
10 bp::scope().attr("yes") = 1;
20
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.
10 bp::scope().attr("no") = 0;
21 {
22 bp::register_ptr_to_python<
23
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 boost::shared_ptr<DifferentialActionModelFreeInvDynamics>>();
24 bp::scope model_outer =
25
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<DifferentialActionModelFreeInvDynamics,
26 bp::bases<DifferentialActionModelAbstract>>(
27 "DifferentialActionModelFreeInvDynamics",
28 "Differential action model for free inverse dynamics in multibody "
29 "systems.\n\n"
30 "This class implements the dynamics using Recursive Newton Euler "
31 "Algorithm (RNEA) as an equality "
32 "constraint.\n"
33 "The stack of cost and constraint functions are implemented in\n"
34 "ConstraintModelManager() and CostModelSum(), respectively.",
35
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::init<boost::shared_ptr<StateMultibody>,
36 boost::shared_ptr<ActuationModelAbstract>,
37 boost::shared_ptr<CostModelSum>,
38 bp::optional<boost::shared_ptr<ConstraintModelManager>>>(
39
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::args("self", "state", "actuation", "costs", "constraints"),
40 "Initialize the free inverse-dynamics action model.\n\n"
41 "It describes the kinematic evolution of the multibody system "
42 "and computes the\n"
43 "needed torques using inverse dynamics.\n"
44 ":param state: multibody state\n"
45 ":param actuation: abstract actuation model\n"
46 ":param costs: stack of cost functions\n"
47 ":param constraints: stack of constraint functions"))
48 .def<void (DifferentialActionModelFreeInvDynamics::*)(
49 const boost::shared_ptr<DifferentialActionDataAbstract>&,
50 const Eigen::Ref<const Eigen::VectorXd>&,
51 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
52 "calc", &DifferentialActionModelFreeInvDynamics::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 ":param data: free inverse-dynamics data\n"
56 ":param x: state point (dim. state.nx)\n"
57 ":param u: control input (dim. nu)")
58 .def<void (DifferentialActionModelFreeInvDynamics::*)(
59 const boost::shared_ptr<DifferentialActionDataAbstract>&,
60
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
61 "calc", &DifferentialActionModelAbstract::calc,
62
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"))
63 .def<void (DifferentialActionModelFreeInvDynamics::*)(
64 const boost::shared_ptr<DifferentialActionDataAbstract>&,
65 const Eigen::Ref<const Eigen::VectorXd>&,
66
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
67 "calcDiff", &DifferentialActionModelFreeInvDynamics::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 differential multibody system "
70 "(free of contact) and\n"
71 "its cost functions.\n\n"
72 "It computes the partial derivatives of the differential "
73 "multibody system and the\n"
74 "cost function. It assumes that calc has been run first.\n"
75 "This function builds a quadratic approximation of the\n"
76 "action model (i.e. dynamical system and cost function).\n"
77 ":param data: free inverse-dynamics data\n"
78 ":param x: state point (dim. state.nx)\n"
79 ":param u: control input (dim. nu)")
80 .def<void (DifferentialActionModelFreeInvDynamics::*)(
81 const boost::shared_ptr<DifferentialActionDataAbstract>&,
82
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
83 "calcDiff", &DifferentialActionModelAbstract::calcDiff,
84
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"))
85
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("createData",
86 &DifferentialActionModelFreeInvDynamics::createData,
87
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self"),
88 "Create the free inverse-dynamics differential action data.")
89
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
90 "actuation",
91
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(
92 &DifferentialActionModelFreeInvDynamics::get_actuation,
93 10 bp::return_value_policy<bp::return_by_value>()),
94 "actuation model")
95
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
96 "costs",
97
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(
98 &DifferentialActionModelFreeInvDynamics::get_costs,
99 10 bp::return_value_policy<bp::return_by_value>()),
100 "total cost model")
101
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
102 "constraints",
103
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(
104 &DifferentialActionModelFreeInvDynamics::get_constraints,
105 10 bp::return_value_policy<bp::return_by_value>()),
106 "constraint model manager")
107
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def(CopyableVisitor<DifferentialActionModelFreeInvDynamics>());
108
109 bp::register_ptr_to_python<boost::shared_ptr<
110
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 DifferentialActionModelFreeInvDynamics::ResidualModelActuation>>();
111
112
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<DifferentialActionModelFreeInvDynamics::ResidualModelActuation,
113 bp::bases<ResidualModelAbstract>>(
114 "ResidualModelActuation",
115 "This residual function enforces the torques of under-actuated joints "
116 "(e.g., floating-base\n"
117 "joints) to be zero. We compute these torques and their derivatives "
118 "using RNEA inside \n"
119 "DifferentialActionModelFreeInvDynamics.",
120
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<boost::shared_ptr<StateMultibody>, std::size_t>(
121
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "state", "nu"),
122 "Initialize the actuation residual model.\n\n"
123 ":param state: state description\n"
124 ":param nu: dimension of the joint torques"))
125 .def<void (
126 DifferentialActionModelFreeInvDynamics::ResidualModelActuation::*)(
127 const boost::shared_ptr<ResidualDataAbstract>&,
128 const Eigen::Ref<const Eigen::VectorXd>&,
129 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
130 "calc",
131 &DifferentialActionModelFreeInvDynamics::ResidualModelActuation::
132 calc,
133
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
134 "Compute the actuation residual.\n\n"
135 ":param data: residual data\n"
136 ":param x: state point (dim. state.nx)\n"
137 ":param u: control input (dim. nu)")
138 .def<void (
139 DifferentialActionModelFreeInvDynamics::ResidualModelActuation::*)(
140 const boost::shared_ptr<ResidualDataAbstract>&,
141
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
142
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 "calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x"))
143 .def<void (
144 DifferentialActionModelFreeInvDynamics::ResidualModelActuation::*)(
145 const boost::shared_ptr<ResidualDataAbstract>&,
146 const Eigen::Ref<const Eigen::VectorXd>&,
147
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
148 "calcDiff",
149 &DifferentialActionModelFreeInvDynamics::ResidualModelActuation::
150 calcDiff,
151
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
152 "Compute the Jacobians of the actuation residual.\n\n"
153 "It assumes that calc has been run first.\n"
154 ":param data: action data\n"
155 ":param x: state point (dim. state.nx)\n"
156 ":param u: control input (dim. nu)\n")
157 .def<void (
158 DifferentialActionModelFreeInvDynamics::ResidualModelActuation::*)(
159 const boost::shared_ptr<ResidualDataAbstract>&,
160
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
161 "calcDiff", &ResidualModelAbstract::calcDiff,
162
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"))
163
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("createData",
164 &DifferentialActionModelFreeInvDynamics::ResidualModelActuation::
165 createData,
166 bp::with_custodian_and_ward_postcall<0, 2>(),
167
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data"),
168 "Create the actuation residual data.\n\n"
169 "Each residual model has its own data that needs to be allocated. "
170 "This function\n"
171 "returns the allocated data for the actuation residual.\n"
172 ":param data: shared data\n"
173 ":return residual data.")
174
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<
175 DifferentialActionModelFreeInvDynamics::ResidualModelActuation>());
176 10 }
177
178 bp::register_ptr_to_python<
179
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 boost::shared_ptr<DifferentialActionDataFreeInvDynamics>>();
180
181 bp::scope data_outer =
182
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<DifferentialActionDataFreeInvDynamics,
183 bp::bases<DifferentialActionDataAbstract>>(
184 "DifferentialActionDataFreeInvDynamics",
185 "Action data for the free inverse-dynamics system.",
186
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::init<DifferentialActionModelFreeInvDynamics*>(
187
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::args("self", "model"),
188 "Create free inverse-dynamics action data.\n\n"
189 ":param model: free inverse-dynamics action model"))
190
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
191 "pinocchio",
192
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataFreeInvDynamics::pinocchio,
193 10 bp::return_internal_reference<>()),
194 "pinocchio data")
195
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
196 "multibody",
197
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataFreeInvDynamics::multibody,
198 10 bp::return_internal_reference<>()),
199 "multibody data")
200
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
201 "costs",
202
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataFreeInvDynamics::costs,
203 10 bp::return_value_policy<bp::return_by_value>()),
204 "total cost data")
205
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("constraints",
206 bp::make_getter(
207
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 &DifferentialActionDataFreeInvDynamics::constraints,
208 10 bp::return_value_policy<bp::return_by_value>()),
209 "constraint data")
210
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def(CopyableVisitor<DifferentialActionDataFreeInvDynamics>());
211
212 bp::register_ptr_to_python<boost::shared_ptr<
213
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 DifferentialActionDataFreeInvDynamics::ResidualDataActuation>>();
214
215
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<DifferentialActionDataFreeInvDynamics::ResidualDataActuation,
216 bp::bases<ResidualDataAbstract>>(
217 "ResidualDataActuation", "Data for actuation residual.\n\n",
218
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<DifferentialActionModelFreeInvDynamics::ResidualModelActuation*,
219 DataCollectorAbstract*>(
220
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::args("self", "model", "data"),
221 "Create actuation residual data.\n\n"
222 ":param model: actuation residual model\n"
223 ":param data: shared data")[bp::with_custodian_and_ward<
224
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 1, 2, bp::with_custodian_and_ward<1, 3>>()])
225
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<
226 DifferentialActionDataFreeInvDynamics::ResidualDataActuation>());
227 10 }
228
229 } // namespace python
230 } // namespace crocoddyl
231