Problem 370970 · medium · Level 03 Linear Management & Searching

How Much Integral Is Enough?

PI control · tuning · overshoot · settling time · step response

A water tank in a brewery must be filled to a target depth (cm) and held there. Its outlet drains h / 10 cm per minute, and the inlet valve adds u cm per minute. The PI controller's proportional gain Kp is fixed; the engineer wants a table showing what the integral gain Ki does.

For each Ki in gains: start with an empty tank, h = 0, and I = 0, take round(minutes / 0.1) steps of dt = 0.1 minutes, and record the depths h[0] = 0, h[1], .... Each step, in this order:

e = target - h
I = I + e * 0.1
u = Kp * e + Ki * I           (no limit on the valve in this problem)
h = h + 0.1 * (u - h / 10)

A PI loop settles at the target, so measure both numbers against target:

  • the percent overshoot: 100 * (peak - target) / target, where peak is the highest recorded depth, or 0.0 if the peak is not above the target;
  • the settling time in minutes: i * 0.1 for the smallest index i such that h[i] and every later depth satisfy abs(h[j] - target) <= 0.02 * target; None if the last depth is outside that band.

Write ki_table(target, Kp, gains, minutes) that returns a list with one tuple (overshoot, settling) per gain, in the order of gains. Plot the depths for each gain on one chart to see the table come alive.

Examples

Input:  target = 50, Kp = 0.5, gains = [0, 0.02, 0.05, 0.2, 1], minutes = 120
Output: [(0.0, None), (0.0, 51.1), (0.0, 7.7), (16.14483274, 11.0), (43.28897818, 12.8)]
Explanation: with Ki = 0 (plain P) the tank stops at 41.7 cm and never reaches the band
around 50 cm. A small Ki gets there, but creeps for 51 minutes. Ki = 0.05 is fastest
with no overshoot; larger gains overshoot more and take longer to calm down.

Input:  target = 50, Kp = 2, gains = [0.2, 1], minutes = 60
Output: [(0.0, 1.8), (10.39669104, 5.1)]

Constraints

  • answers are compared with a tolerance of 1e-6; do not round

Goals

  • Simulate a PI loop for several integral gains
  • Measure overshoot and settling time against the setpoint
  • See that too little integral is slow and too much overshoots
Starting Python…