Integrates existing soaring instruments with the soaring sdk
All reviewed aircraft now support total energy compensated variometers and reuse a common implementation. The following issues have been addressed, either explicitly or as a benefit from the integration: + Fixed incorrect variometer readouts at sim/speed-up values != 1 + Fixed erratic instrument behavior after pause and reinit + Reworked all vario needle animations to be smoother. + Fixed ASK13 yaw string. Now it deflects to the correct side. + Added temperature and (fake) battery readings to ILEC SC7 digital variometer. + Fixed ILEC SC7 sign readout (didn't show the minus sign). Note: The ASK21 models have not been integrated, as they will need a more profound cockpit overhaul.
This commit is contained in:
parent
db995cc8ee
commit
ff071bd858
2 changed files with 238 additions and 267 deletions
|
@ -1,102 +1,73 @@
|
|||
io.include("Aircraft/Generic/soaring-instrumentation-sdk.nas");
|
||||
|
||||
var debug_enabled = 0;
|
||||
|
||||
## helpers
|
||||
#
|
||||
var FT2M=0.30480;
|
||||
var KT2MPS=1852/3600;
|
||||
var square=func(x) return x*x;
|
||||
var get_delta=func (current,previous) {return (current-previous);}
|
||||
var state = {new:func {return{parents:[state]};},altitude_m:0,airspeed_mps:0,timestamp:0,te_read:0};
|
||||
var samples = []; setsize(samples, 30);
|
||||
var te_needle =0;
|
||||
|
||||
setprop("/instrumentation/ilec-sc7/te-reading-mps",0);
|
||||
# Initialize exported properties
|
||||
setprop("/instrumentation/ilec-sc7/volume", 0.8);
|
||||
setprop("/instrumentation/ilec-sc7/audio", 2);
|
||||
setprop("/instrumentation/ilec-sc7/mode", 1);
|
||||
setprop("/instrumentation/ilec-sc7/sensitivity",1);
|
||||
setprop("/instrumentation/ilec-sc7/filter",0.05);
|
||||
setprop("/instrumentation/ilec-sc7/sensitivity", 3);
|
||||
setprop("/instrumentation/ilec-sc7/lcd-digits-abs", 0);
|
||||
setprop("/instrumentation/ilec-sc7/lcd-digits-sgn", 0);
|
||||
setprop("/instrumentation/ilec-sc7/te-reading-mps", 0);
|
||||
setprop("/instrumentation/variometer/te-reading-mps", 0);
|
||||
|
||||
var update_state = func {
|
||||
var s = state.new();
|
||||
s.altitude_m=getprop("/position/altitude-ft")*FT2M;
|
||||
s.airspeed_mps=getprop("/velocities/airspeed-kt")*KT2MPS;
|
||||
s.timestamp=systime();
|
||||
return s;
|
||||
}
|
||||
|
||||
var push30 = func {
|
||||
var i = 0;
|
||||
while ( i < 30 ) {
|
||||
samples[i]=0;
|
||||
i += 1;
|
||||
};
|
||||
}
|
||||
|
||||
##
|
||||
# debug info
|
||||
var s_dump = func(s) {
|
||||
print(s.timestamp," ", s.altitude_m, " ", s.airspeed_mps);
|
||||
}
|
||||
|
||||
var averager = func {
|
||||
var sum = 0 ;
|
||||
var i = 0;
|
||||
while ( i < 29 ) {
|
||||
samples[i] = samples[i+1]; # shift everything to the "left"
|
||||
i += 1;
|
||||
};
|
||||
samples[29] = te_needle; # and set last sample to current
|
||||
i = 0;
|
||||
while ( i < 30 ) {
|
||||
sum = sum + samples[i];
|
||||
i += 1;
|
||||
};
|
||||
var average30 = sum / 30;
|
||||
setprop("/instrumentation/ilec-sc7/average",math.abs(average30));
|
||||
setprop("/instrumentation/ilec-sc7/average-sign",math.sgn(average30));
|
||||
if (debug_enabled) print (" average ",average30);
|
||||
settimer(averager, 1); # update rate
|
||||
}
|
||||
|
||||
|
||||
var tvario = {
|
||||
new: func {return {parents:[tvario]};},
|
||||
state:{previous:,current:},
|
||||
init: func {state.previous=state.new(); state.current=state.new();},
|
||||
update:func {
|
||||
if (debug_enabled) print("\nUpdating TEV:");
|
||||
state.current = update_state();
|
||||
if (debug_enabled) {
|
||||
s_dump(state.current);
|
||||
s_dump(state.previous);
|
||||
}
|
||||
var delta_t = get_delta(state.current.timestamp, state.previous.timestamp);
|
||||
# TE reading = (h2-h1)/t + (v2^2 - v1^2) / 19.62*t
|
||||
if (debug_enabled) print("delta_t:",delta_t);
|
||||
var uncompensated = get_delta(state.current.altitude_m,state.previous.altitude_m) / delta_t;
|
||||
if (debug_enabled) print(" uncompensated:",uncompensated);
|
||||
var adjustment = get_delta(square(state.current.airspeed_mps),square(state.previous.airspeed_mps)) / (19.62 * delta_t);
|
||||
if (debug_enabled) print(" adjustment:",adjustment,"\n");
|
||||
var te_reading = uncompensated + adjustment;
|
||||
if (debug_enabled) print (" te_reading:",te_reading);
|
||||
|
||||
te_needle = getprop("/instrumentation/ilec-sc7/te-reading-mps");
|
||||
var filter = 0.01 + 0.02 * getprop("/instrumentation/ilec-sc7/sensitivity");
|
||||
setprop("/instrumentation/ilec-sc7/filter",filter);
|
||||
|
||||
te_needle = te_needle * (1-filter) + filter * te_reading;
|
||||
setprop("/instrumentation/ilec-sc7/te-reading-mps",te_needle);
|
||||
setprop("/instrumentation/ilec-sc7/te-reading-neg",-te_needle);
|
||||
state.previous = state.current; # save current state for next call
|
||||
settimer(func me.update(), 1/20); # update rate
|
||||
}
|
||||
# Helper function for updating lcd display
|
||||
var update_lcd_props = func(value) {
|
||||
setprop("/instrumentation/ilec-sc7/lcd-digits-abs", math.abs(value));
|
||||
setprop("/instrumentation/ilec-sc7/lcd-digits-sgn", (value < 0) ? 0 : 1);
|
||||
};
|
||||
|
||||
var tv = tvario.new();
|
||||
tv.init();
|
||||
tv.update();
|
||||
push30();
|
||||
averager();
|
||||
# Instrument setup:
|
||||
|
||||
# One TE probe feeds two vario needles and a 25s averager.
|
||||
# LCD digits are controlled by the.. um.. lcd_controller
|
||||
# that switches between battery level, temperature and averager
|
||||
# depending on mode switch posiion.
|
||||
|
||||
# Why a second needle? A digital vario is usually installed together
|
||||
# with a mechanical one, so now we are at it, why not provide a bonus
|
||||
# TE reading for it and avoid loading an extra script?
|
||||
|
||||
var probe = TotalEnergyProbe.new();
|
||||
|
||||
var sc7_needle = Dampener.new(
|
||||
input: probe,
|
||||
dampening: 3,
|
||||
on_update: update_prop("/instrumentation/ilec-sc7/te-reading-mps"));
|
||||
|
||||
var extra_needle = Dampener.new(
|
||||
input: probe,
|
||||
dampening: 2.7,
|
||||
on_update: update_prop("/instrumentation/variometer/te-reading-mps"));
|
||||
|
||||
var averager = Averager.new(
|
||||
input: probe,
|
||||
buffer_size: 25);
|
||||
|
||||
var battery_level = { output: 9.9 };
|
||||
|
||||
var temperature = PropertyReader.new(
|
||||
property: "environment/temperature-degc",
|
||||
scale: 0.1);
|
||||
|
||||
var lcd_controller = InputSwitcher.new(
|
||||
inputs: [battery_level, averager, temperature],
|
||||
active_input: 1,
|
||||
on_update: update_lcd_props);
|
||||
|
||||
# Subscribe property listeners for instrument switches
|
||||
setlistener("instrumentation/ilec-sc7/mode",
|
||||
func(n) { lcd_controller.select_input(n.getValue()) }, 0, 0);
|
||||
|
||||
setlistener("instrumentation/ilec-sc7/sensitivity",
|
||||
func(n) { sc7_needle.dampening = n.getValue() }, 0, 0);
|
||||
|
||||
# Wrap everything together into an instrument
|
||||
var fast_instruments = Instrument.new(
|
||||
update_period: 0,
|
||||
components: [probe, sc7_needle, extra_needle],
|
||||
enable: 1);
|
||||
|
||||
var slow_instruments = Instrument.new(
|
||||
update_period: 1,
|
||||
components: [averager, temperature, lcd_controller],
|
||||
enable: 1);
|
||||
|
|
|
@ -274,8 +274,8 @@
|
|||
<object-name>sens-switch</object-name>
|
||||
<property>instrumentation/ilec-sc7/sensitivity</property>
|
||||
<interpolation>
|
||||
<entry><ind>0</ind><dep>-30</dep></entry>
|
||||
<entry><ind>1.0</ind><dep>30</dep></entry>
|
||||
<entry><ind>1</ind><dep>30</dep></entry>
|
||||
<entry><ind>3</ind><dep>-30</dep></entry>
|
||||
</interpolation>
|
||||
<center>
|
||||
<x-m>0.001</x-m>
|
||||
|
@ -291,15 +291,15 @@
|
|||
|
||||
<animation>
|
||||
<type>pick</type>
|
||||
<object-name>incr-sens</object-name>
|
||||
<object-name>decr-sens</object-name>
|
||||
<action>
|
||||
<button>0</button>
|
||||
<binding>
|
||||
<command>property-adjust</command>
|
||||
<property>instrumentation/ilec-sc7/sensitivity</property>
|
||||
<step>1</step>
|
||||
<min>0</min>
|
||||
<max>1</max>
|
||||
<step>3</step>
|
||||
<min>1</min>
|
||||
<max>3</max>
|
||||
<wrap>false</wrap>
|
||||
</binding>
|
||||
</action>
|
||||
|
@ -307,15 +307,15 @@
|
|||
|
||||
<animation>
|
||||
<type>pick</type>
|
||||
<object-name>decr-sens</object-name>
|
||||
<object-name>incr-sens</object-name>
|
||||
<action>
|
||||
<button>0</button>
|
||||
<binding>
|
||||
<command>property-adjust</command>
|
||||
<property>instrumentation/ilec-sc7/sensitivity</property>
|
||||
<step>-1</step>
|
||||
<min>0</min>
|
||||
<max>1</max>
|
||||
<step>-3</step>
|
||||
<min>1</min>
|
||||
<max>3</max>
|
||||
<wrap>false</wrap>
|
||||
</binding>
|
||||
</action>
|
||||
|
@ -326,7 +326,7 @@
|
|||
<animation>
|
||||
<type>textranslate</type>
|
||||
<object-name>decimals-digit</object-name>
|
||||
<property>instrumentation/ilec-sc7/average</property>
|
||||
<property>instrumentation/ilec-sc7/lcd-digits-abs</property>
|
||||
<factor>1</factor>
|
||||
<step>0.1</step>
|
||||
<bias>0.005</bias>
|
||||
|
@ -340,7 +340,7 @@
|
|||
<animation>
|
||||
<type>textranslate</type>
|
||||
<object-name>units-digit</object-name>
|
||||
<property>instrumentation/ilec-sc7/average</property>
|
||||
<property>instrumentation/ilec-sc7/lcd-digits-abs</property>
|
||||
<factor>0.1</factor>
|
||||
<step>1</step>
|
||||
<bias>0.005</bias>
|
||||
|
@ -354,7 +354,7 @@
|
|||
<animation>
|
||||
<type>textranslate</type>
|
||||
<object-name>sign-digit</object-name>
|
||||
<property>instrumentation/ilec-sc7/average-sign</property>
|
||||
<property>instrumentation/ilec-sc7/lcd-digits-sgn</property>
|
||||
<factor>0.1</factor>
|
||||
<step>1</step>
|
||||
<bias>0.005</bias>
|
||||
|
|
Loading…
Reference in a new issue