GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/actuations/floating-base-propellers.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 30 30 100.0%
Branches: 68 136 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2024-2025, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "crocoddyl/multibody/actuations/floating-base-thrusters.hpp"
10 #include "python/crocoddyl/multibody/multibody.hpp"
11 #include "python/crocoddyl/utils/vector-converter.hpp"
12
13 namespace crocoddyl {
14 namespace python {
15
16 template <typename Model>
17 struct ThrustersVisitor : public bp::def_visitor<ThrustersVisitor<Model>> {
18 typedef typename Model::Scalar Scalar;
19 template <class PyClass>
20 40 void visit(PyClass& cl) const {
21
2/4
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
40 cl.def(bp::init<Scalar, bp::optional<ThrusterType, Scalar, Scalar>>(
22 bp::args("self", "ctorque", "type", "min_thrust", "max_thrust"),
23 "Initialize the thruster in a give pose from the root joint.\n\n"
24 ":param ctorque: coefficient of generated torque per thrust\n"
25 ":param type: type of thruster (clockwise or counterclockwise, "
26 "default clockwise)\n"
27 ":param min_thrust: minimum thrust (default 0.)\n"
28 ":param max_thrust: maximum thrust (default np.inf)"))
29
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite("pose", &Model::pose,
30 "thruster pose (traslation, rotation)")
31
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite("ctorque", &Model::ctorque,
32 "coefficient of generated torque per thrust")
33
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite("type", &Model::type,
34 "type of thruster (clockwise or counterclockwise)")
35
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite("min_thrust", &Model::min_thrust, "minimum thrust")
36
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 .def_readwrite("max_thrust", &Model::min_thrust, "maximum thrust");
37 40 }
38 };
39
40 template <typename Model>
41 struct ActuationModelFloatingBaseThrustersVisitor
42 : public bp::def_visitor<
43 ActuationModelFloatingBaseThrustersVisitor<Model>> {
44 typedef typename Model::Scalar Scalar;
45 typedef typename Model::Data Data;
46 typedef typename Model::VectorXs VectorXs;
47 template <class PyClass>
48 40 void visit(PyClass& cl) const {
49 40 cl.def("calc",
50 static_cast<void (Model::*)(
51 const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&,
52 const Eigen::Ref<const VectorXs>&)>(&Model::calc),
53 bp::args("self", "data", "x", "u"),
54 "Compute the actuation signal and actuation set from the thrust "
55 "forces and joint torque inputs u.\n\n"
56 ":param data: floating base thrusters actuation data\n"
57 ":param x: state point (dim. state.nx)\n"
58 ":param u: joint torque input (dim. nu)")
59
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .def("calcDiff", &Model::calcDiff, bp::args("self", "data", "x", "u"),
60 "Compute the derivatives of the actuation model.\n\n"
61 "It computes the partial derivatives of the thruster actuation. "
62 "It assumes that calc has been run first. The reason is that the "
63 "derivatives are constant and defined in createData. The Hessian "
64 "is constant, so we don't write again this value.\n"
65 ":param data: floating base thrusters actuation data\n"
66 ":param x: state point (dim. state.nx)\n"
67 ":param u: joint torque input (dim. nu)")
68
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .def("commands", &Model::commands, bp::args("self", "data", "x", "tau"),
69 "Compute the thrust and joint torque commands from the "
70 "generalized torques.\n\n"
71 "It stores the results in data.u.\n"
72 ":param data: actuation data\n"
73 ":param x: state point (dim. state.nx)\n"
74 ":param tau: generalized torques (dim state.nv)")
75
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .def("torqueTransform", &Model::torqueTransform,
76 bp::args("self", "data", "x", "tau"),
77 "Compute the torque transform from generalized torques to thrust "
78 "and joint torque inputs.\n\n"
79 "It stores the results in data.Mtau.\n"
80 ":param data: floating base thrusters actuation data\n"
81 ":param x: state point (dim. state.nx)\n"
82 ":param tau: generalized torques (dim state.nv)")
83
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .def("createData", &Model::createData, bp::args("self"),
84 "Create the floating base thrusters actuation data.")
85
4/8
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
80 .add_property(
86 "thrusters",
87 bp::make_function(&Model::get_thrusters,
88 40 bp::return_value_policy<bp::return_by_value>()),
89 bp::make_function(&Model::set_thrusters), "vector of thrusters")
90
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .add_property("nthrusters", bp::make_function(&Model::get_nthrusters),
91 "number of thrusters")
92
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
93 "Wthrust",
94 bp::make_function(&Model::get_Wthrust,
95 40 bp::return_value_policy<bp::return_by_value>()),
96 "matrix mapping from thrusts to thruster wrenches")
97
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
98 "S",
99 bp::make_function(&Model::get_S,
100 40 bp::return_value_policy<bp::return_by_value>()),
101 "selection matrix for under-actuation part");
102 40 }
103 };
104
105 #define CROCODDYL_THRUSTER_BINDINGS(Scalar) \
106 typedef ThrusterTpl<Scalar> Model; \
107 typedef typename pinocchio::SE3Tpl<Scalar> SE3; \
108 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
109 StdVectorPythonVisitor<std::vector<Model>, true>::expose("StdVec_Thruster"); \
110 bp::class_<Model>( \
111 "Thruster", "Model for thrusters", \
112 bp::init<SE3, Scalar, bp::optional<ThrusterType, Scalar, Scalar>>( \
113 bp::args("self", "M", "ctorque", "type", "min_thrust", \
114 "max_thrust"), \
115 "Initialize the thruster in a give pose from the root joint.\n\n" \
116 ":param M: pose from root joint\n" \
117 ":param ctorque: coefficient of generated torque per thrust\n" \
118 ":param type: type of thruster (clockwise or counterclockwise, " \
119 "default clockwise)\n" \
120 ":param min_thrust: minimum thrust (default 0.)\n" \
121 ":param max_thrust: maximum thrust (default np.inf)")) \
122 .def(ThrustersVisitor<Model>()) \
123 .def(CastVisitor<Model>()) \
124 .def(PrintableVisitor<Model>()) \
125 .def(CopyableVisitor<Model>());
126
127 #define CROCODDYL_ACTUATION_MODEL_FLOATINGBASE_THRUSTERS_PYTHON_BINDINGS( \
128 Scalar) \
129 typedef ActuationModelFloatingBaseThrustersTpl<Scalar> Model; \
130 typedef ActuationModelAbstractTpl<Scalar> ModelBase; \
131 typedef ThrusterTpl<Scalar> Thrusters; \
132 typedef StateMultibodyTpl<Scalar> StateMultibody; \
133 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
134 bp::class_<Model, bp::bases<ModelBase>>( \
135 "ActuationModelFloatingBaseThrusters", \
136 "Actuation models for floating base systems actuated with thrusters " \
137 "(e.g. aerial manipulators).", \
138 bp::init<std::shared_ptr<StateMultibody>, std::vector<Thrusters>>( \
139 bp::args("self", "state", "thrusters"), \
140 "Initialize the floating base actuation model equipped with " \
141 "thrusters.\n\n" \
142 ":param state: state of multibody system\n" \
143 ":param thrusters: vector of thrusters")) \
144 .def(ActuationModelFloatingBaseThrustersVisitor<Model>()) \
145 .def(CastVisitor<Model>()) \
146 .def(PrintableVisitor<Model>()) \
147 .def(CopyableVisitor<Model>());
148
149 10 void exposeActuationFloatingBaseThruster() {
150 20 bp::enum_<ThrusterType>("ThrusterType")
151
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .value("CW", CW)
152
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .value("CCW", CCW)
153
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .export_values();
154
155
23/46
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 10 times.
✗ Branch 11 not taken.
✓ Branch 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 10 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 10 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 10 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 10 times.
✗ Branch 34 not taken.
✓ Branch 39 taken 10 times.
✗ Branch 40 not taken.
✓ Branch 42 taken 10 times.
✗ Branch 43 not taken.
✓ Branch 45 taken 10 times.
✗ Branch 46 not taken.
✓ Branch 50 taken 10 times.
✗ Branch 51 not taken.
✓ Branch 54 taken 10 times.
✗ Branch 55 not taken.
✓ Branch 58 taken 10 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 10 times.
✗ Branch 62 not taken.
✓ Branch 68 taken 10 times.
✗ Branch 69 not taken.
✓ Branch 71 taken 10 times.
✗ Branch 72 not taken.
✓ Branch 74 taken 10 times.
✗ Branch 75 not taken.
✓ Branch 77 taken 10 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 10 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 10 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 10 times.
✗ Branch 87 not taken.
20 CROCODDYL_PYTHON_SCALARS(CROCODDYL_THRUSTER_BINDINGS)
156
17/34
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 10 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 10 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 10 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 10 times.
✗ Branch 31 not taken.
✓ Branch 35 taken 10 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 10 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 10 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 10 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 10 times.
✗ Branch 48 not taken.
✓ Branch 50 taken 10 times.
✗ Branch 51 not taken.
✓ Branch 53 taken 10 times.
✗ Branch 54 not taken.
✓ Branch 56 taken 10 times.
✗ Branch 57 not taken.
20 CROCODDYL_PYTHON_SCALARS(
157 CROCODDYL_ACTUATION_MODEL_FLOATINGBASE_THRUSTERS_PYTHON_BINDINGS)
158 10 }
159
160 } // namespace python
161 } // namespace crocoddyl
162