Debian Codegraph @

Aircraft/Generic/century3.nas

raw
1 ##
2 # Century III Autopilot System
3 # Tries to behave like the Century III autopilot
4 # two axis
5 #
6 # One would also need the autopilot configuration file
7 # CENTURYIII.xml and the panel instrument configuration file
8 #
9 # Written by Dave Perry to match functionality described in
10 #
11 # CENTURY III
12 # AUTOPILOT FLIGHT SYSTEM
13 # PILOT'S OPERATING HANDBOOK
14 # NOVEMBER 1998 68S25
15 #
16 # Draws heavily from the kap140 system written by Roy Vegard Ovesen
17 ##
18
19 # Properties
20
21 var locks = "/autopilot/CENTURYIII/locks";
22 var settings = "/autopilot/CENTURYIII/settings";
23 var internal = "/autopilot/internal";
24 var flightControls = "/controls/flight";
25 var autopilotControls = "/autopilot/CENTURYIII/controls";
26
27 # locks
28 var propLocks = props.globals.getNode(locks, 1);
29
30 var lockAltHold = propLocks.getNode("alt-hold", 1);
31 var lockPitchHold = propLocks.getNode("pitch-hold", 1);
32 var lockAprHold = propLocks.getNode("apr-hold", 1);
33 var lockGsHold = propLocks.getNode("gs-hold", 1);
34 var lockHdgHold = propLocks.getNode("hdg-hold", 1);
35 var lockNavHold = propLocks.getNode("nav-hold", 1);
36 var lockOmniHold = propLocks.getNode("omni-hold", 1);
37 var lockRevHold = propLocks.getNode("rev-hold", 1);
38 var lockRollAxis = propLocks.getNode("roll-axis", 1);
39 var lockRollMode = propLocks.getNode("roll-mode", 1);
40 var lockPitchAxis = propLocks.getNode("pitch-axis", 1);
41 var lockPitchMode = propLocks.getNode("pitch-mode", 1);
42 var lockRollArm = propLocks.getNode("roll-arm", 1);
43 var lockPitchArm = propLocks.getNode("pitch-arm", 1);
44
45
46 var rollModes = { "OFF" : 0, "ROL" : 1, "HDG" : 2, "OMNI" : 3, "NAV" : 4, "REV" : 5, "APR" : 6 };
47 var pitchModes = { "OFF" : 0, "VS" : 1, "ALT" : 2, "GS" : 3, "AOA" : 4 };
48 var rollArmModes = { "OFF" : 0, "NAV" : 1, "OMNI" : 2, "APR" : 3, "REV" : 4 };
49 var pitchArmModes = { "OFF" : 0, "ALT" : 1, "GS" : 2 };
50
51 # settings
52 var propSettings = props.globals.getNode(settings, 1);
53
54 var settingTargetAltPressure = propSettings.getNode("target-alt-pressure", 1);
55 var settingTargetInterceptAngle = propSettings.getNode("target-intercept-angle", 1);
56 var settingTargetPressureRate = propSettings.getNode("target-pressure-rate", 1);
57 var settingTargetRollDeg = propSettings.getNode("target-roll-deg", 1);
58 var settingRollKnobDeg = propSettings.getNode("roll-knob-deg", 1);
59 var settingTargetPitchDeg = propSettings.getNode("target-pitch-deg", 1);
60 var settingPitchWheelDeg = propSettings.getNode("pitch-wheel-deg", 1);
61 var settingAutoPitchTrim = propSettings.getNode("auto-pitch-trim", 1);
62 var settingGScaptured = propSettings.getNode("gs-captured", 1);
63 var settingDeltaPitch = propSettings.getNode("delta-pitch", 1);
64
65 #Flight controls
66 var propFlightControls = props.globals.getNode(flightControls, 1);
67
68 var elevatorControl = propFlightControls.getNode("elevator", 1);
69 var elevatorTrimControl = propFlightControls.getNode("elevator-trim", 1);
70
71 #Autopilot controls
72 var propAutopilotControls = props.globals.getNode(autopilotControls, 1);
73
74 var rollControl = propAutopilotControls.getNode("roll", 1);
75 # values 0 (ROLL switch off) 1 (ROLL switch on)
76
77 var hdgControl = propAutopilotControls.getNode("hdg", 1);
78 # values 0 (HDG switch off) 1 (HDG switch on)
79
80 var modeControl = propAutopilotControls.getNode("mode", 1);
81
82 var altControl = propAutopilotControls.getNode("alt", 1);
83 # values 0 (ALT switch off) 1 (ALT switch on)
84
85 var pitchControl = propAutopilotControls.getNode("pitch", 1);
86 # values 0 (PITCH switch off) 1 (PITCH switch on)
87
88 var headingNeedleDeflection = "/instrumentation/nav/heading-needle-deflection";
89 var gsInRange = "/instrumentation/nav/gs-in-range";
90 var gsNeedleDeflection = "/instrumentation/nav/gs-needle-deflection-deg";
91 var elapsedTimeSec = "/sim/time/elapsed-sec";
92 var indicatedPitchDeg = "/instrumentation/attitude-indicator/indicated-pitch-deg";
93 var staticPressure = "/systems/static/pressure-inhg";
94 var altitudePressure = "/autopilot/CENTURYIII/settings/target-alt-pressure";
95 var power="/systems/electrical/outputs/autopilot";
96 var enableAutoTrim = "/sim/model/enable-auto-trim";
97 var filteredHeadingNeedleDeflection = "/autopilot/internal/filtered-heading-needle-deflection";
98
99 var pressureUnits = { "inHg" : 0, "hPa" : 1 };
100 var altPressure = 0.0;
101 var valueTest = 0;
102 var lastValue = 0;
103 var newValue = 0;
104 var minVoltageLimit = 8.0;
105 var newMode = 2;
106 var oldMode = 2;
107 var deviation = 0;
108 var LocModeTimeSec = 0;
109 var AltTimeSec = 0;
110 rollControl.setDoubleValue(0.0);
111 hdgControl.setDoubleValue(0.0);
112 altControl.setDoubleValue(0.0);
113 pitchControl.setDoubleValue(0.0);
114 modeControl.setDoubleValue(2.0);
115 settingTargetPitchDeg.setDoubleValue(0.0);
116 settingPitchWheelDeg.setDoubleValue(0.0);
117 settingDeltaPitch.setDoubleValue(0.0);
118 settingTargetPressureRate.setDoubleValue(0.0);
119 settingGScaptured.setDoubleValue(0.0);
120 # If you need to be able to enable/disable auto trim, make is a menu toggle.
121 # Auto trim enabled by default
122 setprop(enableAutoTrim, 1);
123 var autoPitchTrim = 0.0;
124
125 var apInit = func {
126 ##print("ap init");
127
128 ##
129 # Initialises the autopilot.
130 ##
131
132 lockAltHold.setBoolValue(0);
133 lockAprHold.setBoolValue(0);
134 lockGsHold.setBoolValue(0);
135 lockHdgHold.setBoolValue(0);
136 lockNavHold.setBoolValue(0);
137 lockOmniHold.setBoolValue(0);
138 lockRevHold.setBoolValue(0);
139 lockRollAxis.setBoolValue(0);
140 lockRollMode.setIntValue(rollModes["OFF"]);
141 lockPitchAxis.setBoolValue(0);
142 lockPitchHold.setBoolValue(0);
143 lockPitchMode.setIntValue(pitchModes["OFF"]);
144 lockRollArm.setIntValue(rollArmModes["OFF"]);
145 lockPitchArm.setIntValue(pitchArmModes["OFF"]);
146 # Reset the memory for power down or power up
147 settingTargetAltPressure.setDoubleValue(0.0);
148 settingTargetPitchDeg.setDoubleValue(0.0);
149 settingTargetPressureRate.setDoubleValue(0.0);
150 settingTargetInterceptAngle.setDoubleValue(0.0);
151 settingTargetRollDeg.setDoubleValue(0.0);
152 settingAutoPitchTrim.setDoubleValue(0.0);
153 settingGScaptured.setDoubleValue(0.0);
154 settingRollKnobDeg.setDoubleValue(0.0);
155
156 }
157
158 var apPower = func {
159
160 ## Monitor autopilot power
161 ## Call apInit if the power is too low
162
163 if (getprop(power) < minVoltageLimit) {
164 newValue = 0;
165 } else {
166 newValue = 1;
167 }
168
169 valueTest = newValue - lastValue;
170 # print("v_test = ", v_test);
171 if (valueTest > 0.5) {
172 # autopilot just powered up
173 logprint(3, "CENTURYIII power up");
174 apInit();
175 } elsif (valueTest < -0.5) {
176 # autopilot just lost power
177 logprint(3, "CENTURYIII power lost");
178 apInit();
179 # note: all button and knobs disabled in functions below
180 }
181 lastValue = newValue;
182
183 # Update difference between pitch wheel target and indicated pitch.
184 # Used to animate the Pitch Trim meter to the left of pitch wheel
185 if (rollControl.getValue() ) {
186 settingDeltaPitch.setDoubleValue(settingPitchWheelDeg.getValue()
187 - getprop(indicatedPitchDeg));
188 } else {
189 settingDeltaPitch.setDoubleValue(0.0);
190 }
191 var inrange0 = getprop("/instrumentation/nav[0]/in-range");
192 # Shut off autopilot if HDG switch on and mode != 2 when NAV flag is on
193 if ( !inrange0 ) {
194 if ( hdgControl.getValue() and (modeControl.getValue() != 2)) {
195 rollControl.setDoubleValue(0.0);
196 apRollControl();
197 }
198 }
199 settimer(apPower, 0.5);
200 }
201
202 var apRollControl = func {
203
204 if (rollControl.getValue() ) {
205 rollButton(1);
206 } else {
207 # A/P on/off switch was turned off, so turn off other AP switches
208 hdgControl.setDoubleValue(0.0); #hdgButton(0);
209 altControl.setDoubleValue(0.0); #altButton(0);
210 pitchControl.setDoubleValue(0.0); #pitchButton(0);
211 # rollButton(0);
212 apInit();
213 }
214 }
215
216 var apHdgControl = func {
217
218 if (hdgControl.getValue() ) {
219 # hdg switch turned on sets roll
220 rollControl.setDoubleValue(1.0);
221 rollButton(1);
222 ##
223 # hdg switch is on so check which roll mode is set
224 ##
225 apModeControlsSet();
226 } else {
227 # hdg switch turned off resets alt and pitch
228 hdgControl.setDoubleValue(0.0); hdgButton(0);
229 altControl.setDoubleValue(0.0); altButton(0);
230 pitchControl.setDoubleValue(0.0); pitchButton(0);
231 }
232 }
233
234 var apAltControl = func {
235
236 if ( altControl.getValue() ){
237 # Alt switch on so set ROLL, HDG, and PITCH
238 rollControl.setDoubleValue(1.0);
239 rollButton(1);
240 hdgControl.setDoubleValue(1.0);
241 # roll and hdg switches on so check which roll mode is set
242 apModeControlsSet();
243 pitchControl.setDoubleValue(1.0);
244 pitchButton(1);
245 altButton(1);
246 } else {
247 altButton(0);
248 }
249 }
250
251 var apPitchControl = func {
252
253 if ( pitchControl.getValue() ) {
254 # Pitch switch on so set ROLL and HDG
255 rollControl.setDoubleValue(1.0);
256 rollButton(1);
257 hdgControl.setDoubleValue(1.0);
258 # roll and hdg switches on so check which roll mode is set
259 apModeControlsSet();
260 pitchButton(1);
261 } else {
262 altControl.setDoubleValue(0.0);
263 altButton(0);
264 pitchButton(0);
265 }
266 }
267
268 var rollKnobUpdate = func {
269 if ( rollControl.getValue() and !hdgControl.getValue() ) {
270 settingTargetRollDeg.setDoubleValue( settingRollKnobDeg.getValue() );
271 }
272 }
273
274
275 var pitchWheelUpdate = func {
276 if ( rollControl.getValue() and !altControl.getValue() ) {
277 settingTargetPitchDeg.setDoubleValue( settingPitchWheelDeg.getValue() );
278 }
279 }
280
281
282 var apModeControlsChange = func {
283 ##
284 # Delay mode change to allow time for multi-mode rotation
285 ##
286 settimer(apModeControlsSet, 2);
287 }
288
289 var apModeControlsSet = func {
290 newMode = modeControl.getValue();
291
292 ##
293 # Decouple GS if the mode selector is switched from LOC NORM
294 ##
295 if (oldMode == rollModes["APR"] and newMode != rollModes["APR"])
296 {
297 if (lockPitchMode.getValue() == pitchModes["GS"])
298 {
299 lockPitchMode.setIntValue(pitchModes["OFF"]);
300 }
301 if (lockPitchArmModes.getValue() == pitchArmModes["GS"])
302 {
303 lockPitchArmMode.setIntValue(pitchModes["OFF"]);
304 }
305 lockGsHold.setBoolValue(0);
306 settingGScoupled.setDoubleValue(0.0);
307 }
308
309 oldMode = newMode;
310
311 #All modes entered from hdg mode
312 if ( hdgControl.getValue() ) {
313 hdgButton(1);
314 if (newMode == 0 ){
315 navButton();
316 } elsif (newMode == 1 ) {
317 omniButton();
318 } elsif (newMode == 3 ) {
319 aprButton();
320 } elsif(newMode == 4 ) {
321 revButton();
322 }
323 } else {
324 return;
325 }
326 }
327
328 var rollButton = func(switch_on) {
329 ##print("rollButton");
330 # Disable button if too little power
331 if (getprop(power) < minVoltageLimit) { return; }
332
333 if ( switch_on ) {
334 ##
335 # Engage the autopilot in Wings level mode (ROL) and set the turn rate
336 # from the "ROLL Knob".
337 ##
338
339 lockAprHold.setBoolValue(0);
340 lockHdgHold.setBoolValue(0);
341 lockNavHold.setBoolValue(0);
342 lockOmniHold.setBoolValue(0);
343 lockRevHold.setBoolValue(0);
344 lockRollAxis.setBoolValue(1);
345 lockRollMode.setIntValue(rollModes["ROL"]);
346 lockRollArm.setIntValue(rollArmModes["OFF"]);
347 } else {
348 lockAprHold.setBoolValue(0);
349 lockHdgHold.setBoolValue(0);
350 lockNavHold.setBoolValue(0);
351 lockOmniHold.setBoolValue(0);
352 lockRevHold.setBoolValue(0);
353 lockRollAxis.setBoolValue(0);
354 lockRollMode.setIntValue(rollModes["OFF"]);
355 lockRollArm.setIntValue(rollArmModes["OFF"]);
356 }
357 }
358
359
360 var hdgButton = func(switch_on) {
361 ##print("hdgButton");
362 # Disable button if too little power
363 if (getprop(power) < minVoltageLimit) { return; }
364
365 if (switch_on) {
366 ##
367 # Engage the heading mode (HDG).
368 ##
369 lockAprHold.setBoolValue(0);
370 lockRevHold.setBoolValue(0);
371 lockHdgHold.setBoolValue(1);
372 lockNavHold.setBoolValue(0);
373 lockOmniHold.setBoolValue(0);
374 lockRollAxis.setBoolValue(1);
375 lockRollMode.setIntValue(rollModes["HDG"]);
376 lockRollArm.setIntValue(rollArmModes["OFF"]);
377
378 settingTargetInterceptAngle.setDoubleValue(0.0);
379
380 } else {
381 lockHdgHold.setBoolValue(0);
382 rollKnobUpdate();
383 if ( rollControl.getValue() ) {
384 lockRollMode.setIntValue(rollModes["ROL"]);
385 } else {
386 lockRollMode.setIntValue(rollModes["OFF"]);
387 }
388 }
389 }
390
391 var navButton = func {
392 ##print("navButton");
393 # Disable button if too little power
394 if (getprop(power) < minVoltageLimit) { return; }
395
396 ##
397 # The Mode Selector and DG Course Selector should be set before switching the HDG
398 # rocker switch to "on". The DG Course Selector should be set to the OBS "to" or
399 # "from" bearing.
400 # Set up NAV mode and switch to the 45 degree angle intercept NAV mode
401 ##
402 lockAprHold.setBoolValue(0);
403 lockRevHold.setBoolValue(0);
404 lockHdgHold.setBoolValue(1);
405 lockNavHold.setBoolValue(0);
406 lockOmniHold.setBoolValue(0);
407 lockRollAxis.setBoolValue(1);
408 lockRollArm.setIntValue(rollArmModes["NAV"]);
409 lockRollMode.setIntValue(rollModes["NAV"]);
410
411 navArmFromHdg();
412 }
413
414 var navArmFromHdg = func
415 {
416 ##
417 # Abort the NAV-ARM mode if something has changed the arm mode to something
418 # else than NAV-ARM.
419 ##
420 if (lockRollArm.getValue() != rollArmModes["NAV"])
421 {
422 return;
423 }
424
425 ##
426 # Activate the nav-hold controller and check the needle deviation.
427 ##
428 lockNavHold.setBoolValue(1);
429 deviation = getprop(headingNeedleDeflection);
430 ##
431 # If the deflection is more than 9.95 degrees wait 5 seconds and check again.
432 ##
433 if (abs(deviation) > 9.95)
434 {
435 #print("deviation");
436 settimer(navArmFromHdg, 5);
437 return;
438 }
439 ##
440 # If the deviation is less than 10 degrees turn off the NAV-ARM. End of NAV-ARM sequence.
441 ##
442 elsif (abs(deviation) < 10.0)
443 {
444 #print("capture");
445 lockRollArm.setIntValue(rollArmModes["OFF"]);
446 }
447 }
448
449 var omniButton = func {
450 ##print("navButton");
451 # Disable button if too little power
452 if (getprop(power) < minVoltageLimit) { return; }
453
454 ##
455 # The Mode Selector and DG Course Selector should be set before switching the HDG
456 # rocker switch to "on". The DG Course Selector should be set to the OBS "to" or
457 # "from" bearing.
458 # Set up OMNI mode and switch to the 45 degree angle intercept OMNI mode
459 ##
460 lockAprHold.setBoolValue(0);
461 lockRevHold.setBoolValue(0);
462 lockHdgHold.setBoolValue(1);
463 lockNavHold.setBoolValue(0);
464 lockOmniHold.setBoolValue(0);
465 lockRollAxis.setBoolValue(1);
466 lockRollArm.setIntValue(rollArmModes["OMNI"]);
467 lockRollMode.setIntValue(rollModes["OMNI"]);
468
469 omniArmFromHdg();
470 }
471
472
473 var omniArmFromHdg = func
474 {
475 ##
476 # Abort the OMNI-ARM mode if something has changed the arm mode to something
477 # else than OMNI-ARM.
478 ##
479 if (lockRollArm.getValue() != rollArmModes["OMNI"])
480 {
481 return;
482 }
483
484 ##
485 # Activate the omni-hold controller and check the needle deviation.
486 ##
487 lockOmniHold.setBoolValue(1);
488 deviation = getprop(filteredHeadingNeedleDeflection);
489 ##
490 # If the deflection is more than 9.95 degrees wait 5 seconds and check again.
491 ##
492 if (abs(deviation) > 9.95)
493 {
494 #print("deviation");
495 settimer(omniArmFromHdg, 5);
496 return;
497 }
498 ##
499 # If the deviation is less than 10 degrees turn off the OMNI-ARM. End of OMNI-ARM sequence.
500 ##
501 elsif (abs(deviation) < 10.0)
502 {
503 #print("capture");
504 lockRollArm.setIntValue(rollArmModes["OFF"]);
505 }
506 }
507
508
509 var aprButton = func {
510 ##print("aprButton");
511 # Disable button if too little power
512 if (getprop(power) < minVoltageLimit) { return; }
513 ##
514 # Save the elapsed time when mode switch was set to LOC Norm.
515 # This is used to delay the gsArm at least 20 sec after the mode is set to LOC Norm.
516 # See comment by Figure 24, page 30 in "CENTURY II Autopilot Flight System POH".
517 ##
518 LocModeTimeSec = getprop(elapsedTimeSec);
519
520 ##
521 # The Mode Selector and DG Course Selector should be set before switching the HDG
522 # rocker switch to "on". Set the DG Course Selector to the LOC inbound heading.
523 # Set up APR mode and switch to the 45 degree angle intercept APR mode
524 ##
525 lockAprHold.setBoolValue(1);
526 lockRevHold.setBoolValue(0);
527 lockHdgHold.setBoolValue(1);
528 lockNavHold.setBoolValue(0);
529 lockOmniHold.setBoolValue(0);
530 lockRollAxis.setBoolValue(1);
531 lockRollArm.setIntValue(rollArmModes["APR"]);
532 lockRollMode.setIntValue(rollModes["APR"]);
533
534 aprArmFromHdg();
535 }
536
537 var aprArmFromHdg = func
538 {
539 ##
540 # Abort the APR-ARM mode if something has changed the arm mode to something
541 # else than APR-ARM.
542 ##
543 if (lockRollArm.getValue() != rollArmModes["APR"]
544 or !lockAltHold.getValue())
545 {
546 return;
547 }
548
549 ##
550 # Activate the apr-hold controller and check the needle deviation.
551 ##
552 lockAprHold.setBoolValue(1);
553 deviation = getprop(headingNeedleDeflection);
554 ##
555 # If the deflection is more than 2.5 degrees wait 5 seconds and check again.
556 ##
557 if (abs(deviation) > 2.495)
558 {
559 #print("deviation");
560 settimer(aprArmFromHdg, 5);
561 return;
562 }
563 ##
564 # If the deviation is less than 2.5 degrees, start the GS-ARM sequence
565 ##
566 elsif (abs(deviation) < 2.5)
567 {
568 lockPitchArm.setIntValue(pitchArmModes["GS"]);
569
570 gsArm();
571 }
572 }
573
574 var gsArm = func {
575 ##
576 # Abort the GS-ARM mode if something has changed the arm mode to something
577 # else than GS-ARM.
578 ##
579 if (lockPitchArm.getValue() != pitchArmModes["GS"])
580 {
581 return;
582 }
583 ##
584 # Loop until the LOC Norm mode has been set for at least 20 seconds
585 # and the Alt switch has been on for at least 20 seconds.
586 # See page 30 in "CENTURY II Autopilot Flight System POH".
587 ##
588 if ( (getprop(elapsedTimeSec) - LocModeTimeSec) < 20
589 or (getprop(elapsedTimeSec) - AltTimeSec) < 20 )
590 {
591 settimer(gsArm, 2);
592 return;
593 }
594 ##
595 # Loop until gs is in range
596 ##
597 if (!getprop(gsInRange))
598 {
599 settimer(gsArm, 2);
600 return;
601 }
602 deviation = getprop(gsNeedleDeflection);
603 ##
604 # Abort if above the glide slope as you have passed the gs intercept
605 if (deviation < 0)
606 {
607 return;
608 }
609 ##
610 # If the deflection is more than 0.1 degrees wait 2 seconds and check again.
611 ##
612 if (abs(deviation) > 0.1)
613 {
614 #print("deviation");
615 settimer(gsArm, 2);
616 return;
617 }
618 ##
619 # The deviation is less than 0.1 then activate the GS pitch mode.
620 ##
621 else
622 {
623 #print("capture");
624 lockAltHold.setBoolValue(0);
625 lockGsHold.setBoolValue(1);
626 lockPitchMode.setIntValue(pitchModes["GS"]);
627 lockPitchArm.setIntValue(pitchArmModes["OFF"]);
628 settingGScaptured.setDoubleValue(1.0);
629 }
630 }
631
632
633 var revButton = func {
634 ##print("revButton");
635 # Disable button if too little power
636 if (getprop(power) < minVoltageLimit) { return; }
637
638 ##
639 # The Mode Selector and DG Course Selector should be set before switching the HDG
640 # rocker switch to "on". Set the DG Course Selector to the LOC outbound
641 # (or reverse) heading.
642 # Set up REV mode and switch to the 45 degree angle intercept REV mode
643 ##
644 lockAprHold.setBoolValue(0);
645 lockRevHold.setBoolValue(0);
646 lockHdgHold.setBoolValue(1);
647 lockNavHold.setBoolValue(0);
648 lockOmniHold.setBoolValue(0);
649 lockRollAxis.setBoolValue(1);
650 lockRollArm.setIntValue(rollArmModes["REV"]);
651
652 revArmFromHdg();
653 }
654
655
656 var revArmFromHdg = func
657 {
658 ##
659 # Abort the REV-ARM mode if something has changed the arm mode to something
660 # else than REV-ARM.
661 ##
662 if (lockRollArm.getValue() != rollArmModes["REV"])
663 {
664 return;
665 }
666
667 ##
668 # Activate the rev-hold controller and check the needle deviation.
669 ##
670 lockRevHold.setBoolValue(1);
671 deviation = getprop(headingNeedleDeflection);
672 ##
673 # If the deflection is more than 2.5 degrees wait 5 seconds and check again.
674 ##
675 if (abs(deviation) > 2.495)
676 {
677 #print("deviation");
678 settimer(revArmFromHdg, 5);
679 return;
680 }
681 ##
682 # If the deviation is less than 2.5 - End of REV-ARM sequence.
683 ##
684 elsif (abs(deviation) < 2.5)
685 {
686 #print("capture");
687 lockRollArm.setIntValue(rollArmModes["OFF"]);
688 lockAprHold.setBoolValue(0);
689 lockRevHold.setBoolValue(1);
690 lockHdgHold.setBoolValue(1);
691 lockNavHold.setBoolValue(0);
692 lockOmniHold.setBoolValue(0);
693 lockRollAxis.setBoolValue(1);
694 lockRollMode.setIntValue(rollModes["REV"]);
695 lockRollArm.setIntValue(rollArmModes["OFF"]);
696 }
697 }
698
699
700 var altButton = func(switch_on) {
701 # Disable button if too little power
702 if (getprop(power) < minVoltageLimit) { return; }
703
704 if (switch_on) {
705 ##
706 # Save the elapsed time when Alt switch was turned on.
707 # This is used to delay the gsArm at least 20 sec after the Alt switch is turned on.
708 # See comment by Figure 25, page 30 in "CENTURY II Autopilot Flight System POH".
709 ##
710 AltTimeSec = getprop(elapsedTimeSec);
711 lockAltHold.setBoolValue(1);
712 lockPitchAxis.setBoolValue(1);
713 # lockPitchMode.setIntValue(pitchModes["ALT"]);
714
715 altPressure = getprop(staticPressure);
716 settingTargetAltPressure.setDoubleValue(altPressure);
717 # print("enableAutoTrim = ", getprop(enableAutoTrim));
718 if ( getprop(enableAutoTrim) ) {
719 settingAutoPitchTrim.setDoubleValue(1);
720 }
721 ##
722 # Handle case where mode is LOC Norm and ALT switch is turned off and then back on.
723 # e.g. When descending to a lower GS intercept altitude in a step-down approach
724 ##
725 if (oldMode == 3) { apModeControlsSet(); }
726 } else {
727 lockAltHold.setBoolValue(0);
728 lockPitchAxis.setBoolValue(0);
729 lockPitchMode.setIntValue(pitchModes["OFF"]);
730 lockPitchArm.setIntValue(pitchArmModes["OFF"]);
731 pitchWheelUpdate();
732 settingTargetPressureRate.setDoubleValue(0.0);
733 # alt switch is off so make sure the glide slope is disabled
734 settingGScaptured.setDoubleValue(0.0);
735 lockGsHold.setBoolValue(0);
736 }
737 }
738
739 var pitchButton = func(switch_on) {
740 # Disable button if too little power
741 if (getprop(power) < minVoltageLimit) { return; }
742
743 if (switch_on) {
744 lockPitchHold.setBoolValue(1);
745 # lockPitchAxis.setBoolValue(1);
746 # lockPitchMode.setIntValue(pitchModes["AOA"]);
747 # print("enableAutoTrim = ", getprop(enableAutoTrim));
748 if ( getprop(enableAutoTrim) ) {
749 settingAutoPitchTrim.setDoubleValue(1);
750 }
751 } else {
752 lockPitchHold.setBoolValue(0);
753 lockPitchAxis.setBoolValue(0);
754 lockPitchMode.setIntValue(pitchModes["OFF"]);
755 settingAutoPitchTrim.setDoubleValue(0);
756 }
757 }
758
759 var touchPower = func{
760 setprop(power,apVolts);
761 }
762
763 var apVolts = getprop(power);
764
765 if ( apVolts == nil or apVolts < minVoltageLimit ) {
766 # Wait for autopilot to be powered up
767 var L = setlistener(power, func {
768 apPower();
769 removelistener(L);
770 });
771 } else {
772 # Skip the setlistener since autopilot is already powered up
773 settimer(touchPower ,10);
774 apPower();
775 }
776
777