From 0ffb85a1d83f48d92e6f1b9e49b6148a90d4d4d4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Ji=C5=99i=C5=A1t=C4=9B?= Date: Mon, 25 Nov 2024 14:24:17 +0100 Subject: [PATCH] Change gas_valve handling to a three-way "mode" It would probably be better to make a separate class for a three-way valve, but I think this may be more accessible and is not that bad. In the same way the fill function may not be very object oriented, but I think this is better left exposed for my colleagues. --- Servomatic.ino | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Servomatic.ino b/Servomatic.ino index c1f4853..01787b6 100644 --- a/Servomatic.ino +++ b/Servomatic.ino @@ -20,24 +20,43 @@ static const unsigned long CELL_BARELY_OPEN_EQUILIBRATION_MS = 10000; static const unsigned long EVACUATION_LONG_MS = 600000; static const unsigned long EVACUATION_MS = 60000; +static const unsigned int THREEWAY_TURNS_TO_FILL = 3; + static const float MEASUREMENT_UPPER_LIMIT = 8; static const float MEASUREMENT_LOWER_LIMIT = 0.5; +void threeway_fill(Valve &threeway_valve, unsigned int count) +{ + while (count > 0) + { + threeway_valve.close(); + threeway_valve.open(); + --count; + } + threeway_valve.close(); +} + +// The gas valve needs special treatment, because it is threeway. +// Let's say open means cell-side and closed means gas-side void main_loop() { PressureSensor sensor_1{PRESSURE_SENSOR1_PIN, 10}; Measurement measurement{sensor_1}; Valve vacuum_valve{VACUUM_VALVE_PIN, 760, 2400}; CellValve cell_valve{CELL_VALVE_PIN, 760, 1600, 2400}; - Valve gas_valve{GAS_VALVE_PIN, 760, 2400}; + Valve gas_threeway_valve{GAS_VALVE_PIN, 760, 2400}; + vacuum_valve.close(); + cell_valve.close(); + gas_threeway_valve.open(); while (1) { while (!interrupt_happened && digitalRead(SWITCH_PIN) == HIGH) { // aparature initialization - valve positioning, evacuation - cell_valve.open_barely(); vacuum_valve.open(); + gas_threeway_valve.open(); + cell_valve.open_barely(); delay(CELL_BARELY_OPEN_EQUILIBRATION_MS); cell_valve.open(); cell_valve.close_open_clean(); @@ -49,9 +68,7 @@ void main_loop() && sensor_1.get_pressure() < MEASUREMENT_UPPER_LIMIT) { // absorption cycle - gas_valve.open(); - gas_valve.close_open_clean(); - gas_valve.close(); + threeway_fill(gas_threeway_valve, THREEWAY_TURNS_TO_FILL); cell_valve.open_barely(); delay(CELL_BARELY_OPEN_EQUILIBRATION_MS); cell_valve.open(); -- 2.30.2