Tu-154B2 version 3.1:
[fg:toms-fgdata.git] / Aircraft / tu154b / Nasal / controls.nas
1 #
2 #
3 # Some functions overload  Nasal/controls.nas member
4 #
5 # Project Tupolev for FlightGear
6 #
7 # Yurik V. Nikiforoff, yurik.nsk@gmail.com
8 # Novosibirsk, Russia
9 # jan 2008, nov 2013
10 #
11
12 # turn off autopilot & autothrottle
13 var trigger = func(x) { # x - unused var 
14 absu.absu_stab_off();
15 absu.absu_at_stop();
16 }
17
18
19 var TRIM_RATE = 0.08;
20
21 var elevatorTrim = func {
22     #controls.slewProp("/controls/flight/elevator-trim", arg[0] * TRIM_RATE); 
23     setprop("fdm/jsbsim/fcs/met-cmd", arg[0]);
24     setprop("tu154/systems/warning/elevator-trim-pressed", 1.0 );
25     settimer( elev_trim_stop, 0.2 );
26         }
27
28 # we need clear trim variables when trim button is released
29 var elev_trim_stop = func {
30   setprop("fdm/jsbsim/fcs/met-cmd", 0.0);
31 }
32
33 # It's func intend for support direct trim changing (from home\end keyboard and mouse wheel bindings)
34 # Joysticks drivers use elevatorTrim()
35 var trim_handler = func{
36   var old_trim = num( getprop("tu154/systems/absu/trim") );
37   if ( old_trim == nil ) old_trim = 0.0;
38   var new_trim = num( getprop("/controls/flight/elevator-trim") );
39   if ( new_trim == nil ) new_trim = 0.0;
40   var delta = new_trim - old_trim;
41   setprop( "tu154/systems/absu/trim", new_trim );
42   if( delta > 0.0 ) elevatorTrim(1);
43   if( delta < 0.0 ) elevatorTrim(-1);
44 }
45
46 setlistener( "/controls/flight/elevator-trim", trim_handler );
47
48 #
49 # Brakes
50 #
51
52 var origApplyBrakes = applyBrakes;
53 var applyBrakes = func(v, which = 0) {
54     if (v and getprop("controls/gear/brake-parking")) {
55        setprop("controls/gear/brake-parking", 0);
56        origApplyBrakes(0);
57     }
58     origApplyBrakes(v, which);
59 }
60
61 var origApplyParkingBrake = applyParkingBrake;
62 var applyParkingBrake = func(v) {
63     if (v) {
64         v = origApplyParkingBrake(1);
65         origApplyBrakes(v, 0);
66     }
67     return v;
68 }
69 applyParkingBrake(1);
70
71
72 # Autostart
73 # may 2010
74 var autostart = func{
75         # We should turn off electrical power before engine start, cause engine handlers will cutoff fuel until mandatory procedure will done. They will stop, if power will turn off.
76         setprop("tu154/switches/APU-RAP-selector", 1.0 );
77         setprop("tu154/switches/main-battery", 0.0 );
78         help.messenger("Begin autostart procedure...");
79         # fuel cutoff levers
80         setprop("tu154/switches/cutoff-lever-1", 1.0 );
81         setprop("tu154/switches/cutoff-lever-2", 1.0 );
82         setprop("tu154/switches/cutoff-lever-3", 1.0 );
83         # electrical
84         setprop("tu154/switches/vypr-1", 1.0 );
85         setprop("tu154/switches/vypr-2", 1.0 );
86         setprop("tu154/switches/generator-1", 1.0 );
87         setprop("tu154/switches/generator-2", 1.0 );
88         setprop("tu154/switches/generator-3", 1.0 );
89         setprop("tu154/switches/bano", 1.0 );
90         setprop("tu154/switches/omi", 1.0 );
91         
92         setprop("tu154/switches/ut7-1-serviceable", 1.0 );
93         setprop("tu154/switches/ut7-2-serviceable", 1.0 );
94         setprop("tu154/switches/ut7-3-serviceable", 1.0 );
95         # fuei
96         setprop("tu154/switches/tank-2-left-serviceable", 1.0 );
97         setprop("tu154/switches/tank-2-right-serviceable", 1.0 );
98         setprop("tu154/switches/tank-3-left-serviceable", 1.0 );
99         setprop("tu154/switches/tank-3-right-serviceable", 1.0 );
100         setprop("tu154/switches/tank-4-serviceable", 1.0 );
101         setprop("tu154/switches/pump-1-serviceable", 1.0 );
102         setprop("tu154/switches/pump-2-serviceable", 1.0 );
103         setprop("tu154/switches/pump-3-serviceable", 1.0 );
104         setprop("tu154/switches/pump-4-serviceable", 1.0 );
105         setprop("tu154/switches/fuel-cutoff-valve-1", 1.0 );
106         setprop("tu154/switches/fuel-cutoff-valve-2", 1.0 );
107         setprop("tu154/switches/fuel-cutoff-valve-3", 1.0 );
108         setprop("tu154/switches/fuel-meter-serviceable", 1.0 );
109         setprop("tu154/switches/fuel-autolevel-serviceable", 1.0 );
110         setprop("tu154/switches/fuel-autoconsumption-mode", 1.0 );
111         setprop("tu154/switches/fuel-autoconsumption-serviceable", 1.0 );
112         setprop("tu154/switches/fuel-consumption-meter", 1.0 );
113         # Begin engine start procedure
114         setprop( "controls/engines/engine[0]/cutoff", 1 );
115         setprop( "controls/engines/engine[1]/cutoff", 1 );
116         setprop( "controls/engines/engine[2]/cutoff", 1 );
117
118         setprop( "controls/engines/engine[0]/starter",1 );
119         setprop( "controls/engines/engine[1]/starter",1 );
120         setprop( "controls/engines/engine[2]/starter",1 );
121         autostart_helper_1();
122         # To be continued in helper
123 }
124
125 # Do it after engine autostart
126 var autostart_helper_1 = func{
127         # wait until all engines turn to cutoff rpm
128         if(     ( getprop( "/fdm/jsbsim/propulsion/engine[0]/n2") > 20.0 ) and
129                 ( getprop( "/fdm/jsbsim/propulsion/engine[1]/n2") > 20.0 ) and
130                 ( getprop( "/fdm/jsbsim/propulsion/engine[2]/n2") > 20.0 ) )
131         { 
132         # fire up engines
133                 if( getprop( "controls/engines/engine[0]/cutoff") )
134                         setprop( "controls/engines/engine[0]/cutoff", 0 );
135                 if( getprop( "controls/engines/engine[1]/cutoff") )
136                         setprop( "controls/engines/engine[1]/cutoff", 0 );
137                 if( getprop( "controls/engines/engine[2]/cutoff") )
138                         setprop( "controls/engines/engine[2]/cutoff", 0 );
139         }
140         else 
141         {
142         settimer(autostart_helper_1, 0.5);
143         return;
144         }
145         # wait until engines achieved idle rpm
146         if(     getprop( "controls/engines/engine[0]/starter") or
147                 getprop( "controls/engines/engine[0]/starter") or
148                 getprop( "controls/engines/engine[0]/starter") )
149         {
150         settimer(autostart_helper_1, 0.5);
151         return;
152         }
153         help.messenger("Continue autostart procedure...");
154         # Now, we can switch on electrical power
155         setprop("tu154/switches/main-battery", 1.0 );
156         # Overhead
157         setprop("tu154/switches/AUASP", 1.0 );
158         setprop("tu154/switches/UVID", 1.0 );
159         setprop("tu154/switches/EUP", 1.0 );
160         setprop("tu154/switches/AGR", 1.0 );
161         setprop("tu154/switches/BKK-power", 1.0 );
162         setprop("tu154/switches/PKP-left", 1.0 );
163         setprop("tu154/switches/PKP-right", 1.0 );
164         setprop("tu154/switches/MGV-contr", 1.0 );
165         setprop("tu154/switches/TKC-power-1", 1.0 );
166         setprop("tu154/switches/TKC-power-2", 1.0 );
167         setprop("tu154/switches/TKC-BGMK-1", 1.0 );
168         setprop("tu154/switches/TKC-BGMK-2", 1.0 );
169         setprop("tu154/switches/SVS-power", 1.0 );
170         # Nav-radio Kurs-MP
171         setprop("tu154/switches/KURS-MP-1", 1.0 );
172         setprop("tu154/switches/KURS-MP-2", 1.0 );
173
174         setprop("tu154/switches/dme-1-power", 1);
175         setprop("tu154/switches/dme-2-power", 1);
176
177         setprop("tu154/switches/KURS-PNP-left", 1.0 );
178         setprop("/fdm/jsbsim/instrumentation/pnp-left-selector", 1.0 );
179         setprop("tu154/switches/KURS-PNP-right", 1.0 );
180         setprop("/fdm/jsbsim/instrumentation/pnp-right-selector", 1.0 );
181         setprop("tu154/switches/RV-5-1", 1.0 );
182         setprop("tu154/switches/comm-power-1", 1.0 );
183         setprop("tu154/switches/comm-power-2", 1.0 );
184         setprop("tu154/switches/adf-power-1", 1.0 );
185         setprop("tu154/switches/adf-power-2", 1.0 );
186         setprop("tu154/switches/DISS-check", 1.0 );
187         setprop("fdm/jsbsim/instrumentation/nvu/source", 2);
188         setprop("tu154/switches/DISS-power", 1.0 );
189         setprop("tu154/switches/DISS-surface", 1.0 );
190         setprop("tu154/switches/pu-11-auto", 1.0 );
191         setprop("/fdm/jsbsim/instrumentation/tks-latitude-auto", 1.0 );
192         # console
193         setprop("tu154/switches/busters_1", 1.0 );
194         setprop("tu154/switches/busters_2", 1.0 );
195         setprop("tu154/switches/busters_3", 1.0 );
196         setprop("tu154/switches/busters-cover", 0.0 );
197         # Gyro
198         setprop("tu154/systems/mgv/one", 6.0 );
199         setprop("tu154/systems/mgv/two", 6.0 );
200         setprop("tu154/systems/mgv/contr", 6.0 );
201         # wait until gyroscopes will be aligned
202         settimer( autostart_helper_2, 5.0 );
203         # To be continued...
204 }
205
206 # continue autostart procedure...
207 var autostart_helper_2 = func{
208         # Drop gyros failure control system
209         instruments.bkk_reset(1);
210         instruments.bkk_reset(2);
211         # hydrosystem
212         setprop("tu154/switches/ra-56-pitch-1-hydropower", 1.0 );
213         setprop("tu154/switches/ra-56-pitch-2-hydropower", 1.0 );
214         setprop("tu154/switches/ra-56-pitch-3-hydropower", 1.0 );
215
216         setprop("tu154/switches/ra-56-yaw-1-hydropower", 1.0 );
217         setprop("tu154/switches/ra-56-yaw-2-hydropower", 1.0 );
218         setprop("tu154/switches/ra-56-yaw-3-hydropower", 1.0 );
219
220         setprop("tu154/switches/ra-56-roll-1-hydropower", 1.0 );
221         setprop("tu154/switches/ra-56-roll-2-hydropower", 1.0 );
222         setprop("tu154/switches/ra-56-roll-3-hydropower", 1.0 );
223
224         setprop("fdm/jsbsim/hs/ra56-pitch-1", 1.0 );
225         setprop("fdm/jsbsim/hs/ra56-pitch-2", 1.0 );
226         setprop("fdm/jsbsim/hs/ra56-pitch-3", 1.0 );
227
228         setprop("fdm/jsbsim/hs/ra56-roll-1", 1.0 );
229         setprop("fdm/jsbsim/hs/ra56-roll-2", 1.0 );
230         setprop("fdm/jsbsim/hs/ra56-roll-3", 1.0 );
231
232         setprop("fdm/jsbsim/hs/ra56-yaw-1", 1.0 );
233         setprop("fdm/jsbsim/hs/ra56-yaw-2", 1.0 );
234         setprop("fdm/jsbsim/hs/ra56-yaw-3", 1.0 );
235
236         setprop("tu154/switches/long-control", 1.0 );
237         setprop("fdm/jsbsim/ap/suu-enable", 1.0 );
238         # Busters
239         setprop("fdm/jsbsim/hs/buster-1-switch", 1.0 );
240         setprop("fdm/jsbsim/hs/buster-2-switch", 1.0 );
241         setprop("fdm/jsbsim/hs/buster-3-switch", 1.0 );
242
243         # ABSU
244         setprop("tu154/switches/SAU-STU", 1.0 );
245         setprop("tu154/systems/absu/serviceable", 1.0 );
246         # TKS compass system adjust to magnetic heading
247         setprop("instrumentation/heading-indicator[0]/offset-deg", 
248                 -getprop("environment/magnetic-variation-deg") );
249         setprop("instrumentation/heading-indicator[1]/offset-deg", 
250                 -getprop("environment/magnetic-variation-deg") );
251         # Altimeters
252         var inhgX100 = int(getprop("environment/pressure-inhg") * 100 + 0.5);
253         setprop("tu154/instrumentation/altimeter[0]/inhgX100", inhgX100);
254         setprop("tu154/instrumentation/altimeter[1]/inhgX100", inhgX100);
255         # Steering
256         setprop("tu154/switches/steering-limit", 1.0 );
257         setprop("tu154/switches/steering", 1.0 );
258         setprop("controls/gear/nose-wheel-steering", 1.0 );
259         setprop("controls/gear/steering", 10.0 );
260
261         help.messenger("Autostart done");
262 }