WPILibC++  unspecified
frc::Timer Class Reference

Timer objects measure accumulated time in seconds. More...

#include <Timer.h>

Public Member Functions

 Timer ()
 Create a new timer object. More...
 
 Timer (const Timer &)=delete
 
Timeroperator= (const Timer &)=delete
 
double Get () const
 Get the current time from the timer. More...
 
void Reset ()
 Reset the timer by setting the time to 0. More...
 
void Start ()
 Start the timer running. More...
 
void Stop ()
 Stop the timer. More...
 
bool HasPeriodPassed (double period)
 Check if the period specified has passed and if it has, advance the start time by that period. More...
 

Static Public Member Functions

static double GetFPGATimestamp ()
 Return the FPGA system clock time in seconds. More...
 
static double GetPPCTimestamp ()
 
static double GetMatchTime ()
 Return the approximate match time The FMS does not currently send the official match time to the robots This returns the time since the enable signal sent from the Driver Station At the beginning of autonomous, the time is reset to 0.0 seconds At the beginning of teleop, the time is reset to +15.0 seconds If the robot is disabled, this returns 0.0 seconds Warning: This is not an official time (so it cannot be used to argue with referees). More...
 

Static Public Attributes

static const double kRolloverTime = (1ll << 32) / 1e6
 

Detailed Description

Timer objects measure accumulated time in seconds.

The timer object functions like a stopwatch. It can be started, stopped, and cleared. When the timer is running its value counts up in seconds. When stopped, the timer holds the current value. The implementation simply records the time when started and subtracts the current time whenever the value is requested.

Constructor & Destructor Documentation

Timer::Timer ( )

Create a new timer object.

Create a new timer object and reset the time to zero. The timer is initially not running and must be started.

Member Function Documentation

double Timer::Get ( ) const

Get the current time from the timer.

If the clock is running it is derived from the current system clock the start time stored in the timer class. If the clock is not running, then return the time when it was last stopped.

Returns
Current time value for this timer in seconds
double Timer::GetFPGATimestamp ( )
static

Return the FPGA system clock time in seconds.

Return the time from the FPGA hardware clock in seconds since the FPGA started. Rolls over after 71 minutes.

Returns
Robot running time in seconds.
double Timer::GetMatchTime ( )
static

Return the approximate match time The FMS does not currently send the official match time to the robots This returns the time since the enable signal sent from the Driver Station At the beginning of autonomous, the time is reset to 0.0 seconds At the beginning of teleop, the time is reset to +15.0 seconds If the robot is disabled, this returns 0.0 seconds Warning: This is not an official time (so it cannot be used to argue with referees).

Returns
Match time in seconds since the beginning of autonomous
bool Timer::HasPeriodPassed ( double  period)

Check if the period specified has passed and if it has, advance the start time by that period.

This is useful to decide if it's time to do periodic work without drifting later by the time it took to get around to checking.

Parameters
periodThe period to check for (in seconds).
Returns
True if the period has passed.
void Timer::Reset ( )

Reset the timer by setting the time to 0.

Make the timer startTime the current time so new requests will be relative to now.

void Timer::Start ( )

Start the timer running.

Just set the running flag to true indicating that all time requests should be relative to the system clock.

void Timer::Stop ( )

Stop the timer.

This computes the time as of now and clears the running flag, causing all subsequent time requests to be read from the accumulated time rather than looking at the system clock.


The documentation for this class was generated from the following files: