RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
org.wpilib.system.Timer Class Reference

Public Member Functions

 Timer ()
double get ()
final void reset ()
void start ()
void restart ()
void stop ()
boolean hasElapsed (Time period)
boolean hasElapsed (double seconds)
boolean advanceIfElapsed (double seconds)
boolean isRunning ()

Static Public Member Functions

static double getTimestamp ()
static double getMonotonicTimestamp ()
static double getMatchTime ()
static void delay (final Time period)
static void delay (final double seconds)
static Timer createStarted ()

Detailed Description

A timer class.

Note that if the user calls SimHooks.restartTiming(), they should also reset the timer so get() won't return a negative duration.

Definition at line 18 of file Timer.java.

Constructor & Destructor Documentation

◆ Timer()

org.wpilib.system.Timer.Timer ( )

Creates a new timer. The timer is initially not running and must be started with start() to start measuring time. Consider using createStarted() instead if the timer will be used immediately after creation.

Definition at line 96 of file Timer.java.

Member Function Documentation

◆ advanceIfElapsed()

boolean org.wpilib.system.Timer.advanceIfElapsed ( double seconds)

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
secondsThe period to check.
Returns
Whether the period has passed.

Definition at line 218 of file Timer.java.

◆ createStarted()

Timer org.wpilib.system.Timer.createStarted ( )
static

Creates a new timer that begins started.

This is equivalent to

{

Timer timer = new Timer(); timer.start(); }

Returns
A new started timer.

Definition at line 112 of file Timer.java.

◆ delay() [1/2]

void org.wpilib.system.Timer.delay ( final double seconds)
static

Pause the execution of the thread for a specified period of time given in seconds. Motors will continue to run at their last assigned values, and sensors will continue to update. Only the task containing the wait will pause until the wait time is expired.

Parameters
secondsLength of time to pause

Definition at line 78 of file Timer.java.

◆ delay() [2/2]

void org.wpilib.system.Timer.delay ( final Time period)
static

Pause the execution of the thread for a specified period of time. Motors will continue to run at their last assigned values, and sensors will continue to update. Only the task containing the wait will pause until the wait time is expired.

Parameters
periodLength of time to pause

Definition at line 67 of file Timer.java.

◆ get()

double org.wpilib.system.Timer.get ( )

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

Definition at line 137 of file Timer.java.

◆ getMatchTime()

double org.wpilib.system.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).

When connected to the real field, this number only changes in full integer increments, and always counts down.

When the DS is in practice mode, this number is a floating point number, and counts down.

When the DS is in teleop or autonomous mode, this number returns -1.0.

Simulation matches DS behavior without an FMS connected.

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

Definition at line 56 of file Timer.java.

◆ getMonotonicTimestamp()

double org.wpilib.system.Timer.getMonotonicTimestamp ( )
static

Return the monotonic clock time in seconds.

Returns
Monotonic time in seconds.

Definition at line 35 of file Timer.java.

◆ getTimestamp()

double org.wpilib.system.Timer.getTimestamp ( )
static

Return the clock time in seconds. By default, the time is the time returned by getMonotonicTimestamp(). However, the return value of this method may be modified to use any time base, including non-monotonic time bases.

Returns
Robot running time in seconds.

Definition at line 26 of file Timer.java.

◆ hasElapsed() [1/2]

boolean org.wpilib.system.Timer.hasElapsed ( double seconds)

Check if the period specified has passed.

Parameters
secondsThe period to check in seconds.
Returns
Whether the period has passed.

Definition at line 206 of file Timer.java.

◆ hasElapsed() [2/2]

boolean org.wpilib.system.Timer.hasElapsed ( Time period)

Check if the period specified has passed.

Parameters
periodThe period to check.
Returns
Whether the period has passed.

Definition at line 196 of file Timer.java.

◆ isRunning()

boolean org.wpilib.system.Timer.isRunning ( )

Whether the timer is currently running.

Returns
true if running.

Definition at line 239 of file Timer.java.

◆ reset()

final void org.wpilib.system.Timer.reset ( )

Reset the timer by setting the time to 0.

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

Definition at line 146 of file Timer.java.

◆ restart()

void org.wpilib.system.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.

Definition at line 170 of file Timer.java.

◆ start()

void org.wpilib.system.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.

Definition at line 157 of file Timer.java.

◆ stop()

void org.wpilib.system.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.

Definition at line 183 of file Timer.java.


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