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:

AllTimestamps

property timestamp: phoenix6.timestamp.Timestamp#

The most accurate timestamp associated with this signal

Returns:

The most accurate timestamp associated with this signal.

Return type:

Timestamp

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:

StatusCode

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

wait_for_all(*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.

Parameters:

timeout_seconds – Maximum time to wait for new data in seconds.

Pass zero to refresh all signals without blocking. :type timeout_seconds: second :param signals: Signals to wait for new data against :type signals: tuple[BaseStatusSignal | list[BaseStatusSignal], …] :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. :rtype: StatusCode

refresh_all() 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. :rtype: StatusCode

get_latency_compensated_value(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 – 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). :type signal: StatusSignal[float] :param 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). :type signal: StatusSignal[float] :param max_latency_seconds: 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. :type max_latency_seconds: second :returns: Latency compensated value from the signal StatusSignal. :rtype: float

is_all_good() 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

set_update_frequency_for_all(*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.050 seconds (50ms) 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:

StatusCode

abstract set_update_frequency(frequency_hz: phoenix6.units.hertz, timeout_seconds: phoenix6.units.second = 0.05) 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:

StatusCode

abstract 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