This is a template FRC swerve drive implementation with simulation support and hardware support for both SparkMax and TalonFX motor controllers. It was developed by Team 8032 as a base for our robots, but is optionally open for use by any team. Used in our 2025 codebase.
Simulated and hardware implementations with same codebase using AdvantageKit style IO layers and logging.
- Drive subsystem handles kinematics and odometry. Converts desired speeds to module states. Converts gyroscope data and module positions to chassis position.
- Modules optimize the module state and convert it to motor controller PID setpoints. Read IO data to determine module state.
- ModuleIOs for simulation and to interface with SparkMax or TalonFX motor controllers.
Path following with PathPlannerLib.
Video shows the first run of a path on our teams 2024 robot.
This allows even new software team members to contribute effectively by creating and tuning paths without needing to write low-level robot code
We use a driving and operating Xbox controller for our robot. This template only includes driving functionality so only one is needed here.
We drive field-relative, so when the translation stick is pushed away from you, the robot goes away from you no matter which way the "front" of the robot is facing. This makes it easier for the driver to take full advantage of the capabilities of swerve, including rotating and dodging on the move.
The robot knows it field-relative direction though a gyroscope placed in its center.
driving-in-sim.mp4
Driving Control Scheme
Diagram created with my Xbox controller labeling tool
- The left stick controls robot translation (forward/backward/left/right)
- The right stick controls robot rotation. By default pushing it left or right controls angular velocity.
- When RB is held the right stick controls the heading that you want the robot to face, for example pushing the stick up will cause the robot to rotate to field-relative 0 degrees.
- By default the robot is field-relative, but Y can be pressed to toggle to robot-relative
- Menu button can be held for 3 seconds to reset odometry rotation & field-relative forward.
- D-pad is used to make small robot-relative adjustments.
- X stops the robots and turns the swerve modules to face inwards making an X shaped arrangement. This helps prevent the robot from moving when shoved.
- B cancels any movement related commands, for example canceling auto alignment to return manual control.
Vision processing is handled on OrangePi coprocessors running PhotonVision on the robot, but can also be simulated in a virtual 3D environment. We use April Tags to estimated the position of the robot for auto and alignment. We simulate vision to test camera placement options, filtering algorithms, and tag-relative auto alignment commands.
This video shows a single dummy camera in a simulated 2025 game field, with auto alignment code from that year. (Our 2025 robot had 4 cameras in reality).
Purple ghost robots represent accepted vision pose estimates, while yellow are rejected. Accepted vision estimates are combined with wheel odometry in Kalman filter.
driving-in-sim-with-vision.mp4
- AdvantageKit TalonFX Swerve Template – source for TalonFX IO layer
- Team 6328 Robot Code – drive subsystem, but mostly redone for leaning
- Team 2930 Robot Code – vision subsystem inspiration
- PhotonVision – coprocessor vision software
- WPILib – FRC robot library
- SDS – module hardware
- And of course, Seattle Academy and FRC team 8032 for giving me the wonderful opportunity to participate in a competition where I get to write code for such interesting and complex robots.