Class StatusSignal<T>
- All Implemented Interfaces:
Cloneable
public class StatusSignal<T> extends BaseStatusSignal implements Cloneable
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StatusSignal.SignalMeasurement<L>
Information from a single measurement of a status signal. -
Field Summary
Fields inherited from class com.ctre.phoenix6.BaseStatusSignal
_reportIfOldFunc, baseValue, deviceIdentifier, error, jni, signalName, spn, timestamps, units
-
Constructor Summary
Constructors Constructor Description StatusSignal(DeviceIdentifier deviceIdentifier, int spn, Runnable reportIfOldFunc, Class<T> classOfSignal, ParentDevice.MapGenerator<T> generator, String signalName)
StatusSignal(DeviceIdentifier deviceIdentifier, int spn, Runnable reportIfOldFunc, Class<T> classOfSignal, String signalName)
StatusSignal(Class<T> classOfSignal, StatusCode error)
-
Method Summary
Modifier and Type Method Description Supplier<T>
asSupplier()
Returns a lambda that callsrefresh(boolean)
andgetValue()
on this object.StatusSignal<T>
clone()
double
getAppliedUpdateFrequency()
Gets the rate at which the device will publish this signal.StatusSignal.SignalMeasurement<T>
getDataCopy()
Get a basic data-only container with this information, to be used for things such as data logging.Class<T>
getTypeClass()
T
getValue()
Gets the cached value from this status signal.StatusSignal<T>
refresh()
Refreshes the value of this status signal.StatusSignal<T>
refresh(boolean reportError)
Refreshes the value of this status signal.StatusCode
setUpdateFrequency(double frequencyHz, double timeoutSeconds)
Sets the rate at which the device will publish this signal.String
toString()
StatusSignal<T>
waitForUpdate(double timeoutSec)
Waits up to timeoutSec to get the up-to-date status signal value.StatusSignal<T>
waitForUpdate(double timeoutSec, boolean reportError)
Waits up to timeoutSec to get the up-to-date status signal value.Methods inherited from class com.ctre.phoenix6.BaseStatusSignal
copyFrom, getAllTimestamps, getLatencyCompensatedValue, getLatencyCompensatedValue, getName, getStatus, getTimestamp, getUnits, getValueAsDouble, hasUpdated, isAllGood, refreshAll, setUpdateFrequency, setUpdateFrequencyForAll, waitForAll
-
Constructor Details
-
StatusSignal
public StatusSignal(DeviceIdentifier deviceIdentifier, int spn, Runnable reportIfOldFunc, Class<T> classOfSignal, String signalName) -
StatusSignal
public StatusSignal(DeviceIdentifier deviceIdentifier, int spn, Runnable reportIfOldFunc, Class<T> classOfSignal, ParentDevice.MapGenerator<T> generator, String signalName) -
StatusSignal
-
-
Method Details
-
asSupplier
Returns a lambda that callsrefresh(boolean)
andgetValue()
on this object. This is useful for command-based programming.- Returns:
- Supplier that refreshes this signal and returns it
-
toString
-
clone
-
getTypeClass
-
getValue
Gets the cached value from this status signal.Gets the cached value. To make sure the value is up-to-date call
refresh()
orwaitForUpdate(double)
- Returns:
- Cached value
-
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.- Parameters:
reportError
- Whether to report any errors to the Driver Station/stderr. Defaults true- Returns:
- Reference to itself
-
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
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 updatereportError
- Whether to report any errors to the Driver Station/stderr. Defaults true- Returns:
- Reference to itself
-
waitForUpdate
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
-
setUpdateFrequency
Sets the rate at which the device will publish this signal.A frequency of 0 Hz will turn off the signal. Otherwise, the minimum supported signal frequency is 4 Hz, and the maximum is 1000 Hz.
If other StatusSignals in the same status frame have been set to an update frequency, the fastest requested update frequency will be applied to the frame.
- Specified by:
setUpdateFrequency
in classBaseStatusSignal
- 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
-
getAppliedUpdateFrequency
Gets the rate at which the device will publish this signal.This is typically the last value passed into
setUpdateFrequency(double, double)
. The returned value may be higher if another StatusSignal in the same status frame has been set to a higher update frequency.- Specified by:
getAppliedUpdateFrequency
in classBaseStatusSignal
- Returns:
- Applied update frequency of the signal in Hz
-
getDataCopy
Get a basic data-only container with this information, to be used for things such as data logging.Note 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
-