Swerve Overview#
Important
Swerve functionality is only available for FRC users.
New in 2024 is a high performance swerve framework. This framework 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) andSwerveDrivetrainConstants.Integrates cleanly into WPILib commandbased framework via
CommandSwerveDrivetrain(Java).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) insimulationPeriodic()(Java).
Performance
Odometry is updated synchronous with the motor controllers.
Odometry is received as fast as possible via a separate thread.
Combine with Phoenix Pro (optional) and a CANivore (optional) with timesync for even more 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
SwerveModuleConstantsfor each module on the robot.
SwerveModuleConstants(Java)Represents the characteristics for a given module.
SwerveDrivetrain(Java)Created via
SwerveDrivetrainConstantsand a variable number ofSwerveModuleConstants, this is used to control the swerve drivetrain.
Usage of these classes is available in the following articles in this section.