Learning Swerve From Scratch

Welcome! This site is the training course for our FRC team's swerve drive project.

We are building a swerve drive from scratch to learn how it works. This is a teaching project, not competition code. Once we understand the system, we will switch to an established library (YAGSL) for competition.

Hands-on, in the simulator

Every lab runs in the WPILib simulator against a simulated swerve robot, so you can experiment without blocks, batteries, or broken parts. We start with code that only reads sensors, then add one piece at a time. Each lab gives you knobs (values you can change live from the dashboard), toggles (features you can switch off), and faults (simulated wiring mistakes) so you can see what each part does by breaking it on purpose. Lab 11 moves the same code to the real robot.

How a lab works

  1. Why. A short explanation, just before you need it.
  2. Build it small. Add only this lab's code. Hardware plumbing and the simulated robot are given; the core math (optimizer, kinematics, field-relative, odometry) is written by students and unit-tested against WPILib.
  3. Try it in the simulator, watching the robot in AdvantageScope.
  4. Experiment. Change one knob, predict, watch, explain.
  5. Checkpoint: summary, quiz, and what can go wrong in the real world. Then commit.

Start with the Lab Toolkit: it explains the knobs, the simulated robot, the dashboards, and the real-robot safety checklist.

Labs

Lab What you do You learn
0 Run the simulator, turn the wheels with the sim "hand", find every sensor Project structure, sensor units, hardware-abstraction (ModuleIO)
1 Drive one module from the joystick; fix injected wiring faults Inversions, gear ratios, rotations → meters/radians
2 Steer one module to a dashboard angle PID tuning, continuous input
3 Point all four wheels at any angle Encoder offsets (the #1 swerve bug)
4 First drive: the robot moves on the field, translation only Module states, optimization, deadband
5 Drive and spin at the same time Inverse kinematics, desaturation
6 Wheels hit the speed you ask for, even on a sticky floor Feedforward (kS, kV) + PID, cosine scaling, velocity lag
7 "Stick up" = away from the driver Gyro sign (with a backwards gyro fault), field-relative math
8 Drive a square; compare odometry to the true pose Forward kinematics, odometry, worn wheels, drift
9 SysId; drive straight while spinning Characterization, discretization
10 Drive to a pose by itself PID to pose; what PathPlanner/Choreo/vision add
11 The real robot: same code, real hardware ModuleIOSparkMax, re-measuring, safe bring-up
12 Same robot on YAGSL Map our code to YAGSL; debugging guide

Starting a session

When you open a new work session, say which lab you're on. Recap what the previous lab covered (check the git log and the code), then continue from there.