A volume pump has two important LogicTypes: On and Setting – the flow in litres per tick. Instead of just switching it on and off, you can adjust the flow smoothly to the pressure. Then the tank does not overshoot the target.
Proportional controller
The idea: pump output = distance to target × factor.
sub flow TARGET press # how far to go?
div flow flow 100 # 100 kPa distance = 1 litre/tick
clamp flow flow 0 10 # never below 0, never above 10
clamp r? value min max limits a value to a range. With an empty tank, flow would be huge – clamp turns it into 10. Above the target it would be negative – clamp turns it into 0.
Then the pump only needs to run when there is something to do:
sgtz on flow # 1 if flow > 0
Guarding against NaN
If the pipe analyzer fails, Average returns NaN and flow becomes NaN. For a pump that is risky – who knows what the device does with “not a number”. So catch it explicitly:
snan missing press
select flow missing 0 flow # NaN: 0
Compute first, then guard, then write – in that order the device never receives a nonsense value.
The pipe analyzer’s prefab name is StructurePipeAnalysizer – the typo is in the game like that.
Diagram
Exercise
Task
A pipe analyzer “Tank” measures the pressure, a volume pump “Fuellpumpe” tops it up. Target pressure 5000 kPa.
- Pump
Setting= (5000 − pressure) / 100, limited to 0 to 10 On= 1 if the output is greater than 0, otherwise 0- If the analyzer fails (NaN):
Setting0 andOn0
Hints
Hint 1
Three lines for the output: sub, div, clamp.
Hint 2
Catch NaN: snan missing press, then select flow missing 0 flow.
Hint 3
Finally sgtz on flow – only after the NaN guard.