WPILibC++ 2024.3.2
frc::Timer Class Reference

A timer class. More...

#include <frc/Timer.h>

Public Member Functions

 Timer ()
 Create a new timer object. More...
 
virtual ~Timer ()=default
 
 Timer (const Timer &)=default
 
Timeroperator= (const Timer &)=default
 
 Timer (Timer &&)=default
 
Timeroperator= (Timer &&)=default
 
units::second_t 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 Restart ()
 Restart the timer by stopping the timer, if it is not already stopped, resetting the accumulated time, then starting the timer again. More...
 
void Stop ()
 Stop the timer. More...
 
bool HasElapsed (units::second_t period) const
 Check if the period specified has passed. More...
 
bool AdvanceIfElapsed (units::second_t 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 units::second_t GetFPGATimestamp ()
 Return the FPGA system clock time in seconds. More...
 
static units::second_t GetMatchTime ()
 Return the approximate match time. More...
 

Detailed Description

A timer class.

Note that if the user calls frc::sim::RestartTiming(), they should also reset the timer so Get() won't return a negative duration.

Constructor & Destructor Documentation

◆ Timer() [1/3]

frc::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.

◆ ~Timer()

virtual frc::Timer::~Timer ( )
virtualdefault

◆ Timer() [2/3]

frc::Timer::Timer ( const Timer )
default

◆ Timer() [3/3]

frc::Timer::Timer ( Timer &&  )
default

Member Function Documentation

◆ AdvanceIfElapsed()

bool frc::Timer::AdvanceIfElapsed ( units::second_t  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.
Returns
True if the period has passed.

◆ Get()

units::second_t frc::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

◆ GetFPGATimestamp()

static units::second_t frc::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.

◆ GetMatchTime()

static units::second_t frc::Timer::GetMatchTime ( )
static

Return the approximate match time.

The FMS does not send an official match time to the robots, but does send an approximate match time. The value will count down the time remaining in the current period (auto or teleop).

Warning: This is not an official time (so it cannot be used to dispute ref calls or guarantee that a function will trigger before the match ends).

The Practice Match function of the DS approximates the behavior seen on the field.

Returns
Time remaining in current match period (auto or teleop)

◆ HasElapsed()

bool frc::Timer::HasElapsed ( units::second_t  period) const

Check if the period specified has passed.

Parameters
periodThe period to check.
Returns
True if the period has passed.

◆ operator=() [1/2]

Timer & frc::Timer::operator= ( const Timer )
default

◆ operator=() [2/2]

Timer & frc::Timer::operator= ( Timer &&  )
default

◆ Reset()

void frc::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.

◆ Restart()

void frc::Timer::Restart ( )

Restart the timer by stopping the timer, if it is not already stopped, resetting the accumulated time, then starting the timer again.

If you want an event to periodically reoccur at some time interval from the start time, consider using AdvanceIfElapsed() instead.

◆ Start()

void frc::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. Note that this method is a no-op if the timer is already running.

◆ Stop()

void frc::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 file: