Implement a basic sequence for a measurement
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 25 Nov 2024 11:02:26 +0000 (12:02 +0100)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 25 Nov 2024 11:02:26 +0000 (12:02 +0100)
Servomatic.ino

index 7acfbd1af88141fffed7d849846ee02e2ce30bd1..c1f485314dc78d62fb3acbb93021c637fe80f324 100644 (file)
@@ -9,29 +9,79 @@ static const int      PRESSURE_SENSOR1_PIN = A1;
 static const int       PRESSURE_SENSOR2_PIN = A2;
 static const int       PRESSURE_SENSOR3_PIN = A3;
 
-static const int       SWITCH_PIN = 2; // Only pins 2; 3 have external interrupts
+static const int       SWITCH_PIN = 2; // Only pins 2; 3 have external interrupts?
 
-static const int       THREEWAY_VALVE_PIN = 9;
+static const int       GAS_VALVE_PIN = 9;
 static const int       CELL_VALVE_PIN = 10;
 static const int       PRESSURE_SENSOR_VALVE_PIN = 11;
 static const int       VACUUM_VALVE_PIN = 12;
 
+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 float     MEASUREMENT_UPPER_LIMIT = 8;
+static const float     MEASUREMENT_LOWER_LIMIT = 0.5;
+
 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_threeway_valve{THREEWAY_VALVE_PIN, 760, 2400};
+       Valve                   gas_valve{GAS_VALVE_PIN, 760, 2400};
 
        while (1)
        {
                while (!interrupt_happened && digitalRead(SWITCH_PIN) == HIGH)
                {
-                       if (measurement.wait_for_equilibrium())
-                               break ;
-                       // Operate valves to prepare for next jump.
+                       // aparature initialization - valve positioning, evacuation
+                       cell_valve.open_barely();
+                       vacuum_valve.open();
+                       delay(CELL_BARELY_OPEN_EQUILIBRATION_MS);
+                       cell_valve.open();
+                       cell_valve.close_open_clean();
+                       vacuum_valve.close_open_clean();
+                       interruptable_delay(EVACUATION_LONG_MS);
+                       vacuum_valve.close();
+                       cell_valve.close();
+                       while (!interrupt_happened
+                                       && sensor_1.get_pressure() < MEASUREMENT_UPPER_LIMIT)
+                       {
+                               // absorption cycle
+                               gas_valve.open();
+                               gas_valve.close_open_clean();
+                               gas_valve.close();
+                               cell_valve.open_barely();
+                               delay(CELL_BARELY_OPEN_EQUILIBRATION_MS);
+                               cell_valve.open();
+                               measurement.get_measurement();
+                               cell_valve.close_open_clean();
+                               measurement.wait_for_equilibrium(0.01);
+                               measurement.clear();
+                               cell_valve.close();
+                       }
+                       while (!interrupt_happened
+                                       && sensor_1.get_pressure() > MEASUREMENT_LOWER_LIMIT)
+                       {
+                               // desorption cycle
+                               vacuum_valve.open();
+                               vacuum_valve.close_open_clean();
+                               interruptable_delay(EVACUATION_MS);
+                               vacuum_valve.close();
+                               cell_valve.open_barely();
+                               delay(CELL_BARELY_OPEN_EQUILIBRATION_MS);
+                               cell_valve.open();
+                               measurement.get_measurement();
+                               cell_valve.close_open_clean();
+                               measurement.wait_for_equilibrium(0.01);
+                               measurement.clear();
+                               cell_valve.close();
+                       }
                }
+               vacuum_valve.open();
+               cell_valve.open_barely();
+               delay(CELL_BARELY_OPEN_EQUILIBRATION_MS);
                signal_going_to_sleep();
                sleep();
                interrupt_happened = 0;