MatchTime
Overview
MatchTime
is a tool designed to simplify getting the current time in the match. It provides a straightforward and readable way to track elapsed and remaining time, eliminating the need for manual timer management within your OpModes.
Usage
Setup
To use MatchTime
, simply instantiate it with the desired duration of the match period in seconds:
MatchTime matchTime = new MatchTime(30); // 30 seconds for autonomous
// ---- OR ----
MatchTime matchTime = new MatchTime(120); // 120 seconds for teleop
Then, at the start of your OpMode (typically in the start()
method for OpMode
or after waitForStart()
for LinearOpMode
), call the start()
method to start the timer:
MatchTime matchTime = new MatchTime(30);
@Override
public void start() {
matchTime.start();
}
Methods
The MatchTime
class provides the following methods for interacting with the timer:
matchTime.getElapsed() // Returns time passed since the start of the match
matchTime.getRemaining() // Returns time remaining in the match
matchTime.isLessThan(10) // Returns true if match time is less than 10 seconds left
matchTime.isMoreThan(15) // Returns true if match time is more than 15 seconds left
matchTime.restart() // Restarts the timer
matchTime.hasStarted() // Returns true if the timer has already been started
Example Usage
The following is an example autonomous program that showcases MatchTime
's functionality, using SolversLib's command system:
public class MyAuto extends CommandOpMode {
MatchTime matchTime = new MatchTime(30);
DriveSubsystem driveSubsystem = new DriveSubsystem();
@Override
public void initialize() {
schedule(
// You can show the time remaining
new RunCommand(() -> telemetry.addData("Time Remaining", matchTime.getRemaining())),
// You can make the robot change its strategy based on the remaining time
new ConditionalCommand(
new ScoreCommand(), // If there's time
new ParkCommand(driveSubsystem), // If there's no time
() -> matchTime.isMoreThan(3)
),
// Or make a quick final scoring attempt if there's barely enough time
new ConditionalCommand(
new ScoreCommand(), // If there's time
new FastScoreCommand(), // If there's no time
() -> matchTime.isMoreThan(3)
),
// You can even tell the robot to immediately 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(); // This will run only once
}
}
Last updated