Tu-154B2 version 3.1:
[fg:toms-fgdata.git] / Aircraft / tu154b / Nasal / absu.nas
1 #
2 # ABSU-154 support
3 # Yurik V. Nikiforoff, yurik.nsk@gmail.com
4 # Novosibirsk, Russia
5 # 2007 - 2008,2010,2013
6 #
7
8 #var HEADING_DEVIATION_LIMIT = 20.0;
9 #var GLIDESLOPE_DEVIATION_LIMIT = 10.0;
10 var PITCH_YOKE_LIMIT = 0.5;
11 var BANK_YOKE_LIMIT = 0.5;
12
13 var absu_property_update = func {       # <-   handler begin here
14
15 var param=0.0;
16
17 settimer( absu_property_update, 0 );
18
19 # pn-5 selected mode
20 #var az1 = getprop("tu154/instrumentation/pn-5/az-1");
21 #if( az1 == nil ) az1 = 0.0;
22 var az2 = getprop("tu154/instrumentation/pn-5/az-2");
23 if( az2 == nil ) az2 = 0.0;
24
25
26
27
28
29 # VOR support
30 if( az2 )
31         {
32         var radial_actual = "instrumentation/nav[1]/radials/actual-deg";
33         var radial_reciprocal = "instrumentation/nav[1]/radials/reciprocal-radial-deg";
34         var radial_selected = "instrumentation/nav[1]/radials/selected-deg";
35         var to_flag_prop = "instrumentation/nav[1]/to-flag";
36         }
37 else    {
38         var radial_actual = "instrumentation/nav[0]/radials/actual-deg";
39         var radial_reciprocal = "instrumentation/nav[0]/radials/reciprocal-radial-deg";
40         var radial_selected = "instrumentation/nav[0]/radials/selected-deg";
41         var to_flag_prop = "instrumentation/nav[0]/to-flag";
42         }
43 var to_flag = getprop( to_flag_prop );
44 if( to_flag == nil ) to_flag = 0.0;
45 if( to_flag ) param = getprop(radial_reciprocal);
46 else param = getprop(radial_actual);
47 if( param == nil ) param = 0.0;
48 var param2 = getprop(radial_selected);
49 if( param2 == nil ) param2 = 0.0;
50 param = param - param2;
51 if( param < -180.0 ) param = 360.0 + param;
52 if( param > 180.0 ) param = 360.0 - param;
53 if( to_flag ) param = -param;
54 setprop("fdm/jsbsim/ap/input-heading-delta", param);
55
56 #Delivery gyro heading to TKS compass system
57 param = getprop("orientation/heading-deg")+
58         getprop("instrumentation/heading-indicator[0]/offset-deg");
59 if( param < 0.0 ) param = param + 360.0;
60 if( param > 360.0 ) param = param - 360.0;
61 setprop("fdm/jsbsim/ap/input-heading-gyro-1", param);
62
63 param = getprop("orientation/heading-deg")+
64         getprop("instrumentation/heading-indicator[1]/offset-deg");
65 if( param < 0.0 ) param = param + 360.0;
66 if( param > 360.0 ) param = param - 360.0;
67 setprop("fdm/jsbsim/ap/input-heading-gyro-2", param);
68
69 #Delivery magnetic heading to TKS compass system
70
71 param = getprop("orientation/heading-magnetic-deg");
72 if( param == nil ) param = 0.0;
73 setprop("fdm/jsbsim/ap/input-magnetic-heading", param);
74
75 #Delivery brakes
76 param = getprop("controls/gear/brake-left");
77 if( param == nil ) param = 0.0;
78 setprop("fdm/jsbsim/gear/brake-left", param);
79 param = getprop("controls/gear/brake-right");
80 if( param == nil ) param = 0.0;
81 setprop("fdm/jsbsim/gear/brake-right", param);
82 param = getprop("controls/gear/brake-parking");
83 if( param == nil ) param = 0.0;
84 setprop("fdm/jsbsim/gear/brake-parking", param);
85 # delivery steering parameters
86 param = getprop("controls/gear/steering");
87 if( param == nil ) param = 0.0;
88 setprop("fdm/jsbsim/gear/steering", param);
89 param = getprop("controls/gear/nose-wheel-steering");
90 if( param == nil ) param = 0.0;
91 setprop("fdm/jsbsim/gear/nose-wheel-steering", param);
92
93
94 # PNP 
95
96
97 # "Plane" handle
98 var src_plane = "tu154/instrumentation/pnp[0]/plane-deg";
99 param = getprop("tu154/switches/pn-5-pnp-selector");
100 if( param == nil ) param = 0.0;
101 if( param ) src_plane = "tu154/instrumentation/pnp[1]/plane-deg";
102 param = getprop(src_plane);
103 if( param == nil ) param = 0.0;
104 setprop("fdm/jsbsim/ap/input-heading-pnp", param);
105
106 # ZK handle
107 param = getprop("tu154/switches/zk-selector");
108 if( param == nil ) param = 0.0;
109
110 if( param ) src_plane = "tu154/instrumentation/pnp[1]/heading-deg";
111 else src_plane = "tu154/instrumentation/pnp[0]/heading-deg";
112
113 param = getprop(src_plane);
114 if( param == nil ) param = 0.0;
115 setprop("fdm/jsbsim/ap/input-heading-zk", param);
116
117
118 var needles = getprop("tu154/switches/pn-5-strelki" );
119 if( needles == nil )  needles = 0.0; 
120 if( needles != 0.0 )
121         { 
122         # Directors
123         param = getprop("fdm/jsbsim/ap/pitch/gs-needle");       # Modified by Yurik nov 2103 for new ABSU version
124
125         if( param == nil )  param = 0.0;
126         if( getprop("fdm/jsbsim/ap/pitch-selector") != 5.0 ) param = 0.0;
127         setprop("tu154/instrumentation/pkp[0]/pitch-director", param );
128
129         param = getprop("fdm/jsbsim/ap/ils-out");       # Modified by Yurik nov 2103 for new ABSU version
130
131         if( param == nil )  param = 0.0; 
132         if( getprop("fdm/jsbsim/ap/roll-selector") != 5.0 ) param = 0.0;
133         setprop("tu154/instrumentation/pkp[0]/roll-director", param );
134         }
135 else{
136         interpolate("tu154/instrumentation/pkp[0]/pitch-director", 0.3, 1.0 );
137         interpolate("tu154/instrumentation/pkp[0]/roll-director", 0.3, 1.0 );
138         }       
139
140 # Modified by Yurik dec 2103 for new ABSU version
141 # Glideslope auto switch
142 if( getprop("fdm/jsbsim/fcs/flap-pos-deg") > 40.0 )
143    if( getprop("fdm/jsbsim/ap/roll-selector") == 5.0 )
144     if( getprop("fdm/jsbsim/ap/pitch-selector") != 5.0 )
145       if( getprop("instrumentation/nav[0]/gs-needle-deflection") < 0.2 )
146        if( getprop("instrumentation/nav[0]/gs-needle-deflection") > 0.0 )
147         absu_glideslope();
148                 
149 # Go around procedure
150 if( getprop("fdm/jsbsim/ap/pitch-selector") == 5.0 )
151     if( getprop("fdm/jsbsim/fcs/throttle-cmd-norm[0]") > 0.9 )
152       if( getprop("instrumentation/nav[0]/gs-in-range") )
153                 absu_start_go_around();
154                 
155
156 }
157
158
159
160 # ABSU control
161
162 var absu_stab_on = func {
163 if( absu_powered() == 0 ) return;
164
165 var kren = getprop("tu154/switches/pu-46-kren");
166 if( kren == nil ) kren = 0.0;
167 var tang = getprop("tu154/switches/pu-46-tang");
168 if( tang == nil ) tang = 0.0;
169
170         if( kren != 0  ) 
171         {
172         setprop("tu154/instrumentation/pu-46/stab", 1.0 );
173         absu_stab_roll();
174         setprop("fdm/jsbsim/ap/roll-hold", 1.0 );
175         }
176         
177         if( tang != 0  )
178         {
179         setprop("tu154/instrumentation/pu-46/stab", 1.0 );
180         absu_stab_current_pitch();
181         setprop("fdm/jsbsim/ap/pitch-hold", 1.0 );
182         }
183
184 }
185
186 # Modified by Yurik dec 2013
187 # Go to manual control
188 var absu_stab_off = func {
189 # Autopilot state
190 # Clear audio warning if interpolation of is stale
191         setprop("tu154/systems/warning/alarm/absu_warn", 0.0 );
192         var state = 0;
193         if( getprop("fdm/jsbsim/ap/pitch-hold") ) state = 1;
194         if( getprop("fdm/jsbsim/ap/roll-hold") ) state = state + 1;
195         if( getprop("tu154/instrumentation/pu-46/stab") ) state = state + 1;
196         if( getprop("tu154/instrumentation/pn-6/stab") ) state = state + 1;
197         if( state ) absu_alarm();
198         
199         setprop("fdm/jsbsim/ap/roll-selector", 0.0 );
200         setprop("fdm/jsbsim/ap/pitch-selector", 0.0 );
201         setprop("fdm/jsbsim/ap/pitch-hold", 0.0 );
202         setprop("fdm/jsbsim/ap/roll-hold", 0.0 );
203 # Blue lamp on PU-46
204         setprop("tu154/instrumentation/pu-46/stab", 0.0 );
205 # stop go around        
206         setprop("fdm/jsbsim/ap/go-around", 0.0);
207         clr_pitch_lamp();
208         clr_heading_lamp();
209         
210         if( absu_powered() == 1 )
211         {
212 # PN-5 indicators
213         setprop( "tu154/instrumentation/pn-5/pitch-state", 1 );
214         setprop( "tu154/instrumentation/pn-5/heading-state", 1 );
215         setprop("tu154/instrumentation/pn-5/sbros", 1.0 );
216         }
217         else{
218         setprop( "tu154/instrumentation/pn-5/pitch-state", 0 );
219         setprop( "tu154/instrumentation/pn-5/heading-state", 0 );
220         }
221 }
222
223 # switches on PN-5 
224 # for XML animation
225 var absu_stab_kren = func {
226
227 var state = getprop("tu154/instrumentation/pu-46/stab");
228 if ( state == nil ) state = 0;
229 if ( arg[0] != 0 )      # start roll stabilizer
230         {
231         if( state != 0 ) 
232                 {
233                 absu_stab_roll();
234                 setprop("fdm/jsbsim/ap/roll-hold", 1.0 );
235                 }
236         }
237
238 else    # stop roll stabilizer
239         {
240         setprop("tu154/systems/electrical/indicators/nvu", 0.0 );
241         setprop("tu154/systems/electrical/indicators/vor", 0.0 );
242         setprop("tu154/systems/electrical/indicators/zk", 0.0 );
243         setprop("tu154/systems/electrical/indicators/heading", 0.0 );
244         setprop("tu154/systems/electrical/indicators/stab-heading", 0.0 );
245         setprop("fdm/jsbsim/ap/roll-hold", 0.0 );
246         if( absu_powered() == 1 )
247                 {
248                 absu_alarm();
249                 setprop( "tu154/instrumentation/pn-5/heading-state", 1 );
250                 }
251         if( getprop("tu154/switches/pu-46-tang") != 1.0 )
252                  setprop("tu154/instrumentation/pu-46/stab", 0.0 ); 
253         }
254 }
255
256
257 var absu_stab_tang = func {
258 var state = getprop("tu154/instrumentation/pu-46/stab");
259 if ( state == nil ) state = 0;
260 if ( arg[0] != 0 )      # start pitch stabilizer
261         {
262         if( state != 0 ){ 
263                 absu_stab_current_pitch();
264                 setprop("fdm/jsbsim/ap/pitch-hold", 1.0 );
265                 }
266         }
267
268 else    # stop pitch stabilizer
269         {
270         clr_pitch_lamp();
271         setprop("fdm/jsbsim/ap/pitch-hold", 0.0 );
272         if( absu_powered() == 1 )
273                 {
274                 absu_alarm();
275                 setprop( "tu154/instrumentation/pn-5/pitch-state", 1 );
276                 }
277         if( getprop("tu154/switches/pu-46-kren") != 1.0 )
278                  setprop("tu154/instrumentation/pu-46/stab", 0.0 );
279         }
280 }
281
282 # Helpers
283
284
285 var absu_powered = func{
286 if( getprop("tu154/systems/absu/serviceable" ) == 1 ) return 1;
287 else return 0;
288 }
289
290 var absu_stab_current_pitch = func{     
291         setprop("fdm/jsbsim/ap/pitch-selector", 1.0 ); # 1 - stabilize pitch
292         setprop( "tu154/instrumentation/pn-5/pitch-state", 2 );
293         setprop("tu154/systems/electrical/indicators/stab-pitch", 1.0 );
294 }
295
296 var absu_stab_roll = func{
297         setprop("fdm/jsbsim/ap/stab-input-roll-rad", 0.0 ); # roll=0, stabilize wing level
298         setprop("fdm/jsbsim/ap/roll-selector", 1.0 ); # 1 - stabilize roll
299         setprop( "tu154/instrumentation/pn-5/heading-state", 2 );
300         setprop("tu154/systems/electrical/indicators/stab-heading", 1.0 );
301 }
302
303 var clr_heading_lamp = func{
304 # PU-5
305 setprop("tu154/instrumentation/pn-5/sbros", 0.0 );
306 setprop("tu154/instrumentation/pn-5/zk", 0.0 );
307 setprop("tu154/instrumentation/pn-5/nvu", 0.0 );
308 setprop("tu154/instrumentation/pn-5/az-1", 0.0 );
309 setprop("tu154/instrumentation/pn-5/az-2", 0.0 );
310 setprop("tu154/instrumentation/pn-5/zahod", 0.0 );
311 # Indicators on captain panel
312 setprop("tu154/systems/electrical/indicators/nvu", 0.0 );
313 setprop("tu154/systems/electrical/indicators/vor", 0.0 );
314 setprop("tu154/systems/electrical/indicators/zk", 0.0 );
315 setprop("tu154/systems/electrical/indicators/heading", 0.0 );
316 setprop("tu154/systems/electrical/indicators/stab-heading", 0.0 );
317 }
318
319 var clr_pitch_lamp = func{
320 setprop("tu154/instrumentation/pu-46/m", 0.0 );
321 setprop("tu154/instrumentation/pu-46/v", 0.0 );
322 setprop("tu154/instrumentation/pu-46/h", 0.0 );
323 setprop("tu154/instrumentation/pn-5/gliss", 0.0  );
324 # Indicators on captain panel
325 setprop("tu154/systems/electrical/indicators/glideslope", 0.0 );
326 setprop("tu154/systems/electrical/indicators/stab-pitch", 0.0 );
327 setprop("tu154/systems/electrical/indicators/stab-h", 0.0 );
328 setprop("tu154/systems/electrical/indicators/stab-v", 0.0 );
329 setprop("tu154/systems/electrical/indicators/stab-m", 0.0 );
330 setprop("tu154/systems/electrical/indicators/reject", 0.0 );
331 }
332
333
334 # "Sbros progr" lamp - reset AP to zero roll state
335 # also use in heading wheel animation
336 var absu_reset = func {
337 if( absu_powered() == 0 ) return;
338 clr_heading_lamp();
339 setprop("fdm/jsbsim/ap/roll-selector", 0.0 );
340 setprop("tu154/instrumentation/pn-5/sbros", 1.0  );
341 if( getprop("fdm/jsbsim/ap/pitch-selector" ) == 5 )
342         if( getprop("tu154/instrumentation/pu-46/stab" ) == 1.0 )
343                 absu_stab_current_pitch(); # Glideslope mode -> stab current pitch
344                 
345 setprop("tu154/instrumentation/pn-5/gliss", 0.0  );
346 setprop("tu154/systems/electrical/indicators/glideslope", 0.0 );
347
348 setprop("tu154/systems/electrical/indicators/reject", 0.0 );
349
350 if( getprop("tu154/instrumentation/pu-46/stab" ) == 1.0 
351     and getprop("tu154/switches/pu-46-kren" ) == 1.0 ) 
352     {
353     absu_stab_roll();
354     setprop("fdm/jsbsim/ap/roll-hold", 1.0 );
355     }
356 }
357
358
359 # --------------- Pitch modes ------------------------------
360
361 var absu_drop_mvh = func{
362 if( absu_powered() == 0 ) return;
363 if( getprop("tu154/instrumentation/pu-46/stab" ) == 1.0 )
364 if( getprop("fdm/jsbsim/ap/pitch-selector" ) != 1.0 )
365         {
366         clr_pitch_lamp();
367         setprop("fdm/jsbsim/ap/pitch-selector",0);
368         settimer( set_pitch_stab, 0.1 );
369         setprop("fdm/jsbsim/ap/pitch-hold",1);
370         if( getprop("tu154/switches/pu-46-tang" ) == 1.0 )
371                 {
372                 setprop( "tu154/instrumentation/pn-5/pitch-state", 2 );
373                 setprop("tu154/systems/electrical/indicators/stab-pitch", 1.0 );
374                 }
375         }
376 }
377
378 var set_pitch_stab = func{
379   setprop("fdm/jsbsim/ap/pitch-selector",1 );
380 }
381
382
383 # Clear MET to neutral
384
385 var absu_met_neutral = func{
386   setprop("fdm/jsbsim/ap/met-neutral", 1 );
387   settimer( enable_met, 0.1 );
388 }
389
390 var enable_met = func{
391   setprop("fdm/jsbsim/ap/met-neutral", 0 );
392 }
393
394
395
396 # Altitude stabilizer
397 var absu_h = func{
398 if( absu_powered() == 0 ) return;
399 clr_pitch_lamp();
400 var alt = getprop("instrumentation/altimeter[0]/pressure-alt-ft");              # Modified by Yurik dec 2013
401
402 setprop("fdm/jsbsim/ap/input-altitude", alt );
403 setprop("fdm/jsbsim/ap/pitch-selector", 2 ); # H stab code
404 setprop("tu154/instrumentation/pu-46/h", 1.0 );
405 if( getprop("tu154/switches/pu-46-tang" ) == 1.0 )
406         if( getprop("tu154/instrumentation/pu-46/stab" ) == 1.0 )
407               setprop("tu154/systems/electrical/indicators/stab-h", 1.0 );
408 }
409
410 # Air speed stabilizer
411 var absu_v = func{
412 if( absu_powered() == 0 ) return;
413 var ias = getprop("fdm/jsbsim/velocities/vc-fps");
414 clr_pitch_lamp();
415 setprop("fdm/jsbsim/ap/input-speed", ias );
416 setprop("fdm/jsbsim/ap/pitch-selector", 3 ); # V stab code
417 setprop("tu154/instrumentation/pu-46/v", 1.0 );
418 if( getprop("tu154/switches/pu-46-tang" ) == 1.0 )
419         if( getprop("tu154/instrumentation/pu-46/stab" ) == 1.0 )
420               setprop("tu154/systems/electrical/indicators/stab-v", 1.0 );
421 }
422
423 # Mach stabilizer
424 var absu_m = func{
425 if( absu_powered() == 0 ) return;
426 var mach = getprop("fdm/jsbsim/velocities/mach");
427 #if ( mach == nil ) return;
428 clr_pitch_lamp();
429 setprop("fdm/jsbsim/ap/input-mach", mach );
430 setprop("fdm/jsbsim/ap/pitch-selector", 4 ); # M stab code
431 setprop("tu154/instrumentation/pu-46/m", 1.0 );
432 if( getprop("tu154/switches/pu-46-tang" ) == 1.0 )
433         if( getprop("tu154/instrumentation/pu-46/stab" ) == 1.0 )
434               setprop("tu154/systems/electrical/indicators/stab-m", 1.0 );
435 }
436
437 # GLideslope
438 var absu_glideslope = func{
439 if( absu_powered() == 0 ) return;
440 if( getprop("tu154/switches/pn-5-posadk") != 1.0)return;# "podgotovka posadki" not engaged
441 if( getprop("tu154/switches/pn-5-navigac" ) != 0.0 ) return; # wrong control!
442
443 clr_pitch_lamp();
444 setprop("tu154/instrumentation/pn-5/sbros", 0.0 );
445 setprop("fdm/jsbsim/ap/pitch-selector", 5.0 ); # Glideslope code
446 setprop("tu154/instrumentation/pn-5/gliss", 1.0 );
447 if( getprop("tu154/switches/pu-46-tang" ) == 1.0 )
448         if( getprop("tu154/instrumentation/pu-46/stab" ) == 1.0 )
449                 setprop("tu154/systems/electrical/indicators/glideslope", 1.0 );
450 }
451
452 # --------------- Heading modes ------------------------------
453
454 # ZK
455 var absu_zk = func{
456 if( absu_powered() == 0 ) return;
457
458 clr_heading_lamp();
459 setprop("fdm/jsbsim/ap/roll-selector", 2 ); # ZK code
460 setprop("tu154/instrumentation/pn-5/zk", 1.0 );
461 if( getprop("tu154/switches/pu-46-kren" ) == 1.0 )
462         if( getprop("tu154/instrumentation/pu-46/stab" ) == 1.0 )
463               setprop("tu154/systems/electrical/indicators/zk", 1.0);
464 }
465 # VOR 1
466 var absu_az1 = func{
467 if( absu_powered() == 0 ) return;
468
469 clr_heading_lamp();
470
471 setprop("tu154/instrumentation/pn-5/az-1", 1.0 );
472 setprop("fdm/jsbsim/ap/roll-selector", 3 ); # VOR code
473
474 if( getprop("tu154/switches/pu-46-kren" ) == 1.0 )
475     if( getprop("tu154/instrumentation/pu-46/stab") == 1.0) {
476         if(getprop("tu154/switches/pn-5-navigac") == 1.0 and
477            getprop("tu154/switches/pn-5-posadk") == 0.0)
478             setprop("tu154/systems/electrical/indicators/vor", 1.0);
479         else
480             setprop("tu154/systems/electrical/indicators/stab-heading", 1.0);
481     }
482 }
483 # VOR 2
484 var absu_az2 = func{
485 if( absu_powered() == 0 ) return;
486
487 clr_heading_lamp();
488
489 setprop("tu154/instrumentation/pn-5/az-2", 1.0 );
490 setprop("fdm/jsbsim/ap/roll-selector", 3 ); # VOR code
491 if( getprop("tu154/switches/pu-46-kren" ) == 1.0 )
492     if( getprop("tu154/instrumentation/pu-46/stab") == 1.0) {
493         if(getprop("tu154/switches/pn-5-navigac") == 1.0 and
494            getprop("tu154/switches/pn-5-posadk") == 0.0)
495             setprop("tu154/systems/electrical/indicators/vor", 1.0);
496         else
497             setprop("tu154/systems/electrical/indicators/stab-heading", 1.0);
498     }
499 }
500 # NVU
501 var absu_nvu = func{
502 if( absu_powered() == 0 ) return;
503 clr_heading_lamp();
504
505 setprop("fdm/jsbsim/ap/roll-selector", 4 ); # NVU code
506 setprop("tu154/instrumentation/pn-5/nvu", 1.0 );
507 if( getprop("tu154/switches/pu-46-kren" ) == 1.0 )
508     if( getprop("tu154/instrumentation/pu-46/stab") == 1.0) {
509         if(getprop("tu154/switches/pn-5-navigac") == 1.0 and
510            getprop("tu154/switches/pn-5-posadk") == 0.0)
511             setprop("tu154/systems/electrical/indicators/nvu", 1.0);
512         else
513             setprop("tu154/systems/electrical/indicators/stab-heading", 1.0);
514     }
515 }
516
517 # Approach
518 var absu_approach = func{
519 if( absu_powered() == 0 ) return;
520
521 clr_heading_lamp();
522 setprop("fdm/jsbsim/ap/roll-selector", 5 ); # ILS approach code
523 setprop("tu154/instrumentation/pn-5/zahod", 1.0 );
524 if( getprop("tu154/switches/pu-46-kren" ) == 1.0 )
525     if( getprop("tu154/instrumentation/pu-46/stab" ) == 1.0 ) {
526         if(getprop("tu154/switches/pn-5-navigac") == 0.0 and
527            getprop("tu154/switches/pn-5-posadk") == 1.0)
528             setprop("tu154/systems/electrical/indicators/heading", 1.0 );
529         else
530             setprop("tu154/systems/electrical/indicators/stab-heading", 1.0);
531     }
532 }
533
534
535
536 var absu_shutdown = func {
537 # Drop ABSU to idle state
538 absu_reset();
539 absu_stab_off();
540
541 setprop("tu154/systems/electrical/indicators/stab-heading", 0.0 );
542 setprop("tu154/systems/electrical/indicators/stab-pitch", 0.0 );
543
544 if( getprop( "tu154/systems/absu/serviceable" ) == 0 )
545         {
546         absu_drop_mvh();
547         clr_heading_lamp();
548         clr_pitch_lamp()
549         }
550 }
551
552
553 var absu_alarm = func{
554 setprop("tu154/systems/warning/alarm/absu_warn", 1.0 );
555 interpolate("tu154/systems/warning/alarm/absu_warn", 0.0, 1.4 );
556 }
557
558 var absu_alarm_watchdog = func{
559 if( getprop("tu154/systems/warning/alarm/absu_warn") < 0.1 )
560         setprop("tu154/systems/warning/alarm/absu_warn", 0.0 );
561 }
562
563
564 setlistener("tu154/systems/absu/serviceable", absu_shutdown, 0, 0 );
565 setlistener("tu154/systems/absu/serviceable", absu_alarm, 0, 0 );
566 setlistener("tu154/systems/warning/alarm/absu_warn", absu_alarm_watchdog, 0, 0 );
567
568 absu_property_update();
569
570 # ********************** Go around procedure ********************************
571
572 var absu_start_go_around = func{
573         absu_at_stop();
574         absu_stab_roll();
575         absu_stab_current_pitch();
576         # Modified by Yurik dec 2013
577         # for new AP JSBSim system
578         
579         setprop("fdm/jsbsim/ap/pitch-selector", 6.0);
580         setprop("fdm/jsbsim/ap/roll-selector", 1.0);
581         
582 # Blank indicators, but stay button-lamps on PN-5 untouched
583         setprop("tu154/systems/electrical/indicators/nvu", 0.0 );
584         setprop("tu154/systems/electrical/indicators/vor", 0.0 );
585         setprop("tu154/systems/electrical/indicators/zk", 0.0 );
586         setprop("tu154/systems/electrical/indicators/heading", 0.0 );
587         
588         setprop("tu154/systems/electrical/indicators/glideslope", 0.0 );
589         setprop("tu154/systems/electrical/indicators/stab-pitch", 0.0 );
590         setprop("tu154/systems/electrical/indicators/stab-h", 0.0 );
591         setprop("tu154/systems/electrical/indicators/stab-v", 0.0 );
592         setprop("tu154/systems/electrical/indicators/stab-m", 0.0 );
593         setprop("tu154/systems/electrical/indicators/reject", 0.0 );
594         
595         setprop("tu154/systems/electrical/indicators/reject", 1.0 );
596         setprop("tu154/systems/electrical/indicators/stab-heading", 1.0 );
597 }
598
599 # ========================== yoke ap off =============================
600 var check_yoke_pitch = func{
601 var pitch = abs( getprop("/controls/flight/elevator") );
602 if( pitch < PITCH_YOKE_LIMIT ) return;
603 if( getprop( "fdm/jsbsim/ap/pitch-hold" ) ) absu_stab_tang(0); # drop pitch stabilizer
604 }
605 var check_yoke_bank = func{
606 var bank = abs( getprop("/controls/flight/aileron") );
607 if( bank < BANK_YOKE_LIMIT ) return;
608 if( getprop( "fdm/jsbsim/ap/roll-hold" ) ) absu_stab_kren(0); # drop roll
609 }
610
611 setlistener("/controls/flight/elevator", check_yoke_pitch, 0, 0 );
612 setlistener("/controls/flight/aileron", check_yoke_bank, 0, 0 );
613
614 # ================== AT-6 autothrottle subsystem =====================
615
616
617 var absu_at_handler = func(param) {
618 if( param == 0.0 )
619         {       # drop to power off state
620         absu_at_stop();
621         setprop("tu154/instrumentation/pn-6/g1", 0 );
622         setprop("tu154/instrumentation/pn-6/g2", 0 );
623         setprop("tu154/instrumentation/pn-6/g3", 0 );
624 #       setprop("tu154/instrumentation/pn-6/lamp-1", 0.0 );
625 #       setprop("tu154/instrumentation/pn-6/lamp-2", 0.0 );
626 #       setprop("tu154/instrumentation/pn-6/lamp-3", 0.0 );
627         setprop("tu154/instrumentation/pn-6/lamp-4", 0.0 );
628         setprop("tu154/instrumentation/pn-6/lamp-5", 0.0 );
629         setprop("tu154/instrumentation/pn-6/stab", 0 );
630         setprop("tu154/instrumentation/pn-6/mode", 0.0 );
631         setprop("tu154/systems/electrical/indicators/autothrottle", 0.0 );
632         setprop("fdm/jsbsim/ap/at-podg", 0.0 );
633         return;
634         }
635 if( param == 1.0 ) # power on ( mode "soglasovanie" )
636         {
637         setprop("tu154/instrumentation/pn-6/mode", 1.0 );
638         setprop("fdm/jsbsim/ap/at-podg", 1.0 );
639         absu_at_sogl(); # start "soglasovanie" cycle
640         return;
641         }
642         
643
644 if( param == 2.0 ) # mode "podgotovka" off 
645         {
646     if( getprop( "tu154/instrumentation/pn-6/mode" ) >= 1.0 )
647         {
648         absu_at_stop();
649         setprop("tu154/instrumentation/pn-6/mode", 1.0 );
650         return;
651         }}
652
653 if( param == 3.0 ) # mode "podgotovka" on
654         {
655 #print(param);
656 #print( getprop("tu154/instrumentation/pn-6/mode") );
657     if( getprop("tu154/instrumentation/pn-6/mode") >= 1.0 )
658         {
659         interpolate("tu154/instrumentation/pn-6/mode", 3.0, 10.0 );
660         return;
661         }}
662 }
663
664 setlistener("tu154/instrumentation/pn-6/serviceable", func {
665     absu_at_handler(getprop("tu154/instrumentation/pn-6/serviceable"));
666 }, 0, 0 );
667
668
669 # ABSU AT timer procedure
670 var absu_at_sogl = func{
671 if( getprop("tu154/instrumentation/pn-6/mode") == 0.0 ) return;
672 settimer( absu_at_sogl, 0.3 );
673
674
675 # control lamps
676  if( getprop("tu154/instrumentation/pn-6/mode") > 2.0 )
677  {
678  setprop("tu154/instrumentation/pn-6/lamp-4", 1.0 );
679  setprop("tu154/instrumentation/pn-6/lamp-5", 1.0 );
680  }
681  else
682  {
683  setprop("tu154/instrumentation/pn-6/lamp-4", 0.0 );
684  setprop("tu154/instrumentation/pn-6/lamp-5", 0.0 );
685  }
686
687 # end control lamps
688 if( getprop("tu154/instrumentation/pn-6/stab") == 0 ) # soglasovanie
689         {
690         setprop("fdm/jsbsim/ap/at-podg", 1.0 );
691         setprop("fdm/jsbsim/ap/at-hold-0", 0.0 );
692         setprop("fdm/jsbsim/ap/at-hold-1", 0.0 );
693         setprop("fdm/jsbsim/ap/at-hold-2", 0.0 );
694
695         var kias = getprop("instrumentation/airspeed-indicator/indicated-speed-kt");
696         if( kias != nil ) interpolate("tu154/instrumentation/pn-6/at-kt", kias, 0.3); 
697         }
698 else {
699         var kias = getprop("tu154/instrumentation/pn-6/at-kt");
700 if( kias != nil ) setprop( "fdm/jsbsim/ap/input-at", kias*1.688 ); # from knots to fps
701         absu_at_check_thr(); # check off-line state
702
703         }       
704
705         
706 }
707
708 var absu_at_check = func{
709 if( getprop("tu154/instrumentation/pn-6/mode") > 2.0 )
710         {
711         var state = !arg[0];
712         setprop("tu154/instrumentation/pn-6/lamp-4", state );
713         setprop("tu154/instrumentation/pn-6/lamp-5", state );
714 #       setprop("tu154/instrumentation/pn-6/check-lamp", state );
715         }
716
717 }
718
719 # Start stabilize speed
720 var absu_at_start = func{
721 if( getprop("tu154/instrumentation/pn-6/mode") < 2.0 ) return;
722 if( absu_at_check_thr() ) return; # 2 or 3 engines are offline now
723 # Set AT to stab mode
724 var kias = getprop("instrumentation/airspeed-indicator/indicated-speed-kt");
725 if( kias != nil ){
726         interpolate("tu154/instrumentation/pn-6/at-kt", kias, 0.3);
727         setprop("fdm/jsbsim/ap/input-at", kias*1.688 );
728         }
729
730 setprop("fdm/jsbsim/ap/at-hold-0", 1.0 );
731 setprop("fdm/jsbsim/ap/at-hold-1", 1.0 );
732 setprop("fdm/jsbsim/ap/at-hold-2", 1.0 );
733
734
735 setprop("tu154/instrumentation/pn-6/stab", 1.0 );
736 setprop("tu154/systems/electrical/indicators/autothrottle", 1.0 );
737 }
738
739 # Stop stabilize speed
740 var absu_at_stop = func{
741 var thr_pos0 = getprop("fdm/jsbsim/fcs/throttle-pos-norm[0]");
742 var thr_pos1 = getprop("fdm/jsbsim/fcs/throttle-pos-norm[1]");
743 var thr_pos2 = getprop("fdm/jsbsim/fcs/throttle-pos-norm[2]");
744 setprop("controls/engines/engine[0]/throttle", thr_pos0);
745 setprop("controls/engines/engine[1]/throttle", thr_pos1);
746 setprop("controls/engines/engine[2]/throttle", thr_pos2);
747
748 setprop("fdm/jsbsim/ap/at-podg", 1.0 );
749 setprop("fdm/jsbsim/ap/at-hold-0", 0.0 );
750 setprop("fdm/jsbsim/ap/at-hold-1", 0.0 );
751 setprop("fdm/jsbsim/ap/at-hold-2", 0.0 );
752
753 setprop("tu154/instrumentation/pn-6/lamp-4", 0.0 );
754 setprop("tu154/instrumentation/pn-6/lamp-5", 0.0 );
755
756 if( getprop("tu154/instrumentation/pn-6/stab" ) ) absu_alarm();
757
758 setprop("tu154/instrumentation/pn-6/stab", 0.0 );
759
760 setprop("tu154/systems/electrical/indicators/autothrottle", 0.0 );
761
762 }
763
764 var absu_at_check_thr = func{
765 # Check off-line engines
766 var eng_1 = getprop( "tu154/instrumentation/pn-6/g1" );
767 if( eng_1 == nil ) eng_1 = 0;
768 var eng_2 = getprop( "tu154/instrumentation/pn-6/g2" );
769 if( eng_2 == nil ) eng_2 = 0;
770 var eng_3 = getprop( "tu154/instrumentation/pn-6/g3" );
771 if( eng_3 == nil ) eng_3 = 0;
772
773 if( (eng_1 + eng_2 + eng_3) > 1.0 ) {
774         absu_at_stop();
775         return 1;
776         }
777 if( eng_1 ) setprop("fdm/jsbsim/ap/at-hold-0", 0.0 );
778 else setprop("fdm/jsbsim/ap/at-hold-0", 1.0 );
779 if( eng_2 ) setprop("fdm/jsbsim/ap/at-hold-1", 0.0 );
780 else setprop("fdm/jsbsim/ap/at-hold-1", 1.0 );
781 if( eng_3 ) setprop("fdm/jsbsim/ap/at-hold-2", 0.0 );
782 else setprop("fdm/jsbsim/ap/at-hold-2", 1.0 );
783 return 0;
784 }
785
786 # Power support
787 absu_power = func{
788 var acpwr = getprop( "tu154/systems/electrical/buses/AC3x200-bus-3L/volts" );
789 var mgv1 = getprop("tu154/instrumentation/bkk/mgv-1-failure");
790 if( mgv1 == nil ) mgv1 = 1;
791 var mgv2 = getprop("tu154/instrumentation/bkk/mgv-2-failure");
792 if( mgv2 == nil ) mgv2 = 1;
793 var mgvc = getprop("tu154/instrumentation/bkk/mgv-contr-failure");
794 if( mgvc == nil ) mgvc = 1;
795
796         if( getprop("tu154/switches/SAU-STU")==1 )
797         {
798             if( acpwr == nil ) return; # system not ready yet
799             if( acpwr < 150.0 ) return;
800             # hydrosystem fails or busters off
801             if(  getprop("fdm/jsbsim/hs/busters-serviceable") < 2.5 ) return; 
802             # MGV check
803             var mgv = mgv1 + mgv2 + mgvc;
804             if( mgv > 1 ) return;       # deny stab autopilot if all MGV failure
805             # check hydropower of RA-56 
806             if( getprop("fdm/jsbsim/hs/ra-56-roll-serviceable") < 1.0 ) return;
807             if( getprop("fdm/jsbsim/hs/ra-56-yaw-serviceable") < 1.0 ) return;
808             if( getprop("fdm/jsbsim/hs/ra-56-pitch-serviceable") < 1.0 ) return;
809             if( getprop("fdm/jsbsim/ap/suu-enable") != 1.0 ) return;
810             # All OK, let's turn power on for ABSU
811              setprop("tu154/systems/absu/serviceable", 1 );
812              electrical.AC3x200_bus_3R.add_output( "ABSU", 100.0);
813         }
814         else {
815              setprop("tu154/systems/absu/serviceable", 0 );
816              electrical.AC3x200_bus_3R.rm_output( "ABSU" );
817         }
818 }
819
820
821
822 setlistener("tu154/switches/SAU-STU", absu_power, 0, 0 );
823 # ============================== End AT-6 support ===========================
824
825 gui.Dialog.new("/sim/gui/dialogs/Tu-154B-2/nav/dialog", "Aircraft/tu154b/Dialogs/nav.xml");
826
827
828 setprop("sim/menubar/default/menu[3]/enabled", 0 );
829
830 print("ABSU started, default autopilot disabled");