Class BaseStatusSignal
- Direct Known Subclasses:
StatusSignal
public abstract class BaseStatusSignal extends Object
-
Field Summary
Fields Modifier and Type Field Description protected Runnable
_reportIfOldFunc
protected double
baseValue
protected DeviceIdentifier
deviceIdentifier
protected StatusCode
error
protected StatusSignalJNI
jni
protected String
signalName
protected int
spn
protected AllTimestamps
timestamps
protected String
units
-
Method Summary
Modifier and Type Method Description protected void
copyFrom(BaseStatusSignal other)
AllTimestamps
getAllTimestamps()
Get all timestamps relevant for this signalabstract double
getAppliedUpdateFrequency()
Gets the rate at which the device will publish this signal.static double
getLatencyCompensatedValue(StatusSignal<Double> signal, StatusSignal<Double> signalSlope)
Performs latency compensation on signal using the signalSlope and signal's latency to determine the magnitude of compensation.static double
getLatencyCompensatedValue(StatusSignal<Double> signal, StatusSignal<Double> signalSlope, double maxLatencySeconds)
Performs latency compensation on signal using the signalSlope and signal's latency to determine the magnitude of compensation.String
getName()
Gets the name of this signalStatusCode
getStatus()
Get the error code from when we last received this signalTimestamp
getTimestamp()
Get the best available timestamp for this signalString
getUnits()
Gets the units for this signaldouble
getValueAsDouble()
Gets the value of this signal as a doubleboolean
hasUpdated()
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.StatusCode
setUpdateFrequency(double frequencyHz)
Sets the rate at which the device will publish this signal.abstract StatusCode
setUpdateFrequency(double frequencyHz, 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
waitForAll(double timeoutSeconds, BaseStatusSignal... signals)
Waits for new data on all provided signals up to timeout.
-
Field Details
-
Method Details
-
copyFrom
-
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...)
.- 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 double getLatencyCompensatedValue(StatusSignal<Double> signal, StatusSignal<Double> 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.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 double getLatencyCompensatedValue(StatusSignal<Double> signal, StatusSignal<Double> 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.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.
-
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.050 seconds (50ms) for each signal.
- Parameters:
frequencyHz
- Rate to publish the signal in Hz.signals
- 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.050 seconds (50ms) 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.
- 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)
. 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
-
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 best available timestamp for this signal- Returns:
- Best available timestamp
-
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
-