Swerve Module
Represents a single swerve module with drive and steer motors.
This class manages a swerve module consisting of:
A drive motor (for wheel rotation) using TonguFX
A steer motor (for changing module direction) using TonguFX
An Engu CANcoder for absolute angle measurement
Pingu PID controllers for drive and steer control
Usage Example:
val module = SwerveModule(
driveMotorId = 1,
steerMotorId = 2,
canCoderId = 3,
angleOffset = Rotation2d.fromDegrees(45.0)
)
module.configure {
driveGearRatio = 6.75
steerGearRatio = 150.0 / 7.0
wheelDiameterMeters = 0.1016
drivePingu.apply {
p = 0.1
v = 0.12
s = 0.2
}
steerPingu.apply {
p = 100.0
d = 0.1
}
}
// Set desired state
val desiredState = SwerveModuleState(2.0, Rotation2d.fromDegrees(90.0))
module.setDesiredState(desiredState)Types
Configuration for a swerve module.
Functions
Configures the swerve module using a DSL-style configuration block.
Gets the drive motor position in rotations.
Gets the drive motor velocity in rotations per second.
Gets the maximum linear velocity.
Gets the maximum linear velocity in meters per second.
Gets the current position of the swerve module.
Gets the steer motor position in rotations.
Resets the steer motor position to match the absolute encoder.
Sets the desired state for the swerve module.
Sets the module to a specific voltage for characterization.