GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/core/integ-action-base.cpp Lines: 31 33 93.9 %
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) 2021-2023, LAAS-CNRS, University of Edinburgh,
5
//                     University of Oxford, University of Trento,
6
//                     Heriot-Watt University
7
// Copyright note valid unless otherwise stated in individual files.
8
// All rights reserved.
9
///////////////////////////////////////////////////////////////////////////////
10
11
#include "python/crocoddyl/core/integ-action-base.hpp"
12
13
#include "python/crocoddyl/utils/copyable.hpp"
14
#include "python/crocoddyl/utils/printable.hpp"
15
16
namespace crocoddyl {
17
namespace python {
18
19
10
void exposeIntegratedActionAbstract() {
20
  bp::register_ptr_to_python<
21
10
      boost::shared_ptr<IntegratedActionModelAbstract> >();
22
23
10
  bp::class_<IntegratedActionModelAbstract_wrap, boost::noncopyable,
24
             bp::bases<ActionModelAbstract> >(
25
      "IntegratedActionModelAbstract",
26
      "Abstract class for integrated action models.\n\n"
27
      "In Crocoddyl, an integrated action model transforms a differential "
28
      "action model in a (discrete) action "
29
      "model.\n",
30
10
      bp::init<boost::shared_ptr<DifferentialActionModelAbstract>,
31
               bp::optional<double, bool> >(
32
20
          bp::args("self", "diffModel", "timeStep", "withCostResidual"),
33
          "Initialize the integrated-action model.\n\n"
34
          "You can also integrate autonomous systems (i.e., when diffModel.nu "
35
          "is equals to 0).\n"
36
          ":param diffModel: differential action model\n"
37
          ":param timestep: integration time step (default 1e-3)\n"
38
          ":param withCostResidual: includes the cost residuals and "
39
          "derivatives (default True)."))
40
10
      .def(bp::init<boost::shared_ptr<DifferentialActionModelAbstract>,
41
                    boost::shared_ptr<ControlParametrizationModelAbstract>,
42
                    bp::optional<double, bool> >(
43
20
          bp::args("self", "diffModel", "control", "stepTime",
44
                   "withCostResidual"),
45
          "Initialize the integrated-action integrator.\n\n"
46
          "You can also integrate autonomous systems (i.e., when diffModel.nu "
47
          "is equals to 0).\n"
48
          ":param model: differential action model\n"
49
          ":param control: the control parametrization\n"
50
          ":param stepTime: step time (default 1e-3)\n"
51
          ":param withCostResidual: includes the cost residuals and "
52
10
          "derivatives (default True)."))
53
      .def("calc", pure_virtual(&IntegratedActionModelAbstract_wrap::calc),
54
20
           bp::args("self", "data", "x", "u"),
55
           "Compute the next state and cost value.\n\n"
56
           "It describes the time-discrete evolution of our dynamical system\n"
57
           "in which we obtain the next state. Additionally it computes the\n"
58
           "cost value associated to this discrete state and control pair.\n"
59
           ":param data: integrated-action data\n"
60
           ":param x: state point (dim. state.nx)\n"
61

10
           ":param u: control input (dim. nu)")
62
      .def<void (IntegratedActionModelAbstract::*)(
63
          const boost::shared_ptr<ActionDataAbstract>&,
64
          const Eigen::Ref<const Eigen::VectorXd>&)>(
65
          "calc", &IntegratedActionModelAbstract::calc,
66
20
          bp::args("self", "data", "x"))
67
      .def("calcDiff",
68
           pure_virtual(&IntegratedActionModelAbstract_wrap::calcDiff),
69
20
           bp::args("self", "data", "x", "u"),
70
           "Compute the derivatives of the dynamics and cost functions.\n\n"
71
           "It computes the partial derivatives of the dynamical system and "
72
           "the\n"
73
           "cost function. It assumes that calc has been run first.\n"
74
           "This function builds a quadratic approximation of the\n"
75
           "action model (i.e. linear dynamics and quadratic cost).\n"
76
           ":param data: integrated-action data\n"
77
           ":param x: state point (dim. state.nx)\n"
78

20
           ":param u: control input (dim. nu)")
79
      .def<void (IntegratedActionModelAbstract::*)(
80
          const boost::shared_ptr<ActionDataAbstract>&,
81
          const Eigen::Ref<const Eigen::VectorXd>&)>(
82
          "calcDiff", &IntegratedActionModelAbstract::calcDiff,
83
20
          bp::args("self", "data", "x"))
84
      .def("createData", &IntegratedActionModelAbstract_wrap::createData,
85
           &IntegratedActionModelAbstract_wrap::default_createData,
86
20
           bp::args("self"),
87
           "Create the integrated-action data.\n\n"
88
           "Each integrated-action model (IAM) has its own data that needs to "
89
           "be allocated.\n"
90
           "This function returns the allocated data for a predefined IAM.\n"
91

20
           ":return integrated-action data.")
92
      .add_property("differential",
93
10
                    bp::make_function(
94
                        &IntegratedActionModelAbstract_wrap::get_differential,
95
10
                        bp::return_value_policy<bp::return_by_value>()),
96
10
                    "differential action model")
97
      .add_property(
98
          "control",
99
10
          bp::make_function(&IntegratedActionModelAbstract_wrap::get_control,
100
10
                            bp::return_value_policy<bp::return_by_value>()),
101
10
          "control parametrization model")
102
      .add_property(
103
          "dt",
104
          bp::make_function(&IntegratedActionModelAbstract::get_dt,
105
10
                            bp::return_value_policy<bp::return_by_value>()),
106

10
          &IntegratedActionModelAbstract::set_dt, "step time")
107
10
      .def(PrintableVisitor<IntegratedActionModelAbstract>());
108
109
  bp::register_ptr_to_python<
110
10
      boost::shared_ptr<IntegratedActionDataAbstract> >();
111
112
10
  bp::class_<IntegratedActionDataAbstract, bp::bases<ActionDataAbstract> >(
113
      "IntegratedActionDataAbstract",
114
      "Abstract class for integrated-action data.\n\n"
115
      "In Crocoddyl, an action data contains all the required information for "
116
      "processing an\n"
117
      "user-defined action model. The action data typically is allocated onces "
118
      "by running\n"
119
      "model.createData() and contains the first- and second- order "
120
      "derivatives of the dynamics\n"
121
      "and cost function, respectively.",
122
10
      bp::init<IntegratedActionModelAbstract*>(
123
20
          bp::args("self", "model"),
124
          "Create common data shared between integrated-action models.\n\n"
125
          "The integrated-action data uses its model in order to first process "
126
          "it.\n"
127
          ":param model: integrated-action model"))
128
10
      .def(CopyableVisitor<IntegratedActionDataAbstract>());
129
10
}
130
131
}  // namespace python
132
}  // namespace crocoddyl