GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/tsid/trajectories/trajectory-base.hpp Lines: 21 24 87.5 %
Date: 2024-05-10 01:36:27 Branches: 8 18 44.4 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2017-2021 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
#ifndef __invdyn_trajectory_base_hpp__
19
#define __invdyn_trajectory_base_hpp__
20
21
#include "tsid/deprecated.hh"
22
#include "tsid/macros.hpp"
23
#include "tsid/math/fwd.hpp"
24
#include "tsid/math/utils.hpp"
25
26
#include <string>
27
28
namespace tsid {
29
namespace trajectories {
30
31
typedef Eigen::Map<const Eigen::Matrix<double, 3, 3>> MapMatrix3;
32
33
class TrajectorySample {
34
 public:
35
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
36
37
  // TODO rename pos, vel, acc → value, derivative, second_derivative
38
  TSID_DEPRECATED math::Vector pos, vel, acc;
39
40
  TSID_DISABLE_WARNING_PUSH
41
  TSID_DISABLE_WARNING_DEPRECATED
42
  // getters / setters with updated names for math::Vector
43
9015
  const math::Vector& getValue() const { return pos; }
44
10009
  const math::Vector& getDerivative() const { return vel; }
45
9009
  const math::Vector& getSecondDerivative() const { return acc; }
46
9
  void setValue(const math::Vector& value) { pos = value; }
47
1
  void setDerivative(const math::Vector& derivative) { vel = derivative; }
48
1
  void setSecondDerivative(const math::Vector& second_derivative) {
49
1
    acc = second_derivative;
50
1
  }
51
52

83
  TrajectorySample(unsigned int size = 0) { resize(size); }
53
54

13
  TrajectorySample(unsigned int size_value, unsigned int size_derivative) {
55
13
    resize(size_value, size_derivative);
56
13
  }
57
58
108
  void resize(unsigned int size) { resize(size, size); }
59
60
153
  void resize(unsigned int size_value, unsigned int size_derivative) {
61
153
    pos.setZero(size_value);
62
153
    vel.setZero(size_derivative);
63
153
    acc.setZero(size_derivative);
64
153
  }
65
66
  // declare default constructors / destructors to disable the deprecation
67
  // message for them. TODO: Remove this after the
68
  // pos/vel/acc → value/derivative/second_derivative rename
69
12135
  ~TrajectorySample() = default;
70

12014
  TrajectorySample(const TrajectorySample&) = default;
71
  TSID_DISABLE_WARNING_POP
72
};
73
74
class TrajectoryBase {
75
 public:
76
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
77
78
  TrajectoryBase(const std::string& name) : m_name(name) {}
79
80
18
  virtual ~TrajectoryBase() {}
81
82
  virtual unsigned int size() const = 0;
83
84
  virtual const TrajectorySample& operator()(double time) = 0;
85
86
  virtual const TrajectorySample& computeNext() = 0;
87
88
  virtual const TrajectorySample& getLastSample() const { return m_sample; }
89
90
  virtual void getLastSample(TrajectorySample& sample) const = 0;
91
92
  virtual bool has_trajectory_ended() const = 0;
93
94
 protected:
95
  std::string m_name;
96
  TrajectorySample m_sample;
97
};
98
}  // namespace trajectories
99
}  // namespace tsid
100
101
#endif  // ifndef __invdyn_trajectory_base_hpp__