Task 4: Tune the Controller

Objective

Tune the PID gains manually to achieve stable and responsive behavior.

Tuning Process

Step 1: Start with zeros

  • Set Ki = 0 and Kd = 0
  • Start with small Kp (e.g., Kp = 0.5)

Step 2: Increase Kp

  • Gradually increase Kp until the system begins to oscillate
  • Note the value where oscillation starts
  • Back off slightly (use about 50-70% of that value)

Step 3: Add Kd

  • Introduce Kd to reduce oscillation and improve damping
  • Start small (e.g., Kd = 0.1 * Kp)
  • Increase until oscillations are damped

Step 4: Add Ki

  • Add a small Ki to eliminate steady-state error
  • Start very small (e.g., Ki = 0.01 * Kp)
  • Increase slowly – too much causes overshoot

Key Rules:

  • Change ONE gain at a time
  • Observe system response after each change
  • Record all values and observations

Tuning Table Template

Kp Ki Kd Observation
0.5 0 0 Slow response, no oscillation
1.0 0 0 Faster, slight oscillation
2.0 0 0 Strong oscillation
1.5 0 0 Good response, some overshoot
1.5 0 0.2 Reduced overshoot
1.5 0 0.3 Damped well, slight error
1.5 0.05 0.3 Error eliminated

Final values: Kp = 1.5, Ki = 0.05, Kd = 0.3

Common Issues and Solutions

Problem: System oscillates continuously

  • Solution: Decrease Kp, increase Kd

Problem: System is sluggish

  • Solution: Increase Kp

Problem: Ball settles slightly off-center

  • Solution: Increase Ki (but be careful!)

Problem: Erratic, jerky motion

  • Solution: Check sensor filtering, decrease Kd

Problem: Massive overshoot

  • Solution: Decrease Ki, increase Kd

Key Takeaways

  • Start with Kp only (Ki=0, Kd=0)
  • Increase Kp until oscillation, then back off
  • Add Kd to damp oscillations
  • Add small Ki to eliminate steady-state error
  • Change one gain at a time