phoenix6.base_status_signal
#
Module Contents#
- class phoenix6.base_status_signal.BaseStatusSignal(device_identifer: phoenix6.hardware.device_identifier.DeviceIdentifier, spn: int, signal_name: str, report_if_old_func: Callable[[], None])#
Bases:
abc.ABC
Common parent type for the :ref:StatusSignal: object.
This can be used for a collection of :ref:StatusSignal: objects, but we recommend using the derived class instead when possible
- property name: str#
The name of this signal.
- Returns:
The name of this signal
- Return type:
str
- property units: str#
The units associated with this signal.
- Returns:
Units associated with this signal
- Return type:
str
- property value_as_double: float#
Gets the value as a double instead of the generic type. This may be helpful when working with the base class.
- Returns:
Signal as a double
- Return type:
float
- property all_timestamps: phoenix6.all_timestamps.AllTimestamps#
All the timestamps associated with this signal.
- Returns:
All the timestamps associated with this signal
- Return type:
- property timestamp: phoenix6.timestamp.Timestamp#
The most accurate timestamp available for this signal.
The timestamp sources from most to least accurate are:
TimestampSource.Device
TimestampSource.CANivore
TimestampSource.System
Note that some of these sources may not be available.
- Returns:
The most accurate timestamp available for this signal
- Return type:
- property status: phoenix6.status_code.StatusCode#
The status of the last time this signal was updated.
- Returns:
Status of the last time this signal was updated
- Return type:
- property has_updated: bool#
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
- Return type:
bool
- static wait_for_all(timeout_seconds: phoenix6.units.second, *signals: BaseStatusSignal | list[BaseStatusSignal]) phoenix6.status_code.StatusCode #
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 refresh_all.
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 self.status when this happens.
- Parameters:
timeout_seconds (second) – Maximum time to wait for new data in seconds. Pass zero to refresh all signals without blocking.
signals (tuple[BaseStatusSignal | list[BaseStatusSignal], ...]) – 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. Check the status of each signal to determine which ones failed.
- Return type:
- static refresh_all(*signals: BaseStatusSignal | list[BaseStatusSignal]) phoenix6.status_code.StatusCode #
Performs a non-blocking refresh on all provided signals.
This provides a performance improvement over separately calling refresh() on each signal.
- Parameters:
signals (tuple[BaseStatusSignal | list[BaseStatusSignal], ...]) – 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. Check the status of each signal to determine which ones failed.
- Return type:
- static get_latency_compensated_value(signal: StatusSignal[float], signal_slope: StatusSignal[float], max_latency_seconds: phoenix6.units.second = 0.3) float #
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: compensatedTurns = BaseStatusSignal.get_latency_compensated_value(fx.get_position(), fx.get_velocity())
- Parameters:
signal (StatusSignal[float]) – Signal to be latency compensated. Caller must make sure this signal is up to date either by calling StatusSignal.refresh() or StatusSignal.wait_for_update(double).
signal_slope – Derivative of signal that informs compensation magnitude. Caller must make sure this signal is up to date either by calling StatusSignal.refresh() or StatusSignal.wait_for_update(double).
max_latency_seconds (second) – 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.
- Return type:
float
- static is_all_good(*signals: BaseStatusSignal | list[BaseStatusSignal]) bool #
Checks if all signals have an OK error code. :param signals: Signals to check error code of :type signals: tuple[BaseStatusSignal | list[BaseStatusSignal], …] :returns: True if all are good, False otherwise :rtype: bool
- static set_update_frequency_for_all(frequency_hz: phoenix6.units.hertz, *signals: BaseStatusSignal | list[BaseStatusSignal]) phoenix6.status_code.StatusCode #
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_hz (hertz) – Rate to publish the signal in Hz
signals (tuple[BaseStatusSignal | list[BaseStatusSignal], ...]) – Signals to apply the update frequency to
- Returns:
Status code of the first failed update frequency set call, or OK if all succeeded
- Return type:
- set_update_frequency(frequency_hz: phoenix6.units.hertz, timeout_seconds: phoenix6.units.second = 0.1) phoenix6.status_code.StatusCode #
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_hz (hertz) – Rate to publish the signal in Hz
timeout_seconds (second) – Maximum amount of time to wait when performing the action
- Returns:
Status code of setting the update frequency
- Return type:
- get_applied_update_frequency() phoenix6.units.hertz #
Gets the rate at which the device will publish this signal.
This is typically the last value passed into set_update_frequency. 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
- Return type:
hertz