Package frc.spectrumLib.framework
Class RobotLoop
java.lang.Object
frc.spectrumLib.framework.RobotLoop
Counts robot loops so work can be done "once per loop" or "every Nth loop" without a timer.
Robot.robotPeriodic() calls next() first thing. Anything that wants
to do something once per loop remembers the count it last ran at and compares; anything that
wants a slower cadence uses every(int). Both are a long compare, so they are safe to
call from tight per-loop paths such as status-signal reads.
Main robot thread only. The count is not touched in unit tests, so once-per-loop caches there refresh exactly once.
-
Method Summary
-
Method Details
-
next
public static void next()Advances to the next loop. Called once, at the top ofrobotPeriodic(). -
count
public static long count()Returns the current loop number. Starts at 0 and increases by one pernext().- Returns:
- the current loop count
-
every
public static boolean every(int n) Returnstrueon everynth loop, so a 20 ms loop withn = 5is 10 Hz. All callers in the same loop agree, which keeps related values on the same records.- Parameters:
n- loops betweentrueresults; values below 1 mean every loop- Returns:
- whether this is a loop on which the periodic work should run
-