Package com.crossbotics.ftchelper.match
Class MatchTimer
java.lang.Object
com.crossbotics.ftchelper.match.MatchTimer
Counts down a match period and runs "cues" at set times, for example a gamepad buzz with
20 seconds left, so drivers do not have to watch the field clock.
MatchTimer timer = MatchTimer.teleOp() // 2:00
.rumbleAt(60, gamepad1, gamepad2) // one minute left
.rumbleAt(20, gamepad1, gamepad2); // final 20 seconds
waitForStart();
timer.start();
while (opModeIsActive()) {
timer.update(); // runs cues when their time comes
t.line("Time", timer.format()); // "1:23"
}
The field clock is the official one. This timer starts when YOUR OpMode starts, which can be a second off. Use it for reminders, not for split-second timing.
It never waits: update() only looks at the clock and returns. A cue is remembered as
"the time left when it should happen", and each loop we check whether that time has come.
This is the "remember WHEN, check every loop" idea from docs/guides/non-blocking.md.
Docs: docs/modules/match.md (section "MatchTimer")
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleFTC autonomous length (seconds).static final doubleFTC driver-controlled (TeleOp) length (seconds). -
Constructor Summary
ConstructorsConstructorDescriptionMatchTimer(double lengthSec) A timer for a period of this many seconds.MatchTimer(double lengthSec, LongSupplier clockNanos) For tests: your own clock. -
Method Summary
Modifier and TypeMethodDescriptionstatic MatchTimerA 30-second autonomous timer.Runsactiononce, when this many seconds are left.static MatchTimercurrent()The match timer of the OpMode running now: the one started last sinceforget()(each robot is set up at INIT, which forgets the last OpMode's), or null.doubleSeconds since start (0 before).static voidforget()Forgets the last OpMode's timer (done at every INIT, before the new one starts).format()The time left as text, like the field clock: "1:23".booleanTrue for the 30 s autonomous timer (autonomous()).booleanisOver()True when the time is up.booleanTrue afterstart().reserve(double seconds) Seconds at the end kept for parking (autonomous:parkWithSeconds(...)); 0 = none.doubleThe seconds kept for parking (reserve(double)).rumbleAt(double secondsLeft, com.qualcomm.robotcore.hardware.Gamepad... gamepads) Buzzes the gamepads three times when this many seconds are left.doubleSeconds left (the full length before start, never below 0).voidstart()Starts counting (call right afterwaitForStart()).static MatchTimerteleOp()A 2-minute TeleOp timer.voidupdate()Runs any cue whose time has come.
-
Field Details
-
AUTO_SECONDS
public static final double AUTO_SECONDSFTC autonomous length (seconds).- See Also:
-
TELEOP_SECONDS
public static final double TELEOP_SECONDSFTC driver-controlled (TeleOp) length (seconds).- See Also:
-
-
Constructor Details
-
MatchTimer
public MatchTimer(double lengthSec) A timer for a period of this many seconds. -
MatchTimer
For tests: your own clock.
-
-
Method Details
-
autonomous
A 30-second autonomous timer. -
teleOp
A 2-minute TeleOp timer. -
cueAt
Runsactiononce, when this many seconds are left. The action must be quick (it runs inside your loop).- Parameters:
secondsLeft- seconds left on the clock, e.g. 20 for "final 20 seconds"action- the code to run, e.g.() -> led.flash()(() -> ...is a small piece of code we keep and run later)- Returns:
- this timer, so you can chain more cues
-
rumbleAt
Buzzes the gamepads three times when this many seconds are left. (Gamepad... gamepadsmeans you can pass one gamepad, two, or more.) -
current
The match timer of the OpMode running now: the one started last sinceforget()(each robot is set up at INIT, which forgets the last OpMode's), or null. The launcher reads it to choose its shot mode from the time left. -
forget
public static void forget()Forgets the last OpMode's timer (done at every INIT, before the new one starts). -
reserve
Seconds at the end kept for parking (autonomous:parkWithSeconds(...)); 0 = none. The launcher counts its time to fire up to there. -
reserveSec
public double reserveSec()The seconds kept for parking (reserve(double)). -
isAutonomous
public boolean isAutonomous()True for the 30 s autonomous timer (autonomous()). -
start
public void start()Starts counting (call right afterwaitForStart()). Starting again restarts it. -
isRunning
public boolean isRunning()True afterstart(). -
elapsedSec
public double elapsedSec()Seconds since start (0 before). -
secondsLeft
public double secondsLeft()Seconds left (the full length before start, never below 0). -
isOver
public boolean isOver()True when the time is up. -
update
public void update()Runs any cue whose time has come. Call every loop. Cues already passed at start do not run. -
format
The time left as text, like the field clock: "1:23".
-