From d05146c2a9f4e5b7a85cff28f5c4a8448bbaf639 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 12:02:26 +0100 Subject: [PATCH] Implement a basic sequence for a measurement --- Servomatic.ino | 62 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/Servomatic.ino b/Servomatic.ino index 7acfbd1..c1f4853 100644 --- a/Servomatic.ino +++ b/Servomatic.ino @@ -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; -- 2.30.2