Tupolev Tu-154B-2 by Yurik and his team.
[fg:toms-fgdata.git] / Aircraft / tu154b / Nasal / fuel.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 # sep 2008, 2010
10 #
11
12 # Fuel support
13
14 var FUEL_UPDATE_PERIOD = 1.0;
15 var PORTIONER_TIME = 5.0;
16
17 var AUTO_LEVEL_1 = 1566;
18 var AUTO_LEVEL_2 = 264;
19 var AUTO_LEVEL_3 = 20;
20
21
22 var TANK_2_CONST = 4.0;
23 var TANK_3_CONST = 2.0;
24 var TANK_4_CONST = 2.0;
25
26 var TRANSFER_CONST = 0.74;
27 var ADJUST_CONST = 26.7;
28
29 var FUEL_ALT = 16404; # ft
30
31
32
33 var fuel_handler = func{
34 settimer( fuel_handler, FUEL_UPDATE_PERIOD );
35
36 # Check electrical power
37 #First, check DC
38 var pwr = getprop("tu154/systems/electrical/buses/DC27-bus-L/volts");
39 if( pwr == nil ) return;
40 # check 27V and exit if power off 
41 if(  pwr < 13.0 ){  
42         blank_fuel_lamps(); 
43         return; 
44         }
45         
46 # check AC
47 var ac200_1 = getprop("tu154/systems/electrical/buses/AC3x200-bus-1L/volts");
48 if( ac200_1 == nil ) ac200_1 = 0.0;
49 var ac200_2 = getprop("tu154/systems/electrical/buses/AC3x200-bus-2/volts");
50 if( ac200_2 == nil ) ac200_2 = 0.0;
51 var ac200_3 = getprop("tu154/systems/electrical/buses/AC3x200-bus-3L/volts");
52 if( ac200_3 == nil ) ac200_3 = 0.0;
53
54 pwr = ac200_1 + ac200_2 + ac200_3;
55 if( pwr < 130.0 ) pwr = 0.0;
56         
57 var altitude = getprop("position/altitude-ft");
58 if( altitude == nil ) altitude = 0.0;
59
60
61 # Fuel tanks
62 # tank 1
63 var total = getprop("consumables/fuel/tank[0]/capacity-gal_us" );
64 if( total == nil ) total = 0.0;
65 var level = getprop("consumables/fuel/tank[0]/level-gal_us");
66 if( level == nil ) level = 0.0;
67 var total_consumed = getprop("tu154/systems/fuel/total-consumed-gal_us");
68 if( total_consumed == nil ) total_consumed = 0.0;
69 var total_fill = getprop("tu154/systems/fuel/total-fill-gal_us");
70 if( total_fill == nil ) total_fill = 0.0;
71
72 # Left wing
73 var tank_2_l = getprop("consumables/fuel/tank[1]/level-gal_us" );
74 if( tank_2_l == nil ) tank_2_l = 0.0;
75 var tank_3_l = getprop("consumables/fuel/tank[2]/level-gal_us" );
76 if( tank_3_l == nil ) tank_3_l = 0.0;
77 # Right wing
78 var tank_2_r = getprop("consumables/fuel/tank[3]/level-gal_us" );
79 if( tank_2_r == nil ) tank_2_r = 0.0;
80 var tank_3_r = getprop("consumables/fuel/tank[4]/level-gal_us" );
81 if( tank_3_r == nil ) tank_3_r = 0.0;
82 # Tank 4
83 var tank_4 = getprop("consumables/fuel/tank[5]/level-gal_us" );
84 if( tank_4 == nil ) tank_4_level = 0.0;
85
86 var density = getprop("consumables/fuel/tank[0]/density-ppg" );
87 if( density == nil ) density = 0.0;
88 density = density * 0.454;      # kg/gallon
89
90 # portioner
91 var portioner_flag = getprop("tu154/systems/fuel/portioner");
92 if( portioner_flag == nil ) portioner_flag = 0.0;
93 # ECN-319 fuel pumps
94 var ext_fuel_pump = getprop("tu154/systems/fuel/ecn-319-1");
95 if( ext_fuel_pump == nil ) ext_fuel_pump = 0.0;
96 var apu_fuel_pump = getprop("tu154/systems/fuel/ecn-319-2");
97 if( apu_fuel_pump == nil ) apu_fuel_pump = 0.0;
98
99 #switches
100 var autocon_ok = getprop("tu154/switches/fuel-autoconsumption-serviceable");
101 if( autocon_ok == nil ) autocon_ok = 0;
102 var autocon_selected = getprop("tu154/switches/fuel-autoconsumption-mode");
103 if( autocon_selected == nil ) autocon_selected = 0;
104 var autolevel = getprop("tu154/switches/fuel-autolevel-serviceable");
105 if( autolevel == nil ) autolevel = 0;
106
107 var trans_valve_1 = getprop("tu154/switches/transfer-valve-1");
108 if( trans_valve_1 == nil ) trans_valve_1 = 0;
109 var trans_valve_2 = getprop("tu154/switches/transfer-valve-2");
110 if( trans_valve_2 == nil ) trans_valve_2 = 0;
111
112 var fuel_meter = getprop("tu154/switches/fuel-meter-serviceable");
113 if( fuel_meter == nil ) fuel_meter = 0;
114 var cons_meter = getprop("tu154/switches/fuel-consumption-meter");
115 if( cons_meter == nil ) fuel_meter = 0;
116
117
118 var autolevel_1 = 0;
119 var autolevel_2 = 0;
120 var autolevel_3 = 0;
121 var autolevel_4 = 0;
122 var autolevel_failure = 0;
123
124 # cutoff valve
125 var cv1 = getprop("tu154/switches/fuel-cutoff-valve-1");
126 if( cv1 == nil ) cv1 = 0;
127 var cv2 = getprop("tu154/switches/fuel-cutoff-valve-2");
128 if( cv2 == nil ) cv2 = 0;
129 var cv3 = getprop("tu154/switches/fuel-cutoff-valve-3");
130 if( cv3 == nil ) cv3 = 0;
131
132 # stop engine levers
133 var cl1 = getprop("tu154/switches/cutoff-lever-1");
134 if( cl1 == nil ) cl1 = 0;
135 var cl2 = getprop("tu154/switches/cutoff-lever-2");
136 if( cl2 == nil ) cl2 = 0;
137 var cl3 = getprop("tu154/switches/cutoff-lever-3");
138 if( cl3 == nil ) cl3 = 0;
139
140
141 # APU support
142 var apu_cv = getprop("tu154/switches/APU-cutoff-valve-delay");
143 if( apu_cv == nil ) apu_cv = 0;
144 if( apu_cv > 0.9 ) apu_fuel_pump = 1.0;
145 else apu_fuel_pump = 0.0;
146 setprop("tu154/systems/fuel/ecn-319-2", apu_fuel_pump );
147
148 # manu pumps control
149 var p_1_1 = getprop("tu154/switches/pump-1-serviceable");
150 if( p_1_1 == nil ) p_1_1 = 0;
151 var p_1_2 = getprop("tu154/switches/pump-2-serviceable");
152 if( p_1_2 == nil ) p_1_2 = 0;
153 var p_1_3 = getprop("tu154/switches/pump-3-serviceable");
154 if( p_1_3 == nil ) p_1_3 = 0;
155 var p_1_4 = getprop("tu154/switches/pump-4-serviceable");
156 if( p_1_4 == nil ) p_1_4 = 0;
157
158 var p_2_l = getprop("tu154/switches/tank-2-left-serviceable");
159 if( p_2_l == nil ) p_2_l = 0;
160 var p_2_r = getprop("tu154/switches/tank-2-right-serviceable");
161 if( p_2_r == nil ) p_2_r = 0;
162 var p_3_l = getprop("tu154/switches/tank-3-left-serviceable");
163 if( p_3_l == nil ) p_3_l = 0;
164 var p_3_r = getprop("tu154/switches/tank-3-right-serviceable");
165 if( p_3_r == nil ) p_3_r = 0;
166 var p_4 = getprop("tu154/switches/tank-4-serviceable");
167 if( p_4 == nil ) p_4 = 0;
168
169 # Auto consume procedure
170 # check fuel and select auto consume mode
171 var auto_cons_state = 0;
172
173 if( (tank_2_l + tank_2_r) > AUTO_LEVEL_1 ) auto_cons_state = 1;
174 else auto_cons_state = 2;
175 if( (tank_2_l + tank_2_r) < 1.0 ) auto_cons_state = 3;
176 if( ((tank_3_l + tank_3_r) < 1.0) and ((tank_2_l + tank_2_r) < 1.0) ) auto_cons_state = 4;
177 if( tank_4 < 1.0 ) auto_cons_state = 5;
178 if( autocon_ok == 0 ) auto_cons_state = 5;
179
180 # fuel pump coeft
181 var k2_l = 0.0;
182 var k2_r = 0.0;
183 var k3_l = 0.0;
184 var k3_r = 0.0;
185 var k4 = 0.0;
186
187 if( autocon_ok == 1 ) {
188       if( auto_cons_state == 1 ) {      k2_l = TANK_2_CONST; 
189                                         k2_r = TANK_2_CONST; }
190                                         
191       if( auto_cons_state == 2 ) {      k2_l = TANK_2_CONST; 
192                                         k2_r = TANK_2_CONST; 
193                                         k3_l = TANK_3_CONST;
194                                         k3_r = TANK_3_CONST; }
195                                         
196       if( auto_cons_state == 3 ) {      k3_l = TANK_3_CONST; 
197                                         k3_r = TANK_3_CONST; }
198                                         
199       if( auto_cons_state == 4 ) {      k4 = TANK_4_CONST; }
200       
201 # autolevel support
202 if( autolevel == 1 )
203         {
204         if( abs( tank_2_l - tank_2_r ) > AUTO_LEVEL_3 )
205                 {
206                 if( tank_2_l > tank_2_r ) autolevel_1 = 1;
207                 else autolevel_2 = 1;
208                 }
209         if( abs( tank_3_l - tank_3_r ) > AUTO_LEVEL_3 )
210                 {
211                 if( tank_3_l > tank_3_r ) autolevel_3 = 1;
212                 else autolevel_4 = 1;
213                 }
214         if( abs( tank_2_l - tank_2_r ) > AUTO_LEVEL_2 ) autolevel_failure = 1;
215         if( abs( tank_3_l - tank_3_r ) > AUTO_LEVEL_2 ) autolevel_failure = 1;
216         }
217 }
218       
219 if( autolevel_failure == 0 )
220         {
221         # stop pump for auto level
222         if( autolevel_1 == 1 ) k2_l = 0;
223         if( autolevel_2 == 1 ) k2_r = 0;
224         if( autolevel_3 == 1 ) k3_l = 0;
225         if( autolevel_4 == 1 ) k3_r = 0;
226         }
227 else    { # clear flags cause autolevel failure at all
228         autolevel_1 = 0;
229         autolevel_2 = 0;
230         autolevel_3 = 0;
231         autolevel_4 = 0;
232         }
233 # if auto mode deselected, let's set pumps manually      
234 if( autocon_selected == 0 ) {
235         k2_l = p_2_l * TANK_2_CONST;    # 3 pumps per tanks 2, 2 per tanks 3, 2 per tank 4
236         k2_r = p_2_r * TANK_2_CONST;
237         k3_l = p_3_l * TANK_3_CONST;
238         k3_r = p_3_r * TANK_3_CONST;
239         k4 = p_4 * TANK_4_CONST;
240         }
241             
242       
243 # check empty tanks
244 if( tank_2_l == 0.0 ) k2_l = 0.0;
245 if( tank_2_r == 0.0 ) k2_r = 0.0;
246 if( tank_3_l == 0.0 ) k3_l = 0.0;
247 if( tank_3_r == 0.0 ) k3_r = 0.0;
248 if( tank_4 == 0.0 ) k4 = 0.0;
249
250 # check AC power
251 if( pwr == 0.0 )
252         { # stop all pumps, automatic and manual mode
253         k2_l = 0.0;
254         k2_r = 0.0;
255         k3_l = 0.0;
256         k3_r = 0.0;
257         k4 = 0.0;
258         p_1_1 = 0.0;
259         p_1_2 = 0.0;
260         p_1_3 = 0.0;
261         p_1_4 = 0.0;
262         p_2_l = 0.0;
263         p_2_r = 0.0;
264         p_3_l = 0.0;
265         p_3_r = 0.0;
266         p_4 = 0.0;
267         }
268 # lamps support
269 if( k2_l > 0 )
270         {
271         setprop( "tu154/lamps/pump-l-5", 1.0 );
272         setprop( "tu154/lamps/pump-l-6", 1.0 );
273         }
274 else    {
275         setprop( "tu154/lamps/pump-l-5", 0.0 );
276         setprop( "tu154/lamps/pump-l-6", 0.0 );
277         }
278 if( k2_r > 0 )
279         {
280         setprop( "tu154/lamps/pump-r-5", 1.0 );
281         setprop( "tu154/lamps/pump-r-6", 1.0 );
282         }
283 else    {
284         setprop( "tu154/lamps/pump-r-5", 0.0 );
285         setprop( "tu154/lamps/pump-r-6", 0.0 );
286         }
287 if( k3_l > 0 )
288         {
289         setprop( "tu154/lamps/pump-l-7", 1.0 );
290         setprop( "tu154/lamps/pump-l-8", 1.0 );
291         setprop( "tu154/lamps/pump-l-9", 1.0 );
292         }
293 else    {
294         setprop( "tu154/lamps/pump-l-7", 0.0 );
295         setprop( "tu154/lamps/pump-l-8", 0.0 );
296         setprop( "tu154/lamps/pump-l-9", 0.0 );
297         }
298 if( k3_r > 0 )
299         {
300         setprop( "tu154/lamps/pump-r-7", 1.0 );
301         setprop( "tu154/lamps/pump-r-8", 1.0 );
302         setprop( "tu154/lamps/pump-r-9", 1.0 );
303         }
304 else    {
305         setprop( "tu154/lamps/pump-r-7", 0.0 );
306         setprop( "tu154/lamps/pump-r-8", 0.0 );
307         setprop( "tu154/lamps/pump-r-9", 0.0 );
308         }
309 if( k4 > 0 )
310         {
311         setprop( "tu154/lamps/pump-10", 1.0 );
312         setprop( "tu154/lamps/pump-11", 1.0 );
313         }
314 else    {
315         setprop( "tu154/lamps/pump-10", 0.0 );
316         setprop( "tu154/lamps/pump-11", 0.0 );
317         }
318
319 if( autocon_ok == 1 )   setprop( "tu154/lamps/auto-consumption-failure", 0.0 );
320 else    setprop( "tu154/lamps/auto-consumption-failure", 1.0 ); 
321
322 if( auto_cons_state == 1 )      
323         {
324         setprop( "tu154/lamps/consumption-tank-2", 1.0 );
325         setprop( "tu154/lamps/consumption-tank-3", 0.0 );
326         setprop( "tu154/lamps/consumption-tank-4", 0.0 );       
327         }
328 if( auto_cons_state == 2 )      
329         {
330         setprop( "tu154/lamps/consumption-tank-2", 1.0 );
331         setprop( "tu154/lamps/consumption-tank-3", 1.0 );
332         setprop( "tu154/lamps/consumption-tank-4", 0.0 );
333         }
334 if( auto_cons_state == 3 )      
335         {
336         setprop( "tu154/lamps/consumption-tank-2", 0.0 );
337         setprop( "tu154/lamps/consumption-tank-3", 1.0 );
338         setprop( "tu154/lamps/consumption-tank-4", 0.0 );
339         }
340 if( auto_cons_state == 4 )      
341         {
342         setprop( "tu154/lamps/consumption-tank-2", 0.0 );
343         setprop( "tu154/lamps/consumption-tank-3", 0.0 );
344         setprop( "tu154/lamps/consumption-tank-4", 1.0 );
345         }
346 if( auto_cons_state == 5 )      
347         {
348         setprop( "tu154/lamps/consumption-tank-2", 0.0 );
349         setprop( "tu154/lamps/consumption-tank-3", 0.0 );
350         setprop( "tu154/lamps/consumption-tank-4", 0.0 );
351         }
352 # auto level lamps
353 if( autolevel_1 == 1 ) setprop( "tu154/lamps/tank-2-l-level", 1.0 );
354 else setprop( "tu154/lamps/tank-2-l-level", 0.0 );
355 if( autolevel_2 == 1 ) setprop( "tu154/lamps/tank-2-r-level", 1.0 );
356 else setprop( "tu154/lamps/tank-2-r-level", 0.0 );
357 if( autolevel_3 == 1 ) setprop( "tu154/lamps/tank-3-l-level", 1.0 );
358 else setprop( "tu154/lamps/tank-3-l-level", 0.0 );
359 if( autolevel_4 == 1 ) setprop( "tu154/lamps/tank-3-r-level", 1.0 );
360 else setprop( "tu154/lamps/tank-3-r-level", 0.0 );
361
362 if( autolevel == 1 ) 
363         {
364         if( autocon_ok == 1 ) { setprop( "tu154/lamps/fuel-level-auto", 1.0 ); }
365         else    {
366                 setprop( "tu154/lamps/fuel-level-auto", 0.0 );
367                 setprop( "tu154/lamps/tank-2-l-level", 0.0 );
368                 setprop( "tu154/lamps/tank-2-r-level", 0.0 );
369                 setprop( "tu154/lamps/tank-3-l-level", 0.0 );
370                 setprop( "tu154/lamps/tank-3-r-level", 0.0 );
371                 }
372         }
373 else    {
374         setprop( "tu154/lamps/fuel-level-auto", 0.0 );
375         setprop( "tu154/lamps/tank-2-l-level", 0.0 );
376         setprop( "tu154/lamps/tank-2-r-level", 0.0 );
377         setprop( "tu154/lamps/tank-3-l-level", 0.0 );
378         setprop( "tu154/lamps/tank-3-r-level", 0.0 );
379         }
380
381 if( autolevel_failure == 1 ) 
382         {
383         setprop( "tu154/lamps/tank-2-l-level", 1.0 );
384         setprop( "tu154/lamps/tank-2-r-level", 1.0 );
385         setprop( "tu154/lamps/tank-3-l-level", 1.0 );
386         setprop( "tu154/lamps/tank-3-r-level", 1.0 );
387         setprop( "tu154/lamps/fuel-level-auto", 0.0 );
388         }
389
390 if( trans_valve_1 > 0 )
391         {
392         setprop( "tu154/lamps/valve-l-1", 1.0 );
393         setprop( "tu154/lamps/valve-r-1", 1.0 );
394         }
395 else    {
396         setprop( "tu154/lamps/valve-l-1", 0.0 );
397         setprop( "tu154/lamps/valve-r-1", 0.0 );
398         }
399 if( trans_valve_2 > 0 )
400         {
401         setprop( "tu154/lamps/valve-l-2", 1.0 );
402         setprop( "tu154/lamps/valve-r-2", 1.0 );
403         }
404 else    {
405         setprop( "tu154/lamps/valve-l-2", 0.0 );
406         setprop( "tu154/lamps/valve-r-2", 0.0 );
407         }
408         
409 if( p_1_1 > 0 ) setprop( "tu154/lamps/pump-1", 1.0 );
410 else setprop( "tu154/lamps/pump-1", 0.0 );
411 if( p_1_2 > 0 ) setprop( "tu154/lamps/pump-2", 1.0 );
412 else setprop( "tu154/lamps/pump-2", 0.0 );
413 if( p_1_3 > 0 ) setprop( "tu154/lamps/pump-3", 1.0 );
414 else setprop( "tu154/lamps/pump-3", 0.0 );
415 if( p_1_4 > 0 ) setprop( "tu154/lamps/pump-4", 1.0 );
416 else setprop( "tu154/lamps/pump-4", 0.0 );
417
418 if( cv1 > 0 ) setprop( "tu154/lamps/fuel-cutoff-1", 1.0 );
419 else setprop( "tu154/lamps/fuel-cutoff-1", 0.0 );
420 if( cv2 > 0 ) setprop( "tu154/lamps/fuel-cutoff-2", 1.0 );
421 else setprop( "tu154/lamps/fuel-cutoff-2", 0.0 );
422 if( cv3 > 0 ) setprop( "tu154/lamps/fuel-cutoff-3", 1.0 );
423 else setprop( "tu154/lamps/fuel-cutoff-3", 0.0 );
424
425 # end lamps support     
426
427
428 # portioner procedure
429 var pumps_pressure = k2_l + k2_r + k3_l + k3_r + k4;
430 var consumed = total - level;
431 var consumed_norm = level/total;
432 var overfull = 0.0;
433
434 if( consumed_norm < 0.9545 )    # -150 kg in tank 1
435  {
436   if( portioner_flag == 0.0 )   # avoid multiple start portioner procedure
437   {
438      if( pumps_pressure > 0 )   # deny portioner procedure if tanks 2,3,4 are empty
439         {
440         # total consume value - only for consume gauge
441         setprop("tu154/systems/fuel/total-consumed-gal_us", total_consumed + consumed );
442         
443         # start portioner procedure
444         consumed = consumed/pumps_pressure;
445         portioner_flag = 1.0;
446         setprop( "tu154/systems/fuel/portioner", portioner_flag );
447         interpolate( "tu154/systems/fuel/portioner", 0.0, PORTIONER_TIME );
448         # refueling tank 1
449         setprop( "consumables/fuel/tank[0]/last-gal_us", total);
450         interpolate( "consumables/fuel/tank[0]/level-gal_us", total, PORTIONER_TIME );
451         # get fuel from tanks 2
452         tank_2_l = tank_2_l - consumed * k2_l;
453         if( tank_2_l < 1.0 ) tank_2_l = 0.0;
454         interpolate( "consumables/fuel/tank[1]/level-gal_us", tank_2_l, PORTIONER_TIME );
455         tank_2_r = tank_2_r - consumed * k2_r;
456         if( tank_2_r < 1.0 ) tank_2_r = 0.0;
457         interpolate( "consumables/fuel/tank[3]/level-gal_us", tank_2_r, PORTIONER_TIME );
458         # get fuel from tanks 3
459         tank_3_l = tank_3_l - consumed * k3_l;
460         if( tank_3_l < 1.0 ) tank_3_l = 0.0;
461         interpolate( "consumables/fuel/tank[2]/level-gal_us", tank_3_l, PORTIONER_TIME );
462         tank_3_r = tank_3_r - consumed * k3_r;
463         if( tank_3_r < 1.0 ) tank_3_r = 0.0;
464         interpolate( "consumables/fuel/tank[4]/level-gal_us", tank_3_r, PORTIONER_TIME );
465         # get fuel from tank 4
466         tank_4 = tank_4 - consumed * k4;
467         if( tank_4 < 1.0 ) tank_4 = 0.0;
468         interpolate( "consumables/fuel/tank[5]/level-gal_us", tank_4, PORTIONER_TIME );
469           } 
470          } 
471         } # end portioner procedure
472         
473 # fuel transfer procedure
474 if( portioner_flag == 0.0 ) # don't transfer if portioner in operate 
475         {
476 # From 3 to 2 fuel transfer
477         if( trans_valve_1 == 1.0 )
478                 {
479                 #get
480                 consumed = ( k3_l + k3_r ) * TRANSFER_CONST;
481                 tank_3_l = tank_3_l - k3_l * TRANSFER_CONST;
482                 if( tank_3_l < 1.0 ) tank_3_l = 0.0;
483                 setprop( "consumables/fuel/tank[2]/level-gal_us", tank_3_l );
484                 tank_3_r = tank_3_r - k3_r * TRANSFER_CONST;
485                 if( tank_3_r < 1.0 ) tank_3_r = 0.0;
486                 setprop( "consumables/fuel/tank[4]/level-gal_us", tank_3_r );
487                 # put to tank 1
488                 level = level + consumed;
489                 if( level > total ){
490                         overfull = level - total;
491                         level = total;
492                         }
493                 setprop( "consumables/fuel/tank[0]/level-gal_us", level );
494                 }
495 # From 4 to 2
496         if( trans_valve_2 == 1.0 )
497                 {
498                 #get
499                 consumed = k4 * TRANSFER_CONST;
500                 tank_4 = tank_4 - consumed;
501                 if( tank_4 < 1.0 ) tank_4 = 0.0;
502                 setprop( "consumables/fuel/tank[5]/level-gal_us", tank_4 );
503                 # put to tank 1
504                 level = level + consumed;
505                 if( level > total ){
506                         overfull = overfull + level - total;
507                         level = total;
508                         }
509                 setprop( "consumables/fuel/tank[0]/level-gal_us", level );
510                 }
511 # Puts fuel into
512         tank_2_l = tank_2_l + overfull/2;
513         tank_2_r = tank_2_r + overfull/2;
514         setprop( "consumables/fuel/tank[1]/level-gal_us", tank_2_l );
515         setprop( "consumables/fuel/tank[3]/level-gal_us", tank_2_r );
516         } 
517 # end fuel transfer procedure
518
519 # fuel level meters support
520 setprop("tu154/systems/fuel/fuel-meter-serviceable", fuel_meter );
521 setprop("tu154/systems/fuel/fuel-consumption-serviceable", cons_meter );
522 # reload fuel level of cons tank
523 level = getprop("consumables/fuel/tank[0]/level-gal_us");
524 if( level == nil ) level = 0.0;
525         
526         if( fuel_meter == 1.0 ) {
527 interpolate("tu154/systems/fuel/tank-1-kg", level * density, FUEL_UPDATE_PERIOD );
528 interpolate("tu154/systems/fuel/tank-2-l-kg", tank_2_l * density, FUEL_UPDATE_PERIOD );
529 interpolate("tu154/systems/fuel/tank-2-r-kg", tank_2_r * density, FUEL_UPDATE_PERIOD );
530 interpolate("tu154/systems/fuel/tank-3-l-kg", tank_3_l * density, FUEL_UPDATE_PERIOD );
531 interpolate("tu154/systems/fuel/tank-3-r-kg", tank_3_r * density, FUEL_UPDATE_PERIOD );
532 interpolate("tu154/systems/fuel/tank-4-kg", tank_4 * density, FUEL_UPDATE_PERIOD );
533 # total
534 interpolate( "tu154/systems/fuel/total-kg", 
535  ( level + tank_2_l + tank_2_r + tank_3_l + tank_3_r + tank_4 ) * density,
536  FUEL_UPDATE_PERIOD );
537         }
538         else {
539 interpolate("tu154/systems/fuel/tank-1-kg", 0.0, FUEL_UPDATE_PERIOD );
540 interpolate("tu154/systems/fuel/tank-2-l-kg", 0.0, FUEL_UPDATE_PERIOD );
541 interpolate("tu154/systems/fuel/tank-2-r-kg", 0.0, FUEL_UPDATE_PERIOD );
542 interpolate("tu154/systems/fuel/tank-3-l-kg", 0.0, FUEL_UPDATE_PERIOD );
543 interpolate("tu154/systems/fuel/tank-3-r-kg", 0.0, FUEL_UPDATE_PERIOD );
544 interpolate("tu154/systems/fuel/tank-4-kg", 0.0, FUEL_UPDATE_PERIOD );
545 interpolate( "tu154/systems/fuel/total-kg", 0.0, FUEL_UPDATE_PERIOD );
546         }
547
548 # Fuel consume meter procedure
549         
550 if( cons_meter == 1.0 ) {
551         total_consumed = getprop("tu154/systems/fuel/total-consumed-gal_us" );
552         if( total_consumed == nil ) total_consumed = 0.0;
553         level = ( total_fill - total_consumed ) * density;
554         if( level < 0.0 ) level = 0.0;
555         interpolate("tu154/systems/fuel/rest-kg", level, FUEL_UPDATE_PERIOD );
556         }
557 else    {
558         interpolate("tu154/systems/fuel/rest-kg", 0.0, FUEL_UPDATE_PERIOD );
559         }
560         
561 # cutoff procedure
562 if( cv1 < 1.0 ) setprop( "controls/engines/engine[0]/cutoff", 1 );
563 if( cv2 < 1.0 ) setprop( "controls/engines/engine[1]/cutoff", 1 );
564 if( cv3 < 1.0 ) setprop( "controls/engines/engine[2]/cutoff", 1 );      
565 # stop levers
566 if( cl1 < 1.0 ) setprop( "controls/engines/engine[0]/cutoff", 1 );
567 if( cl2 < 1.0 ) setprop( "controls/engines/engine[1]/cutoff", 1 );
568 if( cl3 < 1.0 ) setprop( "controls/engines/engine[2]/cutoff", 1 );      
569
570
571 var tank_1_pumps = p_1_1 + p_1_2 + p_1_3 + p_1_4 + ext_fuel_pump;
572 if( tank_1_pumps < 1.0 )
573         {
574         if( altitude > FUEL_ALT ) {
575          setprop( "controls/engines/engine[0]/cutoff", 1 );
576          setprop( "controls/engines/engine[1]/cutoff", 1 );
577          setprop( "controls/engines/engine[2]/cutoff", 1 );
578                 }}
579
580 # P fuel indicators
581 # reload fuel level of cons tank
582 level = getprop("consumables/fuel/tank[0]/level-gal_us");
583 if( level == nil ) level = 0.0;
584
585
586 if( level > 0.0 ){
587         if( apu_fuel_pump > 0 ) 
588                 setprop( "tu154/systems/electrical/indicators/apu-fuel-pressure", 1.0 );
589         else    setprop( "tu154/systems/electrical/indicators/apu-fuel-pressure", 0.0 );
590         if( tank_1_pumps > 0.0 ){
591  if( cv1 > 0.0 ){ setprop( "tu154/systems/electrical/indicators/engine-1/p-fuel", 0 ); }
592  else { setprop( "tu154/systems/electrical/indicators/engine-1/p-fuel", 1 ); }
593  if( cv2 > 0.0 ){ setprop( "tu154/systems/electrical/indicators/engine-2/p-fuel", 0 ); }
594  else { setprop( "tu154/systems/electrical/indicators/engine-2/p-fuel", 1 ); }
595  if( cv3 > 0.0 ){ setprop( "tu154/systems/electrical/indicators/engine-3/p-fuel", 0 ); }
596  else { setprop( "tu154/systems/electrical/indicators/engine-3/p-fuel", 1 ); }
597         }
598         else {
599       setprop( "tu154/systems/electrical/indicators/engine-1/p-fuel", 1 ); 
600       setprop( "tu154/systems/electrical/indicators/engine-2/p-fuel", 1 ); 
601       setprop( "tu154/systems/electrical/indicators/engine-3/p-fuel", 1 );
602         }
603      }
604 else { 
605  setprop( "tu154/systems/electrical/indicators/engine-1/p-fuel", 1 ); 
606  setprop( "tu154/systems/electrical/indicators/engine-2/p-fuel", 1 ); 
607  setprop( "tu154/systems/electrical/indicators/engine-3/p-fuel", 1 ); 
608  setprop( "tu154/systems/electrical/indicators/apu-fuel-pressure", 0.0 );
609      }
610
611
612 # end cutoff procedure
613 } # end fuel handler
614
615 var blank_fuel_lamps = func{
616         setprop( "tu154/lamps/pump-l-5", 0.0 );
617         setprop( "tu154/lamps/pump-l-6", 0.0 );
618         setprop( "tu154/lamps/pump-r-5", 0.0 );
619         setprop( "tu154/lamps/pump-r-6", 0.0 );
620         setprop( "tu154/lamps/pump-l-7", 0.0 );
621         setprop( "tu154/lamps/pump-l-8", 0.0 );
622         setprop( "tu154/lamps/pump-l-9", 0.0 );
623         setprop( "tu154/lamps/pump-r-7", 0.0 );
624         setprop( "tu154/lamps/pump-r-8", 0.0 );
625         setprop( "tu154/lamps/pump-r-9", 0.0 );
626         setprop( "tu154/lamps/pump-10", 0.0 );
627         setprop( "tu154/lamps/pump-11", 0.0 );
628         setprop( "tu154/lamps/auto-consumption-failure", 0.0 );
629         setprop( "tu154/lamps/consumption-tank-2", 0.0 );
630         setprop( "tu154/lamps/consumption-tank-3", 0.0 );
631         setprop( "tu154/lamps/consumption-tank-4", 0.0 );       
632         setprop( "tu154/lamps/tank-2-l-level", 0.0 );
633         setprop( "tu154/lamps/tank-2-r-level", 0.0 );
634         setprop( "tu154/lamps/tank-3-l-level", 0.0 );
635         setprop( "tu154/lamps/tank-3-r-level", 0.0 );
636         setprop( "tu154/lamps/fuel-level-auto", 0.0 );
637         setprop( "tu154/lamps/tank-2-l-level", 0.0 );
638         setprop( "tu154/lamps/tank-2-r-level", 0.0 );
639         setprop( "tu154/lamps/tank-3-l-level", 0.0 );
640         setprop( "tu154/lamps/tank-3-r-level", 0.0 );
641         setprop( "tu154/lamps/valve-l-1", 0.0 );
642         setprop( "tu154/lamps/valve-r-1", 0.0 );
643         setprop( "tu154/lamps/valve-l-2", 0.0 );
644         setprop( "tu154/lamps/valve-r-2", 0.0 );
645         setprop( "tu154/lamps/pump-1", 0.0 );
646         setprop( "tu154/lamps/pump-2", 0.0 );
647         setprop( "tu154/lamps/pump-3", 0.0 );
648         setprop( "tu154/lamps/pump-4", 0.0 );
649         setprop( "tu154/lamps/fuel-cutoff-1", 0.0 );
650         setprop( "tu154/lamps/fuel-cutoff-2", 0.0 );
651         setprop( "tu154/lamps/fuel-cutoff-3", 0.0 );
652         setprop( "tu154/systems/electrical/indicators/apu-fuel-pressure", 0.0 );
653         
654         interpolate("tu154/systems/fuel/tank-1-kg", 0.0, FUEL_UPDATE_PERIOD );
655         interpolate("tu154/systems/fuel/tank-2-l-kg", 0.0, FUEL_UPDATE_PERIOD );
656         interpolate("tu154/systems/fuel/tank-2-r-kg", 0.0, FUEL_UPDATE_PERIOD );
657         interpolate("tu154/systems/fuel/tank-3-l-kg", 0.0, FUEL_UPDATE_PERIOD );
658         interpolate("tu154/systems/fuel/tank-3-r-kg", 0.0, FUEL_UPDATE_PERIOD );
659         interpolate("tu154/systems/fuel/tank-4-kg", 0.0, FUEL_UPDATE_PERIOD );
660         interpolate( "tu154/systems/fuel/total-kg", 0.0, FUEL_UPDATE_PERIOD );
661
662 }
663
664
665 # Fuel consume meter adjust
666 cons_meter_adjust = func{
667 var level = getprop("tu154/systems/fuel/total-fill-gal_us");
668 if( level == nil ) level = 0.0;
669 level = level + arg[0] * ADJUST_CONST;
670 if( level < 0.0 ) level = 0.0;
671 setprop("tu154/systems/fuel/total-fill-gal_us", level);
672 }
673
674 # load buses
675
676 # start fuel support
677 fuel_handler();
678
679 print("Fuel support started");