CTRE Phoenix 6 C++ 25.1.0
Loading...
Searching...
No Matches
ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename > Class Template Reference

Swerve Module class that encapsulates a swerve module powered by CTR Electronics devices. More...

#include <ctre/phoenix6/swerve/SwerveModule.hpp>

Public Types

using ModuleRequest = impl::SwerveModuleImpl::ModuleRequest
 Contains everything the swerve module needs to apply a request.
 

Public Member Functions

template<typename DriveMotorConfigsT , typename SteerMotorConfigsT , typename EncoderConfigsT , typename = std::enable_if_t<std::is_base_of_v<configs::ParentConfiguration, DriveMotorConfigsT>>, typename = std::enable_if_t<std::is_base_of_v<configs::ParentConfiguration, SteerMotorConfigsT>>, typename = std::enable_if_t<std::is_base_of_v<configs::ParentConfiguration, EncoderConfigsT>>>
 SwerveModule (SwerveModuleConstants< DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT > const &constants, std::string_view canbusName, impl::SwerveModuleImpl &module)
 Construct a SwerveModule with the specified constants.
 
virtual ~SwerveModule ()=default
 
virtual void Apply (ModuleRequest const &moduleRequest)
 Applies the desired ModuleRequest to this module.
 
template<typename DriveReq , typename SteerReq >
void Apply (DriveReq &&driveRequest, SteerReq &&steerRequest)
 Controls this module using the specified drive and steer control requests.
 
SwerveModulePosition GetPosition (bool refresh)
 Gets the state of this module and passes it back as a SwerveModulePosition object with latency compensated values.
 
SwerveModulePosition GetCachedPosition () const
 Gets the last cached swerve module position.
 
SwerveModuleState GetCurrentState () const
 Get the current state of the module.
 
SwerveModuleState GetTargetState () const
 Get the target state of the module.
 
virtual void ResetPosition ()
 Resets this module's drive motor position to 0 rotations.
 
ClosedLoopOutputType GetDriveClosedLoopOutputType () const
 Gets the closed-loop output type to use for the drive motor.
 
ClosedLoopOutputType GetSteerClosedLoopOutputType () const
 Gets the closed-loop output type to use for the steer motor.
 
DriveMotorT & GetDriveMotor ()
 Gets this module's Drive Motor reference.
 
SteerMotorT & GetSteerMotor ()
 Gets this module's Steer Motor reference.
 
EncoderT & GetEncoder ()
 Gets this module's azimuth encoder reference.
 

Protected Attributes

impl::SwerveModuleImpl_module
 The underlying swerve module instance.
 

Static Protected Attributes

static constexpr int kNumConfigAttempts = 2
 Number of times to attempt config applies.
 

Detailed Description

template<typename DriveMotorT, typename SteerMotorT, typename EncoderT, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
class ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >

Swerve Module class that encapsulates a swerve module powered by CTR Electronics devices.

This class handles the hardware devices and configures them for swerve module operation using the Phoenix 6 API.

This class constructs hardware devices internally, so the user only specifies the constants (IDs, PID gains, gear ratios, etc). Getters for these hardware devices are available.

Member Typedef Documentation

◆ ModuleRequest

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
using ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::ModuleRequest = impl::SwerveModuleImpl::ModuleRequest

Contains everything the swerve module needs to apply a request.

Constructor & Destructor Documentation

◆ SwerveModule()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
template<typename DriveMotorConfigsT , typename SteerMotorConfigsT , typename EncoderConfigsT , typename = std::enable_if_t<std::is_base_of_v<configs::ParentConfiguration, DriveMotorConfigsT>>, typename = std::enable_if_t<std::is_base_of_v<configs::ParentConfiguration, SteerMotorConfigsT>>, typename = std::enable_if_t<std::is_base_of_v<configs::ParentConfiguration, EncoderConfigsT>>>
ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::SwerveModule ( SwerveModuleConstants< DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT > const & constants,
std::string_view canbusName,
impl::SwerveModuleImpl & module )
inline

Construct a SwerveModule with the specified constants.

Parameters
constantsConstants used to construct the module
canbusNameThe name of the CAN bus this module is on
moduleThe impl::SwerveModuleImpl to use

◆ ~SwerveModule()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
virtual ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::~SwerveModule ( )
virtualdefault

Member Function Documentation

◆ Apply() [1/2]

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
template<typename DriveReq , typename SteerReq >
void ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::Apply ( DriveReq && driveRequest,
SteerReq && steerRequest )
inline

Controls this module using the specified drive and steer control requests.

This is intended only to be used for characterization of the robot; do not use this for normal use.

Parameters
driveRequestThe control request to apply to the drive motor
steerRequestThe control request to apply to the steer motor

◆ Apply() [2/2]

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
virtual void ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::Apply ( ModuleRequest const & moduleRequest)
inlinevirtual

Applies the desired ModuleRequest to this module.

Parameters
moduleRequestThe request to apply to this module

◆ GetCachedPosition()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
SwerveModulePosition ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::GetCachedPosition ( ) const
inline

Gets the last cached swerve module position.

This differs from GetPosition in that it will not perform any latency compensation or refresh the signals.

Returns
Last cached SwerveModulePosition

◆ GetCurrentState()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
SwerveModuleState ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::GetCurrentState ( ) const
inline

Get the current state of the module.

This is typically used for telemetry, as the SwerveModulePosition is used for odometry.

Returns
Current state of the module

◆ GetDriveClosedLoopOutputType()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
ClosedLoopOutputType ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::GetDriveClosedLoopOutputType ( ) const
inline

Gets the closed-loop output type to use for the drive motor.

Returns
Drive motor closed-loop output type

◆ GetDriveMotor()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
DriveMotorT & ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::GetDriveMotor ( )
inline

Gets this module's Drive Motor reference.

This should be used only to access signals and change configurations that the swerve drivetrain does not configure itself.

Returns
This module's Drive Motor reference

◆ GetEncoder()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
EncoderT & ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::GetEncoder ( )
inline

Gets this module's azimuth encoder reference.

This should be used only to access signals and change configurations that the swerve drivetrain does not configure itself.

Returns
This module's azimuth encoder reference

◆ GetPosition()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
SwerveModulePosition ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::GetPosition ( bool refresh)
inline

Gets the state of this module and passes it back as a SwerveModulePosition object with latency compensated values.

This function is blocking when it performs a refresh.

Parameters
refreshTrue if the signals should be refreshed
Returns
SwerveModulePosition containing this module's state.

◆ GetSteerClosedLoopOutputType()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
ClosedLoopOutputType ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::GetSteerClosedLoopOutputType ( ) const
inline

Gets the closed-loop output type to use for the steer motor.

Returns
Steer motor closed-loop output type

◆ GetSteerMotor()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
SteerMotorT & ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::GetSteerMotor ( )
inline

Gets this module's Steer Motor reference.

This should be used only to access signals and change configurations that the swerve drivetrain does not configure itself.

Returns
This module's Steer Motor reference

◆ GetTargetState()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
SwerveModuleState ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::GetTargetState ( ) const
inline

Get the target state of the module.

This is typically used for telemetry.

Returns
Target state of the module

◆ ResetPosition()

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
virtual void ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::ResetPosition ( )
inlinevirtual

Resets this module's drive motor position to 0 rotations.

Member Data Documentation

◆ _module

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
impl::SwerveModuleImpl* ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::_module
protected

The underlying swerve module instance.

◆ kNumConfigAttempts

template<typename DriveMotorT , typename SteerMotorT , typename EncoderT , typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>, typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>>
int ctre::phoenix6::swerve::SwerveModule< DriveMotorT, SteerMotorT, EncoderT, typename, typename, typename >::kNumConfigAttempts = 2
staticconstexprprotected

Number of times to attempt config applies.


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