GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/core/integrator/euler.cpp Lines: 34 34 100.0 %
Date: 2024-02-13 11:12:33 Branches: 27 54 50.0 %

Line Branch Exec Source
1
///////////////////////////////////////////////////////////////////////////////
2
// BSD 3-Clause License
3
//
4
// Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh, University of
5
// Oxford,
6
//                          University of Trento, Heriot-Watt University
7
// Copyright note valid unless otherwise stated in individual files.
8
// All rights reserved.
9
///////////////////////////////////////////////////////////////////////////////
10
11
#include "crocoddyl/core/integrator/euler.hpp"
12
13
#include "python/crocoddyl/core/core.hpp"
14
#include "python/crocoddyl/core/integ-action-base.hpp"
15
#include "python/crocoddyl/utils/copyable.hpp"
16
17
namespace crocoddyl {
18
namespace python {
19
20
10
void exposeIntegratedActionEuler() {
21
10
  bp::register_ptr_to_python<boost::shared_ptr<IntegratedActionModelEuler> >();
22
23
10
  bp::class_<IntegratedActionModelEuler,
24
             bp::bases<IntegratedActionModelAbstract, ActionModelAbstract> >(
25
      "IntegratedActionModelEuler",
26
      "Sympletic Euler integrator for differential action models.\n\n"
27
      "This class implements a sympletic Euler integrator (a.k.a "
28
      "semi-implicit\n"
29
      "integrator) give a differential action model, i.e.:\n"
30
      "  [q+, v+] = State.integrate([q, v], [v + a * dt, a * dt] * dt).",
31
10
      bp::init<boost::shared_ptr<DifferentialActionModelAbstract>,
32
               bp::optional<double, bool> >(
33
20
          bp::args("self", "diffModel", "stepTime", "withCostResidual"),
34
          "Initialize the sympletic Euler integrator.\n\n"
35
          ":param diffModel: differential action model\n"
36
          ":param stepTime: step time (default 1e-3)\n"
37
          ":param withCostResidual: includes the cost residuals and "
38
          "derivatives (default True)."))
39
10
      .def(bp::init<boost::shared_ptr<DifferentialActionModelAbstract>,
40
                    boost::shared_ptr<ControlParametrizationModelAbstract>,
41
                    bp::optional<double, bool> >(
42
20
          bp::args("self", "diffModel", "control", "stepTime",
43
                   "withCostResidual"),
44
          "Initialize the Euler integrator.\n\n"
45
          ":param diffModel: differential action model\n"
46
          ":param control: the control parametrization\n"
47
          ":param stepTime: step time (default 1e-3)\n"
48
          ":param withCostResidual: includes the cost residuals and "
49
10
          "derivatives (default True)."))
50
      .def<void (IntegratedActionModelEuler::*)(
51
          const boost::shared_ptr<ActionDataAbstract>&,
52
          const Eigen::Ref<const Eigen::VectorXd>&,
53
          const Eigen::Ref<const Eigen::VectorXd>&)>(
54
          "calc", &IntegratedActionModelEuler::calc,
55
20
          bp::args("self", "data", "x", "u"),
56
          "Compute the time-discrete evolution of a differential action "
57
          "model.\n\n"
58
          "It describes the time-discrete evolution of action model.\n"
59
          ":param data: action data\n"
60
          ":param x: state point (dim. state.nx)\n"
61
20
          ":param u: control input (dim. nu)")
62
      .def<void (IntegratedActionModelEuler::*)(
63
          const boost::shared_ptr<ActionDataAbstract>&,
64
          const Eigen::Ref<const Eigen::VectorXd>&)>(
65

20
          "calc", &ActionModelAbstract::calc, bp::args("self", "data", "x"))
66
      .def<void (IntegratedActionModelEuler::*)(
67
          const boost::shared_ptr<ActionDataAbstract>&,
68
          const Eigen::Ref<const Eigen::VectorXd>&,
69
          const Eigen::Ref<const Eigen::VectorXd>&)>(
70
          "calcDiff", &IntegratedActionModelEuler::calcDiff,
71
20
          bp::args("self", "data", "x", "u"),
72
          "Computes the derivatives of the integrated action model wrt state "
73
          "and control. \n\n"
74
          "This function builds a quadratic approximation of the\n"
75
          "action model (i.e. dynamical system and cost function).\n"
76
          "It assumes that calc has been run first.\n"
77
          ":param data: action data\n"
78
          ":param x: state point (dim. state.nx)\n"
79
10
          ":param u: control input (dim. nu)")
80
      .def<void (IntegratedActionModelEuler::*)(
81
          const boost::shared_ptr<ActionDataAbstract>&,
82
          const Eigen::Ref<const Eigen::VectorXd>&)>(
83
          "calcDiff", &ActionModelAbstract::calcDiff,
84

20
          bp::args("self", "data", "x"))
85
      .def("createData", &IntegratedActionModelEuler::createData,
86

20
           bp::args("self"), "Create the Euler integrator data.")
87
10
      .def(CopyableVisitor<IntegratedActionModelEuler>());
88
89
10
  bp::register_ptr_to_python<boost::shared_ptr<IntegratedActionDataEuler> >();
90
91
10
  bp::class_<IntegratedActionDataEuler,
92
             bp::bases<IntegratedActionDataAbstract> >(
93
      "IntegratedActionDataEuler", "Sympletic Euler integrator data.",
94
10
      bp::init<IntegratedActionModelEuler*>(
95
20
          bp::args("self", "model"),
96
          "Create sympletic Euler integrator data.\n\n"
97
          ":param model: sympletic Euler integrator model"))
98
      .add_property(
99
          "differential",
100
10
          bp::make_getter(&IntegratedActionDataEuler::differential,
101
10
                          bp::return_value_policy<bp::return_by_value>()),
102
10
          "differential action data")
103
      .add_property(
104
          "control",
105
10
          bp::make_getter(&IntegratedActionDataEuler::control,
106
10
                          bp::return_value_policy<bp::return_by_value>()),
107
10
          "control parametrization data")
108
      .add_property("dx",
109
10
                    bp::make_getter(&IntegratedActionDataEuler::dx,
110
10
                                    bp::return_internal_reference<>()),
111
10
                    "state rate.")
112
      .add_property("Lwu",
113
10
                    bp::make_getter(&IntegratedActionDataEuler::Lwu,
114
10
                                    bp::return_internal_reference<>()),
115
                    "Hessian of the cost wrt the differential control (w) and "
116
10
                    "the control parameters (u).")
117
10
      .def(CopyableVisitor<IntegratedActionDataEuler>());
118
10
}
119
120
}  // namespace python
121
}  // namespace crocoddyl