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

Parent class for all devices. More...

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

Inheritance diagram for ctre::phoenix6::hardware::ParentDevice:
ctre::phoenix6::hardware::traits::CommonDevice ctre::phoenix6::hardware::core::CoreCANcoder ctre::phoenix6::hardware::core::CoreCANdi ctre::phoenix6::hardware::core::CoreCANdle ctre::phoenix6::hardware::core::CoreCANrange ctre::phoenix6::hardware::core::CorePigeon2 ctre::phoenix6::hardware::core::CoreTalonFX ctre::phoenix6::hardware::core::CoreTalonFXS ctre::phoenix6::hardware::CANcoder ctre::phoenix6::hardware::CANdi ctre::phoenix6::hardware::CANdle ctre::phoenix6::hardware::CANrange ctre::phoenix6::hardware::Pigeon2 ctre::phoenix6::hardware::TalonFX ctre::phoenix6::hardware::TalonFXS

Public Member Functions

 ParentDevice (int deviceID, std::string model, CANBus canbus)
 
virtual ~ParentDevice ()=0
 
 ParentDevice (ParentDevice const &)=delete
 
ParentDeviceoperator= (ParentDevice const &)=delete
 
int GetDeviceID () const final
 
CANBus GetNetwork () const final
 
uint64_t GetDeviceHash () const final
 Gets a number unique for this device's hardware type and ID.
 
std::shared_ptr< controls::ControlRequest const > GetAppliedControl () const final
 Get the latest applied control.
 
std::shared_ptr< controls::ControlRequestGetAppliedControl () final
 Get the latest applied control.
 
bool HasResetOccurred () final
 
std::function< bool()> GetResetOccurredChecker () const final
 
bool IsConnected (units::second_t maxLatencySeconds=500_ms) final
 Returns whether the device is still connected to the robot.
 
StatusSignal< double > & GetGenericSignal (uint32_t signal, bool refresh=true)
 This is a reserved routine for internal testing.
 
ctre::phoenix::StatusCode OptimizeBusUtilization (units::frequency::hertz_t optimizedFreqHz=4_Hz, units::time::second_t timeoutSeconds=100_ms) final
 Optimizes the device's bus utilization by reducing the update frequencies of its status signals.
 
ctre::phoenix::StatusCode ResetSignalFrequencies (units::time::second_t timeoutSeconds=100_ms) final
 Resets the update frequencies of all the device's status signals to the defaults.
 
- Public Member Functions inherited from ctre::phoenix6::hardware::traits::CommonDevice
virtual ~CommonDevice ()=default
 

Static Public Member Functions

template<std::derived_from< traits::CommonDevice >... 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.
 
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll (std::span< traits::CommonDevice *const > devices)
 Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals.
 
template<std::derived_from< traits::CommonDevice >... Devices>
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll (units::frequency::hertz_t optimizedFreqHz, Devices &... devices)
 Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals.
 
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll (units::frequency::hertz_t optimizedFreqHz, std::span< traits::CommonDevice *const > devices)
 Optimizes the bus utilization of the provided devices by reducing the update frequencies of their status signals.
 
template<std::derived_from< traits::CommonDevice >... Devices>
static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll (Devices &... devices)
 Resets the update frequencies of all the devices' status signals to the defaults.
 
static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll (std::span< traits::CommonDevice *const > devices)
 Resets the update frequencies of all the devices' status signals to the defaults.
 

Protected Member Functions

virtual ctre::phoenix::StatusCode SetControlPrivate (controls::ControlRequest const &request)
 
template<typename T >
StatusSignal< T > & LookupStatusSignal (uint16_t spn, std::string signalName, bool reportOnConstruction, bool refresh)
 
template<typename T >
StatusSignal< T > & LookupStatusSignal (uint16_t spn, std::string signalName, std::function< std::map< uint16_t, std::string >()> mapFiller, bool reportOnConstruction, bool refresh)
 

Protected Attributes

DeviceIdentifier deviceIdentifier
 

Static Protected Attributes

static constexpr controls::EmptyControl _emptyControl {}
 

Detailed Description

Parent class for all devices.

Constructor & Destructor Documentation

◆ ParentDevice() [1/2]

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

◆ ~ParentDevice()

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

◆ ParentDevice() [2/2]

ctre::phoenix6::hardware::ParentDevice::ParentDevice ( ParentDevice const & )
delete

Member Function Documentation

◆ GetAppliedControl() [1/2]

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

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

Implements ctre::phoenix6::hardware::traits::CommonDevice.

◆ GetAppliedControl() [2/2]

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

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

Implements ctre::phoenix6::hardware::traits::CommonDevice.

◆ GetDeviceHash()

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

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.

Implements ctre::phoenix6::hardware::traits::CommonDevice.

◆ GetDeviceID()

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

Implements ctre::phoenix6::hardware::traits::CommonDevice.

◆ GetGenericSignal()

StatusSignal< double > & ctre::phoenix6::hardware::ParentDevice::GetGenericSignal ( uint32_t signal,
bool refresh = true )
inline

This is a reserved routine for internal testing.

Use the other get routines to retrieve signal values.

Parameters
signalSignal to get.
refreshWhether to refresh
Returns
StatusSignalValue holding value

◆ GetNetwork()

CANBus ctre::phoenix6::hardware::ParentDevice::GetNetwork ( ) const
inlinefinalvirtual
Returns
The network this device is on.

Implements ctre::phoenix6::hardware::traits::CommonDevice.

◆ GetResetOccurredChecker()

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

Implements ctre::phoenix6::hardware::traits::CommonDevice.

◆ HasResetOccurred()

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

Implements ctre::phoenix6::hardware::traits::CommonDevice.

◆ IsConnected()

bool ctre::phoenix6::hardware::ParentDevice::IsConnected ( units::second_t maxLatencySeconds = 500_ms)
inlinefinalvirtual

Returns whether the device is still connected to the robot.

This is equivalent to refreshing and checking the latency of the Version status signal.

Parameters
maxLatencySecondsThe maximum latency of the Version status signal before the device is reported as disconnected
Returns
true if the device is connected

Implements ctre::phoenix6::hardware::traits::CommonDevice.

◆ LookupStatusSignal() [1/2]

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

◆ LookupStatusSignal() [2/2]

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

◆ operator=()

ParentDevice & ctre::phoenix6::hardware::ParentDevice::operator= ( ParentDevice const & )
delete

◆ OptimizeBusUtilization()

ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::OptimizeBusUtilization ( units::frequency::hertz_t optimizedFreqHz = 4_Hz,
units::time::second_t timeoutSeconds = 100_ms )
finalvirtual

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 slowed down. 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, call ResetSignalFrequencies. Alternatively, remove this method call, redeploy the robot application, and power-cycle the device on the bus. The user can also override individual status update frequencies using BaseStatusSignal::SetUpdateFrequency.

Parameters
optimizedFreqHzThe update frequency to apply to the optimized status signals. A frequency of 0 Hz will turn off the signals. Otherwise, the minimum supported signal frequency is 4 Hz (default).
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

Implements ctre::phoenix6::hardware::traits::CommonDevice.

◆ OptimizeBusUtilizationForAll() [1/4]

template<std::derived_from< traits::CommonDevice >... 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.

This API defaults to an optimized update frequency of 4 Hz to preserve log data.

All status signals that have not been explicitly given an update frequency using BaseStatusSignal::SetUpdateFrequency will be slowed down. 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, call ResetSignalFrequenciesForAll. Alternatively, remove this method call, redeploy the robot application, and power-cycle the devices on the bus. The user can also override individual status update frequencies using BaseStatusSignal::SetUpdateFrequency.

This will wait up to 0.100 seconds (100ms) 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

◆ OptimizeBusUtilizationForAll() [2/4]

static ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::OptimizeBusUtilizationForAll ( std::span< traits::CommonDevice *const > devices)
inlinestatic

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

This API defaults to an optimized update frequency of 4 Hz to preserve log data.

All status signals that have not been explicitly given an update frequency using BaseStatusSignal::SetUpdateFrequency will be slowed down. 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, call ResetSignalFrequenciesForAll. Alternatively, remove this method call, redeploy the robot application, and power-cycle the devices on the bus. The user can also override individual status update frequencies using BaseStatusSignal::SetUpdateFrequency.

This will wait up to 0.100 seconds (100ms) for each status frame.

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

◆ OptimizeBusUtilizationForAll() [3/4]

template<std::derived_from< traits::CommonDevice >... Devices>
static ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::OptimizeBusUtilizationForAll ( units::frequency::hertz_t optimizedFreqHz,
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 slowed down. 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, call ResetSignalFrequenciesForAll. Alternatively, remove this method call, redeploy the robot application, and power-cycle the devices on the bus. The user can also override individual status update frequencies using BaseStatusSignal::SetUpdateFrequency.

This will wait up to 0.100 seconds (100ms) for each status frame.

Parameters
optimizedFreqHzThe update frequency to apply to the optimized status signals. A frequency of 0 Hz will turn off the signals. Otherwise, the minimum supported signal frequency is 4 Hz (default).
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

◆ OptimizeBusUtilizationForAll() [4/4]

static ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::OptimizeBusUtilizationForAll ( units::frequency::hertz_t optimizedFreqHz,
std::span< traits::CommonDevice *const > 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 slowed down. 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, call ResetSignalFrequenciesForAll. Alternatively, remove this method call, redeploy the robot application, and power-cycle the devices on the bus. The user can also override individual status update frequencies using BaseStatusSignal::SetUpdateFrequency.

This will wait up to 0.100 seconds (100ms) for each status frame.

Parameters
optimizedFreqHzThe update frequency to apply to the optimized status signals. A frequency of 0 Hz will turn off the signals. Otherwise, the minimum supported signal frequency is 4 Hz (default).
devicesDevices for which to optimize bus utilization, passed as a span of device pointers.
Returns
Status code of the first failed optimize call, or OK if all succeeded

◆ ResetSignalFrequencies()

ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::ResetSignalFrequencies ( units::time::second_t timeoutSeconds = 100_ms)
finalvirtual

Resets the update frequencies of all the device's status signals to the defaults.

This restores the default update frequency of all status signals, including status signals explicitly given an update frequency using BaseStatusSignal::SetUpdateFrequency and status signals optimized out using OptimizeBusUtilization.

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

Implements ctre::phoenix6::hardware::traits::CommonDevice.

◆ ResetSignalFrequenciesForAll() [1/2]

template<std::derived_from< traits::CommonDevice >... Devices>
static ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::ResetSignalFrequenciesForAll ( Devices &... devices)
inlinestatic

Resets the update frequencies of all the devices' status signals to the defaults.

This restores the default update frequency of all status signals, including status signals explicitly given an update frequency using BaseStatusSignal::SetUpdateFrequency and status signals optimized out using OptimizeBusUtilizationForAll.

This will wait up to 0.100 seconds (100ms) for each status frame.

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

◆ ResetSignalFrequenciesForAll() [2/2]

static ctre::phoenix::StatusCode ctre::phoenix6::hardware::ParentDevice::ResetSignalFrequenciesForAll ( std::span< traits::CommonDevice *const > devices)
inlinestatic

Resets the update frequencies of all the devices' status signals to the defaults.

This restores the default update frequency of all status signals, including status signals explicitly given an update frequency using BaseStatusSignal::SetUpdateFrequency and status signals optimized out using OptimizeBusUtilizationForAll.

This will wait up to 0.100 seconds (100ms) for each status frame.

Parameters
devicesDevices for which to restore default update frequencies, passed as a span of device pointers.
Returns
Status code of the first failed restore call, or OK if all succeeded

◆ SetControlPrivate()

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

Member Data Documentation

◆ _emptyControl

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

◆ deviceIdentifier

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

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