Change gas_valve handling to a three-way "mode"
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 25 Nov 2024 13:24:17 +0000 (14:24 +0100)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 25 Nov 2024 13:24:17 +0000 (14:24 +0100)
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

index c1f485314dc78d62fb3acbb93021c637fe80f324..01787b6bbaa8305cb214bae198e57f3028e00fe7 100644 (file)
@@ -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();