CTRE Phoenix 6 C++ 24.50.0-alpha-2
ctre::phoenix6::swerve::impl::SwerveModuleImpl Class Reference

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

#include <ctre/phoenix6/swerve/impl/SwerveModuleImpl.hpp>

Public Types

enum class  SteerRequestType { MotionMagicExpo = 0 , Position = 1 }
 All possible control requests for the module steer motor. More...
 
enum class  DriveRequestType { OpenLoopVoltage = 0 , Velocity = 1 }
 All possible control requests for the module drive motor. More...
 

Public Member Functions

 SwerveModuleImpl (SwerveModuleConstants const &constants, CANBus canbus)
 Construct a SwerveModuleImpl with the specified constants. More...
 
void Apply (SwerveModuleState const &state, DriveRequestType driveRequestType, SteerRequestType steerRequestType=SteerRequestType::MotionMagicExpo)
 Applies the desired SwerveModuleState to this module. More...
 
template<typename DriveReq , typename SteerReq >
void Apply (DriveReq &&driveRequest, SteerReq &&steerRequest)
 Controls this module using the specified drive and steer control requests. More...
 
ctre::phoenix::StatusCode ConfigNeutralMode (signals::NeutralModeValue neutralMode, units::second_t timeoutSeconds=0.100_s)
 Configures the neutral mode to use for the module's drive motor. More...
 
SwerveModulePosition GetPosition (bool refresh)
 Gets the state of this module and passes it back as a SwerveModulePosition object with latency compensated values. More...
 
SwerveModulePosition GetCachedPosition () const
 Gets the last cached swerve module position. More...
 
SwerveModuleState GetCurrentState () const
 Get the current state of the module. More...
 
SwerveModuleState GetTargetState () const
 Get the target state of the module. More...
 
void ResetPosition ()
 Resets this module's drive motor position to 0 rotations. More...
 
hardware::core::CoreTalonFXGetDriveMotor ()
 Gets this module's Drive Motor TalonFX reference. More...
 
hardware::core::CoreTalonFXGetSteerMotor ()
 Gets this module's Steer Motor TalonFX reference. More...
 
hardware::core::CoreCANcoderGetCANcoder ()
 Gets this module's CANcoder reference. More...
 

Friends

class SwerveDrivetrainImpl
 

Detailed Description

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

This class handles the hardware devices but does not configure them for swerve module operation using the Phoenix 6 API. Users should create a high-level SwerveModule instead of using this directly.

Member Enumeration Documentation

◆ DriveRequestType

All possible control requests for the module drive motor.

Enumerator
OpenLoopVoltage 

Control the drive motor using an open-loop voltage request.

Velocity 

Control the drive motor using a velocity closed-loop request.

The control output type is determined by SwerveModuleConstants::DriveMotorClosedLoopOutput.

◆ SteerRequestType

All possible control requests for the module steer motor.

Enumerator
MotionMagicExpo 

Control the drive motor using a Motion MagicĀ® Expo request.

The control output type is determined by SwerveModuleConstants::SteerMotorClosedLoopOutput.

Position 

Control the drive motor using an unprofiled position request.

The control output type is determined by SwerveModuleConstants::SteerMotorClosedLoopOutput.

Constructor & Destructor Documentation

◆ SwerveModuleImpl()

ctre::phoenix6::swerve::impl::SwerveModuleImpl::SwerveModuleImpl ( SwerveModuleConstants const &  constants,
CANBus  canbus 
)

Construct a SwerveModuleImpl with the specified constants.

Parameters
constantsConstants used to construct the module
canbusThe CAN bus this module is on

Member Function Documentation

◆ Apply() [1/2]

template<typename DriveReq , typename SteerReq >
void ctre::phoenix6::swerve::impl::SwerveModuleImpl::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]

void ctre::phoenix6::swerve::impl::SwerveModuleImpl::Apply ( SwerveModuleState const &  state,
DriveRequestType  driveRequestType,
SteerRequestType  steerRequestType = SteerRequestType::MotionMagicExpo 
)

Applies the desired SwerveModuleState to this module.

Parameters
stateSpeed and direction the module should target
driveRequestTypeThe DriveRequestType to apply
steerRequestTypeThe SteerRequestType to apply; defaults to SteerRequestType::MotionMagicExpo

◆ ConfigNeutralMode()

ctre::phoenix::StatusCode ctre::phoenix6::swerve::impl::SwerveModuleImpl::ConfigNeutralMode ( signals::NeutralModeValue  neutralMode,
units::second_t  timeoutSeconds = 0.100_s 
)

Configures the neutral mode to use for the module's drive motor.

Parameters
neutralModeThe drive motor neutral mode
timeoutSecondsMaximum amount of time to wait when performing configuration
Returns
Status code response of the request

◆ GetCachedPosition()

SwerveModulePosition ctre::phoenix6::swerve::impl::SwerveModuleImpl::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

◆ GetCANcoder()

hardware::core::CoreCANcoder & ctre::phoenix6::swerve::impl::SwerveModuleImpl::GetCANcoder ( )
inline

Gets this module's CANcoder reference.

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

Returns
This module's CANcoder reference

◆ GetCurrentState()

SwerveModuleState ctre::phoenix6::swerve::impl::SwerveModuleImpl::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

◆ GetDriveMotor()

hardware::core::CoreTalonFX & ctre::phoenix6::swerve::impl::SwerveModuleImpl::GetDriveMotor ( )
inline

Gets this module's Drive Motor TalonFX 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

◆ GetPosition()

SwerveModulePosition ctre::phoenix6::swerve::impl::SwerveModuleImpl::GetPosition ( bool  refresh)

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

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

◆ GetSteerMotor()

hardware::core::CoreTalonFX & ctre::phoenix6::swerve::impl::SwerveModuleImpl::GetSteerMotor ( )
inline

Gets this module's Steer Motor TalonFX 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()

SwerveModuleState ctre::phoenix6::swerve::impl::SwerveModuleImpl::GetTargetState ( ) const
inline

Get the target state of the module.

This is typically used for telemetry.

Returns
Target state of the module

◆ ResetPosition()

void ctre::phoenix6::swerve::impl::SwerveModuleImpl::ResetPosition ( )
inline

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

Friends And Related Function Documentation

◆ SwerveDrivetrainImpl

friend class SwerveDrivetrainImpl
friend

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