Programming language

PID Control

English translation

Selecting a gain based only on response speed can leave the system vulnerable to overshoot or model changes. Compare different performance metrics.

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.

MATLAB · Control System Toolbox

Before practice

01 What error information does each P, I, and D term respond to?

Description

They respond to current error, accumulated error, and error changes. Examine their actual effects in the closed-loop response.

02 What becomes hard to distinguish when several gains change simultaneously?

Description

It becomes difficult to isolate which gain caused the response change.

Practice

Preview practice notebookDownload practice notebookPreview practice mlx scriptDownload practice mlx script

1. Baseline P, PI, and PID comparison

Starting conditions

Motor parameters: J=.01J=.01,b=.1b=.1,K=.01K=.01,R=1R=1,L=.5L=.5. P=(500,0,0), PI=(500,300,0), PID=(500,300,30).

Procedure

  1. Build three closed-loop models using negative unity feedback.
  2. Plot the unit-step responses over 0≤t≤20\le t\le 2 s in the same figure, and check the poles first.
  3. Record overshoot, settling time, and steady-state error for stable models.

Results to retain

Items to record and points to check
Controller
Kp
Ki
Kd
Stability
Overshoot [%]
Settling Time [s]
Steady-State Error

Points to check

  • Are the plant, input, and time axis the same, with only the controller changing?
  • For unstable or unconverged cases, did you give a reason instead of reporting metrics?

2. Changing one term at a time

Starting conditions

Starting from the PID baseline (500,300,30), change only Kp to 250,500,750. Keep Ki and Kd fixed.

Procedure

  1. Use the PID result from Activity 1, (500,300,30)(500,300,30), as the baseline, and change only KpK_p to 250 and 750 in turn. Keep Ki=300K_i=300, Kd=30K_d=30, the plant, and the time axis unchanged.
  2. Plot the unit-step responses of both settings alongside the baseline curve in the same figure. Record overshoot, settling time, and steady-state error using the same ctl.step_infostepinfo settings and the same columns as Activity 1.
  3. Choose one of the two additional settings. Use the table values to explain which metric you aim to improve over the baseline and which changes you are willing to accept.

Results to retain

Items to record and points to check
Changed term
Value
Overshoot [%]
Settling Time [s]
Steady-State Error

Points to check

  • Did you change only one gain at a time?
  • Did you support claims of faster response with specific metrics?

3. Input limits and integrator windup

Starting conditions

1st-order plant ẏ=−y+u\dot y=-y+u, reference 2→.5 (changes at 5 s), u∈[0,1]u\in[0,1], dt=.01 s. Use Kp=2K_p=2, Ki=1K_i=1.

Procedure

  1. In the supplied PI simulation, plot the actual input alongside the input before limiting.
  2. Compare conditional integration enabled and disabled.
  3. Explain why the error persists after lowering the reference, relating it to the integrator state.

Results to retain

In the comparison table, IAE is ∫5tlast|r(t)−y(t)|dt\int_{5}^{t_{\mathrm{last}}}|r(t)-y(t)|\,dt from the reference-change time to the final recording time. Calculate input saturation duration by multiplying the number of samples where the limited uu is 0 or 1 over the entire record by dt.

Use the same interval and calculation method for both integration approaches.

Items to record and points to check
Integration handling
IAE after the reference change
Maximum integral value
Input saturation duration [s]

Points to check

  • Did you distinguish input values before and after limiting?
  • Did you compare only integration handling without also changing the PI gains?