Class Signal<T>
java.lang.Object
com.revrobotics.util.Signal<T>
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends StatusFrame>
Signal<T> create(T statusFrame) get()Get the last known value.Get the last known value if it is recent, or the provided default otherwise.getError()longbooleanisValid()Returns whether the value is recent and was collected without error.<R> Signal<R> Create a new Signal with a value returned by mapper, and the same error and timestamp as this object.static <T> Signal<T> of(T value, long timestamp) Create a Signal with no error.static <T> Signal<T> ofError(T value, REVLibError error, long timestamp) Create a signal that has an error.
-
Method Details
-
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
-
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
-
map
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
Create a Signal with no error. isValid will return true- Parameters:
value- known good valuetimestamp- timestamp the value was collected- Returns:
- A known good signal with the given value
-
ofError
Create a signal that has an error. isValid will return false if the error was not kOk.- Parameters:
value- The latest known good valueerror- error associated with the signaltimestamp- timestamp the value was collected- Returns:
- A signal that may be good or have an error
-
create
-