Set proper values for valves, remove CellValve
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Wed, 4 Dec 2024 10:31:52 +0000 (11:31 +0100)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Wed, 4 Dec 2024 10:38:21 +0000 (11:38 +0100)
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 [deleted file]
CellValve.ino [deleted file]
Makefile
Servomatic.ino
Valve.h
Valve.ino

diff --git a/CellValve.h b/CellValve.h
deleted file mode 100644 (file)
index 0e71379..0000000
+++ /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 (file)
index cdd69e5..0000000
+++ /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);
-}
index cdf5fb4ba3795c70fc35f4611257c9dc0e092c23..4c4718d12a5b8d4070958241b794005532778df8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,6 @@ endif
 SRCS :=        Servomatic.ino          \
                PressureSensor.ino      \
                Valve.ino                       \
-               CellValve.ino           \
                Measurement.ino         \
                helpers.ino                     \
 
index 2e79d28f201cc6b9b89981c57c57bfc876ea7c2c..d4347a4dcd6b160c7077d9a8dc5e146bec6a4f54 100644 (file)
@@ -1,7 +1,6 @@
 #include "helpers.h"
 #include "PressureSensor.h"
 #include "Valve.h"
-#include "CellValve.h"
 #include "Measurement.h"
 #include <avr/sleep.h>
 
@@ -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 07051f19eedc5f316dcd9d2c0baf7b76c1792d71..8ce5c1035d000aa08c0aa0451dd2afd11a8b601e 100644 (file)
--- 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);
 };
index 35e729dc8dd7595291ed02d130ab25671a91f197..1bcb612d9eb4f54507d09d266877446cf4c001cd 100644 (file)
--- 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);