GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/core/actuation-base.hpp Lines: 5 43 11.6 %
Date: 2024-02-13 11:12:33 Branches: 1 188 0.5 %

Line Branch Exec Source
1
2
///////////////////////////////////////////////////////////////////////////////
3
// BSD 3-Clause License
4
//
5
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh
6
// Copyright note valid unless otherwise stated in individual files.
7
// All rights reserved.
8
///////////////////////////////////////////////////////////////////////////////
9
10
#ifndef BINDINGS_PYTHON_CROCODDYL_CORE_ACTUATION_BASE_HPP_
11
#define BINDINGS_PYTHON_CROCODDYL_CORE_ACTUATION_BASE_HPP_
12
13
#include "crocoddyl/core/actuation-base.hpp"
14
#include "crocoddyl/core/utils/exception.hpp"
15
#include "python/crocoddyl/core/core.hpp"
16
17
namespace crocoddyl {
18
namespace python {
19
20
class ActuationModelAbstract_wrap : public ActuationModelAbstract,
21
                                    public bp::wrapper<ActuationModelAbstract> {
22
 public:
23
3
  ActuationModelAbstract_wrap(boost::shared_ptr<StateAbstract> state,
24
                              const std::size_t nu)
25
3
      : ActuationModelAbstract(state, nu),
26
3
        bp::wrapper<ActuationModelAbstract>() {}
27
28
  void calc(const boost::shared_ptr<ActuationDataAbstract>& data,
29
            const Eigen::Ref<const Eigen::VectorXd>& x,
30
            const Eigen::Ref<const Eigen::VectorXd>& u) {
31
    if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
32
      throw_pretty("Invalid argument: "
33
                   << "x has wrong dimension (it should be " +
34
                          std::to_string(state_->get_nx()) + ")");
35
    }
36
    if (static_cast<std::size_t>(u.size()) != nu_) {
37
      throw_pretty("Invalid argument: "
38
                   << "u has wrong dimension (it should be " +
39
                          std::to_string(nu_) + ")");
40
    }
41
    return bp::call<void>(this->get_override("calc").ptr(), data,
42
                          (Eigen::VectorXd)x, (Eigen::VectorXd)u);
43
  }
44
45
  void calcDiff(const boost::shared_ptr<ActuationDataAbstract>& data,
46
                const Eigen::Ref<const Eigen::VectorXd>& x,
47
                const Eigen::Ref<const Eigen::VectorXd>& u) {
48
    if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
49
      throw_pretty("Invalid argument: "
50
                   << "x has wrong dimension (it should be " +
51
                          std::to_string(state_->get_nx()) + ")");
52
    }
53
    if (static_cast<std::size_t>(u.size()) != nu_) {
54
      throw_pretty("Invalid argument: "
55
                   << "u has wrong dimension (it should be " +
56
                          std::to_string(nu_) + ")");
57
    }
58
    return bp::call<void>(this->get_override("calcDiff").ptr(), data,
59
                          (Eigen::VectorXd)x, (Eigen::VectorXd)u);
60
  }
61
62
  void commands(const boost::shared_ptr<ActuationDataAbstract>& data,
63
                const Eigen::Ref<const Eigen::VectorXd>& x,
64
                const Eigen::Ref<const Eigen::VectorXd>& tau) {
65
    if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
66
      throw_pretty("Invalid argument: "
67
                   << "x has wrong dimension (it should be " +
68
                          std::to_string(state_->get_nx()) + ")");
69
    }
70
    if (static_cast<std::size_t>(tau.size()) != state_->get_nv()) {
71
      throw_pretty("Invalid argument: "
72
                   << "tau has wrong dimension (it should be " +
73
                          std::to_string(state_->get_nv()) + ")");
74
    }
75
    return bp::call<void>(this->get_override("commands").ptr(), data,
76
                          (Eigen::VectorXd)x, (Eigen::VectorXd)tau);
77
  }
78
79
  void torqueTransform(const boost::shared_ptr<ActuationDataAbstract>& data,
80
                       const Eigen::Ref<const VectorXs>& x,
81
                       const Eigen::Ref<const VectorXs>& u) {
82
    if (boost::python::override torqueTransform =
83
            this->get_override("torqueTransform")) {
84
      if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
85
        throw_pretty("Invalid argument: "
86
                     << "x has wrong dimension (it should be " +
87
                            std::to_string(state_->get_nx()) + ")");
88
      }
89
      if (static_cast<std::size_t>(u.size()) != nu_) {
90
        throw_pretty("Invalid argument: "
91
                     << "u has wrong dimension (it should be " +
92
                            std::to_string(nu_) + ")");
93
      }
94
      return bp::call<void>(torqueTransform.ptr(), data, (Eigen::VectorXd)x,
95
                            (Eigen::VectorXd)u);
96
    }
97
    return ActuationModelAbstract::torqueTransform(data, x, u);
98
  }
99
100
  void default_torqueTransform(
101
      const boost::shared_ptr<ActuationDataAbstract>& data,
102
      const Eigen::Ref<const VectorXs>& x,
103
      const Eigen::Ref<const VectorXs>& u) {
104
    return this->ActuationModelAbstract::torqueTransform(data, x, u);
105
  }
106
107
  boost::shared_ptr<ActuationDataAbstract> createData() {
108
    enableMultithreading() = false;
109
    if (boost::python::override createData = this->get_override("createData")) {
110
      return bp::call<boost::shared_ptr<ActuationDataAbstract> >(
111
          createData.ptr());
112
    }
113
    return ActuationModelAbstract::createData();
114
  }
115
116
6
  boost::shared_ptr<ActuationDataAbstract> default_createData() {
117
6
    return this->ActuationModelAbstract::createData();
118
  }
119
};
120
121
}  // namespace python
122
}  // namespace crocoddyl
123
124
#endif  // BINDINGS_PYTHON_CROCODDYL_CORE_ACTUATION_BASE_HPP_