GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/core/controls/poly-two-rk.cpp Lines: 28 28 100.0 %
Date: 2024-02-13 11:12:33 Branches: 22 44 50.0 %

Line Branch Exec Source
1
///////////////////////////////////////////////////////////////////////////////
2
// BSD 3-Clause License
3
//
4
// Copyright (C) 2021-2023, 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
      boost::shared_ptr<ControlParametrizationModelPolyTwoRK> >();
22
23
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
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 boost::shared_ptr<ControlParametrizationDataAbstract>&, double,
42
          const Eigen::Ref<const Eigen::VectorXd>&) const>(
43
          "calc", &ControlParametrizationModelPolyTwoRK::calc,
44
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
10
          ":param u: control parameters (dim control.nu)")
49
      .def<void (ControlParametrizationModelPolyTwoRK::*)(
50
          const boost::shared_ptr<ControlParametrizationDataAbstract>&, double,
51
          const Eigen::Ref<const Eigen::VectorXd>&) const>(
52
          "calcDiff", &ControlParametrizationModelPolyTwoRK::calcDiff,
53
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
10
          ":param u: control parameters (dim control.nu)")
60
      .def("createData", &ControlParametrizationModelPolyTwoRK::createData,
61

20
           bp::args("self"), "Create the poly-two-rk data.")
62
      .def<void (ControlParametrizationModelPolyTwoRK::*)(
63
          const boost::shared_ptr<ControlParametrizationDataAbstract>&, double,
64
          const Eigen::Ref<const Eigen::VectorXd>&) const>(
65
          "params", &ControlParametrizationModelPolyTwoRK::params,
66
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
10
          ":param w: control value (dim control.nw)")
71
      .def("convertBounds",
72
           &ControlParametrizationModelPolyTwoRK::convertBounds,
73
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
10
           "parameters (dim control.nu)")
80
      .def("multiplyByJacobian",
81
           &ControlParametrizationModelPolyTwoRK::multiplyByJacobian_J,
82
20
           bp::args("self", "data", "A"),
83
           "Compute the product between the given matrix A and the derivative "
84
           "of the control with respect to the "
85
           "parameters.\n\n"
86
           "It assumes that calc has been run first.\n"
87
           ":param data: poly-two-rk data\n"
88
           ":param A: matrix to multiply (dim na x control.nw)\n"
89
           ":return Product between A and the partial derivative of the "
90
10
           "control (dim na x control.nu)")
91
      .def("multiplyJacobianTransposeBy",
92
           &ControlParametrizationModelPolyTwoRK::multiplyJacobianTransposeBy_J,
93
20
           bp::args("self", "data", "A"),
94
           "Compute the product between the transpose of the derivative of the "
95
           "control with respect to the parameters\n"
96
           "and a given matrix A.\n\n"
97
           "It assumes that calc has been run first.\n"
98
           ":param data: poly-two-rk data\n"
99
           ":param A: matrix to multiply (dim control.nw x na)\n"
100
           ":return Product between the partial derivative of the control "
101
           "(transposed) and A (dim control.nu x "
102
10
           "na)")
103
10
      .def(CopyableVisitor<ControlParametrizationModelPolyTwoRK>());
104
105
  boost::python::register_ptr_to_python<
106
10
      boost::shared_ptr<ControlParametrizationDataPolyTwoRK> >();
107
108
10
  bp::class_<ControlParametrizationDataPolyTwoRK,
109
             bp::bases<ControlParametrizationDataAbstract> >(
110
      "ControlParametrizationDataPolyTwoRK",
111
      "Control-parametrization data for the second-order polynomial control.",
112
10
      bp::init<ControlParametrizationModelPolyTwoRK*>(
113
20
          bp::args("self", "model"),
114
          "Create control-parametrization data.\n\n"
115
          ":param model: second-order polynomial control model"))
116
      .add_property("c",
117
10
                    bp::make_getter(&ControlParametrizationDataPolyTwoRK::c,
118
10
                                    bp::return_internal_reference<>()),
119
10
                    "polynomial coefficients of the second-order control model")
120
10
      .def(CopyableVisitor<ControlParametrizationDataPolyTwoRK>());
121
10
}
122
123
}  // namespace python
124
}  // namespace crocoddyl