An interactive Python simulation for exploring Proportional-Derivative (PD) controller behavior with real-world effects.
pip install -r requirements.txt
# Static plots with sliders
python pd_controller_playground.py
# Animated mass-spring-damper visualization (recommended)
python pd_animated_playground.py
# Armature-controlled DC motor with PD loop
python dc_motor_pd_playground.py| Slider | What it does | What to observe |
|---|---|---|
| Kp | Proportional gain | ↑ Kp → faster response but more overshoot/oscillation |
| Kd | Derivative gain | ↑ Kd → more damping, but amplifies sensor noise |
| dt | Sampling period | ↑ dt → poor discretisation, potential instability |
| Noise σ | Sensor noise std dev | ↑ Noise → jittery control signal (derivative amplifies it) |
| Delay steps | Transport delay | ↑ Delay → phase lag → oscillation → instability |
| Saturation | Actuator limit | ↓ Saturation → limited authority, slow response |
- Instability — Crank up Kp with some delay and watch the system diverge
- Oscillation — High Kp with low Kd produces underdamped ringing
- Steady-state error — PD has no integrator; observe residual offset
- Noise amplification — Add noise and increase Kd to see the control signal go wild