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

Day 328 of 365 · Expert · Month 11: Optimisation and debugging

Project: your own template

Project: your own template for two-point controllers – settings block on top, one subroutine for any number of loops, heating and cooling with the same logic.

Project 45 min Week 47

What you learn today

  • Build a reusable template
  • Settings block
  • Documentation

This year you have written dozens of two-point controllers: a heater here, cooling there, almost the same code every time. This week you build the template you will copy from now on. A good template has three parts: a settings block holding everything you need to adjust, logic you never have to touch again, and documentation that says how to use it.

The idea

A subroutine regeln handles one control loop. What it needs, it gets in registers:

RegisterContent
namename of sensor and device, e.g. HASH("Wohnraum")
typprefab of the device: heater or cooler
low, highlimits in Kelvin
direction1 = device heats, 0 = device cools

When heating, “too cold” switches on and “too warm” off, when cooling it is exactly the other way round. For that the subroutine swaps the roles of ein and aus with two select – after that the actual hysteresis is the same line for both directions.

The state lives in the device

Every control loop needs its own memory: was the device on? Instead of spending registers or the stack on it, the subroutine simply reads the state back from the device:

lbn on typ name On Average      # the state lives in the device itself
snan tmp on
select on tmp 0 on

That way every further loop costs only six lines in the main part, and the subroutine stays unchanged.

Safe state per direction

If a loop's sensor is missing, a heater switches off and a cooler on. The display “Regler” shows how many loops are currently running without a sensor.

The setup

DevicePrefabName
gas sensor and wall heaterStructureGasSensor, StructureWallHeater“Wohnraum”
gas sensor and wall coolerStructureGasSensor, StructureWallCooler“Kuehlraum”
LED displayStructureConsoleLED5“Regler”

Milestones

  1. The living room heats with hysteresis (19/21 °C).
  2. The cold room cools with hysteresis (6/2 °C).
  3. Sensor failure: heater off, cooler on, the display counts the failed loops.
  4. The loops are independent: if one fails, the other keeps controlling.
Tip

Write into the template's header how to add a third loop: six move lines and one jal regeln. Whoever takes over the template then does not need to read the subroutine at all.

Diagram

Calling and returning from a subroutine Main loop 2 l r0 d0 Temperature 3 jal celsius 4 s d2 Setting r1 5 l r0 d1 Temperature 6 jal celsius 7 s d3 Setting r1 8 j start celsius: sub r1 r0 273.15 j ra ra = 4 back to line ra
Every loop hands over name, device type, limits and direction in registers. The subroutine controls and jumps back with j ra.

Project task

Task

Build the template: settings block, devices and registers are already there. Missing are the two calls in the loop, the display of failed loops and the subroutine regeln, which uses the same hysteresis for heating and cooling.

Milestones

  1. Milestone 1: living room heats with hysteresis
  2. Milestone 2: cold room cools with hysteresis
  3. Milestone 3: sensor failure per direction
  4. Milestone 4: loops are independent

Hints

Hint 1

Per loop: five move for name, typ, low, high, direction, then jal regeln.

Hint 2

In the subroutine: slt ein t low, sgt aus t high, then swap by direction with select.

Hint 3

Hysteresis: seqz aus aus, and on on aus, or on on ein. On NaN: select on ok on tmp with tmp = seqz direction.

Quiz

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

Complete the day

  • Passed all milestones of the project
  • 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