Class SwerveModule

java.lang.Object
yams.core.mechanisms.swerve.SwerveModule

public class SwerveModule extends Object
Swerve Module

SwerveModule coordinates the drive motor (velocity control) and the azimuth (steer) motor (position control) that make up one corner of a swerve drivetrain. On construction it reads the absolute encoder and seeds the azimuth relative encoder so the wheel starts at the correct angle. Each periodic cycle you call setSwerveModuleState(SwerveModuleVelocity) to command both motors, and getState() / getPosition() to read back the current wheel velocity and heading.

Typical usage

In almost every case you should not instantiate SwerveModule directly. Instead, pass one SwerveModuleConfig per corner to SwerveDriveConfig and let SwerveDrive create and manage the modules internally:

SwerveDriveConfig driveConfig = new SwerveDriveConfig()
    .withSwerveModuleConfig(frontLeft, frontRight, backLeft, backRight);

SwerveDrive swerveDrive = new SwerveDrive(driveConfig);

Direct instantiation (advanced)

If you need direct access to a module for example when writing unit tests or custom characterisation routines you can construct one from a fully-configured SwerveModuleConfig:

// Assumes 'frontLeftConfig' has already been built with drive/steer motors,
// wheel radius, module location, absolute encoder offset, and telemetry name.
SwerveModule frontLeft = new SwerveModule(frontLeftConfig);

// Command a specific state (angle + speed)
SwerveModuleVelocity desiredState = new SwerveModuleVelocity(1.5, Rotation2d.fromDegrees(45));
frontLeft.setSwerveModuleState(desiredState);

// Read back current state
SwerveModuleVelocity current = frontLeft.getState();