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

Day 296 of 365 · Expert · Month 10: Bits and data

Interpolating

Calculating between two support points instead of jumping: position and fraction from the reading, lerp between the neighbours and curves with few points.

Lesson 18 min Week 43

What you learn today

  • Calculate between points
  • lerp with an index
  • Characteristic curves

Yesterday's table has a catch: at 25.9 °C the pump runs at 10, at 26.0 °C suddenly at 20. It jumps at every step. For ventilation that is noisy, for a control loop restless. A line that interpolates between the table values is better.

Calculating between support points

The table values are now support points: points the curve passes through. For a reading in between you need two things:

  1. Which two neighbours? The integer part of the position.
  2. How far between them? The remainder, a fraction from 0 to 1.

At 27 °C the position is (27 − 20) / 2 = 3.5. The neighbours are slot 3 (20) and slot 4 (30), the fraction is 0.5. The result lies in the middle: 25.

lerp with an index

You have known lerp since day 61: lerp r? a b frac computes a + (b − a) · frac.

floor idx temp                # temp already holds the position
clamp idx idx 0 LAST
sub frac temp idx           # remainder between 0 and 1
get a db idx
add idx idx 1
get b db idx
lerp value a b frac

The index may be at most 6 here, because slot 7 has no right neighbour any more. If the reading lies above the last point, the fraction becomes larger than 1 – lerp limits it to 1 itself. Below the first point it becomes negative and lerp turns it into 0. So the edges of the curve are right on their own.

Curves

With interpolation a few points are enough for a smooth curve:

Usexy
Ventilationtemperaturepump power
Cooling loopoutside temperatureloop setpoint
Tankpressurefill level in percent

Where the curve bends sharply, put the points closer together. Where it is almost straight, a few are enough.

Warning

The fraction must be computed from the unrounded value: sub frac temp idx with the position before floor. If you compute it from the rounded index, it is always 0 and you have steps again.

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 integer part selects the neighbours, the remainder is the fraction for lerp.

Exercise

Task

The same table as yesterday, now interpolated: compute the position (Celsius − 20) / 2, take slot idx (0 to 6) and idx + 1 as neighbours and write lerp of the two with the fraction to the pump “Abluft”. 0 without the sensor.

Hints

Hint 1

Keep the position in temp, floor idx temp, then clamp idx idx 0 LAST.

Hint 2

Fraction: sub frac temp idx.

Hint 3

Two get for the neighbours, then lerp value a b frac.

Quiz

3 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