Class PhoenixSignals

java.lang.Object
frc.robot.util.PhoenixSignals

@NullMarked public class PhoenixSignals extends Object
Utility class that centralizes registration and synchronized refreshing of CTRE Phoenix BaseStatusSignals.

Grouping signals and refreshing them together ensures that all sampled values share the same synchronization fence, minimizing timestamp skew between related measurements.

Signals are maintained in separate groups depending on whether they are sourced from a CANivore bus or the roboRIO CAN bus, as Phoenix requires refresh calls to be performed per bus.

This class is purely static and is not intended to be instantiated.

  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Refreshes all registered Phoenix signals.
    static void
    registerSignals(boolean canivore, com.ctre.phoenix6.BaseStatusSignal... signals)
    Registers one or more Phoenix signals for synchronized refreshing.
    static void
    tryUntilOk(int maxAttempts, Supplier<com.ctre.phoenix6.StatusCode> command)
    Repeatedly executes a Phoenix command until it succeeds or the maximum number of attempts is reached.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • tryUntilOk

      public static void tryUntilOk(int maxAttempts, Supplier<com.ctre.phoenix6.StatusCode> command)
      Repeatedly executes a Phoenix command until it succeeds or the maximum number of attempts is reached.

      This is useful for Phoenix configuration calls that may transiently fail during startup or bus contention.

      Parameters:
      maxAttempts - maximum number of attempts before giving up
      command - supplier that executes the Phoenix command and returns a StatusCode
    • registerSignals

      public static void registerSignals(boolean canivore, com.ctre.phoenix6.BaseStatusSignal... signals)
      Registers one or more Phoenix signals for synchronized refreshing.

      All registered signals will be refreshed together when refreshAll() is called, ensuring consistent timestamps across related measurements.

      Signals must be registered to the correct bus (CANivore vs roboRIO). Mixing buses in a single refresh call is not supported by Phoenix.

      This method should typically be called during subsystem construction or robot initialization, before periodic refreshes occur.

      Parameters:
      canivore - true if the signals are on the CANivore bus, false if they are on the roboRIO CAN bus
      signals - one or more BaseStatusSignals to register
    • refreshAll

      public static void refreshAll()
      Refreshes all registered Phoenix signals.

      This method should be called once per control loop to update all registered signals in a synchronized manner.

      Signals on the CANivore and roboRIO buses are refreshed separately, but each group is internally synchronized.