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. Its generator writes the swerve code for you and handles the kinematics, odometry, and control.
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? Download our complete swerve drive project from the workshop code repository. All the core swerve functionality is already implemented. After downloading, change the team number in `.wpilib/wpilib_preferences.json` and import your tuner constants.
Download Swerve Project (v3.0, Commands v3)Creating a Swerve Project with Phoenix Tuner X
🚀 CTRE Swerve Project Generator
Phoenix Tuner X includes a swerve project generator that creates a complete, competition-ready drivetrain implementation. It's the recommended starting point for any swerve project.
What the Generator Creates:
- Complete CommandSwerveDrivetrain class
- Tuner constants for all swerve parameters
- Module configurations and CAN IDs
- Field-centric and robot-centric drive requests
- Simulation support for testing without hardware
- Odometry & pose estimation wired in
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
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.
Navigate to Swerve Project Generator
Click on Mechanisms in the left sidebar. This will open the configuration wizard.
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
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 Constantsand you'll be ready to override the TunerConstants.java file with your own values.
How the generated swerve code fits the v3 OpMode model
The Tuner X generator emits a CommandSwerveDrivetrain that extends CTRE's Tuner-generated TunerSwerveDrivetrain (a Phoenix 6 swerve class) plus a TunerConstants file.
CommandSwerveDrivetrain is not itself a Mechanism— it's already a class. So the workshop wraps it in a hand-written DriveMechanism that extends Mechanism, owns the drivetrain, exposes the drive commands (e.g. applyRequest(...), seedFieldCentric()), and registers telemetry + the operator perspective on Scheduler.getDefault(). The field-centric requests use the Velocity family: FieldCentric for driving, with ApplyFieldVelocity and ApplyRobotVelocity for field- and robot-relative control. This runs on Java 25 / SystemCore.
What's Next?
Up Next: Driving to a Pose
LinearPath / DriveToPose (the v3 template drives this way instead of PathPlanner).