Package com.crossbotics.ftchelper.util
Class LoopTimer
java.lang.Object
com.crossbotics.ftchelper.util.LoopTimer
Measures how fast your OpMode loop runs.
A slow loop makes the robot feel laggy. Show getHz() on telemetry
to see it. Most robots run at 50 to 200 loops per second (Hz).
Under about 30 Hz, something is slow: see docs/guides/non-blocking.md, and Tutorial 06
(docs/tutorials/06-fast-clear-loop.md) for how to speed a loop up.
LoopTimer loopTimer = new LoopTimer();
while (opModeIsActive()) {
loopTimer.update();
telemetry.addData("Loop", "%.0f Hz", loopTimer.getHz());
...
}
Docs: docs/modules/util.md-
Constructor Summary
ConstructorsConstructorDescriptionMakes a timer that uses the phone's clock.LoopTimer(LongSupplier clockNanos) Makes a timer with your own clock. -
Method Summary
-
Constructor Details
-
LoopTimer
public LoopTimer()Makes a timer that uses the phone's clock. -
LoopTimer
Makes a timer with your own clock. Used by tests.- Parameters:
clockNanos- gives the time now, in nanoseconds
-
-
Method Details
-
update
public double update()Call once at the top of each loop.- Returns:
- seconds since the last call (0 on the first call)
-
getLastSeconds
public double getLastSeconds()Seconds the last loop took. -
getAverageMs
public double getAverageMs()Average loop time in milliseconds (smoothed). -
getHz
public double getHz()Loops per second (smoothed). 0 until two loops have run. -
reset
public void reset()Starts over, as if new.
-