GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/tasks/task-actuation-bounds.cpp Lines: 0 35 0.0 %
Date: 2024-02-02 08:47:34 Branches: 0 94 0.0 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2017 CNRS
3
//
4
// This file is part of tsid
5
// tsid is free software: you can redistribute it
6
// and/or modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation, either version
8
// 3 of the License, or (at your option) any later version.
9
// tsid is distributed in the hope that it will be
10
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// General Lesser Public License for more details. You should have
13
// received a copy of the GNU Lesser General Public License along with
14
// tsid If not, see
15
// <http://www.gnu.org/licenses/>.
16
//
17
18
#include <tsid/tasks/task-actuation-bounds.hpp>
19
#include "tsid/robots/robot-wrapper.hpp"
20
21
namespace tsid {
22
namespace tasks {
23
using namespace math;
24
using namespace trajectories;
25
using namespace pinocchio;
26
27
TaskActuationBounds::TaskActuationBounds(const std::string& name,
28
                                         RobotWrapper& robot)
29
    : TaskActuation(name, robot), m_constraint(name, robot.na(), robot.na()) {
30
  Vector m = Vector::Ones(robot.na());
31
  mask(m);
32
}
33
34
const Vector& TaskActuationBounds::mask() const { return m_mask; }
35
36
void TaskActuationBounds::mask(const Vector& m) {
37
  PINOCCHIO_CHECK_INPUT_ARGUMENT(
38
      m.size() == m_robot.na(),
39
      "The size of the mask needs to equal " + std::to_string(m_robot.na()));
40
  m_mask = m;
41
  const Vector::Index dim = static_cast<Vector::Index>(m.sum());
42
  Matrix S = Matrix::Zero(dim, m_robot.na());
43
  m_activeAxes.resize(dim);
44
  unsigned int j = 0;
45
  for (unsigned int i = 0; i < m.size(); i++)
46
    if (m(i) != 0.0) {
47
      PINOCCHIO_CHECK_INPUT_ARGUMENT(
48
          m(i) == 1.0, "The mask entries need to equal either 0.0 or 1.0");
49
      S(j, i) = 1.0;
50
      m_activeAxes(j) = i;
51
      j++;
52
    }
53
  m_constraint.resize((unsigned int)dim, m_robot.na());
54
  m_constraint.setMatrix(S);
55
}
56
57
int TaskActuationBounds::dim() const { return (int)m_mask.sum(); }
58
59
const Vector& TaskActuationBounds::getLowerBounds() const {
60
  return m_constraint.lowerBound();
61
}
62
63
const Vector& TaskActuationBounds::getUpperBounds() const {
64
  return m_constraint.upperBound();
65
}
66
67
void TaskActuationBounds::setBounds(ConstRefVector lower,
68
                                    ConstRefVector upper) {
69
  PINOCCHIO_CHECK_INPUT_ARGUMENT(
70
      lower.size() == dim(),
71
      "The size of the lower joint bounds vector needs to equal " +
72
          std::to_string(dim()));
73
  PINOCCHIO_CHECK_INPUT_ARGUMENT(
74
      upper.size() == dim(),
75
      "The size of the upper joint bounds vector needs to equal " +
76
          std::to_string(dim()));
77
  m_constraint.setLowerBound(lower);
78
  m_constraint.setUpperBound(upper);
79
}
80
81
const ConstraintBase& TaskActuationBounds::getConstraint() const {
82
  return m_constraint;
83
}
84
85
const ConstraintBase& TaskActuationBounds::compute(const double, ConstRefVector,
86
                                                   ConstRefVector, Data&) {
87
  return m_constraint;
88
}
89
90
}  // namespace tasks
91
}  // namespace tsid