1
0
Fork 0

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:
Anton Gomez Alvedro 2013-11-04 14:13:22 +01:00 committed by Philosopher
parent db995cc8ee
commit ff071bd858
2 changed files with 238 additions and 267 deletions

View file

@ -1,102 +1,73 @@
io.include("Aircraft/Generic/soaring-instrumentation-sdk.nas");
var debug_enabled = 0; # Initialize exported properties
setprop("/instrumentation/ilec-sc7/volume", 0.8);
## helpers setprop("/instrumentation/ilec-sc7/audio", 2);
# setprop("/instrumentation/ilec-sc7/mode", 1);
var FT2M=0.30480; setprop("/instrumentation/ilec-sc7/sensitivity", 3);
var KT2MPS=1852/3600; setprop("/instrumentation/ilec-sc7/lcd-digits-abs", 0);
var square=func(x) return x*x; setprop("/instrumentation/ilec-sc7/lcd-digits-sgn", 0);
var get_delta=func (current,previous) {return (current-previous);} setprop("/instrumentation/ilec-sc7/te-reading-mps", 0);
var state = {new:func {return{parents:[state]};},altitude_m:0,airspeed_mps:0,timestamp:0,te_read:0}; setprop("/instrumentation/variometer/te-reading-mps", 0);
var samples = []; setsize(samples, 30);
var te_needle =0;
setprop("/instrumentation/ilec-sc7/te-reading-mps",0); # Helper function for updating lcd display
setprop("/instrumentation/ilec-sc7/volume",0.8); var update_lcd_props = func(value) {
setprop("/instrumentation/ilec-sc7/audio",2); setprop("/instrumentation/ilec-sc7/lcd-digits-abs", math.abs(value));
setprop("/instrumentation/ilec-sc7/mode",1); setprop("/instrumentation/ilec-sc7/lcd-digits-sgn", (value < 0) ? 0 : 1);
setprop("/instrumentation/ilec-sc7/sensitivity",1); };
setprop("/instrumentation/ilec-sc7/filter",0.05);
var update_state = func { # Instrument setup:
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 { # One TE probe feeds two vario needles and a 25s averager.
var i = 0; # LCD digits are controlled by the.. um.. lcd_controller
while ( i < 30 ) { # that switches between battery level, temperature and averager
samples[i]=0; # depending on mode switch posiion.
i += 1;
};
}
## # Why a second needle? A digital vario is usually installed together
# debug info # with a mechanical one, so now we are at it, why not provide a bonus
var s_dump = func(s) { # TE reading for it and avoid loading an extra script?
print(s.timestamp," ", s.altitude_m, " ", s.airspeed_mps);
}
var averager = func { var probe = TotalEnergyProbe.new();
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 = { var sc7_needle = Dampener.new(
new: func {return {parents:[tvario]};}, input: probe,
state:{previous:,current:}, dampening: 3,
init: func {state.previous=state.new(); state.current=state.new();}, on_update: update_prop("/instrumentation/ilec-sc7/te-reading-mps"));
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; var extra_needle = Dampener.new(
setprop("/instrumentation/ilec-sc7/te-reading-mps",te_needle); input: probe,
setprop("/instrumentation/ilec-sc7/te-reading-neg",-te_needle); dampening: 2.7,
state.previous = state.current; # save current state for next call on_update: update_prop("/instrumentation/variometer/te-reading-mps"));
settimer(func me.update(), 1/20); # update rate
}
};
var tv = tvario.new(); var averager = Averager.new(
tv.init(); input: probe,
tv.update(); buffer_size: 25);
push30();
averager(); 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);

View file

@ -11,7 +11,7 @@
<object-name>decimals-digit</object-name> <object-name>decimals-digit</object-name>
<object-name>units-digit</object-name> <object-name>units-digit</object-name>
<object-name>sign-digit</object-name> <object-name>sign-digit</object-name>
<object-name>dot-digit</object-name> <object-name>dot-digit</object-name>
<emission> <emission>
<red>0.028</red> <red>0.028</red>
<green>0.014</green> <green>0.014</green>
@ -19,14 +19,14 @@
<factor-prop>systems/electrical/outputs/instrument-lights</factor-prop> <factor-prop>systems/electrical/outputs/instrument-lights</factor-prop>
</emission> </emission>
</animation> </animation>
<!--needle--> <!--needle-->
<animation> <animation>
<type>rotate</type> <type>rotate</type>
<object-name>Needle</object-name> <object-name>Needle</object-name>
<property>/instrumentation/ilec-sc7/te-reading-mps</property> <property>/instrumentation/ilec-sc7/te-reading-mps</property>
<interpolation> <interpolation>
<entry><ind> -5</ind><dep>-119.713</dep></entry> <entry><ind> -5</ind><dep>-119.713</dep></entry>
<entry><ind> 0.0</ind><dep> 0.0</dep></entry> <entry><ind> 0.0</ind><dep> 0.0</dep></entry>
<entry><ind> 5</ind><dep>119.7135</dep></entry> <entry><ind> 5</ind><dep>119.7135</dep></entry>
@ -42,9 +42,9 @@
<z>0</z> <z>0</z>
</axis> </axis>
</animation> </animation>
<!-- mc cready --> <!-- mc cready -->
<animation> <animation>
<type>rotate</type> <type>rotate</type>
<object-name>mc-cready</object-name> <object-name>mc-cready</object-name>
@ -61,7 +61,7 @@
<z>0</z> <z>0</z>
</axis> </axis>
</animation> </animation>
<animation> <animation>
<type>pick</type> <type>pick</type>
<object-name>mc-cready</object-name> <object-name>mc-cready</object-name>
@ -80,7 +80,7 @@
</binding> </binding>
</action> </action>
</animation> </animation>
<animation> <animation>
<type>pick</type> <type>pick</type>
<object-name>mc-cready</object-name> <object-name>mc-cready</object-name>
@ -99,9 +99,9 @@
</binding> </binding>
</action> </action>
</animation> </animation>
<!-- volume --> <!-- volume -->
<animation> <animation>
<type>rotate</type> <type>rotate</type>
<object-name>vol-knob</object-name> <object-name>vol-knob</object-name>
@ -118,7 +118,7 @@
<z>0</z> <z>0</z>
</axis> </axis>
</animation> </animation>
<animation> <animation>
<type>pick</type> <type>pick</type>
<object-name>vol-knob</object-name> <object-name>vol-knob</object-name>
@ -137,7 +137,7 @@
</binding> </binding>
</action> </action>
</animation> </animation>
<animation> <animation>
<type>pick</type> <type>pick</type>
<object-name>vol-knob</object-name> <object-name>vol-knob</object-name>
@ -156,9 +156,9 @@
</binding> </binding>
</action> </action>
</animation> </animation>
<!-- audio switch --> <!-- audio switch -->
<animation> <animation>
<type>rotate</type> <type>rotate</type>
<object-name>audio-switch</object-name> <object-name>audio-switch</object-name>
@ -179,191 +179,191 @@
<z>0</z> <z>0</z>
</axis> </axis>
</animation> </animation>
<animation> <animation>
<type>pick</type> <type>pick</type>
<object-name>incr-audio</object-name> <object-name>incr-audio</object-name>
<action> <action>
<button>0</button> <button>0</button>
<binding> <binding>
<command>property-adjust</command> <command>property-adjust</command>
<property>instrumentation/ilec-sc7/audio</property> <property>instrumentation/ilec-sc7/audio</property>
<step>1</step> <step>1</step>
<min>0</min> <min>0</min>
<max>2</max> <max>2</max>
<wrap>false</wrap> <wrap>false</wrap>
</binding> </binding>
</action> </action>
</animation> </animation>
<animation> <animation>
<type>pick</type> <type>pick</type>
<object-name>decr-audio</object-name> <object-name>decr-audio</object-name>
<action> <action>
<button>0</button> <button>0</button>
<binding> <binding>
<command>property-adjust</command> <command>property-adjust</command>
<property>instrumentation/ilec-sc7/audio</property> <property>instrumentation/ilec-sc7/audio</property>
<step>-1</step> <step>-1</step>
<min>0</min> <min>0</min>
<max>2</max> <max>2</max>
<wrap>false</wrap> <wrap>false</wrap>
</binding> </binding>
</action> </action>
</animation>
<!-- mode switch -->
<animation>
<type>rotate</type>
<object-name>mode-switch</object-name>
<property>instrumentation/ilec-sc7/mode</property>
<interpolation>
<entry><ind>0</ind><dep>-30</dep></entry>
<entry><ind>1.0</ind><dep>0</dep></entry>
<entry><ind>2.0</ind><dep>30</dep></entry>
</interpolation>
<center>
<x-m>0.001</x-m>
<y-m>0.025</y-m>
<z-m>-0.013</z-m>
</center>
<axis>
<x>0</x>
<y>-1</y>
<z>0</z>
</axis>
</animation>
<animation>
<type>pick</type>
<object-name>incr-mode</object-name>
<action>
<button>0</button>
<binding>
<command>property-adjust</command>
<property>instrumentation/ilec-sc7/mode</property>
<step>1</step>
<min>0</min>
<max>2</max>
<wrap>false</wrap>
</binding>
</action>
</animation>
<animation>
<type>pick</type>
<object-name>decr-mode</object-name>
<action>
<button>0</button>
<binding>
<command>property-adjust</command>
<property>instrumentation/ilec-sc7/mode</property>
<step>-1</step>
<min>0</min>
<max>2</max>
<wrap>false</wrap>
</binding>
</action>
</animation>
<!-- sensitivity switch -->
<animation>
<type>rotate</type>
<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>
</interpolation>
<center>
<x-m>0.001</x-m>
<y-m>0.003</y-m>
<z-m>-0.031</z-m>
</center>
<axis>
<x>0</x>
<y>-1</y>
<z>0</z>
</axis>
</animation>
<animation>
<type>pick</type>
<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>
<wrap>false</wrap>
</binding>
</action>
</animation>
<animation>
<type>pick</type>
<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>
<wrap>false</wrap>
</binding>
</action>
</animation>
<!-- digits -->
<animation>
<type>textranslate</type>
<object-name>decimals-digit</object-name>
<property>instrumentation/ilec-sc7/average</property>
<factor>1</factor>
<step>0.1</step>
<bias>0.005</bias>
<axis>
<x>1</x>
<y>0</y>
<z>0</z>
</axis>
</animation> </animation>
<animation> <!-- mode switch -->
<type>textranslate</type>
<object-name>units-digit</object-name> <animation>
<property>instrumentation/ilec-sc7/average</property> <type>rotate</type>
<factor>0.1</factor> <object-name>mode-switch</object-name>
<step>1</step> <property>instrumentation/ilec-sc7/mode</property>
<bias>0.005</bias> <interpolation>
<axis> <entry><ind>0</ind><dep>-30</dep></entry>
<x>1</x> <entry><ind>1.0</ind><dep>0</dep></entry>
<y>0</y> <entry><ind>2.0</ind><dep>30</dep></entry>
<z>0</z> </interpolation>
</axis> <center>
</animation> <x-m>0.001</x-m>
<y-m>0.025</y-m>
<animation> <z-m>-0.013</z-m>
<type>textranslate</type> </center>
<object-name>sign-digit</object-name> <axis>
<property>instrumentation/ilec-sc7/average-sign</property> <x>0</x>
<factor>0.1</factor> <y>-1</y>
<step>1</step> <z>0</z>
<bias>0.005</bias> </axis>
<axis> </animation>
<x>1</x>
<y>0</y> <animation>
<z>0</z> <type>pick</type>
</axis> <object-name>incr-mode</object-name>
</animation> <action>
<button>0</button>
<binding>
<command>property-adjust</command>
<property>instrumentation/ilec-sc7/mode</property>
<step>1</step>
<min>0</min>
<max>2</max>
<wrap>false</wrap>
</binding>
</action>
</animation>
<animation>
<type>pick</type>
<object-name>decr-mode</object-name>
<action>
<button>0</button>
<binding>
<command>property-adjust</command>
<property>instrumentation/ilec-sc7/mode</property>
<step>-1</step>
<min>0</min>
<max>2</max>
<wrap>false</wrap>
</binding>
</action>
</animation>
<!-- sensitivity switch -->
<animation>
<type>rotate</type>
<object-name>sens-switch</object-name>
<property>instrumentation/ilec-sc7/sensitivity</property>
<interpolation>
<entry><ind>1</ind><dep>30</dep></entry>
<entry><ind>3</ind><dep>-30</dep></entry>
</interpolation>
<center>
<x-m>0.001</x-m>
<y-m>0.003</y-m>
<z-m>-0.031</z-m>
</center>
<axis>
<x>0</x>
<y>-1</y>
<z>0</z>
</axis>
</animation>
<animation>
<type>pick</type>
<object-name>decr-sens</object-name>
<action>
<button>0</button>
<binding>
<command>property-adjust</command>
<property>instrumentation/ilec-sc7/sensitivity</property>
<step>3</step>
<min>1</min>
<max>3</max>
<wrap>false</wrap>
</binding>
</action>
</animation>
<animation>
<type>pick</type>
<object-name>incr-sens</object-name>
<action>
<button>0</button>
<binding>
<command>property-adjust</command>
<property>instrumentation/ilec-sc7/sensitivity</property>
<step>-3</step>
<min>1</min>
<max>3</max>
<wrap>false</wrap>
</binding>
</action>
</animation>
<!-- digits -->
<animation>
<type>textranslate</type>
<object-name>decimals-digit</object-name>
<property>instrumentation/ilec-sc7/lcd-digits-abs</property>
<factor>1</factor>
<step>0.1</step>
<bias>0.005</bias>
<axis>
<x>1</x>
<y>0</y>
<z>0</z>
</axis>
</animation>
<animation>
<type>textranslate</type>
<object-name>units-digit</object-name>
<property>instrumentation/ilec-sc7/lcd-digits-abs</property>
<factor>0.1</factor>
<step>1</step>
<bias>0.005</bias>
<axis>
<x>1</x>
<y>0</y>
<z>0</z>
</axis>
</animation>
<animation>
<type>textranslate</type>
<object-name>sign-digit</object-name>
<property>instrumentation/ilec-sc7/lcd-digits-sgn</property>
<factor>0.1</factor>
<step>1</step>
<bias>0.005</bias>
<axis>
<x>1</x>
<y>0</y>
<z>0</z>
</axis>
</animation>
</PropertyList> </PropertyList>