Skip to content

First Robotics Competion swerve drive implementation with Simulation and support for SparkMax and TalonFX swerve

Notifications You must be signed in to change notification settings

MichaelLesirge/frc-swerve-drive

Repository files navigation

FRC Swerve Project CI

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.

Simulation of PathPlanner auto

Drive Subsystem Structure

IO layer diagram

Simulated and hardware implementations with same codebase using AdvantageKit style IO layers and logging.

  1. Drive subsystem handles kinematics and odometry. Converts desired speeds to module states. Converts gyroscope data and module positions to chassis position.
  2. Modules optimize the module state and convert it to motor controller PID setpoints. Read IO data to determine module state.
  3. ModuleIOs for simulation and to interface with SparkMax or TalonFX motor controllers.

Path Following

PathPlanner path First path ran on 2024 bot

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


Driving and Dashboard

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 Driving Xbox controller labeled diagram

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

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

Credits

Swerve chassis drifting Swerve chassis on side

About

First Robotics Competion swerve drive implementation with Simulation and support for SparkMax and TalonFX swerve

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages