Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 23.2.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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...
 
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
 
ctre::phoenix::StatusCode SetUpdateFrequency (units::frequency::hertz_t frequencyHz, units::time::second_t timeoutSeconds=50_ms)
 Sets the rate at which the device will publish this signal. More...
 
const std::string & GetUnits () const
 Gets the units for this signal. 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 GetError () const
 Get the error code from when we last received this signal. 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
static ctre::phoenix::StatusCode WaitForAll (units::time::second_t timeoutSeconds, std::initializer_list< BaseStatusSignal * > 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<typename U , typename U_PER_SEC >
static U GetLatencyCompensatedValue (StatusSignal< U > &signal, StatusSignal< U_PER_SEC > &signalSlope)
 
static ctre::phoenix::StatusCode IsAllGood (std::initializer_list< BaseStatusSignal * > signals)
 Checks if all signals have an OK error code. More...
 
- Protected Member Functions inherited from ctre::phoenix6::BaseStatusSignal
void CopyFrom (const BaseStatusSignal &other)
 
 BaseStatusSignal (hardware::DeviceIdentifier deviceIdentifier, uint16_t spn, std::string signalName)
 
 BaseStatusSignal (ctre::phoenix::StatusCode error)
 
ctre::phoenix::StatusCode SetUpdateFrequency (const char *canbus, uint32_t deviceHash, uint16_t spn, units::frequency::hertz_t frequencyHz, units::time::second_t timeoutSeconds)
 
- Static Protected Member Functions inherited from ctre::phoenix6::BaseStatusSignal
static ctre::phoenix::StatusCode Status_WaitForAll (std::initializer_list< BaseStatusSignal * > signals, const char *network, units::time::second_t timeoutSeconds)
 Wait for multiple signals to arrive. More...
 
static ctre::phoenix::StatusCode Status_WaitForAll (const std::vector< BaseStatusSignal * > &signals, const char *network, units::time::second_t timeoutSeconds)
 Wait for multiple signals to arrive. More...
 
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, units::time::second_t timeoutSeconds, double *outValue, double *hwtimestamp, double *swtimestamp, double *ecutimestamp, int32_t *timestampType)
 Get signal update. More...
 
- Protected Attributes inherited from ctre::phoenix6::BaseStatusSignal
hardware::DeviceIdentifier deviceIdentifier
 
uint16_t spn
 
std::string units
 
AllTimestamps timestamps {}
 
int timestampType
 
double baseValue = 0
 
ctre::phoenix::StatusCode error = ctre::phoenix::StatusCode::SigNotUpdated
 
std::string signalName
 

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.

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

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

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