From 7a64ce91d4378f9d7a822a3da1a11b0e5138c9b3 Mon Sep 17 00:00:00 2001 From: zdmx Date: Fri, 27 Sep 2024 23:24:55 +0200 Subject: [PATCH] succd: check currentmost pirani values for safety lock --- succbone/succd/process.go | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/succbone/succd/process.go b/succbone/succd/process.go index f63748b..643d053 100644 --- a/succbone/succd/process.go +++ b/succbone/succd/process.go @@ -123,15 +123,7 @@ func (d *daemon) processOnce(_ context.Context) error { d.aboveRough.process(float64(mbar)) d.aboveHigh.process(float64(mbar)) - klog.Infof("rate of change: %f", d.piraniRateOfChange()) - - // max rate of 1.0 in 500 ms because ringbuffer holds 5 values - if d.piraniRateOfChange() > 2.0 { - if !d.failsafe { - d.failsafe = true - klog.Errorf("Pressure changed too fast; entering failsafe mode") - } - } else if mbar < 4e-6 { + if d.piraniWireBreakDetection() { // Unrealistic result, Pirani probe probably disconnected. Failsafe mode. if !d.failsafe { d.failsafe = true @@ -197,23 +189,20 @@ func (d *daemon) processOnce(_ context.Context) error { return nil } -func (d *daemon) piraniRateOfChange() float32 { - max := d.adcPiraniVolts[0] - min := d.adcPiraniVolts[0] - for _, val := range d.adcPiraniVolts { - if val < min { - min = val - } - if val > max { - max = val - } +func (d *daemon) piraniWireBreakDetection() bool { + if len(d.adcPiraniVolts) < 3 { + return true } - max_bar := math.Pow(10.0, float64(max)-8.5); - max_mbar := float32(max_bar * 1000.0) - min_bar := math.Pow(10.0, float64(min)-8.5); - min_mbar := float32(min_bar * 1000.0) + volts := float32(0.0) + for _, v := range d.adcPiraniVolts[len(d.adcPiraniVolts)-3:] { + volts += v + } + volts /= 3.0 - return max_mbar - min_mbar + bar := math.Pow(10.0, float64(volts)-8.5) + mbar := float32(bar * 1000.0) + + return mbar < 4e-6 } // pirani returns the Pirani gauge voltage and pressure.