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

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

Pattern collection advanced

Four building blocks of the advanced level – state machine, ring buffer, PI controller and device check – and how you plug them together into one chip.

Lesson 20 min Week 26

What you learn today

  • State machine and ring buffer as building blocks
  • PI controller and device check as building blocks
  • Combine blocks

A pro does not write every chip from scratch. He keeps a few proven building blocks in mind and plugs them together. You built these four over the past months:

State machine and ring buffer

BlockCoreWhat for
State machinestate number in a register, transitions every ticksequences, faults, airlocks
Ring bufferpoke at an index, mod for the circle, get db to readmean, history, trend

The ring buffer smooths, the state machine decides. In series you get a decision that does not tip with every outlier:

poke i p
add i i 1
mod i i LENGTH      # 0, 1, 2, 3, 0, ...

PI controller and device check

BlockCoreWhat for
PI controllerP from the error, I accumulated with clampstepless actuators
Device checkNaN with Average, Count, bnan before calculatingsafe state on failure

The device check belongs before every other block: bnan p fault jumps before a NaN gets into the ring buffer or the integral.

Combining blocks

The order is almost always the same: check → smooth → decide → output. Every block gets a section # --- … --- of its own and its own registers. The state machine here holds the alarm until the mean is back above the warning threshold – not just above the alarm threshold:

seq tmp state S_ALARM
and tmp tmp next          # in alarm and still below WARN?
select next tmp S_ALARM next
Warning

An empty ring buffer contains zeros. Without prefilling, the mean reports 25 kPa right after the start – and the state machine goes into alarm. That is why the chip fills the buffer before the start label once with the first reading.

Tip

and tmp tmp next works here because next is only 0, 1 or 2 and the alarm case needs tmp = 1: 1 AND 1 = 1, 1 AND 2 = 0. With bit instructions always check which values really occur.

Diagram

The stack with its pointer slot 0 10 slot 1 20 slot 2 30 slot 3 slot 4 sp = 3 next free slot push 40 pop r0 r0 = 30 last in, first out
The ring buffer uses stack addresses 0 to 3. The index runs in a circle with mod, the mean reads all four.

Exercise

Task

A pressure guard from two building blocks. Prefilling and the device check are done.

  • Block 1: ring buffer over the last 4 pressure readings, mean on display “Mittel”
  • Block 2: state 0 normal, 1 warning (mean below 90 kPa), 2 alarm (below 50 kPa); the alarm stays until the mean reaches at least 90 kPa again
  • Sensor gone: state 3. Display “Zustand”

Hints

Hint 1

Ring buffer: poke i p, add i i 1, mod i i LENGTH, then a loop with get tmp db k over all 4 places.

Hint 2

New state without memory: slt next mean WARN plus slt tmp mean ALARM.

Hint 3

Hold the alarm: if the state was alarm and next is still 1, it stays at S_ALARM.

Quiz

4 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