Swerve Overview#

Important

Swerve functionality is only available for FRC users and is limited to Java at this time.

New in 2024 is a high performance swerve API. This API simplifies the boilerplate necessary for swerve and maximizes performance.

This section focuses on utilizing the Swerve API and configuring it correctly. Tuner X supports a swerve project creator that greatly simplifies this process and removes common error cases.

  • Small API surface, easily debuggable

    • Build robot characteristics using SwerveModuleConstants (Java) and SwerveDrivetrainConstants (Java).

    • Integrates cleanly into WPILib command-based framework using CommandSwerveDrivetrain (from our examples or Tuner X).

    • Telemetrize directly in the odometry loop using the registerTelemetry() (Java) lambda.

    • Supports handling the swerve state via SwerveRequest (Java).

      • Supports robot-centric, field-centric and field-centric facing angle.

      • Supports common scenarios such as X mode (point all modules toward the center of the robot).

  • Simulation

    • Swerve simulation focuses on usability, and as such isn’t perfectly accurate to a real robot.

    • Simply call updateSimState (Java) in simulationPeriodic() (Java).

  • Performance

    • Odometry is updated synchronously with the motor controllers.

    • Odometry is received as fast as possible using a separate thread.

    • Combine with Phoenix Pro and a CANivore with timesync for improved performance.

Note

Simulation boilerplate is automatically handled when generating a robot project using Tuner X.

Hardware Requirements#

Utilizing the swerve API requires that the robot drivetrain is composed of supported Phoenix 6 devices. At a minimum, these requirements are:

  • 8 TalonFX motor controllers (4 steer, 4 drive)

  • 4 CANcoders

  • 1 Pigeon 2.0

Overview on the API#

Simple usage of the API is comprised of 4 core classes:

  • SwerveDrivetrainConstants (Java)

    • This class handles characteristics of the robot that are not module specific. e.g. CAN bus, Pigeon 2 ID, whether FD is enabled or not.

  • SwerveModuleConstantsFactory (Java)

    • Factory class that is used to instantiate SwerveModuleConstants for each module on the robot.

  • SwerveModuleConstants (Java)

    • Represents the characteristics for a given module.

  • SwerveDrivetrain (Java)

    • Created using SwerveDrivetrainConstants and a SwerveModuleConstants for each module, this is used to control the swerve drivetrain.

Usage of these classes is available in the following articles in this section.