5 # Project Tupolev for FlightGear
7 # Yurik V. Nikiforoff, yurik.nsk@gmail.com
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;
19 var start_engine = func{
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
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
40 #let's start selected engine
41 setprop(engine_prop, 1);
45 var break_start = func{
46 # which engine we start now?
48 if( getprop("tu154/switches/startpanel-selector-1" ) == 1.0 )
50 engine_prop = "controls/engines/engine[0]/starter";
51 var engine_cutoff = "controls/engines/engine[0]/cutoff";
53 if( getprop("tu154/switches/startpanel-selector-2" ) == 1.0 )
55 engine_prop = "controls/engines/engine[1]/starter";
56 var engine_cutoff = "controls/engines/engine[1]/cutoff";
58 if( getprop("tu154/switches/startpanel-selector-3" ) == 1.0 )
60 engine_prop = "controls/engines/engine[2]/starter";
61 var engine_cutoff = "controls/engines/engine[2]/cutoff";
63 if( engine_prop == -1 ) return; # engine not selected
65 #break start procedure of selected engine
66 setprop(engine_prop, 0);
67 setprop(engine_cutoff, 1);
71 # Is start subsystem serviceable?
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 );
81 setprop("controls/engines/engine[3]/starter", 0);
82 setprop("controls/engines/engine[3]/cutoff", 1);
86 var eng_1_handler = func{
87 settimer( eng_1_handler, ENGINE_UPDATE_PERIOD );
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; }
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 );
102 if( getprop( "tu154/switches/startpanel-cold" ) == nil ) return;
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 );
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 );
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 );
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 );
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;
126 setprop("tu154/lamps/hi-starter-rpm", starter_rpm_1 + starter_rpm_2 + starter_rpm_3 );
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 );
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;
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 );
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 );
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 );
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;
164 var eng_3_handler = func{
165 settimer( eng_3_handler, ENGINE_UPDATE_PERIOD );
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 );
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;
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 );
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 );
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 );
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;
198 var apu_handler = func{
199 settimer( apu_handler, ENGINE_UPDATE_PERIOD );
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 ) )
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 setprop( "controls/engines/engine[3]/cutoff",1 );
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 );
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 );
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 )
235 if( getprop( "tu154/systems/electrical/indicators/apu-fuel-pressure" ) == 1.0 )
237 if( getprop( "tu154/systems/APU/APU-bleed" ) < 4.8 )
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 );
243 if( getprop( "engines/engine[3]/n2" ) > 90.0 )
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 );
250 setprop("tu154/systems/APU/APU-ready", 0.0 );
251 setprop("tu154/systems/electrical/indicators/apu-ready", 0.0 );
254 if( getprop( "engines/engine[3]/n2" ) > 90.0 and getprop( "tu154/systems/electrical/indicators/apu-fuel-pressure") < 0.2 ) stop_apu();
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 );
307 print("Engines support started");