Class SwerveModule
public class SwerveModule extends Object
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.
-
Constructor Summary
Constructors Constructor Description SwerveModule(SwerveModuleConstants constants, String canbusName, boolean supportsPro)
Construct a SwerveModule with the specified constants. -
Method Summary
Modifier and Type Method Description void
apply(SwerveModuleState state, boolean isOpenLoop)
Applies the desired SwerveModuleState to this module.SwerveModulePosition
getCachedPosition()
Gets the last cached swerve module position.CANcoder
getCANcoder()
Gets this module's CANcoder reference.SwerveModuleState
getCurrentState()
Get the current state of the module.TalonFX
getDriveMotor()
Gets this module's Drive Motor TalonFX reference.SwerveModulePosition
getPosition(boolean refresh)
Gets the state of this module and passes it back as a SwerveModulePosition object with latency compensated values.TalonFX
getSteerMotor()
Gets this module's Steer Motor TalonFX reference.void
resetPosition()
Resets this module's drive motor position to 0 rotations.
-
Constructor Details
-
SwerveModule
Construct a SwerveModule with the specified constants.- Parameters:
constants
- Constants used to construct the modulecanbusName
- The name of the CAN bus this module is onsupportsPro
- True if the devices are licensed to use Pro features
-
-
Method Details
-
getPosition
Gets the state of this module and passes it back as a SwerveModulePosition object with latency compensated values.- Parameters:
refresh
- True if the signals should be refreshed- Returns:
- SwerveModulePosition containing this module's state.
-
apply
Applies the desired SwerveModuleState to this module.- Parameters:
state
- Speed and direction the module should targetisOpenLoop
- True if this should use open-loop control.
-
getCachedPosition
Gets the last cached swerve module position. This differs fromgetPosition(boolean)
in that it will not perform any latency compensation or refresh the signals.- Returns:
- Last cached SwerveModulePosition
-
getCurrentState
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
-
resetPosition
Resets this module's drive motor position to 0 rotations. -
getDriveMotor
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
-
getSteerMotor
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
-
getCANcoder
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
-