GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/core/actuation/actuation-squashing.cpp Lines: 30 32 93.8 %
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) 2019-2023, University of Edinburgh, IRI: CSIC-UPC
5
//                          Heriot-Watt University
6
// Copyright note valid unless otherwise stated in individual files.
7
// All rights reserved.
8
///////////////////////////////////////////////////////////////////////////////
9
10
#include "crocoddyl/core/actuation/actuation-squashing.hpp"
11
12
#include "crocoddyl/core/utils/exception.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 exposeActuationSquashing() {
20
10
  bp::register_ptr_to_python<boost::shared_ptr<ActuationSquashingModel> >();
21
22
10
  bp::class_<ActuationSquashingModel, bp::bases<ActuationModelAbstract> >(
23
      "ActuationSquashingModel", "Class for squashing an actuation model.\n\n",
24
10
      bp::init<boost::shared_ptr<ActuationModelAbstract>,
25
               boost::shared_ptr<SquashingModelAbstract>, int>(
26
20
          bp::args("self", "actuation", "squashing", "nu"),
27
          "Initialize the actuation model with squashing function.\n\n"
28
          ":param actuation: actuation model to be squashed,\n"
29
          ":param squashing: squashing function,\n"
30
          ":param nu: number of controls"))
31
      .def<void (ActuationSquashingModel::*)(
32
          const boost::shared_ptr<ActuationDataAbstract>&,
33
          const Eigen::Ref<const Eigen::VectorXd>&,
34
          const Eigen::Ref<const Eigen::VectorXd>&)>(
35
          "calc", &ActuationSquashingModel::calc,
36
20
          bp::args("self", "data", "x", "u"),
37
          "Compute the actuation signal from the squashing input u.\n\n"
38
          "It describes the time-continuos evolution of the actuation model.\n"
39
          ":param data: actuation data\n"
40
          ":param x: state point (dim. state.nx)\n"
41
10
          ":param u: squashing function input")
42
      .def<void (ActuationSquashingModel::*)(
43
          const boost::shared_ptr<ActuationDataAbstract>&,
44
          const Eigen::Ref<const Eigen::VectorXd>&,
45
          const Eigen::Ref<const Eigen::VectorXd>&)>(
46
          "calcDiff", &ActuationSquashingModel::calcDiff,
47
20
          bp::args("self", "data", "x", "u"),
48
          "Compute the derivatives of the actuation model.\n\n"
49
          "It computes the partial derivatives of the actuation model which "
50
          "is\n"
51
          "describes in continouos time. It assumes that calc has been run "
52
          "first.\n"
53
          ":param data: actuation data\n"
54
          ":param x: state point (dim. state.nx)\n"
55
10
          ":param u: control input (dim. nu).")
56
20
      .def("createData", &ActuationSquashingModel::createData, bp::args("self"),
57
           "Create the actuation squashing data.\n\n"
58
           "Each actuation model (AM) has its own data that needs to be "
59
           "allocated.\n"
60
           "This function returns the allocated data for a predefined AM.\n"
61
10
           ":return AM data.")
62
      .add_property(
63
          "squashing",
64
10
          bp::make_function(&ActuationSquashingModel::get_squashing,
65
10
                            bp::return_value_policy<bp::return_by_value>()),
66
10
          "squashing")
67
      .add_property(
68
          "actuation",
69
10
          bp::make_function(&ActuationSquashingModel::get_actuation,
70
10
                            bp::return_value_policy<bp::return_by_value>()),
71
10
          "actuation")
72
10
      .def(CopyableVisitor<ActuationSquashingModel>());
73
74
10
  bp::register_ptr_to_python<boost::shared_ptr<ActuationSquashingData> >();
75
76
10
  bp::class_<ActuationSquashingData, bp::bases<ActuationDataAbstract> >(
77
      "ActuationSquashingData",
78
      "Class for actuation datas using squashing functions.\n\n"
79
      "In crocoddyl, an actuation data contains all the required information "
80
      "for processing an\n"
81
      "user-defined actuation model. The actuation data typically is allocated "
82
      "onces by running\n"
83
      "model.createData().",
84
10
      bp::init<ActuationSquashingModel*>(
85
20
          bp::args("self", "model"),
86
          "Create common data shared between actuation models.\n\n"
87
          "The actuation data uses the model in order to first process it.\n"
88
          ":param model: actuation model"))
89
      .add_property(
90
          "squashing",
91
10
          bp::make_getter(&ActuationSquashingData::squashing,
92
                          bp::return_value_policy<bp::return_by_value>()),
93
20
          bp::make_setter(&ActuationSquashingData::squashing),
94
10
          "Data of the associated squashing model")
95
      .add_property(
96
          "actuation",
97
10
          bp::make_getter(&ActuationSquashingData::actuation,
98
                          bp::return_value_policy<bp::return_by_value>()),
99
20
          bp::make_setter(&ActuationSquashingData::actuation),
100
10
          "Data of the associated actuation model")
101
10
      .def(CopyableVisitor<ActuationSquashingData>());
102
10
}
103
104
}  // namespace python
105
}  // namespace crocoddyl