File-By-File
SwerveDrive

SwerveDrive

A very simple (and very lovely) swerve drive implementation. A swerve drive (or at least this type of swerve drive) is a type of drive system that has eight motors in total. The swerve chassis is composed of four SwerveModules, each of which contain two motors. One of these motors controls the direction the module is facing, and the other motor controls the robot's actual movement on the ground. Most simply, a swerve chassis works by rotating all of the swerve modules to the angle that corresponds with the direction it should move in and then moving in that direction.

Fields

frontRightModule

The front-right swerve module of the chassis.

frontLeftModule

The front-left swerve module of the chassis.

backRightModule

The back-right swerve module of the chassis.

backLeftModule

The back-left swerve module of the chassis.

kinematics

The RelativeSwerveDriveKinematics instance used for calculating swerve module states from a given translation.

translation

The current Translation that the chassis is moving according to.

modifier

A Function<Translation, Translation> that modifies any inputted translations before they are applied to the drive.

Methods

SwerveDrive(SwerveModule frontRightModule, SwerveModule frontLeftModule, SwerveModule backRightModule, SwerveModule backLeftModule, Controller moduleController, double turnCoefficient)

Constructs a new SwerveDrive instance.

  • frontRightModule: The front-right swerve module.
  • frontLeftModule: The front-left swerve module.
  • backRightModule: The back-right swerve module.
  • backLeftModule: The back-left swerve module.
  • moduleController: A Controller used for controlling the turn angle of each swerve module. It accepts degrees as input and as the target.
  • turnCoefficient: A coefficient used in calculating how fast the chassis should turn. Higher values result in faster turns, lower values result in slower turns. This value typically requires tuning (around 0.1 is a common starting point).

getTranslation()

Returns the last Translation that was set to the robot's drive train.

setTranslation(Translation translation)

Sets a new translation for the robot. This method applies the configured modifier to the input translation, calculates the required RelativeSwerveState using kinematics, determines the individual RelativeSwerveModuleState for each module, and then sets these states to the respective swerve modules, causing the robot to move.

getDriveModifier()

Returns the currently configured Function<Translation, Translation> that modifies the drive's translation.

setDriveModifier(Function<Translation, Translation> modifier)

Sets a new Function<Translation, Translation> to be used as the drive modifier. This allows for custom logic to be applied to translations before they are sent to the swerve modules.