Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change slewed gauge display to low-pass filtered gauge display. #1315

Open
wants to merge 1 commit into
base: Orbiter2016
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Orbitersdk/samples/ProjectApollo/src_sys/toggleswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_sys/toggleswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down