๐Ÿ’ป Programming ยท EZ Template ยท Intermediate

PID Tuning with EZ Template

The built-in PID tuner lets you dial in drive, turn, and swing constants live on the robot โ€” no code re-upload between tests. This guide walks through the full tuning sequence from scratch.

What this is: PID stands for Proportionalโ€“Integralโ€“Derivative. It's the math that makes the robot reach a target distance or angle reliably. EZ Template calculates it for you โ€” you just tune three numbers per motion type until the robot behaves the way you want.
๐ŸŽฎ Interactive PID Response Simulator

Drag the sliders to see how each constant affects robot motion. The cyan line is your target. The colored line is where the robot actually goes.

โšก PID Response VisualizerAdjust sliders โ†“
0.30
How hard it pushes toward target
0.20
Braking force, reduces oscillation
0.00
Corrects persistent error (rarely needed)
Adjust kP to start tuning. Watch for overshoot and oscillation.
๐Ÿ”ง Setting Up the PID Tuner in Code

EZ Template has a built-in interactive tuner โ€” you use controller buttons to adjust constants live and see the result immediately. Add this to your opcontrol():

void opcontrol() {
  chassis.drive_brake_set(MOTOR_BRAKE_COAST);
  while (true) {
    // โ”€โ”€ PID Tuner (only runs when NOT at a competition) โ”€โ”€
    if (!pros::competition::is_connected()) {
      // X button: toggle tuner on/off
      if (master.get_digital_new_press(DIGITAL_X))
        chassis.pid_tuner_toggle();
      // B button: run the autonomous you want to tune
      if (master.get_digital_new_press(DIGITAL_B))
        autonomous();
      // This updates the tuner display every loop
      chassis.pid_tuner_iterate();
    }
    chassis.opcontrol_tank();
    pros::delay(ez::util::DELAY_TIME);
  }
}
๐ŸŽฏ Tuning Sequence โ€” Drive โ†’ Turn โ†’ Swing
Always tune in this order: Drive PID first, then Turn PID, then Swing. Each depends on the previous being stable. Skipping ahead means you're tuning on a shaky foundation.
1
Set the test auton โ€” in autons.cpp write a simple test routine:
chassis.pid_drive_set(24_in, 110); chassis.pid_wait();
Register it in the selector as "Drive Test". This is what you run with the B button during tuning.
2
Enable the tuner (X button) โ€” the Brain screen shows current kP/kD/kI values. Use the controller directional buttons: Up/Down = select which constant, Left/Right = decrease/increase the value. The tuner increments by 0.1 by default.
3
Tune kP first (kI and kD = 0) โ€” run B, watch the robot. Increase kP until the robot overshoots the target. Back it off by ~20%. That's your starting kP. Typical 4-motor tank: kP = 0.35โ€“0.6.
4
Add kD to kill the oscillation โ€” after setting kP, increase kD until oscillation stops. kD fights rapid changes in error. Too much kD = sluggish approach. Typical kD = 2โ€“5ร— kP.
5
Test at multiple distances โ€” run 12", 24", 48". Good constants work at all distances. If 48" is fine but 12" overshoots: kP too high. If 12" is fine but 48" doesn't reach: kP too low.
6
Repeat for turns โ€” change the test to chassis.pid_turn_set(90_deg, 110); chassis.pid_wait(); Select "Turn PID" in the tuner. Tune kP then kD the same way. Turn constants are usually different from drive constants.
7
Copy constants to your auton file โ€” after tuning, write down the values. Add them at the top of your auton initialization function.
chassis.pid_drive_constants_set(0.45, 0, 5.0);
chassis.pid_turn_constants_set(3.0, 0.003, 20.0);
๐Ÿ“Š What Each Constant Does โ€” Plain Language
ConstantMetaphorToo LowToo HighTypical Starting Value
kP (drive)Gas pedal forceRobot creeps, never quite reaches targetRobot overshoots and bounces back0.35โ€“0.60
kD (drive)Brake force near targetOscillates past target repeatedlySluggish, approaches target very slowly at the endkP ร— 3โ€“5
kI (drive)Persistent error correctionN/A (zero is fine)Robot winds up and jerks at start0 (rarely needed)
kP (turn)Rotation forceUnder-turns consistentlyOver-turns, spins back2.0โ€“4.0
kD (turn)Rotation brakeWobbles around the target headingTurns too slowly at the endkP ร— 5โ€“10
Don't add kI yet. Almost every VRC autonomous works without kI. It causes instability more often than it helps. Only add it if your robot consistently undershoots the same amount on a flat, consistent surface, and kP can't fix it without causing overshoot.
๐Ÿ“–
OFFICIAL EZ TEMPLATE โ€” PID TUNER REFERENCE
Full PID Tuner API, tuning constants reference, and the PID tutorial for subsystems like lifts and arms
๐ŸŽฏ PID Tuner Docs โ†’ ๐Ÿ“– PID Tutorial โ†’ โš™ Tuning Constants โ†’
⚙ STEM Highlight Mathematics: Proportional-Integral-Derivative Control Theory
PID tuning applies control theory: the proportional term (kP) drives toward the target; the derivative term (kD) opposes the rate of change to prevent overshoot; the integral term (kI) eliminates steady-state error. Oscillation indicates insufficient kD damping. Sluggish response indicates insufficient kP. Steady-state error indicates kI need. Each symptom maps to a specific mathematical cause.
🎤 Interview line: “We tune PID constants systematically using control theory. When we see oscillation, we increase kD — the derivative term damps oscillation by opposing the rate of error change. We never change two constants simultaneously because we cannot isolate cause from effect. Our PID documentation shows 7 tuning iterations with the theory-backed reasoning for each change.”
Your drive PID oscillates past its target and corrects, then oscillates again. Which constant adjustment dampens this behavior?
⬛ Increase kI to correct the accumulated error driving the oscillation
⬛ Increase kD — the derivative term dampens oscillation by opposing the rate of error change
⬛ Decrease kP so the initial drive force is smaller
📝
Notebook entry tip: Test & Evaluate — Cyan slide — Each tuning session is a test entry: record starting constants, observed symptom, what you changed and why (cite the PID principle), and the outcome metric. A sequence of 5+ tuning sessions showing progression from oscillation to convergence — with the reasoning for each step — is exactly the systematic test documentation that earns Expert-level scores.
← ALL GUIDES