GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/multibody/wrench-cone.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 27 27 100.0%
Branches: 51 102 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2020-2025, University of Edinburgh, University of Oxford,
5 // Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "crocoddyl/multibody/wrench-cone.hpp"
11
12 #include "python/crocoddyl/multibody/multibody.hpp"
13 #include "python/crocoddyl/utils/copyable.hpp"
14 #include "python/crocoddyl/utils/deprecate.hpp"
15 #include "python/crocoddyl/utils/printable.hpp"
16
17 namespace crocoddyl {
18 namespace python {
19
20 template <typename Model>
21 struct WrenchConeVisitor : public bp::def_visitor<WrenchConeVisitor<Model>> {
22 typedef typename Model::Scalar Scalar;
23 typedef typename Model::Matrix3s Matrix3s;
24 typedef typename Model::Vector2s Vector2s;
25 template <class PyClass>
26 40 void visit(PyClass& cl) const {
27
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<>(bp::args("self"),
28 "Default initialization of the wrench cone."))
29
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
80 .def("update", static_cast<void (Model::*)()>(&Model::update),
30 bp::args("self"),
31 "Update the linear inequality (matrix and bounds).\n\n"
32 "Run this function if you have changed one of the parameters.")
33
3/6
✓ 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.
120 .def("update",
34 static_cast<void (Model::*)(const Matrix3s&, const Scalar,
35 const Vector2s&, const Scalar,
36 const Scalar)>(&Model::update),
37
2/4
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
80 deprecated<>("Deprecated. Use update()."),
38 bp::args("self", "R", "mu", "box", "min_nforce", "max_nforce"),
39 "Update the linear inequality (matrix and bounds).\n\n"
40 ":param R: rotation matrix that defines the cone orientation\n"
41 ":param mu: friction coefficient\n"
42 ":param box: dimension of the foot surface dim = (length, width)\n"
43 ":param min_nforce: minimum normal force (default 0.)\n"
44 ":param max_nforce: maximum normal force (default "
45 "sys.float_info.max)")
46
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
47 "A",
48 40 bp::make_function(&Model::get_A, bp::return_internal_reference<>()),
49 "inequality matrix")
50
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property("ub",
51 bp::make_function(&Model::get_ub,
52 40 bp::return_internal_reference<>()),
53 "inequality upper bound")
54
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property("lb",
55 bp::make_function(&Model::get_lb,
56 40 bp::return_internal_reference<>()),
57 "inequality lower bound")
58
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
59 "nf",
60 bp::make_function(&Model::get_nf,
61 40 bp::return_value_policy<bp::return_by_value>()),
62 "number of facets")
63
3/6
✓ 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.
80 .add_property(
64 "R",
65 40 bp::make_function(&Model::get_R, bp::return_internal_reference<>()),
66 bp::make_function(&Model::set_R), "rotation matrix")
67
3/6
✓ 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.
80 .add_property("box",
68 bp::make_function(&Model::get_box,
69 40 bp::return_internal_reference<>()),
70 bp::make_function(&Model::set_box),
71 "box size used to define the sole")
72
3/6
✓ 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.
80 .add_property("mu", bp::make_function(&Model::get_mu),
73 bp::make_function(&Model::set_mu), "friction coefficient")
74
3/6
✓ 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.
80 .add_property("inner_appr", bp::make_function(&Model::get_inner_appr),
75 bp::make_function(&Model::set_inner_appr),
76 "type of friction cone approximation")
77
3/6
✓ 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.
80 .add_property(
78 "min_nforce",
79 bp::make_function(&Model::get_min_nforce,
80 40 bp::return_value_policy<bp::return_by_value>()),
81 bp::make_function(&Model::set_min_nforce), "minimum normal force")
82
3/6
✓ 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.
80 .add_property(
83 "max_nforce",
84 bp::make_function(&Model::get_max_nforce,
85 40 bp::return_value_policy<bp::return_by_value>()),
86 bp::make_function(&Model::set_max_nforce), "maximum normal force");
87 40 }
88 };
89
90 #define CROCODDYL_WRENCH_CONE_PYTHON_BINDINGS(Scalar) \
91 typedef WrenchConeTpl<Scalar> Model; \
92 typedef typename Model::Matrix3s Matrix3s; \
93 typedef typename Model::Vector2s Vector2s; \
94 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
95 bp::class_<Model>( \
96 "WrenchCone", "Model of the wrench cone as lb <= Af <= ub", \
97 bp::init<Matrix3s, Scalar, Vector2s, \
98 bp::optional<std::size_t, bool, Scalar, Scalar>>( \
99 bp::args("self", "R", "mu", "box", "nf", "inner_appr", "min_nforce", \
100 "max_nforce"), \
101 "Initialize the linearize wrench cone.\n\n" \
102 ":param R: rotation matrix that defines the cone orientation\n" \
103 ":param mu: friction coefficient\n" \
104 ":param box: dimension of the foot surface dim = (length, width)\n" \
105 ":param nf: number of facets (default 4)\n" \
106 ":param inner_appr: inner or outer approximation (default True)\n" \
107 ":param min_nforce: minimum normal force (default 0.)\n" \
108 ":param max_nforce: maximum normal force (default " \
109 "sys.float_info.max)")) \
110 .def(WrenchConeVisitor<Model>()) \
111 .def(CastVisitor<Model>()) \
112 .def(PrintableVisitor<Model>()) \
113 .def(CopyableVisitor<Model>());
114
115 10 void exposeWrenchCone() {
116 #pragma GCC diagnostic push // TODO: Remove once the deprecated update call has
117 // been removed in a future release
118 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
119
120
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(CROCODDYL_WRENCH_CONE_PYTHON_BINDINGS)
121
122 #pragma GCC diagnostic pop
123 10 }
124
125 } // namespace python
126 } // namespace crocoddyl
127