From 60886da1d83515961ee8490486a90f3c009975df Mon Sep 17 00:00:00 2001 From: Colin Geniet Date: Sat, 14 Mar 2020 11:47:27 +0100 Subject: [PATCH 1/7] Model: Fix missing weather effects due to typo Add the same typo (s/Windsheild/Windshield/) to the fuselage.xml files to avoid changing fuselage.ac for now. --- Models/Fuselages/A320-100/fuselage.xml | 2 +- Models/Fuselages/A320/fuselage.xml | 2 +- Models/Fuselages/A320neo/fuselage.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Models/Fuselages/A320-100/fuselage.xml b/Models/Fuselages/A320-100/fuselage.xml index 4877bde7..3a74a144 100644 --- a/Models/Fuselages/A320-100/fuselage.xml +++ b/Models/Fuselages/A320-100/fuselage.xml @@ -14,7 +14,7 @@ Effects/glass - Windshield + Windsheild Windows glass glass1 diff --git a/Models/Fuselages/A320/fuselage.xml b/Models/Fuselages/A320/fuselage.xml index 4877bde7..3a74a144 100644 --- a/Models/Fuselages/A320/fuselage.xml +++ b/Models/Fuselages/A320/fuselage.xml @@ -14,7 +14,7 @@ Effects/glass - Windshield + Windsheild Windows glass glass1 diff --git a/Models/Fuselages/A320neo/fuselage.xml b/Models/Fuselages/A320neo/fuselage.xml index 4877bde7..3a74a144 100644 --- a/Models/Fuselages/A320neo/fuselage.xml +++ b/Models/Fuselages/A320neo/fuselage.xml @@ -14,7 +14,7 @@ Effects/glass - Windshield + Windsheild Windows glass glass1 From f6e8bed92b340d34aa0118a8c48ae8f5310b823b Mon Sep 17 00:00:00 2001 From: Colin Geniet Date: Wed, 11 Mar 2020 21:58:12 +0100 Subject: [PATCH 2/7] Rewrite nasal icing system Rewrite the iceable components nasal code. Remove code duplication and excessive setprop/getprop. Fix that tags were ignored. --- A320-main.xml | 2 +- Nasal/Systems/icing.nas | 132 +++++++++++++--------------------------- 2 files changed, 42 insertions(+), 92 deletions(-) diff --git a/A320-main.xml b/A320-main.xml index 9386dbb9..0174f383 100644 --- a/A320-main.xml +++ b/A320-main.xml @@ -45,7 +45,7 @@ 0.0 /controls/deice/windowprobeheat 0.5 - + /environment/aircraft-effects/frost-level Fuselage diff --git a/Nasal/Systems/icing.nas b/Nasal/Systems/icing.nas index 9ffffad4..b404c780 100644 --- a/Nasal/Systems/icing.nas +++ b/Nasal/Systems/icing.nas @@ -3,6 +3,35 @@ # Copyright (c) 2019 Joshua Davidson (Octal450) +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); + }, +}; + + var dewpoint = 0; var temperature = 0; var speed = 0; @@ -31,34 +60,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 @@ -80,6 +88,13 @@ 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.simulatedTime = 1; icing_timer.start(); } @@ -126,74 +141,9 @@ var icingModel = func { } else if (temperature < -40 and temperature >= -99 and icingCond) { setprop("systems/icing/severity", "1"); } - - 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); + + foreach(iceable; iceables) { + iceable.update(factor, melt); } # Do we create ice? From 197ce0c664af7377d57b25cb98cf43c3cd3e14c6 Mon Sep 17 00:00:00 2001 From: Colin Geniet Date: Thu, 12 Mar 2020 12:48:28 +0100 Subject: [PATCH 3/7] Rewrite icing parameters computation Remove unnecessary properties I/O. --- Nasal/Systems/icing.nas | 112 ++++++++++++++++++++++------------------ Systems/libraries.xml | 21 -------- 2 files changed, 62 insertions(+), 71 deletions(-) diff --git a/Nasal/Systems/icing.nas b/Nasal/Systems/icing.nas index b404c780..0ad2dc6d 100644 --- a/Nasal/Systems/icing.nas +++ b/Nasal/Systems/icing.nas @@ -3,6 +3,8 @@ # Copyright (c) 2019 Joshua Davidson (Octal450) + +### Ice sensitive components definition. var Iceable = { new: func(node) { var m = { parents: [Iceable] }; @@ -32,17 +34,64 @@ var Iceable = { }; -var dewpoint = 0; -var temperature = 0; -var speed = 0; -var visibility = 0; -var visibLclWx = 0; -var severity = 0; -var factor = 0; +### 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"), +}; + + +# 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; @@ -60,7 +109,6 @@ var lengAnti = 0; var rengAnti = 0; var WingHasBeenTurnedOff = 0; var GroundModeFinished = 0; -var spread = 0; var windowprb = 0; var stateL = 0; var stateR = 0; @@ -68,11 +116,6 @@ 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); @@ -99,17 +142,8 @@ var icingInit = func { } 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"); @@ -127,39 +161,17 @@ var icingModel = func { rengAnti = getprop("controls/deice/rengine"); 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); - } - - # 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); + iceable.update(factor, melt_factor); } if (WingHasBeenTurnedOff and !wowl and !wowr and GroundModeFinished) { setprop("controls/deice/wing", 1); setprop("controls/switches/WingHasBeenTurnedOff", 0); } - + # If we have low pressure we have a fault if (PSI < 10) { setprop("controls/switches/wingfault", 1); @@ -182,7 +194,7 @@ var icingModel = func { setprop("systems/pitot/failed", 0); } } - + # if ((getprop("systems/electrical/bus/dc-1") == 0 or getprop("systems/electrical/bus/dc-2") == 0) and getprop("fdm/jsbsim/position/wow") == 0) { # setprop("controls/switches/leng", 1); # setprop("controls/switches/reng", 1); diff --git a/Systems/libraries.xml b/Systems/libraries.xml index 06bb51a4..acd2b244 100644 --- a/Systems/libraries.xml +++ b/Systems/libraries.xml @@ -608,27 +608,6 @@ /systems/pressurization/targetvs - - Icing Severity - gain - 1.0 - 0.1 - - - - /systems/icing/severity - 0-0.00000166 - 1 0.00000277 - 2 0.00000277 - 3 0.00000554 - 4 0.00001108 - 5 0.00002216 -
-
- - /systems/icing/factor -
- TAS gain From 7acb378e7d9b1b9fce98a880c07cb65643220c1a Mon Sep 17 00:00:00 2001 From: Colin Geniet Date: Sat, 14 Mar 2020 11:42:32 +0100 Subject: [PATCH 4/7] Delete unused file glass-effect2.xml --- A320-100-CFM.xml | 2 +- A320-200-CFM.xml | 2 +- A320-200-IAE.xml | 2 +- A320neo-CFM.xml | 2 +- A320neo-PW.xml | 2 +- .../{glass-effect1.xml => glass-effect.xml} | 2 +- Systems/glass-effect2.xml | 40 ------------------- 7 files changed, 6 insertions(+), 46 deletions(-) rename Systems/{glass-effect1.xml => glass-effect.xml} (98%) delete mode 100644 Systems/glass-effect2.xml diff --git a/A320-100-CFM.xml b/A320-100-CFM.xml index e79ddbcd..eeb5ebf1 100644 --- a/A320-100-CFM.xml +++ b/A320-100-CFM.xml @@ -160,7 +160,7 @@ xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd"> - + diff --git a/A320-200-CFM.xml b/A320-200-CFM.xml index c731d0f4..b0a11a23 100644 --- a/A320-200-CFM.xml +++ b/A320-200-CFM.xml @@ -159,7 +159,7 @@ xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd"> - + diff --git a/A320-200-IAE.xml b/A320-200-IAE.xml index fd7dac96..872f5b88 100644 --- a/A320-200-IAE.xml +++ b/A320-200-IAE.xml @@ -159,7 +159,7 @@ xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd"> - + diff --git a/A320neo-CFM.xml b/A320neo-CFM.xml index 67cb63e2..e19a453e 100644 --- a/A320neo-CFM.xml +++ b/A320neo-CFM.xml @@ -159,7 +159,7 @@ xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd"> - + diff --git a/A320neo-PW.xml b/A320neo-PW.xml index 78827afc..7d3de32e 100644 --- a/A320neo-PW.xml +++ b/A320neo-PW.xml @@ -159,7 +159,7 @@ xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd"> - + diff --git a/Systems/glass-effect1.xml b/Systems/glass-effect.xml similarity index 98% rename from Systems/glass-effect1.xml rename to Systems/glass-effect.xml index 654426e3..f253bff9 100644 --- a/Systems/glass-effect1.xml +++ b/Systems/glass-effect.xml @@ -2,7 +2,7 @@ - + diff --git a/Systems/glass-effect2.xml b/Systems/glass-effect2.xml deleted file mode 100644 index aea5dfbb..00000000 --- a/Systems/glass-effect2.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - splashX - gain - - /fdm/jsbsim/glass-effects/splashx - - - /environment/aircraft-effects/splash-vector-x - - - - - splashY - gain - - 0.0 - - - /environment/aircraft-effects/splash-vector-y - - - - - splashZ - gain - - /fdm/jsbsim/glass-effects/splashz - - - /environment/aircraft-effects/splash-vector-z - - - - From b10a164a62db3e2b4f8f78e2acc248fd906eb5bf Mon Sep 17 00:00:00 2001 From: Colin Geniet Date: Mon, 16 Mar 2020 08:48:45 +0100 Subject: [PATCH 5/7] Icing: Add scaling factor to frost-level Significantly increase scaling factor of /environment/aircraft-effects/frost-level, so that frost effects are visible. --- A320-main.xml | 2 +- Nasal/Systems/icing.nas | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/A320-main.xml b/A320-main.xml index 0174f383..6342d3b2 100644 --- a/A320-main.xml +++ b/A320-main.xml @@ -45,7 +45,7 @@ 0.0 /controls/deice/windowprobeheat 0.5 - /environment/aircraft-effects/frost-level + /environment/aircraft-effects/frost-inch
Fuselage diff --git a/Nasal/Systems/icing.nas b/Nasal/Systems/icing.nas index 0ad2dc6d..e0bd7ac5 100644 --- a/Nasal/Systems/icing.nas +++ b/Nasal/Systems/icing.nas @@ -43,6 +43,11 @@ var environment = { 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; @@ -166,6 +171,8 @@ var icingModel = func { foreach(iceable; iceables) { iceable.update(factor, melt_factor); } + + effects.frost_norm.setDoubleValue(effects.frost_inch.getValue() * 50); if (WingHasBeenTurnedOff and !wowl and !wowr and GroundModeFinished) { setprop("controls/deice/wing", 1); From 9847ae8ea9c514ba1d41fd2bd5d7f116b659ab27 Mon Sep 17 00:00:00 2001 From: Colin Geniet Date: Mon, 16 Mar 2020 12:33:58 +0100 Subject: [PATCH 6/7] Improve rain drops on windshield effect --- Systems/glass-effect.xml | 64 +++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/Systems/glass-effect.xml b/Systems/glass-effect.xml index f253bff9..62accb79 100644 --- a/Systems/glass-effect.xml +++ b/Systems/glass-effect.xml @@ -3,56 +3,54 @@ - - - - - - - - /velocities/airspeed-kt - 40 - - 40 - - - - - - - -0.1 - - 2.0 - /fdm/jsbsim/glass-effects/airspeed-clamped-sqrt - - + + velocities/u-aero-fps + + 0 0.01 + 7 0.01 + 8 -0.01 + 25 -0.5 + 50 -1.2 + 120 -2 + +
/environment/aircraft-effects/splash-vector-x
- 0.0 + + velocities/v-aero-fps + + -25 -0.5 + -8 0 + 8 0 + 25 0.5 + +
/environment/aircraft-effects/splash-vector-y
- - 1.0 - - 1.35 - /fdm/jsbsim/glass-effects/airspeed-clamped-sqrt - - + + velocities/u-aero-fps + + 0 1.2 + 7 1.2 + 8 0.9 + 25 0.9 + 50 -0.2 + 120 -0.5 + +
/environment/aircraft-effects/splash-vector-z
-
-
From fc50a1fbb5ec2ee3863854b501d32ed051bcbc9b Mon Sep 17 00:00:00 2001 From: Colin Geniet Date: Mon, 16 Mar 2020 23:01:05 +0100 Subject: [PATCH 7/7] Fix error when calling icingInit twice --- Nasal/Systems/icing.nas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nasal/Systems/icing.nas b/Nasal/Systems/icing.nas index e0bd7ac5..35262a8e 100644 --- a/Nasal/Systems/icing.nas +++ b/Nasal/Systems/icing.nas @@ -142,7 +142,6 @@ var icingInit = func { iceables[i] = Iceable.new(iceables[i]); } - icing_timer.simulatedTime = 1; icing_timer.start(); } @@ -333,3 +332,4 @@ var update_Icing = func { } var icing_timer = maketimer(0.2, update_Icing); +icing_timer.simulatedTime = 1;