Gray Matter LogoGray Matter Workshop

Creating a Swerve Drive Project

Using Phoenix Tuner X to Generate Swerve Code

With the swerve drive fundamentals covered, we're ready to create a complete swerve drivetrain using CTRE's Phoenix Tuner X. This powerful tool generates production-ready swerve code, handling all the complexity of kinematics, odometry, and control.

Key Concept: Phoenix Tuner X generates a complete, competition-ready swerve drivetrain with one configuration wizard.

Prerequisites Complete?

Before proceeding, make sure you've reviewed the Swerve Drive Prerequisites page, which covers:

  • Holonomic motion and swerve drive concepts
  • Module anatomy (drive motor, azimuth motor, CANcoder)
  • Coordinate systems (robot-centric vs field-centric)

📦 Quick Start: Download Baseline Code

Need a baseline to get started? Download our complete swerve drive project from the workshop code repository. This serves as an excellent starting point with all the core swerve functionality already implemented. After downloading just change the Team Number in the `.wpilib/wpilib_preferences.json` and import tuner constants.

Download Swerve Project (v1.0)

Creating a Swerve Project with Phoenix Tuner X

🚀 CTRE Swerve Project Generator

CTRE provides a comprehensive swerve drive project generator in Phoenix Tuner X that creates a complete, competition-ready swerve drivetrain implementation. This is the recommended starting point for all swerve projects.

What the Generator Creates:

  • Complete CommandSwerveDrivetrain subsystem
  • Tuner constants for all swerve parameters
  • Module configurations and CAN IDs
  • Field-centric and robot-centric drive commands
  • Simulation support for testing without hardware
  • PathPlanner integration for autonomous

Required Information:

  • CAN IDs for all drive motors, steer motors, encoders
  • CANivore name (if using CANivore)
  • Wheel diameter and gear ratios
  • Module positions (wheelbase and trackwidth)

Step-by-Step Setup Process

1

Open Phoenix Tuner X

Launch Phoenix Tuner X and connect to your robot or CANivore. Ensure all swerve motors and encoders are visible and have unique CAN IDs.

2

Navigate to Swerve Project Generator

Click on Mechanisms in the left sidebar. This will open the configuration wizard.

3

Configure Robot Parameters

Enter your robot's physical parameters:

  • Wheelbase: Front-to-back distance between modules (meters)
  • Trackwidth: Side-to-side distance between modules (meters)
  • Wheel Diameter: Diameter of drive wheels (inches)
  • Drive Gear Ratio: Motor rotations per wheel rotation
4

Follow the Steps to Generate and Export

Click New Project and follow the steps in Tuner X to set up and test your swerve drivetrain. Once you finish, click Generate Tuner Constants and you'll be ready to override the TunerConstants.java file with your own values.

CTRE Swerve Project Generator Documentation

What's Next?

Up Next: PathPlanner

Now that your swerve project is generated, the next step is autonomous path following with PathPlanner.