Skip to content
learnFRC.org
programmingmodule110 min

Stage 04 - Swerve Drivetrain & Autonomous Routines

Swerve kinematics, generating Tuner X swerve code, calibrating CANcoder offsets, and building multi-piece autonomous routines with PathPlanner.

What you will learn

  • Configure swerve module hardware parameters and measure zero-heading CANcoder offsets.
  • Implement forward and inverse kinematics using WPILib SwerveDriveKinematics.
  • Desaturate wheel speeds and manage field-oriented driver controls with Pigeon 2 IMU heading.
  • Design and follow multi-piece autonomous trajectories using PathPlannerLib.

Prerequisites:Stage 03 - Mechanism Programming & Simulation

Swerve drivetrains give FRC robots omnidirectional holonomic agility: the chassis can translate in any direction across the field while spinning independently.

Stage 4 teaches the mathematics of swerve kinematics, generating a calibrated drivetrain project in Phoenix Tuner X, and building multi-piece autonomous routines using PathPlanner.

A modern swerve drivebase pipeline consists of four computational steps every 20ms:

[ Driver Joystick Inputs ] --> [ Field-Oriented Transformation ] --> [ SwerveDriveKinematics ] --> [ 4x Module Control Loops ]
▲ ▲
[ Pigeon 2.0 IMU ] [ 1 kHz Talon FX ]
  1. Driver Input: Commanded forward (vxv_x), strafe (vyv_y), and rotation (ω\omega) velocities.
  2. Field-Orientation: Vector rotation based on IMU yaw heading.
  3. Kinematics Inverse Transform: Computes target speed and azimuth steering angle for each module.
  4. Onboard Closed-Loop Execution: Steer motor holds angle via CANcoder feedback; drive motor holds velocity via kV/kSkV/kS feedforward.
Swerve Code Template

For reference swerve implementations and tuning constants, consult the team drivebase examples.

Verified Sources & Standards

Evergreen Standard Verified: Sep 25, 2026

Lessons