1
0
Fork 0

Merge pull request #86 from colingeniet/weather-effects

Add weather effects on windshield
This commit is contained in:
merspieler 2020-03-17 09:46:15 +11:00 committed by GitHub
commit b2b6365146
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 174 additions and 268 deletions

View file

@ -160,7 +160,7 @@ xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd">
</tank>
</propulsion>
<system file="glass-effect1"/>
<system file="glass-effect"/>
<system file="a320-fcs"/>
<system file="a320-fuel"/>
<system file="a320-fwc"/>

View file

@ -159,7 +159,7 @@ xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd">
</tank>
</propulsion>
<system file="glass-effect1"/>
<system file="glass-effect"/>
<system file="a320-fcs"/>
<system file="a320-adr"/>
<system file="a320-fuel"/>

View file

@ -159,7 +159,7 @@ xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd">
</tank>
</propulsion>
<system file="glass-effect1"/>
<system file="glass-effect"/>
<system file="a320-fcs"/>
<system file="a320-fuel"/>
<system file="a320-fwc"/>

View file

@ -45,7 +45,7 @@
<ice-inches>0.0</ice-inches>
<salvage-control>/controls/deice/windowprobeheat</salvage-control>
<sensitivity type="double">0.5</sensitivity>
<!-- not relevant for fdm, ignore output-property -->
<output-property>/environment/aircraft-effects/frost-inch</output-property>
</iceable>
<iceable>
<name>Fuselage</name>

View file

@ -159,7 +159,7 @@ xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd">
</tank>
</propulsion>
<system file="glass-effect1"/>
<system file="glass-effect"/>
<system file="a320-fcs"/>
<system file="a320-fuel"/>
<system file="a320-fwc"/>

View file

@ -159,7 +159,7 @@ xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd">
</tank>
</propulsion>
<system file="glass-effect1"/>
<system file="glass-effect"/>
<system file="a320-fcs"/>
<system file="a320-fuel"/>
<system file="a320-fwc"/>

View file

@ -14,7 +14,7 @@
<effect>
<inherits-from>Effects/glass</inherits-from>
<object-name>Windshield</object-name>
<object-name>Windsheild</object-name>
<object-name>Windows</object-name>
<object-name>glass</object-name>
<object-name>glass1</object-name>

View file

@ -14,7 +14,7 @@
<effect>
<inherits-from>Effects/glass</inherits-from>
<object-name>Windshield</object-name>
<object-name>Windsheild</object-name>
<object-name>Windows</object-name>
<object-name>glass</object-name>
<object-name>glass1</object-name>

View file

@ -14,7 +14,7 @@
<effect>
<inherits-from>Effects/glass</inherits-from>
<object-name>Windshield</object-name>
<object-name>Windsheild</object-name>
<object-name>Windows</object-name>
<object-name>glass</object-name>
<object-name>glass1</object-name>

View file

@ -3,17 +3,100 @@
# Copyright (c) 2019 Joshua Davidson (Octal450)
var dewpoint = 0;
var temperature = 0;
var speed = 0;
var visibility = 0;
var visibLclWx = 0;
var severity = 0;
var factor = 0;
### Ice sensitive components definition.
var Iceable = {
new: func(node) {
var m = { parents: [Iceable] };
m.ice_inches = node.getNode("ice-inches", 1);
m.sensitivity = node.getNode("sensitivity", 1);
var deice_prop = node.getValue("salvage-control");
m.deice = deice_prop ? props.globals.getNode(deice_prop, 1) : nil;
var output_prop = node.getValue("output-property");
m.output = output_prop ? props.globals.getNode(output_prop, 1): nil;
return m;
},
update: func(factor, melt) {
var icing = me.ice_inches.getValue();
if(me.deice != nil and me.deice.getBoolValue()) {
icing += melt;
} else {
icing += factor * me.sensitivity.getValue();
}
if(icing < 0) icing = 0;
me.ice_inches.setValue(icing);
if(me.output != nil) me.output.setValue(icing);
},
};
### Icing parameters computation.
# Environmental parameters of the icing model.
var environment = {
dewpoint: props.globals.getNode("environment/dewpoint-degc"),
temperature: props.globals.getNode("environment/temperature-degc"),
visibility: props.globals.getNode("environment/effective-visibility-m"),
visibLclWx: props.globals.getNode("environment/visibility-m"),
};
var effects = {
frost_inch: props.globals.getNode("environment/aircraft-effects/frost-inch", 1),
frost_norm: props.globals.getNode("environment/aircraft-effects/frost-level"),
};
# Icing factor computation.
var maxSpread = 0;
var icingCond = 0;
var severity_factor_table = [
-0.00000166,
0.00000277,
0.00000277,
0.00000554,
0.00001108,
0.00002216,
];
var melt_factor = -0.00005;
var icing_factor = func() {
var temperature = environment.temperature.getValue();
var dewpoint = environment.dewpoint.getValue();
var visibility = environment.visibility.getValue();
var visibLclWx = environment.visibLclWx.getValue();
# Do we create ice?
var spread = temperature - dewpoint;
# freezing fog or low temp and below dp or in advanced wx cloud
var icingCond = ((spread < maxSpread or visibility < 1000 or visibLclWx < 5000)
and temperature < 0);
# todo: turn this into a table or something
var severity = 0;
if (icingCond) {
if (temperature >= -2) {
severity = 1;
} else if (temperature >= -12) {
severity = 3;
} else if (temperature >= -30) {
severity = 5;
} else if (temperature >= -40) {
severity = 3;
} else if (temperature >= -99) {
severity = 1;
}
}
return severity_factor_table[severity];
}
var speed = 0;
var pause = 0;
var melt = 0;
var windowprobe = 0;
var wingBtn = 0;
var wingFault = 0;
@ -31,40 +114,13 @@ var lengAnti = 0;
var rengAnti = 0;
var WingHasBeenTurnedOff = 0;
var GroundModeFinished = 0;
var icing1 = 0;
var sensitive1 = 0;
var v = 0;
var a = 0;
var icing2 = 0;
var sensitive2 = 0;
var u = 0;
var b = 0;
var icing3 = 0;
var sensitive3 = 0;
var t = 0;
var c = 0;
var icing4 = 0;
var sensitive4 = 0;
var s = 0;
var d = 0;
var icing5 = 0;
var sensitive5 = 0;
var r = 0;
var icing6 = 0;
var sensitive6 = 0;
var q = 0;
var e = 0;
var spread = 0;
var windowprb = 0;
var stateL = 0;
var stateR = 0;
var iceables = [];
var icingInit = func {
setprop("systems/icing/severity", "0"); # maximum severity: we will make it random
setprop("systems/icing/factor", 0.0); # the factor is how many inches we add per second
setprop("systems/icing/max-spread-degc", 0.0);
setprop("systems/icing/melt-w-heat-factor", -0.00005000);
setprop("systems/icing/icingcond", 0);
setprop("controls/switches/windowprobeheat", 0);
setprop("controls/switches/wing", 0);
setprop("controls/switches/wingfault", 0);
@ -80,21 +136,18 @@ var icingInit = func {
setprop("systems/pitot/failed", 1);
setprop("controls/deice/WingHasBeenTurnedOff", 0);
setprop("controls/deice/GroundModeFinished", 0);
iceables = props.globals.getNode("sim/model/icing", 1).getChildren("iceable");
forindex(var i; iceables) {
iceables[i] = Iceable.new(iceables[i]);
}
icing_timer.start();
}
var icingModel = func {
dewpoint = getprop("environment/dewpoint-degc");
temperature = getprop("environment/temperature-degc");
speed = getprop("velocities/airspeed-kt");
visibility = getprop("environment/effective-visibility-m");
visibLclWx = getprop("environment/visibility-m");
severity = getprop("systems/icing/severity");
factor = getprop("systems/icing/factor");
maxSpread = getprop("systems/icing/max-spread-degc");
icingCond = getprop("systems/icing/icingcond");
pause = getprop("sim/freeze/master");
melt = getprop("systems/icing/melt-w-heat-factor");
windowprobe = getprop("controls/deice/windowprobeheat");
wingBtn = getprop("controls/switches/wing");
wingFault = getprop("controls/switches/wingfault");
@ -113,97 +166,12 @@ var icingModel = func {
WingHasBeenTurnedOff = getprop("controls/deice/WingHasBeenTurnedOff");
GroundModeFinished = getprop("controls/deice/GroundModeFinished");
if (temperature >= 0 or !icingCond) {
setprop("systems/icing/severity", "0");
} else if (temperature < 0 and temperature >= -2 and icingCond) {
setprop("systems/icing/severity", "1");
} else if (temperature < -2 and temperature >= -12 and icingCond) {
setprop("systems/icing/severity", "3");
} else if (temperature < -12 and temperature >= -30 and icingCond) {
setprop("systems/icing/severity", "5");
} else if (temperature < -30 and temperature >= -40 and icingCond) {
setprop("systems/icing/severity", "3");
} else if (temperature < -40 and temperature >= -99 and icingCond) {
setprop("systems/icing/severity", "1");
var factor = icing_factor();
foreach(iceable; iceables) {
iceable.update(factor, melt_factor);
}
icing1 = getprop("sim/model/icing/iceable[0]/ice-inches");
sensitive1 = getprop("sim/model/icing/iceable[0]/sensitivity");
v = icing1 + (factor * sensitive1);
a = icing1 + melt;
if (icing1 < 0.0 and !pause) {
setprop("sim/model/icing/iceable[0]/ice-inches", 0.0);
} else if (wingAnti) {
setprop("sim/model/icing/iceable[0]/ice-inches", a);
} else if (!pause and !wingAnti) {
setprop("sim/model/icing/iceable[0]/ice-inches", v);
}
icing2 = getprop("sim/model/icing/iceable[1]/ice-inches");
sensitive2 = getprop("sim/model/icing/iceable[1]/sensitivity");
u = icing2 + (factor * sensitive2);
b = icing2 + melt;
if (icing2 < 0.0 and !pause) {
setprop("sim/model/icing/iceable[1]/ice-inches", 0.0);
} else if (lengAnti) {
setprop("sim/model/icing/iceable[1]/ice-inches", b);
} else if (!pause and !lengAnti) {
setprop("sim/model/icing/iceable[1]/ice-inches", u);
}
icing3 = getprop("sim/model/icing/iceable[2]/ice-inches");
sensitive3 = getprop("sim/model/icing/iceable[2]/sensitivity");
t = icing3 + (factor * sensitive3);
c = icing3 + melt;
if (icing3 < 0.0 and !pause) {
setprop("sim/model/icing/iceable[2]/ice-inches", 0.0);
} else if (rengAnti) {
setprop("sim/model/icing/iceable[2]/ice-inches", c);
} else if (!pause and !rengAnti) {
setprop("sim/model/icing/iceable[2]/ice-inches", t);
}
icing4 = getprop("sim/model/icing/iceable[3]/ice-inches");
sensitive4 = getprop("sim/model/icing/iceable[3]/sensitivity");
s = icing4 + (factor * sensitive4);
d = icing4 + melt;
if (icing4 < 0.0 and !pause) {
setprop("sim/model/icing/iceable[3]/ice-inches", 0.0);
} else if (windowprobe) {
setprop("sim/model/icing/iceable[3]/ice-inches", d);
} else if (!pause and !windowprobe) {
setprop("sim/model/icing/iceable[3]/ice-inches", s);
}
icing5 = getprop("sim/model/icing/iceable[4]/ice-inches");
sensitive5 = getprop("sim/model/icing/iceable[4]/sensitivity");
r = icing5 + (factor * sensitive5);
if (icing5 < 0.0 and !pause) {
setprop("sim/model/icing/iceable[4]/ice-inches", 0.0);
} else if (!pause) {
setprop("sim/model/icing/iceable[4]/ice-inches", r);
}
icing6 = getprop("sim/model/icing/iceable[5]/ice-inches");
sensitive6 = getprop("sim/model/icing/iceable[5]/sensitivity");
q = icing6 + (factor * sensitive6);
e = icing6 + melt;
if (icing6 < 0.0 and !pause) {
setprop("sim/model/icing/iceable[5]/ice-inches", 0.0);
} else if (windowprobe) {
setprop("sim/model/icing/iceable[5]/ice-inches", e);
} else if (!pause and !windowprobe) {
setprop("sim/model/icing/iceable[5]/ice-inches", q);
}
# Do we create ice?
spread = temperature - dewpoint;
# freezing fog or low temp and below dp or in advanced wx cloud
if ((spread < maxSpread and temperature < 0) or (temperature < 0 and visibility < 1000) or (visibLclWx < 5000 and temperature < 0)) {
setprop("systems/icing/icingcond", 1);
} else {
setprop("systems/icing/icingcond", 0);
}
effects.frost_norm.setDoubleValue(effects.frost_inch.getValue() * 50);
if (WingHasBeenTurnedOff and !wowl and !wowr and GroundModeFinished) {
setprop("controls/deice/wing", 1);
@ -364,3 +332,4 @@ var update_Icing = func {
}
var icing_timer = maketimer(0.2, update_Icing);
icing_timer.simulatedTime = 1;

56
Systems/glass-effect.xml Normal file
View file

@ -0,0 +1,56 @@
<?xml version="1.0"?>
<!-- Copyright (c) 2019 Joshua Davidson (Octal450) -->
<system name="glass-effect">
<channel name="rain">
<fcs_function name="glass-effects/splashx">
<function>
<table>
<independentVar>velocities/u-aero-fps</independentVar>
<tableData>
0 0.01
7 0.01
8 -0.01
25 -0.5
50 -1.2
120 -2
</tableData>
</table>
</function>
<output>/environment/aircraft-effects/splash-vector-x</output>
</fcs_function>
<fcs_function name="glass-effects/splashy">
<function>
<table>
<independentVar>velocities/v-aero-fps</independentVar>
<tableData>
-25 -0.5
-8 0
8 0
25 0.5
</tableData>
</table>
</function>
<output>/environment/aircraft-effects/splash-vector-y</output>
</fcs_function>
<fcs_function name="glass-effects/splashz">
<function>
<table>
<independentVar>velocities/u-aero-fps</independentVar>
<tableData>
0 1.2
7 1.2
8 0.9
25 0.9
50 -0.2
120 -0.5
</tableData>
</table>
</function>
<output>/environment/aircraft-effects/splash-vector-z</output>
</fcs_function>
</channel>
</system>

View file

@ -1,58 +0,0 @@
<?xml version="1.0"?>
<!-- Copyright (c) 2019 Joshua Davidson (Octal450) -->
<system name="glass-effect1">
<channel name="rain">
<fcs_function name="glass-effects/airspeed-clamped-sqrt">
<function>
<sqrt>
<quotient>
<min>
<property>/velocities/airspeed-kt</property>
<value>40</value>
</min>
<value>40</value>
</quotient>
</sqrt>
</function>
</fcs_function>
<fcs_function name="glass-effects/splashx">
<function>
<difference>
<value>-0.1</value>
<product>
<value>2.0</value>
<property>/fdm/jsbsim/glass-effects/airspeed-clamped-sqrt</property>
</product>
</difference>
</function>
<output>/environment/aircraft-effects/splash-vector-x</output>
</fcs_function>
<fcs_function name="glass-effects/splashy">
<function>
<value>0.0</value>
</function>
<output>/environment/aircraft-effects/splash-vector-y</output>
</fcs_function>
<fcs_function name="glass-effects/splashz">
<function>
<difference>
<value>1.0</value>
<product>
<value>1.35</value>
<property>/fdm/jsbsim/glass-effects/airspeed-clamped-sqrt</property>
</product>
</difference>
</function>
<output>/environment/aircraft-effects/splash-vector-z</output>
</fcs_function>
</channel>
</system>

View file

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2019 Joshua Davidson (Octal450) -->
<PropertyList>
<filter>
<name>splashX</name>
<type>gain</type>
<input>
<property>/fdm/jsbsim/glass-effects/splashx</property>
</input>
<output>
<property>/environment/aircraft-effects/splash-vector-x</property>
</output>
</filter>
<filter>
<name>splashY</name>
<type>gain</type>
<input>
<value>0.0</value>
</input>
<output>
<property>/environment/aircraft-effects/splash-vector-y</property>
</output>
</filter>
<filter>
<name>splashZ</name>
<type>gain</type>
<input>
<property>/fdm/jsbsim/glass-effects/splashz</property>
</input>
<output>
<property>/environment/aircraft-effects/splash-vector-z</property>
</output>
</filter>
</PropertyList>

View file

@ -608,27 +608,6 @@
<output>/systems/pressurization/targetvs</output>
</filter>
<filter>
<name>Icing Severity</name>
<type>gain</type>
<gain>1.0</gain>
<update-interval-secs type="double">0.1</update-interval-secs>
<input>
<expression>
<table>
<property>/systems/icing/severity</property>
<entry><ind>0</ind><dep>-0.00000166</dep></entry>
<entry><ind>1</ind><dep> 0.00000277</dep></entry>
<entry><ind>2</ind><dep> 0.00000277</dep></entry>
<entry><ind>3</ind><dep> 0.00000554</dep></entry>
<entry><ind>4</ind><dep> 0.00001108</dep></entry>
<entry><ind>5</ind><dep> 0.00002216</dep></entry>
</table>
</expression>
</input>
<output>/systems/icing/factor</output>
</filter>
<filter>
<name>TAS</name>
<type>gain</type>