CTRE Phoenix 6 C++ 24.2.0
ctre::phoenix6::hardware::ParentDevice Class Reference

Parent class for all devices. More...

#include <ctre/phoenix6/hardware/ParentDevice.hpp>

Inheritance diagram for ctre::phoenix6::hardware::ParentDevice:
ctre::phoenix6::hardware::core::CoreCANcoder ctre::phoenix6::hardware::core::CorePigeon2 ctre::phoenix6::hardware::core::CoreTalonFX ctre::phoenix6::hardware::CANcoder ctre::phoenix6::hardware::Pigeon2 ctre::phoenix6::hardware::TalonFX

Classes

struct  is_all_device
 Type trait to verify that all types passed in are subclasses of ParentDevice. More...
 

Public Member Functions

 ParentDevice (int deviceID, std::string model, std::string canbus)
 
virtual ~ParentDevice ()=default
 
int GetDeviceID () const
 
const std::string & GetNetwork () const
 
uint64_t GetDeviceHash () const
 Gets a number unique for this device's hardware type and ID. More...
 
std::shared_ptr< const controls::ControlRequestGetAppliedControl () const
 Get the latest applied control. More...
 
std::shared_ptr< controls::ControlRequestGetAppliedControl ()
 Get the latest applied control. More...
 
bool HasResetOccurred ()
 
std::function< bool()> GetResetOccurredChecker () const
 
StatusSignal< double > & GetGenericSignal (uint32_t signal)
 This is a reserved routine for internal testing. More...
 
ctre::phoenix::StatusCode OptimizeBusUtilization (units::time::second_t timeoutSeconds=50_ms)
 Optimizes the device's bus utilization by reducing the update frequencies of its status signals. More...
 

Static Public Member Functions

template<typename... Devices, typename = std::enable_if_t<is_all_device_v<Devices...>>>
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll (Devices &... devices)
 Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals. More...
 
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll (const std::vector< ParentDevice * > &devices)
 Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals. More...
 
template<size_t N>
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll (const std::array< ParentDevice *, N > &devices)
 Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals. More...
 

Protected Member Functions

virtual ctre::phoenix::StatusCode SetControlPrivate (controls::ControlRequest &request)
 
template<typename T >
StatusSignal< T > & LookupStatusSignal (uint16_t spn, std::string signalName, bool reportOnConstruction)
 
template<typename T >
StatusSignal< T > & LookupStatusSignal (uint16_t spn, uint16_t mapper_iter, std::function< std::map< int, StatusSignal< T > >()> map_filler, std::string signalName, bool reportOnConstruction)
 
template<typename T , typename U >
StatusSignal< T > LookupDimensionlessStatusSignal (uint16_t spn, std::string signalName)
 Returns a unitless version of the StatusSignal by value. More...
 

Protected Attributes

DeviceIdentifier deviceIdentifier
 

Static Protected Attributes

static controls::EmptyControl _emptyControl {}
 
template<typename... Devices>
static constexpr bool is_all_device_v = is_all_device<Devices...>::value
 Whether all types passed in are subclasses of ParentDevice. More...
 

Detailed Description

Parent class for all devices.

Constructor & Destructor Documentation

◆ ParentDevice()

ctre::phoenix6::hardware::ParentDevice::ParentDevice ( int  deviceID,
std::string  model,
std::string  canbus 
)
inline

◆ ~ParentDevice()

virtual ctre::phoenix6::hardware::ParentDevice::~ParentDevice ( )
virtualdefault

Member Function Documentation

◆ GetAppliedControl() [1/2]

std::shared_ptr< controls::ControlRequest > ctre::phoenix6::hardware::ParentDevice::GetAppliedControl ( )
inline

Get the latest applied control.

Caller can cast this to the derived class if they know its type. Otherwise, use controls::ControlRequest::GetControlInfo to get info out of it.

This returns a shared pointer to avoid becoming a dangling pointer due to parallel operations changing the underlying data. Make sure to save the shared_ptr to a variable before chaining function calls, otherwise the data may be freed early.

Returns
Latest applied control

◆ GetAppliedControl() [2/2]

std::shared_ptr< const controls::ControlRequest > ctre::phoenix6::hardware::ParentDevice::GetAppliedControl ( ) const
inline

Get the latest applied control.

Caller can cast this to the derived class if they know its type. Otherwise, use controls::ControlRequest::GetControlInfo to get info out of it.

This returns a shared pointer to avoid becoming a dangling pointer due to parallel operations changing the underlying data. Make sure to save the shared_ptr to a variable before chaining function calls, otherwise the data may be freed early.

Returns
Latest applied control

◆ GetDeviceHash()

uint64_t ctre::phoenix6::hardware::ParentDevice::GetDeviceHash ( ) const
inline

Gets a number unique for this device's hardware type and ID.

This number is not unique across networks.

This can be used to easily reference hardware devices on the same network in collections such as maps.

Returns
Hash of this device.

◆ GetDeviceID()

int ctre::phoenix6::hardware::ParentDevice::GetDeviceID ( ) const
inline
Returns
The device ID of this device [0,62].

◆ GetGenericSignal()

StatusSignal< double > & ctre::phoenix6::hardware::ParentDevice::GetGenericSignal ( uint32_t  signal)
inline

This is a reserved routine for internal testing.

Use the other get routines to retrieve signal values.

Parameters
signalSignal to get.
Returns
StatusSignalValue holding value

◆ GetNetwork()

const std::string & ctre::phoenix6::hardware::ParentDevice::GetNetwork ( ) const
inline
Returns
Name of the network this device is on.

◆ GetResetOccurredChecker()

std::function< bool()> ctre::phoenix6::hardware::ParentDevice::GetResetOccurredChecker ( ) const
inline
Returns
a function that checks for device resets.

◆ HasResetOccurred()

bool ctre::phoenix6::hardware::ParentDevice::HasResetOccurred ( )
inline
Returns
true if device has reset since the previous call of this routine.

◆ LookupDimensionlessStatusSignal()

template<typename T , typename U >
StatusSignal< T > ctre::phoenix6::hardware::ParentDevice::LookupDimensionlessStatusSignal ( uint16_t  spn,
std::string  signalName 
)
inlineprotected

Returns a unitless version of the StatusSignal by value.

Do not store the result in a reference.

◆ LookupStatusSignal() [1/2]

template<typename T >
StatusSignal< T > & ctre::phoenix6::hardware::ParentDevice::LookupStatusSignal ( uint16_t  spn,
std::string  signalName,
bool  reportOnConstruction 
)
inlineprotected

◆ LookupStatusSignal() [2/2]

template<typename T >
StatusSignal< T > & ctre::phoenix6::hardware::ParentDevice::LookupStatusSignal ( uint16_t  spn,
uint16_t  mapper_iter,
std::function< std::map< int, StatusSignal< T > >()>  map_filler,
std::string  signalName,
bool  reportOnConstruction 
)
inlineprotected

◆ OptimizeBusUtilization()

ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::OptimizeBusUtilization ( units::time::second_t  timeoutSeconds = 50_ms)

Optimizes the device's bus utilization by reducing the update frequencies of its status signals.

All status signals that have not been explicitly given an update frequency using BaseStatusSignal::SetUpdateFrequency will be disabled. Note that if other status signals in the same status frame have been given an update frequency, the update frequency will be honored for the entire frame.

This function only needs to be called once on this device in the robot program. Additionally, this method does not necessarily need to be called after setting the update frequencies of other signals.

To restore the default status update frequencies, remove this method call, redeploy the robot application, and power-cycle the devices on the bus. Alternatively, the user can override individual status update frequencies using BaseStatusSignal::SetUpdateFrequency.

Parameters
timeoutSecondsMaximum amount of time to wait for each status frame when performing the action
Returns
Status code of the first failed update frequency set call, or OK if all succeeded

◆ OptimizeBusUtilizationForAll() [1/3]

template<size_t N>
static ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::OptimizeBusUtilizationForAll ( const std::array< ParentDevice *, N > &  devices)
inlinestatic

Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals.

All status signals that have not been explicitly given an update frequency using BaseStatusSignal::SetUpdateFrequency will be disabled. Note that if other status signals in the same status frame have been given an update frequency, the update frequency will be honored for the entire frame.

This function only needs to be called once in the robot program for the provided devices. Additionally, this method does not necessarily need to be called after setting the update frequencies of other signals.

To restore the default status update frequencies, remove this method call, redeploy the robot application, and power-cycle the devices on the bus. Alternatively, the user can override individual status update frequencies using BaseStatusSignal::SetUpdateFrequency.

This will wait up to 0.050 seconds (50ms) for each status frame.

Parameters
devicesDevices for which to optimize bus utilization, passed as an array of device addresses.
Returns
Status code of the first failed optimize call, or OK if all succeeded

◆ OptimizeBusUtilizationForAll() [2/3]

static ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::OptimizeBusUtilizationForAll ( const std::vector< ParentDevice * > &  devices)
inlinestatic

Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals.

All status signals that have not been explicitly given an update frequency using BaseStatusSignal::SetUpdateFrequency will be disabled. Note that if other status signals in the same status frame have been given an update frequency, the update frequency will be honored for the entire frame.

This function only needs to be called once in the robot program for the provided devices. Additionally, this method does not necessarily need to be called after setting the update frequencies of other signals.

To restore the default status update frequencies, remove this method call, redeploy the robot application, and power-cycle the devices on the bus. Alternatively, the user can override individual status update frequencies using BaseStatusSignal::SetUpdateFrequency.

This will wait up to 0.050 seconds (50ms) for each status frame.

Parameters
devicesDevices for which to optimize bus utilization, passed as a vector or initializer list of device addresses.
Returns
Status code of the first failed optimize call, or OK if all succeeded

◆ OptimizeBusUtilizationForAll() [3/3]

template<typename... Devices, typename = std::enable_if_t<is_all_device_v<Devices...>>>
static ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::OptimizeBusUtilizationForAll ( Devices &...  devices)
inlinestatic

Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals.

All status signals that have not been explicitly given an update frequency using BaseStatusSignal::SetUpdateFrequency will be disabled. Note that if other status signals in the same status frame have been given an update frequency, the update frequency will be honored for the entire frame.

This function only needs to be called once in the robot program for the provided devices. Additionally, this method does not necessarily need to be called after setting the update frequencies of other signals.

To restore the default status update frequencies, remove this method call, redeploy the robot application, and power-cycle the devices on the bus. Alternatively, the user can override individual status update frequencies using BaseStatusSignal::SetUpdateFrequency.

This will wait up to 0.050 seconds (50ms) for each status frame.

Parameters
devicesDevices for which to optimize bus utilization, passed as a comma-separated list of device references.
Returns
Status code of the first failed optimize call, or OK if all succeeded

◆ SetControlPrivate()

virtual ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::SetControlPrivate ( controls::ControlRequest request)
protectedvirtual

Member Data Documentation

◆ _emptyControl

controls::EmptyControl ctre::phoenix6::hardware::ParentDevice::_emptyControl {}
inlinestaticprotected

◆ deviceIdentifier

DeviceIdentifier ctre::phoenix6::hardware::ParentDevice::deviceIdentifier
protected

◆ is_all_device_v

template<typename... Devices>
constexpr bool ctre::phoenix6::hardware::ParentDevice::is_all_device_v = is_all_device<Devices...>::value
staticconstexprprotected

Whether all types passed in are subclasses of ParentDevice.


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