What you learn today
- Average, minimum and count of batteries
- Report the weakest battery
- Detect failure
The battery bank in the basement carries the base through the night. If a battery fails or one lags clearly behind, you want to know before it gets dark. This week you learned everything a monitor needs for that.
The setup
Three station batteries (StructureBattery) named “Akku 1”, “Akku 2” and “Akku 3”. There are no other station batteries on this network. In addition:
| Device | Prefab | Name |
|---|---|---|
| LED display | StructureConsoleLED5 | Mittel |
| LED display | StructureConsoleLED5 | Minimum |
| LED display | StructureConsoleLED5 | Anzahl |
| LED display | StructureConsoleLED5 | Schwach |
| flashing light | StructureFlashingLight | Akkuwarnung |
Every battery reports its charge in Ratio, from 0 to 1.
Milestones
- Average: “Mittel” shows the average charge of all batteries in percent.
- Minimum and warning: “Minimum” shows the lowest charge in percent. Below 20 % “Akkuwarnung” lights up.
- Count: “Anzahl” shows how many batteries are on the network. If there are fewer than 3, the warning lights up as well.
- Weakest battery: “Schwach” shows the number (1, 2 or 3) of the battery with the lowest charge.
- Failure: if all batteries are gone, “Mittel” and “Minimum” show 0 instead of NaN, and the warning lights up.
Finding the weakest
The minimum tells you how weak the weakest battery is, but not which one. For that you go through the batteries one by one and remember the smallest value so far:
lbn value BATTERY HASH("Akku 1") Ratio Average
move lowest value
move number 1
lbn value BATTERY HASH("Akku 2") Ratio Average
slt tmp value lowest # smaller than the smallest so far?
select number tmp 2 number
min lowest lowest value
For battery 3 you repeat the three lines from slt onwards.
If “Akku 1” is missing, lowest becomes NaN and every comparison after it is false. The number then stays at 1. That is not a false report, because a missing battery is the weakest of all.
Here you may use Count, because only these three station batteries hang on the network. Write this assumption as a comment into the settings block, so nobody overlooks it at the next rebuild.
Diagram
Project task
Task
Build the battery bank monitor with the devices and names from the table. The milestones are listed above the editor.
Milestones
- Milestone 1: average 60 %
- Milestone 2: minimum and warning
- Milestone 3: count
- Milestone 4: weakest battery
- Milestone 5: all batteries gone
Hints
Hint 1
Average with lb … Ratio Average, turn NaN into 0 with snan and select, then times 100.
Hint 2
Minimum with lb … Ratio Minimum, the count with lb … PrefabHash Count, warning from both with or.
Hint 3
Weakest battery: take battery 1 as the start, then compare batteries 2 and 3 with slt and select.
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