succd: check currentmost pirani values for safety lock

This commit is contained in:
zdmx 2024-09-27 23:24:55 +02:00
parent 9db2213fa6
commit 7a64ce91d4

View file

@ -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.