Tu-154B2 version 3.1:
[fg:toms-fgdata.git] / Aircraft / tu154b / Nasal / engines.nas
1 #
2 #
3 # Engine support
4 #
5 # Project Tupolev for FlightGear
6 #
7 # Yurik V. Nikiforoff, yurik.nsk@gmail.com
8 # Novosibirsk, Russia
9 # aug 2008
10 #
11
12 # engine support
13
14 var ENGINE_UPDATE_PERIOD = 0.5;
15 var starter_rpm_1 = 0.0;
16 var starter_rpm_2 = 0.0;
17 var starter_rpm_3 = 0.0;
18
19 var start_engine = func{
20         var engine_prop = -1;
21         # Is start subsystem  serviceable?
22         if( getprop("tu154/switches/startpanel-start" ) != 1.0 ) return;
23         if( getprop("tu154/lamps/pump-1") != 1.0 ) return;
24         if( getprop("tu154/lamps/pump-2") != 1.0 ) return;
25         if( getprop("tu154/lamps/pump-3") != 1.0 ) return;
26         if( getprop("tu154/lamps/pump-4") != 1.0 ) return;
27         if( getprop("tu154/lamps/auto-consumption-failure") == 1.0 ) return;
28         if( getprop( "tu154/systems/APU/APU-ready" ) == 0 ) return;
29         if( getprop( "tu154/systems/APU/APU-bleed" ) != 5.0 ) return;   # need bleed
30         
31         # which engine we want start?
32         if( getprop("tu154/switches/startpanel-selector-1" ) == 1.0 )
33                 engine_prop = "controls/engines/engine[0]/starter";
34         if( getprop("tu154/switches/startpanel-selector-2" ) == 1.0 )
35                 engine_prop = "controls/engines/engine[1]/starter";
36         if( getprop("tu154/switches/startpanel-selector-3" ) == 1.0 )
37                 engine_prop = "controls/engines/engine[2]/starter";
38         if( engine_prop == -1 ) return; # engine not selected
39         
40 #let's start selected engine
41         setprop(engine_prop, 1);
42 }
43
44
45 var break_start = func{
46 # which engine we start now?
47         var engine_prop = -1;
48         if( getprop("tu154/switches/startpanel-selector-1" ) == 1.0 )
49                 {
50                 engine_prop = "controls/engines/engine[0]/starter";
51                 var engine_cutoff = "controls/engines/engine[0]/cutoff";
52                 }
53         if( getprop("tu154/switches/startpanel-selector-2" ) == 1.0 )
54                 {
55                 engine_prop = "controls/engines/engine[1]/starter";
56                 var engine_cutoff = "controls/engines/engine[1]/cutoff";
57                 }
58         if( getprop("tu154/switches/startpanel-selector-3" ) == 1.0 )
59                 {
60                 engine_prop = "controls/engines/engine[2]/starter";
61                 var engine_cutoff = "controls/engines/engine[2]/cutoff";
62                 }
63         if( engine_prop == -1 ) return; # engine not selected
64         
65 #break start procedure of selected engine
66         setprop(engine_prop, 0);
67         setprop(engine_cutoff, 1);
68 }
69
70 var start_apu = func{
71 # Is start subsystem  serviceable?
72
73 if( getprop( "tu154/switches/APU-starter-selector" ) != 1.0 ) return;
74 if( getprop("tu154/systems/electrical/indicators/apu-ready-to-start") != 1.0 ) return;
75 #let's start selected engine
76         setprop("controls/engines/engine[3]/starter", 1);
77         setprop("tu154/systems/electrical/indicators/apu-start", 1.0 );
78 }
79
80 var stop_apu = func{
81         setprop("controls/engines/engine[3]/starter", 0);
82         setprop("controls/engines/engine[3]/cutoff", 1);
83 }
84
85
86 var eng_1_handler = func{
87 settimer( eng_1_handler, ENGINE_UPDATE_PERIOD );
88
89 if( getprop( "engines/engine[0]/egt-degf" ) == nil ) return;            
90 if( getprop( "controls/engines/engine[0]/cutoff" ) == nil ) return;
91 if( getprop( "engines/engine[0]/n2" ) == nil ) return;
92 var pwr = getprop("tu154/systems/electrical/buses/DC27-bus-L/volts");
93 if( pwr == nil ) return;
94 # check 27V and blank lamps and exit if power off 
95 if(  pwr < 13.0 ) { check_lamps_eng(); return; }
96
97 # EGT delivery to fdm property tree
98 setprop( "fdm/jsbsim/propulsion/engine[0]/egt-degc", 
99                 getprop( "engines/engine[0]/egt-degf" ) * 0.55 - 17 );
100
101
102 if( getprop( "tu154/switches/startpanel-cold" ) == nil ) return;
103
104 if( getprop( "controls/engines/engine[0]/cutoff" ) == 1 )
105  if( getprop( "engines/engine[0]/n2" ) > 20.0 )
106       if( getprop( "tu154/switches/startpanel-cold" ) == 1 )
107          if( getprop( "engines/engine[0]/starter" ) == 1 )
108                 setprop( "controls/engines/engine[0]/cutoff",0 );
109 # indicator support
110  if( getprop( "engines/engine[0]/oil-pressure-psi" ) < 20 )
111         setprop("tu154/systems/electrical/indicators/engine-1/p-oil", 1.0 );
112  else setprop("tu154/systems/electrical/indicators/engine-1/p-oil", 0.0 );      
113
114  if( getprop( "engines/engine[0]/n2" ) < 40 )
115         setprop("tu154/systems/electrical/indicators/engine-failure-1", 1.0 );
116  else setprop("tu154/systems/electrical/indicators/engine-failure-1", 0.0 );    
117  
118  if( getprop( "controls/engines/engine[0]/throttle" ) > 0.8 )
119         setprop("tu154/systems/electrical/indicators/throttle-levers-unlocked", 1.0 );
120  else setprop("tu154/systems/electrical/indicators/throttle-levers-unlocked", 0.0 );    
121
122  if( getprop( "engines/engine[0]/n2" ) > 48.5 )
123                  starter_rpm_1 = getprop( "engines/engine[0]/starter" );
124  else starter_rpm_1 = 0.0;
125  
126  setprop("tu154/lamps/hi-starter-rpm", starter_rpm_1 + starter_rpm_2 + starter_rpm_3 ); 
127
128
129 }
130
131 var eng_2_handler = func{
132 settimer( eng_2_handler, ENGINE_UPDATE_PERIOD );
133 if( getprop( "controls/engines/engine[1]/cutoff" ) == nil ) return;
134 if( getprop( "engines/engine[1]/n2" ) == nil ) return;
135 # EGT delivery to fdm property tree
136 setprop( "fdm/jsbsim/propulsion/engine[1]/egt-degc", 
137                 getprop( "engines/engine[1]/egt-degf" ) * 0.55 - 17 );
138
139 if( getprop( "tu154/switches/startpanel-cold" ) == nil ) return;
140 var pwr = getprop("tu154/systems/electrical/buses/DC27-bus-L/volts");
141 if( pwr == nil ) return;
142 if(  pwr < 13.0 ) return;
143
144 if( getprop( "controls/engines/engine[1]/cutoff" ) == 1 ) 
145  if( getprop( "engines/engine[1]/n2" ) > 20.0 )
146       if( getprop( "tu154/switches/startpanel-cold" ) == 1 )
147          if( getprop( "engines/engine[1]/starter" ) == 1 )
148                 setprop( "controls/engines/engine[1]/cutoff",0 );
149 # indicator support
150  if( getprop( "engines/engine[1]/oil-pressure-psi" ) < 20 )
151         setprop("tu154/systems/electrical/indicators/engine-2/p-oil", 1.0 );
152  else setprop("tu154/systems/electrical/indicators/engine-2/p-oil", 0.0 );      
153
154  if( getprop( "engines/engine[1]/n2" ) < 40 )
155         setprop("tu154/systems/electrical/indicators/engine-failure-2", 1.0 );
156  else setprop("tu154/systems/electrical/indicators/engine-failure-2", 0.0 );    
157
158  if( getprop( "engines/engine[1]/n2" ) > 48.5 )
159                  starter_rpm_2 = getprop( "engines/engine[1]/starter" );
160  else starter_rpm_2 = 0.0;
161                 
162 }
163
164 var eng_3_handler = func{
165 settimer( eng_3_handler, ENGINE_UPDATE_PERIOD );
166
167 if( getprop( "controls/engines/engine[2]/cutoff" ) == nil ) return;
168 if( getprop( "engines/engine[2]/n2" ) == nil ) return;
169 # EGT delivery to fdm property tree
170 setprop( "fdm/jsbsim/propulsion/engine[2]/egt-degc", 
171                 getprop( "engines/engine[2]/egt-degf" ) * 0.55 - 17 );
172
173 if( getprop( "tu154/switches/startpanel-cold" ) == nil ) return;
174 var pwr = getprop("tu154/systems/electrical/buses/DC27-bus-L/volts");
175 if( pwr == nil ) return;
176 if(  pwr < 13.0 ) return;
177
178 if( getprop( "controls/engines/engine[2]/cutoff" ) == 1 )
179    if( getprop( "engines/engine[2]/n2" ) > 20.0 )
180          if( getprop( "engines/engine[2]/starter" ) == 1 )
181                 setprop( "controls/engines/engine[2]/cutoff",0 );
182 # indicator support
183  if( getprop( "engines/engine[2]/oil-pressure-psi" ) < 20 )
184         setprop("tu154/systems/electrical/indicators/engine-3/p-oil", 1.0 );
185  else setprop("tu154/systems/electrical/indicators/engine-3/p-oil", 0.0 );      
186
187  if( getprop( "engines/engine[2]/n2" ) < 40 )
188         setprop("tu154/systems/electrical/indicators/engine-failure-3", 1.0 );
189  else setprop("tu154/systems/electrical/indicators/engine-failure-3", 0.0 );    
190  
191  if( getprop( "engines/engine[2]/n2" ) > 48.5 )
192                  starter_rpm_3 = getprop( "engines/engine[2]/starter" );
193  else starter_rpm_3 = 0.0;
194
195         
196 }
197
198 var apu_handler = func{
199 settimer( apu_handler, ENGINE_UPDATE_PERIOD );
200 var param = 0.0;
201 if( getprop( "controls/engines/engine[3]/cutoff" ) == nil ) return;
202 if( getprop( "engines/engine[3]/n2" ) == nil ) return;
203 var pwr = getprop("tu154/systems/electrical/buses/DC27-bus-L/volts");
204 if( pwr == nil ) return;
205 # stop APU if 27 V failure
206 if(  (pwr < 13.0) or (getprop( "tu154/switches/APU-starter-switch" ) != 1 ) ) 
207         {
208         setprop("tu154/systems/electrical/indicators/apu-ready", 0.0 );
209         setprop("tu154/systems/electrical/indicators/apu-oil-pressure", 0.0 );
210         setprop("tu154/systems/electrical/indicators/apu-fuel-pressure", 0.0 );
211         setprop("tu154/systems/electrical/indicators/apu-start", 0.0 ); 
212         setprop("tu154/systems/electrical/indicators/apu-levers-open", 0.0 );   
213         setprop("tu154/systems/electrical/indicators/apu-ready-to-start", 0.0 );
214         stop_apu();
215         return;
216         }
217
218 if( getprop( "controls/engines/engine[3]/cutoff" ) == 1 )
219  if( getprop( "engines/engine[3]/n2" ) > 20.0 )
220       if( getprop( "tu154/switches/APU-starter-selector" ) == 1 )
221          if( getprop( "engines/engine[3]/starter" ) == 1 )
222                 setprop( "controls/engines/engine[3]/cutoff",0 );
223 # indicator support
224   if( getprop( "engines/engine[3]/oil-pressure-psi" ) < 20 )
225         setprop("tu154/systems/electrical/indicators/apu-oil-pressure", 1.0 );
226   else setprop("tu154/systems/electrical/indicators/apu-oil-pressure", 0.0 );   
227
228   param = 0.0;
229     
230   if( getprop( "tu154/systems/APU/APU-damper" ) > 0.95 )
231         setprop("tu154/systems/electrical/indicators/apu-levers-open", 1.0 );
232   else setprop("tu154/systems/electrical/indicators/apu-levers-open", 0.0 );    
233   if( getprop( "tu154/systems/electrical/indicators/apu-levers-open" ) == 1.0 )
234         param = param + 1;
235    if( getprop( "tu154/systems/electrical/indicators/apu-fuel-pressure" ) == 1.0 )
236         param = param + 1; 
237     if( getprop( "tu154/systems/APU/APU-bleed" ) < 4.8 )
238         param = param + 1;
239  if( param == 3.0 ) 
240         setprop("tu154/systems/electrical/indicators/apu-ready-to-start", 1.0 );
241  else setprop("tu154/systems/electrical/indicators/apu-ready-to-start", 0.0 );
242      
243   if( getprop( "engines/engine[3]/n2" ) > 90.0 )
244         {
245         setprop("tu154/systems/APU/APU-ready", 1.0 );
246         setprop("tu154/systems/electrical/indicators/apu-ready", 1.0 );
247         setprop("tu154/systems/electrical/indicators/apu-start", 0.0 );
248         }
249   else {
250         setprop("tu154/systems/APU/APU-ready", 0.0 );
251         setprop("tu154/systems/electrical/indicators/apu-ready", 0.0 );
252         }
253
254 if( getprop( "engines/engine[3]/n2" ) > 90.0 and getprop( "tu154/systems/electrical/indicators/apu-fuel-pressure") < 0.2 ) stop_apu();
255
256 }
257
258 var check_lamps_eng = func{
259         var pwr = getprop("tu154/systems/electrical/buses/DC27-bus-L/volts");
260         if( pwr == nil ) return;
261         var param = getprop( "tu154/systems/electrical/checking-lamps/engine-panel" );
262         if( param == nil ) param = 0.0;
263         if(  pwr < 13.0 ) param = 0.0;
264         setprop("tu154/systems/electrical/indicators/autothrottle-on", param );
265         setprop("tu154/systems/electrical/indicators/throttle-levers-unlocked", param );
266         setprop("tu154/systems/electrical/indicators/engine-1/egt-danger", param );
267         setprop("tu154/systems/electrical/indicators/engine-1/egt-stop", param );
268         setprop("tu154/systems/electrical/indicators/engine-1/filter-clog", param );
269         setprop("tu154/systems/electrical/indicators/engine-1/low-oil", param );
270         setprop("tu154/systems/electrical/indicators/engine-1/metal-in-oil", param );
271         setprop("tu154/systems/electrical/indicators/engine-1/overflow-oil", param );
272         setprop("tu154/systems/electrical/indicators/engine-1/p-fuel", param );
273         setprop("tu154/systems/electrical/indicators/engine-1/p-oil", param );
274         setprop("tu154/systems/electrical/indicators/engine-1/revers-dampers", param );
275         setprop("tu154/systems/electrical/indicators/engine-1/revers-lock", param );
276         setprop("tu154/systems/electrical/indicators/engine-1/t-bearing-danger", param );
277         setprop("tu154/systems/electrical/indicators/engine-1/vibration", param );
278         setprop("tu154/systems/electrical/indicators/engine-2/egt-danger", param );
279         setprop("tu154/systems/electrical/indicators/engine-2/egt-stop", param );
280         setprop("tu154/systems/electrical/indicators/engine-2/filter-clog", param );
281         setprop("tu154/systems/electrical/indicators/engine-2/low-oil", param );
282         setprop("tu154/systems/electrical/indicators/engine-2/metal-in-oil", param );
283         setprop("tu154/systems/electrical/indicators/engine-2/overflow-oil", param );
284         setprop("tu154/systems/electrical/indicators/engine-2/p-fuel", param );
285         setprop("tu154/systems/electrical/indicators/engine-2/p-oil", param );
286         setprop("tu154/systems/electrical/indicators/engine-2/t-bearing-danger", param );
287         setprop("tu154/systems/electrical/indicators/engine-2/vibration", param );       
288         setprop("tu154/systems/electrical/indicators/engine-3/egt-danger", param );
289         setprop("tu154/systems/electrical/indicators/engine-3/egt-stop", param );
290         setprop("tu154/systems/electrical/indicators/engine-3/filter-clog", param );
291         setprop("tu154/systems/electrical/indicators/engine-3/low-oil", param );
292         setprop("tu154/systems/electrical/indicators/engine-3/metal-in-oil", param );
293         setprop("tu154/systems/electrical/indicators/engine-3/overflow-oil", param );
294         setprop("tu154/systems/electrical/indicators/engine-3/p-fuel", param );
295         setprop("tu154/systems/electrical/indicators/engine-3/p-oil", param );
296         setprop("tu154/systems/electrical/indicators/engine-3/revers-dampers", param );
297         setprop("tu154/systems/electrical/indicators/engine-3/revers-lock", param );
298         setprop("tu154/systems/electrical/indicators/engine-3/t-bearing-danger", param );
299         setprop("tu154/systems/electrical/indicators/engine-3/vibration", param );  
300 }
301
302 eng_1_handler();
303 eng_2_handler();
304 eng_3_handler();
305 apu_handler();
306
307 print("Engines support started");