Package com.ctre.phoenix6
Class BaseStatusSignal
java.lang.Object
com.ctre.phoenix6.BaseStatusSignal
- Direct Known Subclasses:
StatusSignal
public abstract class BaseStatusSignal extends Object
Class that provides operations to retrieve
information about a status signal.
-
Field Summary
Fields Modifier and Type Field Description protected doublebaseValueprotected DeviceIdentifierdeviceIdentifierprotected StatusCodeerrorprotected StatusSignalJNIjniprotected StringsignalNameprotected intspnprotected AllTimestampstimestampsprotected Stringunits -
Method Summary
Modifier and Type Method Description protected voidcopyFrom(BaseStatusSignal other)AllTimestampsgetAllTimestamps()Get all timestamps relevant for this signalStatusCodegetError()Get the error code from when we last received this signalstatic doublegetLatencyCompensatedValue(StatusSignal<Double> signal, StatusSignal<Double> signalSlope)Performs latency compensation on signal using the signalSlope and signal's latency to determine the magnitude of compensation.TimestampgetTimestamp()Get the best available timestamp for this signalStringgetUnits()Gets the units for this signalstatic booleanisAllGood(BaseStatusSignal... signals)Checks if all signals have an OK error code.StatusCodesetUpdateFrequency(double frequencyHz)Sets the rate at which the device will publish this signal.StatusCodesetUpdateFrequency(double frequencyHz, double timeoutSeconds)Sets the rate at which the device will publish this signal.static StatusCodewaitForAll(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.
- 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 getError() 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.
Example: double compensatedTurns = 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.
-
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
-
setUpdateFrequency
Sets the rate at which the device will publish this signal.The minimum supported signal frequency is 4 Hz, and the maximum is 1000 Hz.
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.The minimum supported signal frequency is 4 Hz, and the maximum is 1000 Hz.
- 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
-
getUnits
Gets the units for this signal- Returns:
- String representation of units for this signal
-
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
-
getError
Get the error code from when we last received this signal- Returns:
- Last cached Error Code
-