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:
- Which two neighbours? The integer part of the position.
- 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:
| Use | x | y |
|---|---|---|
| Ventilation | temperature | pump power |
| Cooling loop | outside temperature | loop setpoint |
| Tank | pressure | fill level in percent |
Where the curve bends sharply, put the points closer together. Where it is almost straight, a few are enough.
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
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