succd: calcuate change rate for safety interlock directly from adc ringbuffer
This commit is contained in:
parent
d3391b28ec
commit
9ad6ce7dad
|
@ -31,7 +31,6 @@ func main() {
|
|||
}
|
||||
d.aboveRough.threshold = float64(flagPressureThresholdRough)
|
||||
d.aboveHigh.threshold = float64(flagPressureThresholdHigh)
|
||||
d.lastPressures = newRingbuffer()
|
||||
if flagFake {
|
||||
klog.Infof("Starting with fake peripherals")
|
||||
d.adcPirani = &fakeADC{}
|
||||
|
|
|
@ -17,8 +17,6 @@ type daemon struct {
|
|||
// Pirani gauge.
|
||||
adcPirani adc
|
||||
|
||||
lastPressures ringbuffer
|
||||
|
||||
failsafe bool
|
||||
highPressure bool
|
||||
|
||||
|
@ -125,10 +123,8 @@ func (d *daemon) processOnce(_ context.Context) error {
|
|||
d.aboveRough.process(float64(mbar))
|
||||
d.aboveHigh.process(float64(mbar))
|
||||
|
||||
d.lastPressures.AddValue(mbar)
|
||||
|
||||
// max rate of 1.0 in 500 ms because ringbuffer holds 5 values
|
||||
if d.lastPressures.MaxMinDiff() > 1.0 {
|
||||
if d.piraniRateOfChange() > 2.0 {
|
||||
if !d.failsafe {
|
||||
d.failsafe = true
|
||||
klog.Errorf("Pressure changed too fast; entering failsafe mode")
|
||||
|
@ -199,6 +195,25 @@ 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
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
||||
return max_mbar - min_mbar
|
||||
}
|
||||
|
||||
// pirani returns the Pirani gauge voltage and pressure.
|
||||
func (d *daemon) pirani() (volts float32, mbar float32) {
|
||||
d.mu.RLock()
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package main
|
||||
|
||||
type ringbuffer struct {
|
||||
data []float32
|
||||
idx int
|
||||
}
|
||||
|
||||
func newRingbuffer() ringbuffer {
|
||||
return ringbuffer {
|
||||
data: make([]float32, 5),
|
||||
idx: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (rb *ringbuffer) AddValue(value float32) {
|
||||
rb.data[rb.idx] = value;
|
||||
rb.idx = (rb.idx + 1) % len(rb.data)
|
||||
}
|
||||
|
||||
func (rb *ringbuffer) MaxMinDiff() float32 {
|
||||
min := rb.data[0]
|
||||
max := rb.data[0]
|
||||
|
||||
for _, val := range rb.data {
|
||||
if val < min {
|
||||
min = val
|
||||
}
|
||||
if val > max {
|
||||
max = val
|
||||
}
|
||||
}
|
||||
|
||||
return max - min
|
||||
}
|
Loading…
Reference in a new issue