GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/controls/poly-two-rk.cpp
Date: 2025-02-24 23:41:29
Exec Total Coverage
Lines: 31 31 100.0%
Branches: 24 48 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2025, University of Edinburgh, University of Trento
5 // Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "crocoddyl/core/controls/poly-two-rk.hpp"
11
12 #include "python/crocoddyl/core/control-base.hpp"
13 #include "python/crocoddyl/core/core.hpp"
14 #include "python/crocoddyl/utils/copyable.hpp"
15
16 namespace crocoddyl {
17 namespace python {
18
19 10 void exposeControlParametrizationPolyTwoRK() {
20 bp::register_ptr_to_python<
21 10 std::shared_ptr<ControlParametrizationModelPolyTwoRK> >();
22
23
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ControlParametrizationModelPolyTwoRK,
24 bp::bases<ControlParametrizationModelAbstract> >(
25 "ControlParametrizationModelPolyTwoRK",
26 "Second-order polynomial control for RK integrators.\n\n"
27 "This control is a quadratic function of time (normalized in [0,1]).\n"
28 "It comes in two versions, one specialized for RK3 integration, another "
29 "for RK4 integration."
30 "The first third of the parameter vector contains the initial value of "
31 "the differential control w,\n"
32 "the second third contains the value of w at t=0.5 (for RK4) or 1/3 (for "
33 "RK3), and the last third is the final\n"
34 "value\n of w at time t=1 (for RK4) or 2/3 (for RK3).",
35
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<std::size_t, RKType>(
36 20 bp::args("self", "nw", "rktype"),
37 "Initialize the control dimensions.\n\n"
38 ":param nw: dimension of differential control space\n"
39 ":param rktype: type of RK parametrization"))
40 .def<void (ControlParametrizationModelPolyTwoRK::*)(
41 const std::shared_ptr<ControlParametrizationDataAbstract>&, double,
42
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&) const>(
43 "calc", &ControlParametrizationModelPolyTwoRK::calc,
44
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "t", "u"),
45 "Compute the control value.\n\n"
46 ":param data: poly-two-rk data\n"
47 ":param t: normalized time in [0, 1]\n"
48 ":param u: control parameters (dim control.nu)")
49 .def<void (ControlParametrizationModelPolyTwoRK::*)(
50 const std::shared_ptr<ControlParametrizationDataAbstract>&, double,
51
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&) const>(
52 "calcDiff", &ControlParametrizationModelPolyTwoRK::calcDiff,
53
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "t", "u"),
54 "Compute the Jacobian of the control value with respect to the "
55 "control parameters.\n"
56 "It assumes that calc has been run first.\n\n"
57 ":param data: poly-two-rk data\n"
58 ":param t: normalized time in [0, 1]\n"
59 ":param u: control parameters (dim control.nu)")
60
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("createData", &ControlParametrizationModelPolyTwoRK::createData,
61
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self"), "Create the poly-two-rk data.")
62 .def<void (ControlParametrizationModelPolyTwoRK::*)(
63 const std::shared_ptr<ControlParametrizationDataAbstract>&, double,
64
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&) const>(
65 "params", &ControlParametrizationModelPolyTwoRK::params,
66
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "t", "w"),
67 "Compute the control parameters.\n\n"
68 ":param data: poly-two-rk data\n"
69 ":param t: normalized time in [0, 1]\n"
70 ":param w: control value (dim control.nw)")
71
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("convertBounds",
72 &ControlParametrizationModelPolyTwoRK::convertBounds,
73
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "w_lb", "w_ub"),
74 "Convert the bounds on the control to bounds on the control "
75 "parameters.\n\n"
76 ":param w_lb: lower bounds on w (dim control.nw)\n"
77 ":param w_ub: upper bounds on w (dim control.nw)\n"
78 ":return u_lb, u_ub: lower and upper bounds on the control "
79 "parameters (dim control.nu)")
80
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("multiplyByJacobian",
81 &ControlParametrizationModelPolyTwoRK::multiplyByJacobian_J,
82
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 ControlParametrizationModelAbstract_multiplyByJacobian_J_wrap(
83
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "A", "op"),
84 "Compute the product between the given matrix A and the "
85 "derivative "
86 "of the control with respect to the "
87 "parameters.\n\n"
88 "It assumes that calc has been run first.\n"
89 ":param data: poly-two-rk data\n"
90 ":param A: matrix to multiply (dim na x control.nw)\n"
91 ":op assignment operator which sets, adds, or removes the given "
92 "results\n"
93 ":return Product between A and the partial derivative of the "
94 "control (dim na x control.nu)"))
95
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(
96 "multiplyJacobianTransposeBy",
97 &ControlParametrizationModelPolyTwoRK::multiplyJacobianTransposeBy_J,
98
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 ControlParametrizationModelAbstract_multiplyJacobianTransposeBy_J_wrap(
99
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "A", "op"),
100 "Compute the product between the transpose of the derivative of "
101 "the "
102 "control with respect to the parameters\n"
103 "and a given matrix A.\n\n"
104 "It assumes that calc has been run first.\n"
105 ":param data: poly-two-rk data\n"
106 ":param A: matrix to multiply (dim control.nw x na)\n"
107 ":op assignment operator which sets, adds, or removes the given "
108 "results\n"
109 ":return Product between the partial derivative of the control "
110 "(transposed) and A (dim control.nu x "
111 "na)"))
112
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ControlParametrizationModelPolyTwoRK>());
113
114 boost::python::register_ptr_to_python<
115 10 std::shared_ptr<ControlParametrizationDataPolyTwoRK> >();
116
117
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<ControlParametrizationDataPolyTwoRK,
118 bp::bases<ControlParametrizationDataAbstract> >(
119 "ControlParametrizationDataPolyTwoRK",
120 "Control-parametrization data for the second-order polynomial control.",
121
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<ControlParametrizationModelPolyTwoRK*>(
122 20 bp::args("self", "model"),
123 "Create control-parametrization data.\n\n"
124 ":param model: second-order polynomial control model"))
125
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("c",
126
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&ControlParametrizationDataPolyTwoRK::c,
127 10 bp::return_internal_reference<>()),
128 "polynomial coefficients of the second-order control model")
129
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<ControlParametrizationDataPolyTwoRK>());
130 10 }
131
132 } // namespace python
133 } // namespace crocoddyl
134