CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
ctre::phoenix6::BaseStatusSignal Class Referenceabstract

Class that provides operations to retrieve information about a status signal. More...

#include <ctre/phoenix6/StatusSignal.hpp>

Inheritance diagram for ctre::phoenix6::BaseStatusSignal:
ctre::phoenix6::StatusSignal< units::angle::turn_t > ctre::phoenix6::StatusSignal< units::length::meter_t > ctre::phoenix6::StatusSignal< bool > ctre::phoenix6::StatusSignal< int > ctre::phoenix6::StatusSignal< units::angle::degree_t > ctre::phoenix6::StatusSignal< units::angular_velocity::degrees_per_second_t > ctre::phoenix6::StatusSignal< units::dimensionless::scalar_t > ctre::phoenix6::StatusSignal< units::degree_t > ctre::phoenix6::StatusSignal< units::degrees_per_second_t > ctre::phoenix6::StatusSignal< units::turn_t > ctre::phoenix6::StatusSignal< units::turns_per_second_t > ctre::phoenix6::StatusSignal< ctre::unit::newton_meters_per_ampere_t > ctre::phoenix6::StatusSignal< units::ampere_t > ctre::phoenix6::StatusSignal< T >

Public Member Functions

virtual ~BaseStatusSignal ()=0
 
std::string const & GetName () const
 Gets the name of this signal.
 
std::string const & GetUnits () const
 Gets the units for this signal.
 
double GetValueAsDouble () const
 Gets the value of this signal as a double.
 
AllTimestamps const & GetAllTimestamps () const
 Gets the timestamps of this signals.
 
Timestamp const & GetTimestamp () const
 Gets the most accurate timestamp available for this signal.
 
ctre::phoenix::StatusCode GetStatus () const
 Gets the error code from when we last received this signal.
 
bool HasUpdated ()
 Checks whether the signal has been updated since the last check.
 
ctre::phoenix::StatusCode SetUpdateFrequency (units::frequency::hertz_t frequencyHz, units::time::second_t timeoutSeconds=100_ms)
 Sets the rate at which the device will publish this signal.
 
units::frequency::hertz_t GetAppliedUpdateFrequency () const
 Gets the rate at which the device will publish this signal.
 

Static Public Member Functions

template<typename U , typename U_PER_SEC >
requires units::traits::is_unit_t_v<U> && units::traits::is_unit_t_v<U_PER_SEC> && units::traits::is_convertible_unit_v< typename units::traits::unit_t_traits<U>::unit_type, units::compound_unit<typename units::traits::unit_t_traits<U_PER_SEC>::unit_type, units::seconds> >
static U GetLatencyCompensatedValue (StatusSignal< U > const &signal, StatusSignal< U_PER_SEC > const &signalSlope, units::time::second_t maxLatencySeconds=0.300_s)
 Performs latency compensation on signal using the signalSlope and signal's latency to determine the magnitude of compensation.
 
template<std::derived_from< BaseStatusSignal >... Signals>
static ctre::phoenix::StatusCode WaitForAll (units::time::second_t timeoutSeconds, Signals &... signals)
 Waits for new data on all provided signals up to timeout.
 
static ctre::phoenix::StatusCode WaitForAll (units::time::second_t timeoutSeconds, std::span< BaseStatusSignal *const > signals)
 Waits for new data on all provided signals up to timeout.
 
template<std::derived_from< BaseStatusSignal >... Signals>
static ctre::phoenix::StatusCode RefreshAll (Signals &... signals)
 Performs a non-blocking refresh on all provided signals.
 
static ctre::phoenix::StatusCode RefreshAll (std::span< BaseStatusSignal *const > signals)
 Performs a non-blocking refresh on all provided signals.
 
template<std::derived_from< BaseStatusSignal >... Signals>
static bool IsAllGood (Signals const &... signals)
 Checks if all signals have an OK error code.
 
static bool IsAllGood (std::span< BaseStatusSignal const *const > signals)
 Checks if all signals have an OK error code.
 
template<std::derived_from< BaseStatusSignal >... Signals>
static ctre::phoenix::StatusCode SetUpdateFrequencyForAll (units::frequency::hertz_t frequencyHz, Signals &... signals)
 Sets the update frequency of all specified status signals to the provided common frequency.
 
static ctre::phoenix::StatusCode SetUpdateFrequencyForAll (units::frequency::hertz_t frequencyHz, std::span< BaseStatusSignal *const > signals)
 Sets the update frequency of all specified status signals to the provided common frequency.
 

Protected Member Functions

 BaseStatusSignal (hardware::DeviceIdentifier deviceIdentifier, uint16_t spn, std::string signalName, std::function< void()> checkFirmVersFunction)
 
 BaseStatusSignal (hardware::DeviceIdentifier deviceIdentifier, uint16_t spn, std::string signalName, std::function< void()> checkFirmVersFunction, std::function< std::map< uint16_t, std::string >()> const &unitsGenerator)
 
 BaseStatusSignal (ctre::phoenix::StatusCode error)
 
void RefreshValue (bool waitForUpdate, units::time::second_t timeout, bool ReportOnError)
 
void UpdateUnits (uint16_t unitsKey)
 

Static Protected Member Functions

static std::string Status_GetUnits (uint32_t signal)
 
static ctre::phoenix::StatusCode Status_Get (BaseStatusSignal &signal, char const *network, bool bWaitForUpdate, double timeoutSeconds)
 
static ctre::phoenix::StatusCode Status_WaitForAll (std::span< BaseStatusSignal *const > signals, char const *network, double timeoutSeconds)
 
static ctre::phoenix::StatusCode Status_SetUpdateFrequency (char const *canbus, uint32_t deviceHash, uint16_t spn, double frequencyHz, double timeoutSeconds)
 
static ctre::phoenix::StatusCode Status_SetUpdateFrequencyForAll (std::span< BaseStatusSignal *const > signals, double frequencyHz, double timeoutSeconds)
 
static double Status_GetAppliedUpdateFrequency (char const *canbus, uint32_t deviceHash, uint16_t spn)
 
static ctre::phoenix::StatusCode WaitForAllImpl (char const *location, units::time::second_t timeoutSeconds, std::span< BaseStatusSignal *const > signals)
 

Protected Attributes

std::string units
 
double baseValue = 0
 
AllTimestamps timestamps {}
 
ctre::phoenix::StatusCode error = ctre::phoenix::StatusCode::SigNotUpdated
 

Detailed Description

Class that provides operations to retrieve information about a status signal.

Constructor & Destructor Documentation

◆ BaseStatusSignal() [1/3]

ctre::phoenix6::BaseStatusSignal::BaseStatusSignal ( hardware::DeviceIdentifier deviceIdentifier,
uint16_t spn,
std::string signalName,
std::function< void()> checkFirmVersFunction )
inlineprotected

◆ BaseStatusSignal() [2/3]

ctre::phoenix6::BaseStatusSignal::BaseStatusSignal ( hardware::DeviceIdentifier deviceIdentifier,
uint16_t spn,
std::string signalName,
std::function< void()> checkFirmVersFunction,
std::function< std::map< uint16_t, std::string >()> const & unitsGenerator )
inlineprotected

◆ BaseStatusSignal() [3/3]

ctre::phoenix6::BaseStatusSignal::BaseStatusSignal ( ctre::phoenix::StatusCode error)
inlineprotected

◆ ~BaseStatusSignal()

virtual ctre::phoenix6::BaseStatusSignal::~BaseStatusSignal ( )
pure virtual

Member Function Documentation

◆ GetAllTimestamps()

AllTimestamps const & ctre::phoenix6::BaseStatusSignal::GetAllTimestamps ( ) const
inline

Gets the timestamps of this signals.

Returns
All timestamps for this signal

◆ GetAppliedUpdateFrequency()

units::frequency::hertz_t ctre::phoenix6::BaseStatusSignal::GetAppliedUpdateFrequency ( ) const
inline

Gets the rate at which the device will publish this signal.

This is typically the last value passed into SetUpdateFrequency. 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

◆ GetLatencyCompensatedValue()

template<typename U , typename U_PER_SEC >
requires units::traits::is_unit_t_v<U> && units::traits::is_unit_t_v<U_PER_SEC> && units::traits::is_convertible_unit_v< typename units::traits::unit_t_traits<U>::unit_type, units::compound_unit<typename units::traits::unit_t_traits<U_PER_SEC>::unit_type, units::seconds> >
static U ctre::phoenix6::BaseStatusSignal::GetLatencyCompensatedValue ( StatusSignal< U > const & signal,
StatusSignal< U_PER_SEC > const & signalSlope,
units::time::second_t maxLatencySeconds = 0.300_s )
inlinestatic

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 usage:

units::turn_t compensatedTurns = BaseStatusSignal::GetLatencyCompensatedValue(fx.GetPosition(), fx.GetVelocity());
static U GetLatencyCompensatedValue(StatusSignal< U > const &signal, StatusSignal< U_PER_SEC > const &signalSlope, units::time::second_t maxLatencySeconds=0.300_s)
Performs latency compensation on signal using the signalSlope and signal's latency to determine the m...
Definition StatusSignal.hpp:278
Template Parameters
UType of signal's underlying type. This is the type that the function will return.
U_PER_SECType of signalSlope's underlying type. This must be the derivative of U.
Parameters
signalSignal to be latency compensated. Caller must make sure this signal is up to date either by calling Refresh() or WaitForUpdate().
signalSlopeDerivative of signal that informs compensation magnitude. Caller must make sure this signal is up to date either by calling Refresh() or WaitForUpdate().
maxLatencySecondsThe 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.

◆ GetName()

std::string const & ctre::phoenix6::BaseStatusSignal::GetName ( ) const
inline

Gets the name of this signal.

Returns
Name of this signal

◆ GetStatus()

ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::GetStatus ( ) const
inline

Gets the error code from when we last received this signal.

Returns
Last cached Error Code

◆ GetTimestamp()

Timestamp const & ctre::phoenix6::BaseStatusSignal::GetTimestamp ( ) const
inline

Gets 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 for this signal

◆ GetUnits()

std::string const & ctre::phoenix6::BaseStatusSignal::GetUnits ( ) const
inline

Gets the units for this signal.

Returns
String representation of units for this signal

◆ GetValueAsDouble()

double ctre::phoenix6::BaseStatusSignal::GetValueAsDouble ( ) const
inline

Gets the value of this signal as a double.

Returns
Value of this signal as a double instead of the generic type

◆ HasUpdated()

bool ctre::phoenix6::BaseStatusSignal::HasUpdated ( )
inline

Checks 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

◆ IsAllGood() [1/2]

template<std::derived_from< BaseStatusSignal >... Signals>
static bool ctre::phoenix6::BaseStatusSignal::IsAllGood ( Signals const &... signals)
inlinestatic

Checks if all signals have an OK error code.

Parameters
signalsSignals to check error code of, passed as a comma-separated list of signal references.
Returns
True if all signals are OK, false otherwise

◆ IsAllGood() [2/2]

static bool ctre::phoenix6::BaseStatusSignal::IsAllGood ( std::span< BaseStatusSignal const *const > signals)
inlinestatic

Checks if all signals have an OK error code.

Parameters
signalsSignals to check error code of, passed as a span of signal pointers.
Returns
True if all signals are OK, false otherwise

◆ RefreshAll() [1/2]

template<std::derived_from< BaseStatusSignal >... Signals>
static ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::RefreshAll ( Signals &... signals)
inlinestatic

Performs a non-blocking refresh on all provided signals.

This provides a performance improvement over separately calling Refresh() on each signal.

Parameters
signalsSignals to refresh, passed as a comma-separated list of signal references.
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.

◆ RefreshAll() [2/2]

static ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::RefreshAll ( std::span< BaseStatusSignal *const > signals)
inlinestatic

Performs a non-blocking refresh on all provided signals.

This provides a performance improvement over separately calling Refresh() on each signal.

Parameters
signalsSignals to refresh, passed as a span of signal pointers.
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.

◆ RefreshValue()

void ctre::phoenix6::BaseStatusSignal::RefreshValue ( bool waitForUpdate,
units::time::second_t timeout,
bool ReportOnError )
protected

◆ SetUpdateFrequency()

ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::SetUpdateFrequency ( units::frequency::hertz_t frequencyHz,
units::time::second_t timeoutSeconds = 100_ms )
inline

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. Additionally, some update frequencies are not supported and will be promoted up to the next highest supported frequency.

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
frequencyHzRate to publish the signal in Hz.
timeoutSecondsMaximum amount of time to wait when performing the action
Returns
Status code of setting the update frequency

◆ SetUpdateFrequencyForAll() [1/2]

template<std::derived_from< BaseStatusSignal >... Signals>
static ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::SetUpdateFrequencyForAll ( units::frequency::hertz_t frequencyHz,
Signals &... signals )
inlinestatic

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. Additionally, some update frequencies are not supported and will be promoted up to the next highest supported frequency.

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
frequencyHzRate to publish the signal in Hz.
signalsSignals to apply the update frequency to, passed as a comma-separated list of signal references.
Returns
Status code of the first failed update frequency set call, or OK if all succeeded

◆ SetUpdateFrequencyForAll() [2/2]

static ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::SetUpdateFrequencyForAll ( units::frequency::hertz_t frequencyHz,
std::span< BaseStatusSignal *const > signals )
inlinestatic

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. Additionally, some update frequencies are not supported and will be promoted up to the next highest supported frequency.

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
frequencyHzRate to publish the signal in Hz.
signalsSignals to apply the update frequency to, passed as a span of signal pointers.
Returns
Status code of the first failed update frequency set call, or OK if all succeeded

◆ Status_Get()

static ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::Status_Get ( BaseStatusSignal & signal,
char const * network,
bool bWaitForUpdate,
double timeoutSeconds )
staticprotected

◆ Status_GetAppliedUpdateFrequency()

static double ctre::phoenix6::BaseStatusSignal::Status_GetAppliedUpdateFrequency ( char const * canbus,
uint32_t deviceHash,
uint16_t spn )
staticprotected

◆ Status_GetUnits()

static std::string ctre::phoenix6::BaseStatusSignal::Status_GetUnits ( uint32_t signal)
staticprotected

◆ Status_SetUpdateFrequency()

static ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::Status_SetUpdateFrequency ( char const * canbus,
uint32_t deviceHash,
uint16_t spn,
double frequencyHz,
double timeoutSeconds )
staticprotected

◆ Status_SetUpdateFrequencyForAll()

static ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::Status_SetUpdateFrequencyForAll ( std::span< BaseStatusSignal *const > signals,
double frequencyHz,
double timeoutSeconds )
staticprotected

◆ Status_WaitForAll()

static ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::Status_WaitForAll ( std::span< BaseStatusSignal *const > signals,
char const * network,
double timeoutSeconds )
staticprotected

◆ UpdateUnits()

void ctre::phoenix6::BaseStatusSignal::UpdateUnits ( uint16_t unitsKey)
protected

◆ WaitForAll() [1/2]

template<std::derived_from< BaseStatusSignal >... Signals>
static ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::WaitForAll ( units::time::second_t timeoutSeconds,
Signals &... signals )
inlinestatic

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.

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
timeoutSecondsMaximum time to wait for all the signals to arrive. Pass zero to refresh all signals without blocking.
signalsSignals to wait on, passed as a comma-separated list of signal references.
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.

◆ WaitForAll() [2/2]

static ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::WaitForAll ( units::time::second_t timeoutSeconds,
std::span< BaseStatusSignal *const > signals )
inlinestatic

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.

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
timeoutSecondsMaximum time to wait for all the signals to arrive. Pass zero to refresh all signals without blocking.
signalsSignals to wait on, passed as a span of signal pointers.
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.

◆ WaitForAllImpl()

static ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::WaitForAllImpl ( char const * location,
units::time::second_t timeoutSeconds,
std::span< BaseStatusSignal *const > signals )
staticprotected

Member Data Documentation

◆ baseValue

double ctre::phoenix6::BaseStatusSignal::baseValue = 0
protected

◆ error

ctre::phoenix::StatusCode ctre::phoenix6::BaseStatusSignal::error = ctre::phoenix::StatusCode::SigNotUpdated
protected

◆ timestamps

AllTimestamps ctre::phoenix6::BaseStatusSignal::timestamps {}
protected

◆ units

std::string ctre::phoenix6::BaseStatusSignal::units
protected

The documentation for this class was generated from the following file: