GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/actions/unicycle.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 14 14 100.0%
Branches: 43 86 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2025, 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 "crocoddyl/core/actions/unicycle.hpp"
11
12 #include "python/crocoddyl/core/action-base.hpp"
13 #include "python/crocoddyl/core/core.hpp"
14
15 namespace crocoddyl {
16 namespace python {
17
18 template <typename Model>
19 struct ActionModelUnicycleVisitor
20 : public bp::def_visitor<ActionModelUnicycleVisitor<Model>> {
21 typedef typename Model::ActionDataAbstract Data;
22 typedef typename Model::VectorXs VectorXs;
23 BOOST_PYTHON_FUNCTION_OVERLOADS(ActionModelLQR_Random_wrap, Model::Random, 2,
24 4)
25 template <class PyClass>
26 40 void visit(PyClass& cl) const {
27 40 cl.def("calc",
28 static_cast<void (Model::*)(
29 const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&,
30 const Eigen::Ref<const VectorXs>&)>(&Model::calc),
31 bp::args("self", "data", "x", "u"),
32 "Compute the next state and cost value.\n\n"
33 "It describes the time-discrete evolution of the unicycle system. "
34 "Additionally it computes the cost value associated to this "
35 "discrete state and control pair.\n"
36 ":param data: action data\n"
37 ":param x: state point (dim. state.nx)\n"
38 ":param u: control input (dim. nu)")
39
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .def("calc",
40 static_cast<void (Model::*)(const std::shared_ptr<Data>&,
41 const Eigen::Ref<const VectorXs>&)>(
42 &Model::calc),
43 bp::args("self", "data", "x"))
44
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .def(
45 "calcDiff",
46 static_cast<void (Model::*)(
47 const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&,
48 const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff),
49 bp::args("self", "data", "x", "u"),
50 "Compute the derivatives of the unicycle dynamics and cost "
51 "functions.\n\n"
52 "It computes the partial derivatives of the unicycle system and "
53 "the cost function. It assumes that calc has been run first. This "
54 "function builds a quadratic approximation of the action model "
55 "(i.e. dynamical system and cost function).\n"
56 ":param data: action data\n"
57 ":param x: state point (dim. state.nx)\n"
58 ":param u: control 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",
60 static_cast<void (Model::*)(const std::shared_ptr<Data>&,
61 const Eigen::Ref<const VectorXs>&)>(
62 &Model::calcDiff),
63 bp::args("self", "data", "x"))
64
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"),
65 "Create the unicycle action data.")
66
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("dt", bp::make_function(&Model::get_dt),
67 bp::make_function(&Model::set_dt), "integration time")
68
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("costWeights",
69 bp::make_function(&Model::get_cost_weights,
70 40 bp::return_internal_reference<>()),
71 bp::make_function(&Model::set_cost_weights),
72 "cost weights");
73 40 }
74 };
75
76 #define CROCODDYL_ACTION_MODEL_UNICYCLE_PYTHON_BINDINGS(Scalar) \
77 typedef ActionModelUnicycleTpl<Scalar> Model; \
78 typedef ActionModelAbstractTpl<Scalar> ModelBase; \
79 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
80 bp::class_<Model, bp::bases<ModelBase>>( \
81 "ActionModelUnicycle", \
82 "Unicycle action model.\n\n" \
83 "The transition model of an unicycle system is described as\n" \
84 " xnext = [v*cos(theta); v*sin(theta); w],\n" \
85 "where the position is defined by (x, y, theta) and the control input " \
86 "by (v,w). Note that the state is defined only with the position. On " \
87 "the other hand, we define the quadratic cost functions for the state " \
88 "and control.", \
89 bp::init<>(bp::args("self"), "Initialize the unicycle action model.")) \
90 .def(ActionModelUnicycleVisitor<Model>()) \
91 .def(CastVisitor<Model>()) \
92 .def(PrintableVisitor<Model>()) \
93 .def(CopyableVisitor<Model>());
94
95 #define CROCODDYL_ACTION_DATA_UNICYCLE_PYTHON_BINDINGS(Scalar) \
96 typedef ActionDataUnicycleTpl<Scalar> Data; \
97 typedef ActionDataAbstractTpl<Scalar> DataBase; \
98 typedef ActionModelUnicycleTpl<Scalar> Model; \
99 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
100 bp::class_<Data, bp::bases<DataBase>>( \
101 "ActionDataUnicycle", \
102 "Action data for the Unicycle system.\n\n" \
103 "The unicycle data, apart of common one, contains the cost residuals " \
104 "used for the computation of calc and calcDiff.", \
105 bp::init<Model*>(bp::args("self", "model"), \
106 "Create unicycle data.\n\n" \
107 ":param model: unicycle action model")) \
108 .def(CopyableVisitor<Data>());
109
110 10 void exposeActionUnicycle() {
111
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_ACTION_MODEL_UNICYCLE_PYTHON_BINDINGS)
112
11/22
✓ 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 15 taken 10 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 10 times.
✗ Branch 22 not taken.
✓ Branch 26 taken 10 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 10 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 10 times.
✗ Branch 33 not taken.
✓ Branch 35 taken 10 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 10 times.
✗ Branch 39 not taken.
20 CROCODDYL_PYTHON_SCALARS(CROCODDYL_ACTION_DATA_UNICYCLE_PYTHON_BINDINGS)
113 10 }
114
115 } // namespace python
116 } // namespace crocoddyl
117