Lab Toolkit¶
Every lab uses the same tools. Read this page once, then come back when you need it.
How a lab works¶
- Build it small. Add only the code for this lab.
- Try it in the simulator. WPILib: Simulate Robot Code → Sim GUI. Enable Teleoperated and drive with an Xbox controller plugged into the laptop (or keyboard).
- Experiment. Change one knob, predict what will happen, then watch. If your prediction was wrong, that's where the learning is.
- Checkpoint. Summary, quiz, and what can go wrong in the real world.
- Commit once the lab works:
git commit -m "Lab N: ...".
Theory comes just before you need it, in a short Why section. The full math is written by students (kinematics, optimization, odometry); the hardware plumbing and the simulated robot are given to you so you can get to the interesting part quickly.
Knobs: change values without redeploying¶
Every number you'll want to play with (kP, max speed, deadband...) is a tunable. It appears on the dashboard under Tune/, and the robot reads it every loop. Change it on the dashboard and the robot uses the new value immediately, with no restart.
It's already in the project (robot/src/main/java/frc/robot/lib/Tunable.java):
package frc.robot.lib;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
* Values we can change live from the dashboard while the robot runs.
* They reset to the default on reboot, so once you find a good value,
* copy it into Constants.java.
*/
public final class Tunable {
private Tunable() {}
/** A number knob. Shows up on the dashboard as "Tune/<key>". */
public static double number(String key, double defaultValue) {
String fullKey = "Tune/" + key;
if (!SmartDashboard.containsKey(fullKey)) {
SmartDashboard.putNumber(fullKey, defaultValue);
}
return SmartDashboard.getNumber(fullKey, defaultValue);
}
/** An on/off switch. Use it to turn a feature off and see why it exists. */
public static boolean toggle(String key, boolean defaultValue) {
String fullKey = "Tune/" + key;
if (!SmartDashboard.containsKey(fullKey)) {
SmartDashboard.putBoolean(fullKey, defaultValue);
}
return SmartDashboard.getBoolean(fullKey, defaultValue);
}
}
Use it like this:
double kP = Tunable.number("Steer/kP", 0.5);
if (Tunable.toggle("Swerve/UseOptimization", true)) { ... }
Which dashboard? Use Elastic (installed with WPILib) to edit values: add a widget for each Tune/ entry. Use AdvantageScope to watch values: line graphs, the Swerve view (module arrows), and the 2D Field (robot pose). File → Connect to Simulator.
Feature toggles you'll meet¶
| Toggle | Lab | Turn it off and you'll see... |
|---|---|---|
Steer/ContinuousInput |
2 | The wheel takes the long way around (340° instead of 20°) |
Swerve/UseOptimization |
4 | Wheels spin 180° every time you reverse the stick |
Swerve/HoldAngleAtZero |
4 | Wheels snap back to 0° every time you let go of the stick |
Swerve/UseDesaturation |
5 | The robot curves the wrong way at full stick while spinning |
Drive/UseCosineScaling |
6 | The robot lurches sideways while wheels are still turning |
Drive/FieldRelative |
7 | "Stick up" means "robot's front", not "away from me" |
Gyro/Invert |
7 | Set wrong for your gyro: field-relative goes haywire as soon as the robot rotates |
Drive/UseDiscretize |
9 | The robot drifts in an arc when driving and spinning |
The simulated robot¶
robot/src/main/java/frc/robot/sim/ is a fake robot: NEO motor physics with friction, absolute encoders mounted at random angles, a gyro, and the robot's true pose on the field. Our code only reaches it through ModuleIO and GyroIO, the same interfaces the real robot uses in Lab 11.
What the simulator publishes (things a real robot can't tell you):
| Key | What it is |
|---|---|
Sim/TruePose |
Where the robot really is on the field. Compare to your odometry (Lab 8). |
Sim/TrueModuleStates |
Where each wheel really points and how fast it really rolls |
Sim/Field |
The true pose on a Field2d (Sim GUI or Elastic) |
Simulator knobs (Tune/Sim/...):
| Knob | Default | Lab | What it does |
|---|---|---|---|
Sim/Hand/ModuleIndex, Sim/Hand/SteerVolts, Sim/Hand/DriveVolts |
0 | 0, 2, 3 | A "hand" that turns or rolls one module, even while disabled |
Sim/DriveFrictionVolts, Sim/SteerFrictionVolts |
0.25, 0.15 | 1, 2, 6 | Voltage lost to friction. Raise it for a "stickier floor". |
Sim/VelocityFilterTaps |
1 | 6 | Averages the last N velocity readings, like a real NEO's lag (try 5) |
Sim/TrueWheelSizeScale |
1.0 | 8, 10 | Real wheel size vs. what Constants says (0.97 = worn tread) |
Sim/GyroDriftDegPerSec |
0 | 7, 8 | Gyro drift |
Fault injection (Tune/Sim/Faults/...): switch on a wiring or mounting mistake, then find and fix it from the sensors, like on a real robot.
| Fault | Lab | What it fakes |
|---|---|---|
Sim/Faults/<FL/FR/BL/BR>/DriveReversed |
1, 4 | Wheel rolls backward when the motor spins forward |
Sim/Faults/<FL/FR/BL/BR>/EncoderReversed |
1, 2 | Absolute encoder counts the other way |
Sim/Faults/GyroClockwisePositive |
7 | A gyro that counts clockwise as positive |
Simplifications (so you know what the simulator doesn't teach): wheels never slip, each wheel spins on its own (wheels that disagree don't fight), and the battery is always a perfect 12 V.
Safety checklist (Lab 11, the real robot)¶
Before you enable a real robot
- Robot on blocks, wheels off the ground, until the lab says otherwise.
- One person on the E-stop (space bar on the Driver Station disables; Enter is E-stop). Say "enabling" out loud before you enable.
- Low limits first (0.5 m/s, 4 V steer). Raise them only after it works.
- Hands, hair, and cables away from the wheels.
- When anything surprises you: disable first, think second.
Versions¶
This course targets the 2026 WPILib and REVLib releases (simulator, and a roboRIO in Lab 11). APIs change every season. If you're on a newer version, check the current docs before copying code. Things we know will change for 2027 (SystemCore):
- Analog inputs on SystemCore read 0–3.3 V, not 0–5 V. Check the Thrifty encoder's output voltage before wiring it to SystemCore.
- WPILib packages and some method names change (for example, motor
set()becomessetThrottle()).