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

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

Project: data logger

A data logger for the lab: write temperatures into a ring buffer at a fixed rhythm, show count, mean, minimum and maximum and survive sensor failures.

Project 45 min Week 43

What you learn today

  • Record values
  • Compute statistics
  • Show the result

In the lab the temperature over the last minutes should be recorded: how warm was it on average, how cold at its coldest, how hot at its hottest? A chip with a ring buffer and statistics is your data logger.

The setup

DevicePrefabName
Gas sensorStructureGasSensor“Labor”
Wall lightStructureWallLight“Sensor”
LED displaysStructureConsoleLED5“Anzahl”, “Mittel”, “Minimum”, “Maximum”

Recording values

Not every tick is stored, only every INTERVAL-th one. A tick counter decides that. The value goes in Celsius to the write position pos, then pos moves on and jumps back to 0 with mod after the last slot – a ring buffer (day 125). count keeps track of how many slots are already filled, at most 8.

Computing statistics

The evaluation runs every tick over the filled slots 0 to count − 1: sum, min, max. As long as the buffer is not full, the values sit in the first slots. Once it is full, all eight are valid – wherever pos happens to be.

Milestones

  1. The display “Anzahl” counts the readings, at most 8.
  2. “Mittel” shows the average of the stored values.
  3. “Minimum” and “Maximum” show the extremes.
  4. The buffer forgets old values: after eight new readings only these count.
  5. If the sensor fails, the light “Sensor” is on and nothing is recorded. The statistics of the old values stay.
Tip

In the game you use a larger interval, for example define INTERVAL 120 for one reading per minute. Eight slots are then eight minutes of history. With 64 slots that becomes an hourly log – but then take the instruction budget from next week into account.

Warning

NaN does not belong in the buffer. A single NaN value turns sum and mean into NaN until it drops out again after eight readings. That is why bnan temp evaluate jumps over the storing.

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 write position runs in a circle, the evaluation reads all filled slots.

Project task

Task

Build the data logger following the milestones above. Every INTERVAL-th tick one reading in Celsius into the ring buffer (8 slots), then show count, mean, minimum and maximum every tick.

Milestones

  1. Milestone 1: counting readings
  2. Milestone 2: mean
  3. Milestone 3: minimum and maximum
  4. Milestone 4: ring buffer forgets
  5. Milestone 5: sensor fails

Hints

Hint 1

Tick: add tick tick 1, blt tick INTERVAL evaluate, then move tick 0.

Hint 2

Store: poke pos temp, add pos pos 1, mod pos pos SLOTS, limit count to 8 with min.

Hint 3

Only evaluate when count is not 0 – otherwise you divide by 0.

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