TimerEx is an extended timer utility built on top of ElapsedTime. It provides convenient methods for tracking elapsed time, remaining time, and includes extra features such as pause/resume support.
TimerEx can be used as:
A simple stopwatch (no duration provided).
A countdown timer for match time.
Check out the "Time Awareness" page to learn how to use TimerEx for autonomous behaviors.
Usage
Setup
To use TimerEx, simply instantiate it with your desired settings (default unit is seconds):
@Autonomous
public class MyAuto extends CommandOpMode {
TimerEx matchTime = new TimerEx(30); // 30 second autonomous
DriveSubsystem driveSubsystem = new DriveSubsystem();
@Override
public void initialize() {
schedule(
// Display the remaining time
new RunCommand(() -> telemetry.addData("Time Remaining", matchTime.getRemaining())),
// Choose actions based on time left
new ConditionalCommand(
new ScoreCommand(), // If enough time remains
new ParkCommand(driveSubsystem), // If almost out of time
() -> matchTime.isMoreThan(3)
),
// Attempt a fast score if only a few seconds remain
new ConditionalCommand(
new ScoreCommand(), // If enough time remains
new FastScoreCommand(), // If almost out of time
() -> matchTime.isMoreThan(3)
),
// Automatically park when 5 seconds remain
new SequentialCommandGroup(
new WaitUntilCommand(() -> matchTime.isLessThan(5)),
new ParkCommand(driveSubsystem)
)
);
}
@Override
public void run() {
super.run();
telemetry.update();
matchTime.start(); // Runs only once
}
}