GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/residuals/control.cpp
Date: 2025-01-30 11:01:55
Exec Total Coverage
Lines: 24 25 96.0%
Branches: 21 42 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/core/residuals/control.hpp"
10
11 #include "python/crocoddyl/core/core.hpp"
12 #include "python/crocoddyl/utils/copyable.hpp"
13
14 namespace crocoddyl {
15 namespace python {
16
17 10 void exposeResidualControl() {
18 10 bp::register_ptr_to_python<std::shared_ptr<ResidualModelControl> >();
19
20
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ResidualModelControl, bp::bases<ResidualModelAbstract> >(
21 "ResidualModelControl",
22 "This residual function defines a residual vector as r = u - uref, with "
23 "u and uref as the current and "
24 "reference\n"
25 "control, respectively.",
26
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<std::shared_ptr<StateAbstract>, Eigen::VectorXd>(
27 20 bp::args("self", "state", "uref"),
28 "Initialize the control residual model.\n\n"
29 ":param state: state description\n"
30 ":param uref: reference control"))
31
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def(bp::init<std::shared_ptr<StateAbstract>, std::size_t>(
32
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "state", "nu"),
33 "Initialize the control residual model.\n\n"
34 "The default reference control is obtained from np.zero(nu).\n"
35 ":param state: state description\n"
36 ":param nu: dimension of the control vector"))
37
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def(bp::init<std::shared_ptr<StateAbstract> >(
38
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "state"),
39 "Initialize the control residual model.\n\n"
40 "The default reference control is obtained from np.zero(nu).\n"
41 ":param state: state description"))
42 .def<void (ResidualModelControl::*)(
43 const std::shared_ptr<ResidualDataAbstract>&,
44 const Eigen::Ref<const Eigen::VectorXd>&,
45 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
46 "calc", &ResidualModelControl::calc,
47
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
48 "Compute the control residual.\n\n"
49 ":param data: residual data\n"
50 ":param x: state point (dim. state.nx)\n"
51 ":param u: control input (dim. nu)")
52 .def<void (ResidualModelControl::*)(
53 const std::shared_ptr<ResidualDataAbstract>&,
54
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
55
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 "calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x"))
56 .def<void (ResidualModelControl::*)(
57 const std::shared_ptr<ResidualDataAbstract>&,
58 const Eigen::Ref<const Eigen::VectorXd>&,
59
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 const Eigen::Ref<const Eigen::VectorXd>&)>(
60 "calcDiff", &ResidualModelControl::calcDiff,
61
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
62 "Compute the Jacobians of the control residual.\n\n"
63 "It assumes that calc has been run first.\n"
64 ":param data: action data\n"
65 ":param x: state point (dim. state.nx)\n"
66 ":param u: control input (dim. nu)")
67 .def<void (ResidualModelControl::*)(
68 const std::shared_ptr<ResidualDataAbstract>&,
69 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
70 "calcDiff", &ResidualModelAbstract::calcDiff,
71
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"))
72
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("createData", &ResidualModelControl::createData,
73 bp::with_custodian_and_ward_postcall<0, 2>(),
74
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data"),
75 "Create the control residual data.\n\n"
76 "Each residual model has its own data that needs to be allocated. "
77 "This function\n"
78 "returns the allocated data for the control residual.\n"
79 ":param data: shared data\n"
80 ":return residual data.")
81
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("reference",
82
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&ResidualModelControl::get_reference,
83 10 bp::return_internal_reference<>()),
84 &ResidualModelControl::set_reference,
85 "reference control vector")
86
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ResidualModelControl>());
87 10 }
88
89 } // namespace python
90 } // namespace crocoddyl
91