Class Signal<T>

java.lang.Object
com.revrobotics.util.Signal<T>

public final class Signal<T> extends Object
  • Method Details

    • get

      public T get()
      Get the last known value. This value may or may not be recent. Check isValid() to know if this value was recently collected. Prefer get(T defaultValue) if you have a reasonable default.
      Returns:
      The last known value.
    • get

      public T get(T defaultValue)
      Get the last known value if it is recent, or the provided default otherwise.
      Parameters:
      defaultValue - the default to use if the value is not valid
      Returns:
      The last known value, or the default.
    • getTimestamp

      public long getTimestamp()
    • isValid

      public boolean isValid()
      Returns whether the value is recent and was collected without error. You can still get the last known value through 'get' if this method returns false, but the value may be outdated.
      Returns:
      Whether the value returned by 'get' is valid and recent.
    • getError

      public REVLibError getError()
    • map

      public <R> Signal<R> map(Function<T,R> mapper)
      Create a new Signal with a value returned by mapper, and the same error and timestamp as this object.
      Type Parameters:
      R - the new object's signal type
      Parameters:
      mapper - a function that converts this object's signal to another signal
      Returns:
      A new signal object with the same error and timestamp, but a new value
    • of

      public static <T> Signal<T> of(T value, long timestamp)
      Create a Signal with no error. isValid will return true
      Parameters:
      value - known good value
      timestamp - timestamp the value was collected
      Returns:
      A known good signal with the given value
    • ofError

      public static <T> Signal<T> ofError(T value, REVLibError error, long timestamp)
      Create a signal that has an error. isValid will return false if the error was not kOk.
      Parameters:
      value - The latest known good value
      error - error associated with the signal
      timestamp - timestamp the value was collected
      Returns:
      A signal that may be good or have an error
    • create

      public static <T extends StatusFrame> Signal<T> create(T statusFrame)