Debian Codegraph @

Aircraft/c172p/Nasal/pitot-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 Heiko H. Schulz 2018
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 airspeed indicator due to icing of the pitot tube
21 # Maintainer: Torsten Dreyer (Torsten at t3r dot de)
22 #
23 # inputs
24 # /instrumentation/airspeed-indicator[n]/icing
25 #
26 # outputs
27 # /instrumentation/airspeed-indicator/serviceable
28 # /instrumentation/airspeed-indicator/indicated-speed-kt
29 #############################################################################
30
31 #############################################################################
32 # Taken from c182 team, with thanks!
33 #############################################################################
34
35 var PitotIcingHandler = {};
36 PitotIcingHandler.new = func {
37 var m = {};
38 m.parents = [PitotIcingHandler];
39
40 m.failAtIcelevel = arg[1];
41
42 m.baseNodeName = "/systems/pitot[" ~ arg[0] ~ "]";
43
44 print( "creating PitotIcingHandler for " ~ m.baseNodeName );
45
46 m.baseN = props.globals.getNode( m.baseNodeName );
47
48 m.icingN = m.baseN.initNode( "icing", 0.0 );
49
50 m.serviceableN = m.baseN.initNode( "serviceable", 1, "BOOL" );
51
52 setlistener( m.icingN, func { m.listener() } );
53
54 return m;
55 };
56
57 #########################################################################################
58 # The handler. Check if ice is above threshold, then fail the device
59 #########################################################################################
60
61 PitotIcingHandler.listener = func {
62
63 if( me.icingN.getValue() < me.failAtIcelevel ) {
64 # everything is fine
65
66 if( me.serviceableN.getBoolValue() == 0 ) {
67 # if the inidcator failed before, re-enable it
68 #print( me.baseNodeName ~ " is functional again" );
69 me.serviceableN.setBoolValue( 1 );
70 }
71
72 } else {
73 # pitot is iced
74
75 if( me.serviceableN.getBoolValue() != 0 ) {
76 # if the indicator was servicable before, fail it now
77 #print( me.baseNodeName ~ " is failing" );
78 me.serviceableN.setBoolValue( 0 );
79 }
80
81 }
82 };
83
84 # Fail pitot at 0.03" of ice
85 PitotIcingHandler.new( 0, 0.03 );