Class StatusSignal<T>

java.lang.Object
com.ctre.phoenix6.BaseStatusSignal
com.ctre.phoenix6.StatusSignal<T>
All Implemented Interfaces:
Cloneable

public class StatusSignal<T> extends BaseStatusSignal implements Cloneable
Represents a status signal with data of type T, and operations available to retrieve information about the signal.
  • Constructor Details

  • Method Details

    • getTypeClass

      public final Class<T> getTypeClass()
    • clone

      public StatusSignal<T> clone()
      Overrides:
      clone in class Object
    • getValue

      public final T getValue()
      Gets the cached value from this status signal.

      Gets the cached value. To make sure the value is up-to-date call refresh() or waitForUpdate(double)

      Returns:
      Cached value
    • refresh

      public final StatusSignal<T> refresh(boolean reportError)
      Refreshes the value of this status signal.

      If the user application caches this StatusSignal object instead of periodically fetching it from the hardware device, this function must be called to fetch fresh data.

      This performs a non-blocking refresh operation. If you want to wait until you receive the signal, call waitForUpdate(double) instead.

      Parameters:
      reportError - Whether to report any errors to the Driver Station/stderr. Defaults true
      Returns:
      Reference to itself
    • refresh

      public final StatusSignal<T> refresh()
      Refreshes the value of this status signal.

      If the user application caches this StatusSignal object instead of periodically fetching it from the hardware device, this function must be called to fetch fresh data.

      This performs a non-blocking refresh operation. If you want to wait until you receive the signal, call waitForUpdate(double) instead.

      Returns:
      Reference to itself
    • waitForUpdate

      public final StatusSignal<T> waitForUpdate(double timeoutSec, boolean reportError)
      Waits up to timeoutSec to get the up-to-date status signal value.

      This performs a blocking refresh operation. If you want to non-blocking refresh the signal, call refresh() instead.

      Parameters:
      timeoutSec - Maximum time to wait for the signal to update
      reportError - Whether to report any errors to the Driver Station/stderr. Defaults true
      Returns:
      Reference to itself
    • waitForUpdate

      public final StatusSignal<T> waitForUpdate(double timeoutSec)
      Waits up to timeoutSec to get the up-to-date status signal value.

      This performs a blocking refresh operation. If you want to non-blocking refresh the signal, call refresh() instead.

      Parameters:
      timeoutSec - Maximum time to wait for the signal to update
      Returns:
      Reference to itself
    • isNear

      public final boolean isNear(double target, double tolerance)
      Checks whether the signal is near a target value within the given tolerance.
      Parameters:
      target - The target value of the signal
      tolerance - The error tolerance between the target and measured values
      Returns:
      Whether the signal is near the target value
    • isNear

      public final boolean isNear(T target, T tolerance)
      Checks whether the signal is near a target value within the given tolerance. This signal must be a numeric or unit type.
      Parameters:
      target - The target value of the signal
      tolerance - The error tolerance between the target and measured values
      Returns:
      Whether the signal is near the target value
    • asSupplier

      public final Supplier<T> asSupplier()
      Returns a lambda that calls refresh(boolean) and getValue() on this object. This is useful for command-based programming.
      Returns:
      Supplier that refreshes this signal and returns it
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getDataCopy

      Get a basic data-only container with a copy of the current signal data.

      If looking for Phoenix 6 logging features, see the SignalLogger class instead.

      This function returns a new object every call. As a result, we recommend that this is not called inside a tight loop.

      Returns:
      Basic structure with all relevant information