WPILibC++  2020.3.2
Timer.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <units/units.h>
11 #include <wpi/deprecated.h>
12 #include <wpi/mutex.h>
13 
14 #include "frc/Base.h"
15 #include "frc2/Timer.h"
16 
17 namespace frc {
18 
29 void Wait(double seconds);
30 
36 double GetTime();
37 
47 class Timer {
48  public:
55  Timer();
56 
57  virtual ~Timer() = default;
58 
59  Timer(const Timer& rhs) = default;
60  Timer& operator=(const Timer& rhs) = default;
61  Timer(Timer&& rhs) = default;
62  Timer& operator=(Timer&& rhs) = default;
63 
71  double Get() const;
72 
79  void Reset();
80 
87  void Start();
88 
96  void Stop();
97 
106  bool HasPeriodPassed(double period);
107 
116  static double GetFPGATimestamp();
117 
133  static double GetMatchTime();
134 
135  // The time, in seconds, at which the 32-bit FPGA timestamp rolls over to 0
136  static const double kRolloverTime;
137 
138  private:
139  frc2::Timer m_timer;
140 };
141 
142 } // namespace frc
frc::Timer::Timer
Timer()
Create a new timer object.
frc::Timer::Reset
void Reset()
Reset the timer by setting the time to 0.
frc::Timer::Start
void Start()
Start the timer running.
frc::Timer::GetMatchTime
static double GetMatchTime()
Return the approximate match time.
frc2::Timer
A wrapper for the frc::Timer class that returns unit-typed values.
Definition: Timer.h:40
frc::Timer::Stop
void Stop()
Stop the timer.
frc::Timer
Timer objects measure accumulated time in seconds.
Definition: Timer.h:47
frc::Timer::HasPeriodPassed
bool HasPeriodPassed(double period)
Check if the period specified has passed and if it has, advance the start time by that period.
frc::GetTime
double GetTime()
Gives real-time clock system time with nanosecond resolution.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
frc::Timer::Get
double Get() const
Get the current time from the timer.
frc::Wait
void Wait(double seconds)
Pause the task for a specified time.
frc::Timer::GetFPGATimestamp
static double GetFPGATimestamp()
Return the FPGA system clock time in seconds.