From c6ef4ea110e9a8d06a850460b08c6c80ab3cad04 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Ji=C5=99i=C5=A1t=C4=9B?= Date: Wed, 4 Dec 2024 11:31:52 +0100 Subject: [PATCH] Set proper values for valves, remove CellValve The CellValve is not needed as a separate class, so its only functionality is absorbed into the Valve class. This is because my colleague wanted to have the barely open position for the vacuum valve also and the three-way valve has a closed position in between so the convention for it is changed and also uses the barely-open argument. The values for the servos of the valves were measured and so are filled in the executable. --- CellValve.h | 23 ----------------------- CellValve.ino | 17 ----------------- Makefile | 1 - Servomatic.ino | 30 ++++++++++++++++++------------ Valve.h | 5 ++++- Valve.ino | 9 ++++++++- 6 files changed, 30 insertions(+), 55 deletions(-) delete mode 100644 CellValve.h delete mode 100644 CellValve.ino diff --git a/CellValve.h b/CellValve.h deleted file mode 100644 index 0e71379..0000000 --- a/CellValve.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef CELLVALVE_H -# define CELLVALVE_H - -#include "Valve.h" - -class CellValve : public Valve -{ - private: - const int m_usec_barely_opened; - - public: - CellValve() = delete; - CellValve(const CellValve &other) = delete; - CellValve(pin control_pin, int usec_opened, int usec_barely_opened, - int isec_closed); - ~CellValve(); - - CellValve &operator=(const CellValve &other) = delete; - - void open_barely(float seconds = 5); -}; - -#endif // CELLVALVE_H diff --git a/CellValve.ino b/CellValve.ino deleted file mode 100644 index cdd69e5..0000000 --- a/CellValve.ino +++ /dev/null @@ -1,17 +0,0 @@ -#include "CellValve.h" - -CellValve::CellValve(pin control_pin, int usec_opened, int usec_barely_opened, - int usec_closed) - : Valve{control_pin, usec_opened, usec_closed} - , m_usec_barely_opened{usec_barely_opened} -{ -} - -CellValve::~CellValve() -{ -} - -void CellValve::open_barely(float seconds) -{ - write_usec_timed(m_usec_barely_opened, seconds); -} diff --git a/Makefile b/Makefile index cdf5fb4..4c4718d 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,6 @@ endif SRCS := Servomatic.ino \ PressureSensor.ino \ Valve.ino \ - CellValve.ino \ Measurement.ino \ helpers.ino \ diff --git a/Servomatic.ino b/Servomatic.ino index 2e79d28..d4347a4 100644 --- a/Servomatic.ino +++ b/Servomatic.ino @@ -1,7 +1,6 @@ #include "helpers.h" #include "PressureSensor.h" #include "Valve.h" -#include "CellValve.h" #include "Measurement.h" #include @@ -16,11 +15,11 @@ static constexpr int CELL_VALVE_PIN = 10; static constexpr int PRESSURE_SENSOR_VALVE_PIN = 11; static constexpr int VACUUM_VALVE_PIN = 12; -static constexpr unsigned long CELL_BARELY_OPEN_EQUILIBRATION_MS = 10000; +static constexpr unsigned long CELL_BARELY_OPEN_EQUILIBRATION_MS = 30000; static constexpr unsigned long EVACUATION_LONG_MS = 600000; static constexpr unsigned long EVACUATION_MS = 60000; -static constexpr unsigned int THREEWAY_TURNS_TO_FILL = 3; +static constexpr unsigned int THREEWAY_TURNS_TO_FILL = 1; static constexpr float MEASUREMENT_UPPER_LIMIT = 8; static constexpr float MEASUREMENT_LOWER_LIMIT = 0.5; @@ -29,7 +28,7 @@ void threeway_fill(Valve &threeway_valve, unsigned int count) { while (count > 0) { - threeway_valve.close(); + threeway_valve.open_barely(); threeway_valve.open(); --count; } @@ -37,18 +36,21 @@ void threeway_fill(Valve &threeway_valve, unsigned int count) } // The gas valve needs special treatment, because it is threeway. -// Let's say open means cell-side and closed means gas-side +// Let's say open means cell-side, closed means closed and barely open means +// gas-side void main_loop() { - PressureSensor sensor_1{PRESSURE_SENSOR1_PIN, 10}; + PressureSensor sensor_1{PRESSURE_SENSOR1_PIN, 10, 242}; + //PressureSensor sensor_2{PRESSURE_SENSOR2_PIN, 10, 241}; + //PressureSensor sensor_3{PRESSURE_SENSOR3_PIN, 10, 241}; 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{GAS_VALVE_PIN, 760, 2400}; + Valve vacuum_valve{VACUUM_VALVE_PIN, 2295, 1494, 802}; + Valve cell_valve{CELL_VALVE_PIN, 2000, 1535, 1276}; + Valve gas_threeway_valve{GAS_VALVE_PIN, 1301, 1641, 2036}; vacuum_valve.close(); cell_valve.close(); - gas_threeway_valve.open(); + gas_threeway_valve.close(); while (1) { if (!interrupt_happened && digitalRead(SWITCH_PIN) == HIGH) @@ -73,7 +75,7 @@ void main_loop() cell_valve.open_barely(); delay(CELL_BARELY_OPEN_EQUILIBRATION_MS); cell_valve.open(); - measurement.wait_for_equilibrium(0.01); + measurement.wait_for_equilibrium(0.05); measurement.clear(); cell_valve.close(); } @@ -88,14 +90,18 @@ void main_loop() cell_valve.open_barely(); delay(CELL_BARELY_OPEN_EQUILIBRATION_MS); cell_valve.open(); - measurement.wait_for_equilibrium(0.01); + measurement.wait_for_equilibrium(0.05); measurement.clear(); cell_valve.close(); } } vacuum_valve.open(); + gas_threeway_valve.open(); cell_valve.open_barely(); delay(CELL_BARELY_OPEN_EQUILIBRATION_MS); + cell_valve.open(); + delay(10000); + vacuum_valve.close(); signal_going_to_sleep(); sleep(); interrupt_happened = 0; diff --git a/Valve.h b/Valve.h index 07051f1..8ce5c10 100644 --- a/Valve.h +++ b/Valve.h @@ -8,6 +8,7 @@ class Valve private: const Servo m_servo; const int m_usec_opened; + const int m_usec_barely_opened; const int m_usec_closed; int m_usec_current; @@ -21,12 +22,14 @@ class Valve public: Valve() = delete; Valve(const Valve &other) = delete; - Valve(pin control_pin, int usec_opened, int isec_closed); + Valve(pin control_pin, int usec_opened, int usec_barely_opened, + int isec_closed); ~Valve(); Valve &operator=(const Valve &other) = delete; void open(float seconds = 5); + void open_barely(float seconds = 5); void close(float seconds = 5); void close_open_clean(unsigned int count = 3); }; diff --git a/Valve.ino b/Valve.ino index 35e729d..1bcb612 100644 --- a/Valve.ino +++ b/Valve.ino @@ -1,8 +1,10 @@ #include "Valve.h" -Valve::Valve(pin control_pin, int usec_opened, int usec_closed) +Valve::Valve(pin control_pin, int usec_opened, int usec_barely_opened, + int usec_closed) : m_servo{} , m_usec_opened{usec_opened} + , m_usec_barely_opened{usec_barely_opened} , m_usec_closed{usec_closed} , m_usec_current{usec_closed} { @@ -51,6 +53,11 @@ void Valve::open(float seconds) write_usec_timed(m_usec_opened, seconds); } +void Valve::open_barely(float seconds) +{ + write_usec_timed(m_usec_barely_opened, seconds); +} + void Valve::close(float seconds) { write_usec_timed(m_usec_closed, seconds); -- 2.30.2