3 # Some functions overload Nasal/controls.nas member
5 # Project Tupolev for FlightGear
7 # Yurik V. Nikiforoff, yurik.nsk@gmail.com
12 # turn off autopilot & autothrottle
13 var trigger = func(x) { # x - unused var
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 );
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);
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);
46 setlistener( "/controls/flight/elevator-trim", trim_handler );
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);
58 origApplyBrakes(v, which);
61 var origApplyParkingBrake = applyParkingBrake;
62 var applyParkingBrake = func(v) {
64 v = origApplyParkingBrake(1);
65 origApplyBrakes(v, 0);
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...");
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 );
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 );
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 );
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 );
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
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 ) )
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 );
142 settimer(autostart_helper_1, 0.5);
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") )
150 settimer(autostart_helper_1, 0.5);
153 help.messenger("Continue autostart procedure...");
154 # Now, we can switch on electrical power
155 setprop("tu154/switches/main-battery", 1.0 );
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 );
171 setprop("tu154/switches/KURS-MP-1", 1.0 );
172 setprop("tu154/switches/KURS-MP-2", 1.0 );
174 setprop("tu154/switches/dme-1-power", 1);
175 setprop("tu154/switches/dme-2-power", 1);
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 );
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 );
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 );
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);
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 );
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 );
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 );
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 );
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 );
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 );
236 setprop("tu154/switches/long-control", 1.0 );
237 setprop("fdm/jsbsim/ap/suu-enable", 1.0 );
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 );
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") );
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);
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 );
261 help.messenger("Autostart done");