GCC Code Coverage Report


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