diff --git a/Orbitersdk/samples/ProjectApollo/src_sys/toggleswitch.cpp b/Orbitersdk/samples/ProjectApollo/src_sys/toggleswitch.cpp index 86bc5b0a8..27c2ca72e 100644 --- a/Orbitersdk/samples/ProjectApollo/src_sys/toggleswitch.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_sys/toggleswitch.cpp @@ -3817,7 +3817,11 @@ double MeterSwitch::GetDisplayValue() { double dt = oapiGetSimTime() - lastDrawTime; // oapiGetSimTime() - lastDrawTime; if (dt > 0) { if (fabs(value - displayValue) / dt > (maxValue - minValue) / minMaxTime) { - displayValue += ((value - displayValue) / fabs(value - displayValue)) * (maxValue - minValue) / minMaxTime * dt; + // discrete time LPF where y[n] = y[n-1]*(1-a) + x[n]*a + // assumed that 5tau is minMaxTime, i.e. time to reach 99.3% of a step input. + // therefore 1/tau is (5/minMaxTime) for each slice {dt}. + double filtConstant = max(min(GAUGE_LPF_SCALAR * dt * 5.0/minMaxTime, 1.0),0.0); + displayValue = displayValue*(1-filtConstant) + (value*filtConstant); } else { displayValue = value; } diff --git a/Orbitersdk/samples/ProjectApollo/src_sys/toggleswitch.h b/Orbitersdk/samples/ProjectApollo/src_sys/toggleswitch.h index 4600c0115..373f2e858 100644 --- a/Orbitersdk/samples/ProjectApollo/src_sys/toggleswitch.h +++ b/Orbitersdk/samples/ProjectApollo/src_sys/toggleswitch.h @@ -74,6 +74,9 @@ #define TIME_UPDATE_MINUTES 1 #define TIME_UPDATE_HOURS 2 +// Lowpass filter for gauges assumes 5tau ~~ minMaxTime. All 5tau components can be globally scaled by GAUGE_LPF_SCALAR if relationship does not hold well. (higher->faster) +#define GAUGE_LPF_SCALAR 1.0 + class SwitchRow; class PanelSwitchScenarioHandler; class PanelSwitchCallbackInterface;