diff --git a/succbone/succd/index.html b/succbone/succd/index.html index a26db5d..6be0c1d 100644 --- a/succbone/succd/index.html +++ b/succbone/succd/index.html @@ -5,12 +5,11 @@ @@ -59,19 +68,7 @@ td > span {

succd

nothing more permanent than a temporary solution

-

- - - - - - - - - - -
Pirani GaugeVoltage{{ .Pirani.Volts }}
Pressure{{ .Pirani.Mbar }}
- +

@@ -96,6 +93,19 @@ td > span {
Thresholds
+ + + + + + + + + + +
Pirani GaugeVoltage{{ .Pirani.Volts }}
Pressure{{ .Pirani.Mbar }}
+ + @@ -122,13 +132,14 @@ td > span { - +
ControlStatus OK Load......
-

-

- -

+ +

+ +

+

{{ .System.Hostname }} | load: {{ .System.Load }} | pprof | metrics | ws ping: diff --git a/succbone/succd/main.go b/succbone/succd/main.go index 23427b6..4a39d11 100644 --- a/succbone/succd/main.go +++ b/succbone/succd/main.go @@ -11,17 +11,21 @@ import ( ) var ( - flagFake bool - flagListenHTTP string - flagPressureThresholdRough = ScientificNotationValue(1e-1) - flagPressureThresholdHigh = ScientificNotationValue(1e-4) + flagFake bool + flagListenHTTP string + flagPressureThresholdRough = ScientificNotationValue(1e-1) + flagPressureThresholdRoughHysteresis = ScientificNotationValue(2e-2) + flagPressureThresholdHigh = ScientificNotationValue(1e-4) + flagPressureThresholdHighHysteresis = ScientificNotationValue(2e-5) ) func main() { flag.BoolVar(&flagFake, "fake", false, "Enable fake mode which allows to run succd for tests outside the succbone") flag.StringVar(&flagListenHTTP, "listen_http", ":8080", "Address at which to listen for HTTP requests") flag.TextVar(&flagPressureThresholdRough, "pressure_threshold_rough", &flagPressureThresholdRough, "Threshold for opening up diffusion pump (mbar)") + flag.TextVar(&flagPressureThresholdRoughHysteresis, "pressure_threshold_rough_hysteresis", &flagPressureThresholdRoughHysteresis, "+-Hysteresis for rough threshold (mbar)") flag.TextVar(&flagPressureThresholdHigh, "pressure_threshold_high", &flagPressureThresholdHigh, "Threshold for enabling high voltage circuits (mbar)") + flag.TextVar(&flagPressureThresholdHighHysteresis, "pressure_threshold_high_hysteresis", &flagPressureThresholdHighHysteresis, "+-Hysteresis for high threshold (mbar)") flag.Parse() ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt) @@ -32,7 +36,9 @@ func main() { d.daemonState.piraniVolts100.limit = 100 d.aboveRough.threshold = float64(flagPressureThresholdRough) + d.aboveRough.hysteresis = float64(flagPressureThresholdRoughHysteresis) d.aboveHigh.threshold = float64(flagPressureThresholdHigh) + d.aboveHigh.hysteresis = float64(flagPressureThresholdHighHysteresis) if flagFake { klog.Infof("Starting with fake peripherals") d.adcPirani = &fakeADC{} diff --git a/succbone/succd/process_blocks.go b/succbone/succd/process_blocks.go index 0b37193..ae1294d 100644 --- a/succbone/succd/process_blocks.go +++ b/succbone/succd/process_blocks.go @@ -30,13 +30,20 @@ type thresholdOutput struct { debounce time.Time // threshold is the setpoint of the block. threshold float64 + // hysteresis around the process setpoint (min/max is threshold +- hysteresis) + hysteresis float64 } func (t *thresholdOutput) process(value float64) { if time.Now().Before(t.debounce) { return } - new := value > t.threshold + new := t.output + if t.output { + new = value > (t.threshold - t.hysteresis) + } else { + new = value > (t.threshold + t.hysteresis) + } if new != t.output { t.output = new t.debounce = time.Now().Add(time.Second * 5) diff --git a/succbone/succd/process_blocks_test.go b/succbone/succd/process_blocks_test.go index 4dd028c..24b75f6 100644 --- a/succbone/succd/process_blocks_test.go +++ b/succbone/succd/process_blocks_test.go @@ -26,20 +26,37 @@ func TestMomentaryOutput(t *testing.T) { func TestThresholdOutput(t *testing.T) { to := thresholdOutput{ - threshold: 1, + threshold: 1, + hysteresis: 0.2, } - to.process(0) + to.process(0.7) if to.output { t.Fatalf("output shouldn't have triggered") } - to.process(2) + to.process(1) + if to.output { + t.Fatalf("output shouldn't have triggered") + } + to.process(1.3) if !to.output { t.Fatalf("output should have triggered") } - to.process(0) + to.process(1) + if !to.output { + t.Fatalf("output should have triggered") + } + to.process(0.7) if !to.output { t.Fatalf("output should have triggered (in debounce)") } + + // let debounce timeout pass + time.Sleep(time.Second * 6) + + to.process(0.7) + if to.output { + t.Fatalf("output shouldn't have triggered") + } } func TestRingbufferInput(t *testing.T) {