Debian Codegraph @

Aircraft/c172p/Nasal/static-icing.nas

raw
1 #############################################################################
2 # This file is part of FlightGear, the free flight simulator
3 # http://www.flightgear.org/
4 #
5 # Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
6 # modified and used for C182S by B. Hallinger 2020
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2 of the
11 # License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
17 #############################################################################
18
19 #########################################################################################
20 # Fail the primary static ports on the fuselage due to icing
21 # Maintainer: Torsten Dreyer (Torsten at t3r dot de)
22 #
23 # inputs
24 # /systems/static[n]/icing
25 #
26 # outputs
27 # /systems/static/serviceable
28 #########################################################################################
29
30 #############################################################################
31 # Taken from c182 team, with thanks!
32 #############################################################################
33
34 var StaticIcingHandler = {};
35 StaticIcingHandler.new = func {
36 var m = {};
37 m.parents = [StaticIcingHandler];
38
39 m.failAtIcelevel = arg[1];
40
41 m.baseNodeName = "/systems/static[" ~ arg[0] ~ "]";
42
43 print( "creating StaticIcingHandler for " ~ m.baseNodeName );
44
45 m.baseN = props.globals.getNode( m.baseNodeName );
46
47 m.icingN = m.baseN.initNode( "icing", 0.0 );
48
49 m.serviceableN = m.baseN.initNode( "serviceable", 1, "BOOL" );
50
51 setlistener( m.icingN, func { m.listener() } );
52
53 return m;
54 };
55
56 #########################################################################################
57 # The handler. Check if ice is above threshold, then fail the device
58 #########################################################################################
59
60 StaticIcingHandler.listener = func {
61
62 if( me.icingN.getValue() < me.failAtIcelevel ) {
63 # everything is fine
64
65 if( me.serviceableN.getBoolValue() == 0 ) {
66 # if the static failed before, re-enable it
67 #print( me.baseNodeName ~ " is functional again" );
68 me.serviceableN.setBoolValue( 1 );
69 }
70
71 } else {
72 # static port is iced
73
74 if( me.serviceableN.getBoolValue() != 0 ) {
75 # if the indicator was servicable before, fail it now
76 #print( me.baseNodeName ~ " is failing" );
77 me.serviceableN.setBoolValue( 0 );
78 }
79
80 }
81 };
82
83 # Fail static at 0.05" of ice
84 # Note: without static, the pitot will also block. When only the pitot is iced, it can be heated.
85 StaticIcingHandler.new( 0, 0.05 );