Drake
piecewise_function.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <random>
4 #include <vector>
5 
6 #include <Eigen/Core>
7 
9  protected:
10  std::vector<double> breaks;
11 
12  public:
13  /// Minimum delta quantity used for comparing time.
14  static constexpr double kEpsilonTime = 1e-10;
15 
16  /// @throws std::runtime_exception if `breaks` increments are
17  /// smaller than kEpsilonTime.
18  explicit PiecewiseFunction(std::vector<double> const& breaks);
19 
20  virtual ~PiecewiseFunction();
21 
22  virtual Eigen::Index rows() const = 0;
23 
24  virtual Eigen::Index cols() const = 0;
25 
26  int getNumberOfSegments() const;
27 
28  double getStartTime(int segment_number) const;
29 
30  double getEndTime(int segment_number) const;
31 
32  double getDuration(int segment_number) const;
33 
34  double getStartTime() const;
35 
36  double getEndTime() const;
37 
38  /**
39  * Returns true iff `t >= getStartTime() && t <= getEndTime()`.
40  */
41  bool isTimeInRange(double t) const;
42 
43  int getSegmentIndex(double t) const;
44 
45  const std::vector<double>& getSegmentTimes() const;
46 
47  void segmentNumberRangeCheck(int segment_number) const;
48 
49  static std::vector<double> randomSegmentTimes(
50  // TODO(#2274) Fix this NOLINTNEXTLINE(runtime/references)
51  int num_segments, std::default_random_engine& generator);
52 
53  protected:
55  double tol = kEpsilonTime) const;
56 
57  void checkScalarValued() const;
58 
60 
61  private:
62  int GetSegmentIndexRecursive(double time, int start, int end) const;
63 };
int getNumberOfSegments() const
Definition: piecewise_function.cc:33
virtual ~PiecewiseFunction()
Definition: piecewise_function.cc:25
Definition: piecewise_function.h:8
double getEndTime() const
Definition: piecewise_function.cc:53
const std::vector< double > & getSegmentTimes() const
Definition: piecewise_function.cc:87
void checkScalarValued() const
Definition: piecewise_function.cc:122
static std::vector< double > randomSegmentTimes(int num_segments, std::default_random_engine &generator)
Definition: piecewise_function.cc:100
virtual Eigen::Index cols() const =0
double getDuration(int segment_number) const
Definition: piecewise_function.cc:47
bool isTimeInRange(double t) const
Returns true iff t >= getStartTime() && t <= getEndTime().
Definition: piecewise_function.cc:29
std::vector< double > breaks
Definition: piecewise_function.h:10
static constexpr double kEpsilonTime
Minimum delta quantity used for comparing time.
Definition: piecewise_function.h:14
const double time
Definition: robot_plan_interpolator_test.cc:64
bool segmentTimesEqual(const PiecewiseFunction &b, double tol=kEpsilonTime) const
Definition: piecewise_function.cc:113
int getSegmentIndex(double t) const
Definition: piecewise_function.cc:78
void segmentNumberRangeCheck(int segment_number) const
Definition: piecewise_function.cc:91
PiecewiseFunction()
Definition: piecewise_function.cc:21
double getStartTime() const
Definition: piecewise_function.cc:51
virtual Eigen::Index rows() const =0