stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 156

Day 156 of 365 · Advanced · Month 6: Atmosphere and control

PI controller

The I term adds up the error tick by tick and removes the steady-state error. Anti-windup with clamp and a NaN guard keep it under control.

Lesson 16 min Week 23

What you learn today

  • Accumulate the integral term
  • Anti-windup with clamp
  • Time base per tick

Yesterday's P controller holds the buffer tank at 1800 kPa instead of 2000. The pump would permanently need Setting 4, and the P controller only gives that while 200 kPa are missing. More gain makes it restless. The solution is a second term that remembers how long something has been missing.

The integral term

The I term i is a register that receives a share of the error every tick:

i = i + KI · e and u = KP · e + i

mul tmp e KI
add i i tmp               # i grows while e > 0
mul u e KP
add u u i                 # P term plus I term
clamp u u 0 MAXPUMP

With 200 kPa missing, i grows tick by tick, the pump delivers more, the pressure rises. At 2000 kPa e = 0: the P term is zero, but i stays where it is – exactly at the value the pump needs to cover the consumption. The steady-state error is gone.

For this to work you set i to 0 only once, before the start label. If move i 0 sits inside the loop, the controller forgets everything every tick.

Time base per tick

A tick lasts 0.5 s. If your loop has exactly one yield, the chip computes twice per second and KI applies per tick. With KI = 0.001 and 200 kPa of error, i grows by 0.2 per tick, i.e. by 0.4 per second.

If you restructure the loop, for example with sleep 1 instead of yield, the chip computes only once per second. Then i grows half as fast even though nothing else in the code changed. If you want to think in seconds, include the pass time:

define KI_S 0.002         # I term per kPa and second
define DT 0.5             # seconds per pass
mul tmp e KI_S
mul tmp tmp DT            # gives KI per pass
Note

Work out KI per tick yourself and put the final number into the define. define KI KI_S with another define as its value gives NaN – without any error message.

Anti-windup with clamp

Mars morning, the tank is empty after a repair. The pump runs at its limit, more than Setting 10 is not possible. The I term knows nothing about that: with 2000 kPa of error it grows by 2 per tick and reaches 240 after one minute. When the tank is finally full, this mountain has to be worked off first. Until then the pump keeps running at full power and pushes the tank far above the setpoint. This is called windup.

The fix is one line: limit i to the range the actuator really has.

add i i tmp
clamp i i 0 MAXPUMP       # anti-windup: i never more than the pump can do

NaN poisons the integral term

If the analyzer fails, press is NaN, and so are e and tmp. A single add i i tmp turns i into NaN – and NaN plus anything stays NaN. Not even clamp saves that. So check before accumulating and jump into a safe branch that does not touch i:

lbn press ANALYZER HASH("Puffer") Pressure Average
bnan press fault          # before any calculation with e
Warning

A NaN in the I term stays forever. Even if you rebuild the analyzer, the controller keeps computing with NaN and writes nonsense to the pump. Only a restart of the chip, which runs through move i 0 again, resets i.

Exercise

Task

The P controller for the buffer tank is already there. Add the I term:

  • i (r2) grows by KI · e every tick
  • Anti-windup: i stays between 0 and MAXPUMP
  • Setting = KP · e + i, limited to 0 to 10
  • Analyzer gone: pump off, i stays unchanged (no NaN)

Hints

Hint 1

mul tmp e KI, then add i i tmp.

Hint 2

Right after that clamp i i 0 MAXPUMP – that is the anti-windup.

Hint 3

Add add u u i to the P term before you limit u. The jump to fault already comes before the calculation, so i stays untouched on NaN.

Quiz

5 questions. You pass from 60 % – the server does the grading.

Complete the day

  • Passed the simulator exercise
  • Passed the quiz with at least 60 %

Without an account progress is saved in this browser only.

Report a mistake in this lesson

Please sign in to report. Sign in

Esc
↑ ↓ selectEnter open/ opens search anywhere