succd: tristate pirani safety detection

This commit is contained in:
Serge Bazanski 2024-09-28 07:31:06 +02:00
parent 85d2afbdd0
commit 80f482b732

View file

@ -123,7 +123,10 @@ func (d *daemon) processOnce(_ context.Context) error {
d.aboveRough.process(float64(mbar))
d.aboveHigh.process(float64(mbar))
if d.piraniWireBreakDetection() {
// Check if the pirani gauge is disconnected. Note: this will assume the
// pirani gauge is connected for the first couple of processing runs as
// samples are still being captured.
if d.piraniDetection() == piraniDetectionDisconnected {
// Unrealistic result, Pirani probe probably disconnected. Failsafe mode.
if !d.failsafe {
d.failsafe = true
@ -191,9 +194,24 @@ func (d *daemon) processOnce(_ context.Context) error {
return nil
}
func (d *daemon) piraniWireBreakDetection() bool {
type piraniDetection uint
const (
// piraniDetectionUnknown means the system isn't yet sure whether the pirani
// gauge is connected.
piraniDetectionUnknown piraniDetection = iota
// piraniDetectionConnected means the system assumes the pirani gauge is
// connected.
piraniDetectionConnected = iota
// piraniDetectionDisconnected means the system assumes the pirani gauge is
// disconnected.
piraniDetectionDisconnected = iota
)
// piraniDetection guesses whether the pirani gauge is connected.
func (d *daemon) piraniDetection() piraniDetection {
if len(d.adcPiraniVolts) < 3 {
return true
return piraniDetectionUnknown
}
volts := float32(0.0)
for _, v := range d.adcPiraniVolts[len(d.adcPiraniVolts)-3:] {
@ -204,7 +222,10 @@ func (d *daemon) piraniWireBreakDetection() bool {
bar := math.Pow(10.0, float64(volts)-8.5)
mbar := float32(bar * 1000.0)
return mbar < 4e-6
if mbar < 4e-6 {
return piraniDetectionDisconnected
}
return piraniDetectionConnected
}
// pirani returns the Pirani gauge voltage and pressure.
@ -267,11 +288,11 @@ func (d *daemon) vacuumStatusGet() (rough, high bool) {
}
func (d *daemon) safetyStatusGet() (failsafe, highPressure bool) {
d.mu.RLock()
defer d.mu.RUnlock()
failsafe = d.failsafe
highPressure = d.highPressure
return
d.mu.RLock()
defer d.mu.RUnlock()
failsafe = d.failsafe
highPressure = d.highPressure
return
}
// pumpDownPressed toggles the pump down relay for 500ms.