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

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

Tuning a controller

You recognise oscillation by sign changes of the error. You set the gain step by step and log the values into the stack as a ring buffer.

Lesson 16 min Week 23

What you learn today

  • Recognise oscillation
  • Gain step by step
  • log values in the stack

The greenhouse heater now has a PI controller, but it swings: ten minutes too warm, ten minutes too cold. Is it KP? KI? Guessing costs hours because every change only shows after minutes. Better measure what the controller does.

Recognising oscillation

A controller that oscillates overshoots above and below the setpoint in turn. So the error e keeps changing its sign. That is exactly what the chip counts:

sgtz sg e                 # 1 = too cold, 0 = too warm
sne tmp sg sgOld          # different from last time?
add flips flips tmp
move sgOld sg

A few changes per hour are normal, the controller is looking for the setpoint. Many changes at regular intervals, each time missing by a similar amount – that is oscillation.

One catch: around the setpoint the reading always jitters a little. Without a countermeasure every jitter counts as a change. That is why the counter gets a dead band: if the magnitude of e is below BAND, the sign is not evaluated again at all.

Gain step by step

  1. KI = 0 and KD = 0. Only KP, and a small one.
  2. Double KP, wait, count changes. Keep going until the controller starts to oscillate.
  3. Go back to half of that KP value.
  4. Now add a small KI and raise it slowly until the steady-state error disappears in acceptable time. If it oscillates again, lower KI.

Always change only one value at a time and wait long enough – a large room needs minutes before a change shows. So you do not have to rewrite the chip every time, the controller reads KP from a logic memory (StructureLogicMemory, Setting read and write). If the memory is missing, the value from the define applies:

lbn kp MEMORY HASH("Kp") Setting Average
snan tmp kp
select kp tmp KP_STD kp   # without memory: default value

Logging values in the stack

A display only shows the moment. For the history you put the error into a ring buffer in the stack: poke writes to a fixed address without changing sp. With 60 slots and one entry every 10 ticks you keep the last five minutes in memory:

add count count 1
blt count TICKS skip          # only every 10th tick
move count 0
poke idx e
add idx idx 1
mod idx idx SLOTS             # after the last slot back to the front
skip:

With get value db address you read an entry back, for example to find the largest error of the last few minutes. A second chip can also read the buffer with get.

Warning

Without the mod, idx runs past the 512 slots of the stack and poke stops the chip with an error. The controller then stands still in the middle of operation.

Exercise

Task

A watchdog chip observes the temperature in the lab (gas sensor “Labor”) and counts how often the controller overshoots the setpoint.

  • e = TARGET − temperature
  • If the magnitude of e is below BAND, the sign is not evaluated again
  • Otherwise: sg = 1 for e > 0, else 0. If sg differs from sgOld, flips (r4) counts up by one. At the very first sign (sgOld = −1) nothing is counted
  • Every tick e goes into the ring buffer: poke idx e, idx (r5) runs from 0 to 59 and then starts at 0 again
  • The display “Wechsel” shows the number of changes, −1 without a sensor

Hints

Hint 1

abs tmp e and blt tmp BAND log skip the counting inside the dead band.

Hint 2

sgtz sg e, then bltz sgOld keep for the first pass, sne tmp sg sgOld and add flips flips tmp. Under keep: comes move sgOld sg.

Hint 3

Under log: follow poke idx e, add idx idx 1 and mod idx idx SLOTS.

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