Class BaseStatusSignal

java.lang.Object
com.ctre.phoenix6.BaseStatusSignal
Direct Known Subclasses:
StatusSignal

public abstract class BaseStatusSignal
extends Object
Class that provides operations to retrieve information about a status signal.
  • Field Details

  • Method Details

    • copyFrom

      protected void copyFrom​(BaseStatusSignal other)
    • waitForAll

      public static StatusCode waitForAll​(double timeoutSeconds, BaseStatusSignal... signals)
      Waits for new data on all provided signals up to timeout. This API is typically used with CANivore Bus signals as they will be synced using the CANivore Timesync feature and arrive simultaneously. Signals on a roboRIO bus cannot be synced and may require a significantly longer blocking call to receive all signals.

      Note that CANivore Timesync requires Phoenix Pro.

      This can also be used with a timeout of zero to refresh many signals at once, which is faster than calling refresh() on every signal.

      Parameters:
      timeoutSeconds - Maximum time to wait for new data in seconds. Pass zero to refresh all signals without blocking.
      signals - Signals to wait for new data against
      Returns:
      An InvalidParamValue if signals array is empty, InvalidNetwork if signals are on different CAN bus networks, RxTimeout if it took longer than timeoutSeconds to receive all the signals, MultiSignalNotSupported if using the roboRIO bus with more than one signal and a non-zero timeout. An OK status code means that all signals arrived within timeoutSeconds and they are all OK. Any other value represents the StatusCode of the first failed signal. Call getError() on each signal to determine which ones failed.
    • getLatencyCompensatedValue

      public static double getLatencyCompensatedValue​(StatusSignal<Double> signal, StatusSignal<Double> signalSlope)
      Performs latency compensation on signal using the signalSlope and signal's latency to determine the magnitude of compensation. The caller must refresh these StatusSignals beforehand; this function only does the math required for latency compensation.

      Important: The signalSlope must be the rate of change of the signal. If it is not the latency compensation may not perform as expected.

      Example: double compensatedTurns = getLatencyCompensatedValue(fx.getPosition(), fx.getVelocity());

      Parameters:
      signal - Signal to be latency compensated. Caller must make sure this signal is up to date either by calling StatusSignal.refresh() or StatusSignal.waitForUpdate(double).
      signalSlope - Derivative of signal that informs compensation magnitude. Caller must make sure this signal is up to date either by calling StatusSignal.refresh() or StatusSignal.waitForUpdate(double).
      Returns:
      Latency compensated value from the signal StatusSignal.
    • isAllGood

      public static boolean isAllGood​(BaseStatusSignal... signals)
      Checks if all signals have an OK error code.
      Parameters:
      signals - Signals to check error code of.
      Returns:
      True if all are good, false otherwise
    • setUpdateFrequency

      public StatusCode setUpdateFrequency​(double frequencyHz)
      Sets the rate at which the device will publish this signal.

      The minimum supported signal frequency is 4 Hz, and the maximum is 1000 Hz.

      This will wait up to 0.050 seconds (50ms) by default.

      Parameters:
      frequencyHz - Rate to publish the signal in Hz.
      Returns:
      Status code of setting the update frequency
    • setUpdateFrequency

      public StatusCode setUpdateFrequency​(double frequencyHz, double timeoutSeconds)
      Sets the rate at which the device will publish this signal.

      The minimum supported signal frequency is 4 Hz, and the maximum is 1000 Hz.

      Parameters:
      frequencyHz - Rate to publish the signal in Hz.
      timeoutSeconds - Maximum amount of time to wait when performing the action
      Returns:
      Status code of setting the update frequency
    • getUnits

      public String getUnits()
      Gets the units for this signal
      Returns:
      String representation of units for this signal
    • getAllTimestamps

      Get all timestamps relevant for this signal
      Returns:
      All timestamps available for this signal
    • getTimestamp

      Get the best available timestamp for this signal
      Returns:
      Best available timestamp
    • getError

      public StatusCode getError()
      Get the error code from when we last received this signal
      Returns:
      Last cached Error Code