Class BackgroundSampler
java.lang.Object
frc.spectrumLib.util.BackgroundSampler
Runs slow reads, such as files under
/proc and CAN bus status, on one low-priority daemon
thread. The robot loop only ever picks up the latest result.
On SystemCore the main thread runs at real-time priority. A read that blocks for a millisecond
there (CANBus.getStatus() can) or walks sixty /proc files makes the loop late. The
results are telemetry and alerts, which are outputs, so where they are computed does not matter
to AdvantageKit replay.
Start samplers during robot init: threads inherit the scheduling policy of the thread that creates them, and the main thread becomes real-time at the end of init.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe latest value a background read produced. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> BackgroundSampler.Latest<T> RunsreadeveryperiodSecondson the sampler thread.
-
Method Details
-
every
RunsreadeveryperiodSecondson the sampler thread.- Parameters:
periodSeconds- time between readsread- the read; exceptions are swallowed so one bad read cannot stop the thread- Returns:
- where each result lands
-