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

Day 61 of 365 · Beginner · Month 3: First systems

Scaling values with lerp

lerp computes between two values by a ratio from 0 to 1 – and clamps the ratio by itself. That turns percentages and readings into device values.

Lesson 11 min Week 9

What you learn today

  • lerp between two values
  • Turn percent into device values
  • lerp clamps the ratio

The warmer the server room, the faster the cooling pump should run: 2 litres at 22 °C, 10 at 30 °C. Smoothly in between. That is a straight line between two points – exactly what lerp is for.

lerp

lerp r0 a b t        # r0 = a + (b - a) * t
tResult
0a
0.5exactly in the middle
1b

lerp r0 2 10 0.25 gives 4: a quarter of the way from 2 to 10.

lerp clamps the ratio

The special thing: t is clamped to 0 to 1 first. At t = 2 the result is b, not double. At t = −1 the result is a. That saves you the clamp – the result always lies between a and b.

lerp r0 0 100 2      # 100, not 200

From reading to ratio

You compute the ratio from the reading: (value − start) / (end − start).

sub t temp LOWER     # LOWER = 295.15, 22 C
div t t 8            # 8 degrees up to 30 C
lerp flow 2 10 t     # 2 to 10 litres

Below 22 °C t is negative, lerp turns it into 2. Above 30 °C t is greater than 1, lerp turns it into 10. That way a pump never runs below its minimum flow and never above its maximum.

Percent into device values

A share from 0 to 1 already is a finished ratio. A battery with Ratio 0.3 converts directly: lerp r1 0 10 ratio gives 3. Percent values from 0 to 100 you divide by 100 first.

Falling curves work too: lerp flow 10 2 t gives 10 at t = 0 and 2 at t = 1 – the fuller a tank, the slower the filling pump.

Warning

If the sensor is missing, t is NaN, and lerp returns NaN as well. The safe direction depends on the device: a cooling pump would rather run at full on failure, a filling pump would rather stand still. You decide it with snan and select.

Diagram

Data flow of an arithmetic instruction add r1 r0 273.15 r0 = 21 273.15 + r1 = 294.15 the target always comes first
lerp reads three values – start, end, ratio – and stores the result in the target register.

Exercise

Task

A sliding cooling pump. On the network: gas sensor “Serverraum”, volume pump “Kuehlpumpe”, LED display “Pumpenlast”.

  • Ratio t = (temperature − 22 °C) / 8 K.
  • Pump Setting = lerp from 2 to 10 with t; On always 1.
  • “Pumpenlast” shows t, limited to 0 to 1, in Percent mode.
  • If the sensor fails, the pump runs at full (10) and the display shows 100 %.

Hints

Hint 1

t: sub t temp LOWER, then div t t SPAN.

Hint 2

Replace NaN with 1 first – then the pump runs at full on failure.

Hint 3

lerp flow MINFLOW MAXFLOW t clamps t by itself; for the display you still need a clamp.

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