Package com.crossbotics.ftchelper.core
Class Time
java.lang.Object
com.crossbotics.ftchelper.core.Time
The library's clock: the time now, in nanoseconds. On the robot it is the real clock
(
System.nanoTime()). A JUnit test can swap in a pretend clock, so it moves the time forward by
hand ("0.2 s later") instead of waiting: the test is quick and gives the same result on a slow computer.
Most of the robot's parts (the five-files modules, the launcher, the mechanisms, the match timer, the PID and slew controllers) read it each time they need the time. A part made before the swap uses the pretend clock too.
PretendClock clock = PretendClock.use(); // testkit: swaps it in
robot.intake.in();
clock.addSec(0.2); // 0.2 s later, at once
robot.all().update();
PretendClock.stopUsing(); // in @After: the real clock again
Code that measures how long the loop itself takes (the slow-loop warning) keeps the real clock. So does
the camera aim (Aim, the Limelight fix): the camera stamps its pictures with System.nanoTime().
Docs: docs/modules/core.md
-
Method Summary
Modifier and TypeMethodDescriptionstatic longnanos()The time now, nanoseconds (only differences mean anything).static voiduseForTests(LongSupplier clockNanos) For JUnit tests only: use this clock (nanoseconds) instead of the real one.
-
Method Details
-
nanos
public static long nanos()The time now, nanoseconds (only differences mean anything). Never waits. -
useForTests
For JUnit tests only: use this clock (nanoseconds) instead of the real one. Pass null to go back to the real clock (do it in@After, so the next test gets the real one).
-