Desktop Required

This PID Tuning simulation is optimized for desktop browsers and does not work on mobile devices due to complex interactions and canvas rendering limitations.

Please switch to a desktop or laptop computer to continue.

If you're already on desktop and see this, try refreshing the page or make sure your window is fullscreen size.

PID TUNING


The blue robot has two wheels and a light sensor (yellow) in the front left corner. The light sensor is constantly asking three questions about the line:


Present: “How far off the edge of the track am I right now?”
Past: “Have I been pushed off-center for a while?”
Future: “Am I heading toward a big mistake?”


The PID controller answers each question with its own term:

P reacts instantly to the present error
I remembers the past and applies a steady correction
D predicts the future and brakes before overshooting


Your job: tune these three voices so they work together perfectly. Start with P (present), add I to erase drift (past), then finish with D for smooth curves (future).

PID Control Quick Reference

×

Core PID Principles – The Three Voices of Control

P = The Present Voice

“We’re off the line RIGHT NOW - turn harder!”

Gives instant kick
Too loud → wobbling

I = The Memory Voice

“We’ve been off to the left for the last 5 seconds - keep correcting until we’re centered.”

Never forgets
Eliminates permanent drift

D = The Future Voice

“We’re heading off fast - ease up before we overshoot!”

Predicts the swing
Calms the ride

The Golden Tuning Rule (never break this order):
1. Turn up P first → get the robot reacting quickly (even if it wobbles a bit).
2. Add I second → eliminate any steady drift (watch it doesn’t start swinging slowly).
3. Add D last → smooth everything out and kill the wobble.

Listen to your robot: Drifting slowly away? → I is speaking too quietly. Wobbling? → P is shouting or D is missing. Jerky on straights? → D is too loud.

Troubleshooting

IssueRoot (Principle)Fix
Drifts off lineP can't fix bias; needs accumulationIncrease Ki slightly
Oscillates/wobblesP too strong; no predictionLower Kp; add small Kd
Slow to correctWeak P responseRaise Kp; check motor lag
Twitchy/noisyD amplifies small changesLower Kd; use filter

Performance Metrics

MetricWhy It MattersTarget
Avg ErrorOverall tracking quality (P/I balance)<10
Drift OffsetEnd-lap bias (needs I)Near 0
RoughnessSteering jerkiness (D reduces)<20
ScoreCombined speed + accuracy90+

Ziegler-Nichols Method

Find Critical Point:
• Ki=Kd=0; raise Kp until constant wobble.
• Ku=that Kp; Pu=oscillation period (from graph).
Set Gains:
TypeKpKiKd
P0.5 Ku00
PI0.45 Ku1.2 Kp / Pu0
PID0.6 Ku2 Kp / PuKp Pu / 8

Derivative Filtering Explained

Derivatives react to tiny error flickers (noise), causing jitter. This sim filters D over 0.05s (vs. 0.016s loop) to mimic real low-pass filters - keeps prediction useful without overreacting.

Why filter? Raw D turns sensor "grain" into jerky turns; smoothing lets it focus on true trends.

Robot tie-in: Like averaging wheel speeds before differentiating - stable D = fluid curves.

Teacher Resources

×


Core Idea to Teach (the “aha” moment):
PID is not three random letters; it is a complete theory of time.

Present → P term answers: “How far off am I right now?”
Past → I term remembers: “Have I been consistently off (e.g., wind, friction)?”
Future → D term predicts: “Am I changing too fast and about to overshoot?”

Learning Objectives

  • Explain PID control using only the concepts of past, present, and future.
  • Tune a PID controller iteratively in the correct order: P → I → D.
  • Quantify performance improvements using lap score, total error, and roughness metrics.
  • Discover why all three terms are necessary to achieve a score > 110.

Recommended 3 Stage Discovery Sequence

StageGoalStudent TaskKey Question to Ask
1 Discover Proportional (P) Set I=0, D=0. Tune only Kp for fastest lap without crashing. “Why can’t any P value make the long-term drift exactly zero?”
2 Discover Integral (I) Add Ki. Eliminate steady-state error / end-of-lap bias. “How does ‘remembering the past’ cancel a constant disturbance like wind?”
3 Discover Derivative (D) Add Kd. Smooth sharp corners and reduce overshoot. “How can we start braking before we overshoot instead of after?”

Quick Discussion or Exit-Ticket Prompts

  • “Explain PID control using only the words past, present, and future.”
  • “Why must we always tune in the order P → I → D?”
  • “Look at your two best laps; which term made the biggest visible difference and why?”
  • “A score above 110 is impossible without all three terms. Prove it to a classmate.”

Ready-to-Use Materials

PID Tuning Lab Worksheet PDF
PID Tuning Lab Worksheet WORD

Pro tip for teachers: Let students believe a perfect controller exists with just P or P+I. The simulator mathematically proves no score > 110 is possible without all three terms; they will discover this themselves and never forget it.

PID TUNING
BETA

"The PID controller remains the workhorse of industrial control, balancing responsiveness, accuracy, and stability in dynamic systems."

ASSUMPTIONS

Light Sensor: Provides an output of 0 (full black) to 100 (full white) with a target of 50.

Error: Zero is balanced, Positive (too white = turn right) and Negative (too black = turn left).

Delta Time: 0.016s steps for responsive updates, like real robot sensors.

Derivative Filtering: Uses 0.05s steps (slower than P/I) to preventing twitchy over correction.

Motor Physics: Wheels accelerate gradually (inertia) like real motors.

Roughness Score: Measures rapid changes in steering (jerkiness).

PID Equation

Correction = Kp × Error + Ki × ∫(Error × Δτ) + Kd × ΔError Δτ
PROPORTIONAL TERM
0.0
INTEGRAL TERM
0.0
DERIVATIVE TERM
0.0
Press Run to begin.

PID GAIN

Kp PROPORTIONAL GAIN
0.25
Ki INTEGRAL GAIN
0.00
Kd DERIVATIVE GAIN
0.00

ERROR AND TIME

Error 0.0
Integral Error 0.0
Delta Error 0.0
Delta Time (Δτ) (P/I) 0.016s
Delta Time (Δτ) (D) 0.05s

TERM RESULTS

P Term 0.0
I Term 0.0
D Term 0.0
Turn Speed Correction
READY 0.0

Error History

The line shows how far off-center the sensor is. Zero error is perfect. Positive: too much white (turn left). Negative: too much black (turn right).

Lap History

This table shows your past lap's performance metrics. Higher Score is better (combines time, error, and roughness). Use 'Sort by' to find quickly.

NO LAP DATA RECORDED YET.
© 2026 Scott Hanneman. All rights reserved.