CTRE Phoenix 6 C++ 24.3.0
ctre::phoenix6::StatusSignal< T > Class Template Reference

Represents a status signal with data of type T, and operations available to retrieve information about the signal. More...

#include <ctre/phoenix6/StatusSignal.hpp>

Inheritance diagram for ctre::phoenix6::StatusSignal< T >:
ctre::phoenix6::BaseStatusSignal

Public Member Functions

std::string ToString () const
 
GetValue () const
 Gets the cached value from this status signal. More...
 
StatusSignal< T > & Refresh (bool ReportOnError=true)
 Refreshes the value of this status signal. More...
 
StatusSignal< T > & WaitForUpdate (units::time::second_t timeoutSec, bool ReportOnError=true)
 Waits up to timeoutSec to get the up-to-date status signal value. More...
 
ctre::phoenix::StatusCode SetUpdateFrequency (units::frequency::hertz_t frequencyHz, units::time::second_t timeoutSeconds=50_ms) override
 Sets the rate at which the device will publish this signal. More...
 
virtual units::frequency::hertz_t GetAppliedUpdateFrequency () const override
 Gets the rate at which the device will publish this signal. More...
 
SignalMeasurement< T > GetDataCopy () const
 Get a basic data-only container with this information, to be used for things such as data logging. More...
 
std::function< T()> AsSupplier ()
 Returns a lambda that calls Refresh and GetValue on this object. More...
 
- Public Member Functions inherited from ctre::phoenix6::BaseStatusSignal
virtual ~BaseStatusSignal ()=0
 
virtual ctre::phoenix::StatusCode SetUpdateFrequency (units::frequency::hertz_t frequencyHz, units::time::second_t timeoutSeconds=50_ms)=0
 Sets the rate at which the device will publish this signal. More...
 
virtual units::frequency::hertz_t GetAppliedUpdateFrequency () const =0
 Gets the rate at which the device will publish this signal. More...
 
const std::string & GetName () const
 Gets the name of this signal. More...
 
const std::string & GetUnits () const
 Gets the units for this signal. More...
 
double GetValueAsDouble () const
 Gets the value of this signal as a double. More...
 
const AllTimestampsGetAllTimestamps () const
 Get the timestamps of this signals. More...
 
const TimestampGetTimestamp () const
 Get the best timestamp available to this signal. More...
 
ctre::phoenix::StatusCode GetStatus () const
 Get the error code from when we last received this signal. More...
 
bool HasUpdated ()
 Check whether the signal has been updated since the last check. More...
 

Friends

class hardware::ParentDevice
 
std::ostream & operator<< (std::ostream &os, const StatusSignal< T > &data)
 

Additional Inherited Members

- Static Public Member Functions inherited from ctre::phoenix6::BaseStatusSignal
template<typename... Signals, typename = std::enable_if_t<is_all_status_signal_v<Signals...>>>
static ctre::phoenix::StatusCode WaitForAll (units::time::second_t timeoutSeconds, Signals &... signals)
 Waits for new data on all provided signals up to timeout. More...
 
static ctre::phoenix::StatusCode WaitForAll (units::time::second_t timeoutSeconds, const std::vector< BaseStatusSignal * > &signals)
 Waits for new data on all provided signals up to timeout. More...
 
template<size_t N>
static ctre::phoenix::StatusCode WaitForAll (units::time::second_t timeoutSeconds, const std::array< BaseStatusSignal *, N > &signals)
 Waits for new data on all provided signals up to timeout. More...
 
template<typename... Signals, typename = std::enable_if_t<is_all_status_signal_v<Signals...>>>
static ctre::phoenix::StatusCode RefreshAll (Signals &... signals)
 Performs a non-blocking refresh on all provided signals. More...
 
static ctre::phoenix::StatusCode RefreshAll (const std::vector< BaseStatusSignal * > &signals)
 Performs a non-blocking refresh on all provided signals. More...
 
template<size_t N>
static ctre::phoenix::StatusCode RefreshAll (const std::array< BaseStatusSignal *, N > &signals)
 Performs a non-blocking refresh on all provided signals. More...
 
template<typename U , typename U_PER_SEC >
static U GetLatencyCompensatedValue (StatusSignal< U > &signal, StatusSignal< U_PER_SEC > &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. More...
 
template<typename... Signals, typename = std::enable_if_t<is_all_status_signal_v<Signals...>>>
static bool IsAllGood (Signals &... signals)
 Checks if all signals have an OK error code. More...
 
static bool IsAllGood (const std::vector< BaseStatusSignal * > &signals)
 Checks if all signals have an OK error code. More...
 
template<size_t N>
static bool IsAllGood (const std::array< BaseStatusSignal *, N > &signals)
 Checks if all signals have an OK error code. More...
 
template<typename... Signals, typename = std::enable_if_t<is_all_status_signal_v<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. More...
 
static ctre::phoenix::StatusCode SetUpdateFrequencyForAll (units::frequency::hertz_t frequencyHz, const std::vector< BaseStatusSignal * > &signals)
 Sets the update frequency of all specified status signals to the provided common frequency. More...
 
template<size_t N>
static ctre::phoenix::StatusCode SetUpdateFrequencyForAll (units::frequency::hertz_t frequencyHz, const std::array< BaseStatusSignal *, N > &signals)
 Sets the update frequency of all specified status signals to the provided common frequency. More...
 
- Protected Member Functions inherited from ctre::phoenix6::BaseStatusSignal
void CopyFrom (const BaseStatusSignal &other)
 
 BaseStatusSignal (hardware::DeviceIdentifier deviceIdentifier, uint16_t spn, std::string signalName, std::function< void()> checkFirmVersFunction)
 
 BaseStatusSignal (ctre::phoenix::StatusCode error)
 
- Static Protected Member Functions inherited from ctre::phoenix6::BaseStatusSignal
static ctre::phoenix::StatusCode Status_WaitForAll (BaseStatusSignal *const *signals, size_t count, const char *network, double timeoutSeconds)
 Wait for multiple signals to arrive. More...
 
static ctre::phoenix::StatusCode Status_SetUpdateFrequency (const char *canbus, uint32_t deviceHash, uint16_t spn, double frequencyHz, double timeoutSeconds)
 
static ctre::phoenix::StatusCode Status_SetUpdateFrequencyForAll (BaseStatusSignal *const *signals, size_t count, double frequencyHz, double timeoutSeconds)
 
static double Status_GetAppliedUpdateFrequency (const char *canbus, uint32_t deviceHash, uint16_t spn)
 
static std::string Status_GetUnits (uint32_t signal)
 Gets signal units. More...
 
static ctre::phoenix::StatusCode Status_Get (const char *network, int deviceHash, uint32_t signal, bool bWaitForUpdate, double timeoutSeconds, double *outValue, double *hwtimestamp, double *swtimestamp, double *ecutimestamp)
 Get signal update. More...
 
template<typename Arr >
static ctre::phoenix::StatusCode WaitForAllImpl (const char *location, units::time::second_t timeoutSeconds, const Arr &signals)
 Implementation of the WaitForAll API. More...
 
- Protected Attributes inherited from ctre::phoenix6::BaseStatusSignal
hardware::DeviceIdentifier deviceIdentifier
 
uint16_t spn
 
std::string units
 
AllTimestamps timestamps {}
 
double baseValue = 0
 
ctre::phoenix::StatusCode error = ctre::phoenix::StatusCode::SigNotUpdated
 
std::string signalName
 
std::function< void()> _checkFirmVersFunction
 
units::time::second_t _lastTimestamp {0_s}
 
- Static Protected Attributes inherited from ctre::phoenix6::BaseStatusSignal
template<typename... Signals>
static constexpr bool is_all_status_signal_v = is_all_status_signal<Signals...>::value
 Whether all types passed in are subclasses of BaseStatusSignal. More...
 

Detailed Description

template<typename T>
class ctre::phoenix6::StatusSignal< T >

Represents a status signal with data of type T, and operations available to retrieve information about the signal.

Member Function Documentation

◆ AsSupplier()

template<typename T >
std::function< T()> ctre::phoenix6::StatusSignal< T >::AsSupplier ( )
inline

Returns a lambda that calls Refresh and GetValue on this object.

This is useful for command-based programming.

Returns
std::function<T()> that calls Refresh() and returns this value.

◆ GetAppliedUpdateFrequency()

template<typename T >
virtual units::frequency::hertz_t ctre::phoenix6::StatusSignal< T >::GetAppliedUpdateFrequency ( ) const
inlineoverridevirtual

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

Implements ctre::phoenix6::BaseStatusSignal.

◆ GetDataCopy()

template<typename T >
SignalMeasurement< T > ctre::phoenix6::StatusSignal< T >::GetDataCopy ( ) const
inline

Get a basic data-only container with this information, to be used for things such as data logging.

Note if looking for Phoenix 6 logging features, see the SignalLogger class instead.

Returns
Basic structure with all relevant information

◆ GetValue()

template<typename T >
T ctre::phoenix6::StatusSignal< T >::GetValue ( ) const
inline

Gets the cached value from this status signal.

Gets the cached value. To make sure the value is up-to-date call Refresh() or WaitForUpdate()

Returns
Cached value

◆ Refresh()

template<typename T >
StatusSignal< T > & ctre::phoenix6::StatusSignal< T >::Refresh ( bool  ReportOnError = true)
inline

Refreshes the value of this status signal.

If the user application caches this StatusSignal object instead of periodically fetching it from the hardware device, this function must be called to fetch fresh data.

This performs a non-blocking refresh operation. If you want to wait until you receive the signal, call WaitForUpdate() instead.

Parameters
ReportOnErrorWhether to report any errors to the Driver Station/stderr.
Returns
Reference to itself

◆ SetUpdateFrequency()

template<typename T >
ctre::phoenix::StatusCode ctre::phoenix6::StatusSignal< T >::SetUpdateFrequency ( units::frequency::hertz_t  frequencyHz,
units::time::second_t  timeoutSeconds = 50_ms 
)
inlineoverridevirtual

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

Implements ctre::phoenix6::BaseStatusSignal.

◆ ToString()

template<typename T >
std::string ctre::phoenix6::StatusSignal< T >::ToString ( ) const
inline

◆ WaitForUpdate()

template<typename T >
StatusSignal< T > & ctre::phoenix6::StatusSignal< T >::WaitForUpdate ( units::time::second_t  timeoutSec,
bool  ReportOnError = true 
)
inline

Waits up to timeoutSec to get the up-to-date status signal value.

This performs a blocking refresh operation. If you want to non-blocking refresh the signal, call Refresh() instead.

Parameters
timeoutSecMaximum time to wait for the signal to update
ReportOnErrorWhether to report any errors to the Driver Station/stderr.
Returns
Reference to itself

Friends And Related Function Documentation

◆ hardware::ParentDevice

template<typename T >
friend class hardware::ParentDevice
friend

◆ operator<<

template<typename T >
std::ostream & operator<< ( std::ostream &  os,
const StatusSignal< T > &  data 
)
friend

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