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

Day 23 of 365 · Beginner · Month 1: First steps

Comparing against zero: sltz, sgtz & co.

Instead of comparing two values you build the deviation and only ask: less than, greater than or equal to zero?

Lesson 10 min Week 4

What you learn today

  • Know sltz, sgtz, slez, sgez, seqz, snez
  • Judge deviations from a target
  • seqz as logical not

With a heater you rarely care about the temperature itself. What matters is how far it is from the target and in which direction. There is a group of set instructions for exactly that: they compare a value with zero.

The six z instructions

Instructionregister = 1 if
sltz r? aa < 0
sgtz r? aa > 0
slez r? aa ≤ 0
sgez r? aa ≥ 0
seqz r? aa = 0
snez r? aa ≠ 0

Otherwise the result is 0. The z stands for zero. Compared with slt r1 r0 0 you save the zero and a few characters – with 4096 characters per chip that adds up eventually.

Deviation first, comparison second

l r0 d0 Temperature
sub r0 r0 293.15   # deviation from 20 C
sltz r1 r0         # 1 = too cold
sgtz r2 r0         # 1 = too warm

r0 is now negative when it is too cold, positive when it is too warm, and exactly zero only in the rare case of exactly 20 °C. You can put the deviation straight onto a display: a value of −2.5 says more than 290.65.

Adding a small band

If the heater reacted to every tiny deviation it would switch all the time. Simply shift the limit with an addition:

add r1 r0 1        # only negative below -1
sltz r1 r1         # heater on below 19 C
sub r2 r0 1        # only positive above +1
sgtz r2 r2         # cooler on above 21 C

Between 19 and 21 °C both stay off. That is not a real hysteresis with memory yet – that comes in week 7 – but for many rooms it is enough.

seqz as “not”

For values that are only 0 or 1, seqz flips the value: 1 becomes 0, 0 becomes 1. snez does the opposite job and turns any non-zero number into a clean 1.

seqz r3 r1         # 1 if the heater is NOT running
Tip

The jump instructions from week 3 exist against zero as well: bltz, bgtz, blez, bgez, beqz, bnez. The z set instructions are their jump-free siblings.

Note

If the sensor returns NaN, sltz and sgtz are both 0 – heater and cooler then stay off.

Diagram

Comparison and select as a switch temp = 313 sgt r1 temp 303 r1 = 1 select Color.Red Color.Green 4 if r1 ≠ 0 if r1 = 0
A comparison turns into 0 or 1. With the z instructions the second number is always zero – one operand less.

Exercise

Task

d0 holds a gas sensor, d1 a wall heater, d2 a wall cooler and d3 an LED display. The target is 20 °C (293.15 K).

  • r0 = deviation from the target, the display on d3 shows it
  • heater on when the deviation is below −1 (colder than 19 °C)
  • cooler on when the deviation is above +1 (warmer than 21 °C)
  • use the z instructions, no conditional jumps – only j start for the loop

Hints

Hint 1

For the heater: first add r1 r0 1, then sltz r1 r1.

Hint 2

For the cooler the same with sub and sgtz.

Hint 3

The display simply gets s d3 Setting r0.

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