PID Control · Lesson
English translation
Execution setup
The Python option uses python-control. If the module is missing, run %pip install control==0.10.2 in a Colab or Jupyter code cell.
Topics covered
Selecting a gain based only on response speed can leave the system vulnerable to overshoot or model changes. Compare different performance metrics.
Overall workflow
Reference and error → P, I, D commands → input limits → response and integrator state
Current, accumulated, and changing error
PID is expressed as . P responds to current error, I accumulates remaining error, and D responds to rapid changes. Gain effects depend on the plant and observation interval, so compare using the same input and time axis.
Practical control with input limits
Output voltage and torque have limits. If the integral keeps accumulating when u is already at its maximum, a large command may persist after the reference is lowered.
Conditional integration is one way to stop integral accumulation that would worsen the error while the input is saturated.
Why accumulate error?
Compare and for . First examine steady-state error with a simple plant, then use a motor in the practice activity.
import numpy as np
import matplotlib.pyplot as plt
import control as ctl
s=ctl.tf('s')
G=1/(s+1);t=np.linspace(0,12,601)
for name,C in [('P',2),('PI',2+1/s)]:
closed=ctl.feedback(C*G,1);tm,y=ctl.step_response(closed,t)
plt.plot(tm,y,label=name);print(name,'DC gain',ctl.dcgain(closed))
plt.axhline(1,color='gray',linestyle='--');plt.xlabel('Time [s]');plt.ylabel('Output');plt.grid();plt.legend()
P DC gain 0.6666666666666666 PI DC gain 1.0
Reference example
View more examples