Class BaseStatusSignal
- Direct Known Subclasses:
StatusSignal
-
Field Summary
Modifier and TypeFieldDescriptionprotected Runnable
protected double
protected DeviceIdentifier
protected StatusCode
protected StatusSignalJNI
protected final String
protected int
protected AllTimestamps
protected String
-
Method Summary
Modifier and TypeMethodDescriptionGet all timestamps relevant for this signal.double
Gets the rate at which the device will publish this signal.edu.wpi.first.units.measure.Frequency
Gets the rate at which the device will publish this signal as a unit type.static <U extends Unit,
U_PER_SEC extends PerUnit<U, TimeUnit>, MEAS extends Measure<U>, MEAS_PER_SEC extends Measure<U_PER_SEC>>
Measure<U>getLatencyCompensatedValue
(StatusSignal<MEAS> signal, StatusSignal<MEAS_PER_SEC> signalSlope) Performs latency compensation on signal using the signalSlope and signal's latency to determine the magnitude of compensation.static <U extends Unit,
U_PER_SEC extends PerUnit<U, TimeUnit>, MEAS extends Measure<U>, MEAS_PER_SEC extends Measure<U_PER_SEC>>
Measure<U>getLatencyCompensatedValue
(StatusSignal<MEAS> signal, StatusSignal<MEAS_PER_SEC> signalSlope, double maxLatencySeconds) Performs latency compensation on signal using the signalSlope and signal's latency to determine the magnitude of compensation.static double
getLatencyCompensatedValueAsDouble
(BaseStatusSignal signal, BaseStatusSignal signalSlope) Performs latency compensation on signal using the signalSlope and signal's latency to determine the magnitude of compensation.static double
getLatencyCompensatedValueAsDouble
(BaseStatusSignal signal, BaseStatusSignal signalSlope, double maxLatencySeconds) Performs latency compensation on signal using the signalSlope and signal's latency to determine the magnitude of compensation.getName()
Gets the name of this signal.Get the error code from when we last received this signal.Get the most accurate timestamp available for this signal.getUnits()
Gets the units for this signal.double
Gets the value of this signal as a double.boolean
Check whether the signal has been updated since the last check.static boolean
isAllGood
(BaseStatusSignal... signals) Checks if all signals have an OK error code.static StatusCode
refreshAll
(BaseStatusSignal... signals) Performs a non-blocking refresh on all provided signals.setUpdateFrequency
(double frequencyHz) Sets the rate at which the device will publish this signal.setUpdateFrequency
(double frequencyHz, double timeoutSeconds) Sets the rate at which the device will publish this signal.setUpdateFrequency
(edu.wpi.first.units.measure.Frequency frequency) Sets the rate at which the device will publish this signal.setUpdateFrequency
(edu.wpi.first.units.measure.Frequency frequency, double timeoutSeconds) Sets the rate at which the device will publish this signal.static StatusCode
setUpdateFrequencyForAll
(double frequencyHz, BaseStatusSignal... signals) Sets the update frequency of all specified status signals to the provided common frequency.static StatusCode
setUpdateFrequencyForAll
(edu.wpi.first.units.measure.Frequency frequency, BaseStatusSignal... signals) Sets the update frequency of all specified status signals to the provided common frequency.protected abstract void
updateUnits
(int spn) static StatusCode
waitForAll
(double timeoutSeconds, BaseStatusSignal... signals) Waits for new data on all provided signals up to timeout.
-
Field Details
-
deviceIdentifier
-
spn
-
units
-
error
-
baseValue
-
timestamps
-
signalName
-
_reportIfOldFunc
-
jni
-
-
Method Details
-
updateUnits
-
waitForAll
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. This is equivalent to calling
refreshAll(com.ctre.phoenix6.BaseStatusSignal...)
.If a signal arrives multiple times while waiting, such as when *not* using CANivore Timesync, the newest signal data is fetched. Additionally, if this function times out, the newest signal data is fetched for all signals (when possible). We recommend checking the individual status codes using
getStatus()
when this happens.- 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 getStatus() on each signal to determine which ones failed.
-
refreshAll
Performs a non-blocking refresh on all provided signals.This provides a performance improvement over separately calling refresh() on each signal.
- Parameters:
signals
- Signals to refresh- Returns:
- An InvalidParamValue if signals array is empty, InvalidNetwork if signals are on different CAN bus networks. An OK status code means that all signals are OK. Any other value represents the StatusCode of the first failed signal. Call getStatus() on each signal to determine which ones failed.
-
getLatencyCompensatedValue
public static <U extends Unit,U_PER_SEC extends PerUnit<U, Measure<U> getLatencyCompensatedValueTimeUnit>, MEAS extends Measure<U>, MEAS_PER_SEC extends Measure<U_PER_SEC>> (StatusSignal<MEAS> signal, StatusSignal<MEAS_PER_SEC> 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.This compensates for up to 300ms of latency by default.
Example: var compensatedTurns = BaseStatusSignal.getLatencyCompensatedValue(fx.getPosition(), fx.getVelocity());
- Parameters:
signal
- Signal to be latency compensated. Caller must make sure this signal is up to date either by callingStatusSignal.refresh()
orStatusSignal.waitForUpdate(double)
.signalSlope
- Derivative of signal that informs compensation magnitude. Caller must make sure this signal is up to date either by callingStatusSignal.refresh()
orStatusSignal.waitForUpdate(double)
.- Returns:
- Latency compensated value from the signal StatusSignal.
-
getLatencyCompensatedValue
public static <U extends Unit,U_PER_SEC extends PerUnit<U, Measure<U> getLatencyCompensatedValueTimeUnit>, MEAS extends Measure<U>, MEAS_PER_SEC extends Measure<U_PER_SEC>> (StatusSignal<MEAS> signal, StatusSignal<MEAS_PER_SEC> signalSlope, double maxLatencySeconds) 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.Example: var compensatedTurns = BaseStatusSignal.getLatencyCompensatedValue(fx.getPosition(), fx.getVelocity());
- Parameters:
signal
- Signal to be latency compensated. Caller must make sure this signal is up to date either by callingStatusSignal.refresh()
orStatusSignal.waitForUpdate(double)
.signalSlope
- Derivative of signal that informs compensation magnitude. Caller must make sure this signal is up to date either by callingStatusSignal.refresh()
orStatusSignal.waitForUpdate(double)
.maxLatencySeconds
- The maximum amount of latency to compensate for in seconds. A negative or zero value disables the max latency cap. This is used to cap the contribution of latency compensation for stale signals, such as after the device has been disconnected from the CAN bus.- Returns:
- Latency compensated value from the signal StatusSignal.
-
getLatencyCompensatedValueAsDouble
public static double getLatencyCompensatedValueAsDouble(BaseStatusSignal signal, BaseStatusSignal 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.
This compensates for up to 300ms of latency by default.
Example: double compensatedTurns = BaseStatusSignal.getLatencyCompensatedValueAsDouble(fx.getPosition(), fx.getVelocity());
- Parameters:
signal
- Signal to be latency compensated. Caller must make sure this signal is up to date either by callingStatusSignal.refresh()
orStatusSignal.waitForUpdate(double)
.signalSlope
- Derivative of signal that informs compensation magnitude. Caller must make sure this signal is up to date either by callingStatusSignal.refresh()
orStatusSignal.waitForUpdate(double)
.- Returns:
- Latency compensated value from the signal StatusSignal.
-
getLatencyCompensatedValueAsDouble
public static double getLatencyCompensatedValueAsDouble(BaseStatusSignal signal, BaseStatusSignal signalSlope, double maxLatencySeconds) 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 = BaseStatusSignal.getLatencyCompensatedValueAsDouble(fx.getPosition(), fx.getVelocity());
- Parameters:
signal
- Signal to be latency compensated. Caller must make sure this signal is up to date either by callingStatusSignal.refresh()
orStatusSignal.waitForUpdate(double)
.signalSlope
- Derivative of signal that informs compensation magnitude. Caller must make sure this signal is up to date either by callingStatusSignal.refresh()
orStatusSignal.waitForUpdate(double)
.maxLatencySeconds
- The maximum amount of latency to compensate for in seconds. A negative or zero value disables the max latency cap. This is used to cap the contribution of latency compensation for stale signals, such as after the device has been disconnected from the CAN bus.- Returns:
- Latency compensated value from the signal StatusSignal.
-
isAllGood
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
-
setUpdateFrequencyForAll
Sets the update frequency of all specified status signals to the provided common frequency.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.
This will wait up to 0.100 seconds (100ms) for each signal.
- Parameters:
frequencyHz
- Rate to publish the signal in Hzsignals
- Signals to apply the update frequency to- Returns:
- Status code of the first failed update frequency set call, or OK if all succeeded
-
setUpdateFrequencyForAll
public static StatusCode setUpdateFrequencyForAll(edu.wpi.first.units.measure.Frequency frequency, BaseStatusSignal... signals) Sets the update frequency of all specified status signals to the provided common frequency.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.
This will wait up to 0.100 seconds (100ms) for each signal.
- Parameters:
frequency
- Rate to publish the signalsignals
- Signals to apply the update frequency to- Returns:
- Status code of the first failed update frequency set call, or OK if all succeeded
-
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.
This will wait up to 0.100 seconds (100ms) by default.
- Parameters:
frequencyHz
- Rate to publish the signal in Hz- Returns:
- Status code of setting the update frequency
-
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.
This will wait up to 0.100 seconds (100ms) by default.
- Parameters:
frequency
- Rate to publish the signal- Returns:
- Status code of setting the update frequency
-
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.
- Parameters:
frequencyHz
- Rate to publish the signal in HztimeoutSeconds
- Maximum amount of time to wait when performing the action- Returns:
- Status code of setting the update frequency
-
setUpdateFrequency
public StatusCode setUpdateFrequency(edu.wpi.first.units.measure.Frequency frequency, double timeoutSeconds) 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.
- Parameters:
frequency
- Rate to publish the signaltimeoutSeconds
- 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)
. The returned value may be higher if another StatusSignal in the same status frame has been set to a higher update frequency.- Returns:
- Applied update frequency of the signal in Hz
-
getAppliedUpdateFrequencyMeasure
Gets the rate at which the device will publish this signal as a unit type.This is typically the last value passed into
setUpdateFrequency(double)
. The returned value may be higher if another StatusSignal in the same status frame has been set to a higher update frequency.- Returns:
- Applied update frequency of the signal
-
getName
Gets the name of this signal.- Returns:
- Name of this signal
-
getUnits
Gets the units for this signal.- Returns:
- String representation of units for this signal
-
getValueAsDouble
Gets the value of this signal as a double.- Returns:
- Value of this signal as a double instead of the generic type
-
getAllTimestamps
Get all timestamps relevant for this signal.- Returns:
- All timestamps available for this signal
-
getTimestamp
Get the most accurate timestamp available for this signal.The timestamp sources from most to least accurate are:
Note that some of these sources may not be available.- Returns:
- The most accurate timestamp available
-
getStatus
Get the error code from when we last received this signal.- Returns:
- Last cached Error Code
-
hasUpdated
Check whether the signal has been updated since the last check.Note that the signal must be refreshed before calling this routine.
- Returns:
- true if the signal has updated since the previous call of this routine
-