WPILibC++  unspecified
Timer.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 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 <mutex>
11 
12 #include "Base.h"
13 
14 namespace frc {
15 
16 typedef void (*TimerInterruptHandler)(void* param);
17 
18 void Wait(double seconds);
19 double GetClock();
20 double GetTime();
21 
30 class Timer {
31  public:
32  Timer();
33  virtual ~Timer() = default;
34 
35  Timer(const Timer&) = delete;
36  Timer& operator=(const Timer&) = delete;
37 
38  double Get() const;
39  void Reset();
40  void Start();
41  void Stop();
42  bool HasPeriodPassed(double period);
43 
44  static double GetFPGATimestamp();
45  static double GetPPCTimestamp();
46  static double GetMatchTime();
47 
48  // The time, in seconds, at which the 32-bit FPGA timestamp rolls over to 0
49  static const double kRolloverTime;
50 
51  private:
52  double m_startTime = 0.0;
53  double m_accumulatedTime = 0.0;
54  bool m_running = false;
55  mutable std::mutex m_mutex;
56 };
57 
58 } // namespace frc
Definition: Timer.cpp:18
void Start()
Start the timer running.
Definition: Timer.cpp:121
Timer()
Create a new timer object.
Definition: Timer.cpp:69
void Reset()
Reset the timer by setting the time to 0.
Definition: Timer.cpp:109
Timer objects measure accumulated time in seconds.
Definition: Timer.h:30
double Get() const
Get the current time from the timer.
Definition: Timer.cpp:82
static double GetFPGATimestamp()
Return the FPGA system clock time in seconds.
Definition: Timer.cpp:173
void Stop()
Stop the timer.
Definition: Timer.cpp:136
bool HasPeriodPassed(double period)
Check if the period specified has passed and if it has, advance the start time by that period...
Definition: Timer.cpp:154
static double GetMatchTime()
Return the approximate match time The FMS does not currently send the official match time to the robo...
Definition: Timer.cpp:192