| 1 |
## |
| 2 |
# Bendix/King KAP140 Autopilot System |
| 3 |
# Tries to behave like the Bendix/King KAP140 autopilot |
| 4 |
# two axis w/altitude preselect. |
| 5 |
# |
| 6 |
# One would also need the autopilot configuration file |
| 7 |
# KAP140.xml and the panel instrument configuration file |
| 8 |
# |
| 9 |
# Written by Roy Vegard Ovesen |
| 10 |
# "Power-check" edits by Dave Perry |
| 11 |
## |
| 12 |
|
| 13 |
# Properties |
| 14 |
|
| 15 |
var locks = "/autopilot/KAP140/locks"; |
| 16 |
var settings = "/autopilot/KAP140/settings"; |
| 17 |
var annunciators = "/autopilot/KAP140/annunciators"; |
| 18 |
var internal = "/autopilot/internal"; |
| 19 |
var power="/systems/electrical/outputs/autopilot"; |
| 20 |
var encoder = "/instrumentation/altimeter"; |
| 21 |
var flightControls = "/controls/flight"; |
| 22 |
|
| 23 |
# locks |
| 24 |
var propLocks = props.globals.getNode(locks, 1); |
| 25 |
|
| 26 |
var lockAltHold = propLocks.getNode("alt-hold", 1); |
| 27 |
var lockAprHold = propLocks.getNode("apr-hold", 1); |
| 28 |
var lockGsHold = propLocks.getNode("gs-hold", 1); |
| 29 |
var lockHdgHold = propLocks.getNode("hdg-hold", 1); |
| 30 |
var lockNavHold = propLocks.getNode("nav-hold", 1); |
| 31 |
var lockRevHold = propLocks.getNode("rev-hold", 1); |
| 32 |
var lockRollAxis = propLocks.getNode("roll-axis", 1); |
| 33 |
var lockRollMode = propLocks.getNode("roll-mode", 1); |
| 34 |
var lockPitchAxis = propLocks.getNode("pitch-axis", 1); |
| 35 |
var lockPitchMode = propLocks.getNode("pitch-mode", 1); |
| 36 |
var lockRollArm = propLocks.getNode("roll-arm", 1); |
| 37 |
var lockPitchArm = propLocks.getNode("pitch-arm", 1); |
| 38 |
|
| 39 |
|
| 40 |
var rollModes = { "OFF" : 0, "ROL" : 1, "HDG" : 2, "NAV" : 3, "REV" : 4, "APR" : 5 }; |
| 41 |
var pitchModes = { "OFF" : 0, "VS" : 1, "ALT" : 2, "GS" : 3 }; |
| 42 |
var rollArmModes = { "OFF" : 0, "NAV" : 1, "APR" : 2, "REV" : 3 }; |
| 43 |
var pitchArmModes = { "OFF" : 0, "ALT" : 1, "GS" : 2 }; |
| 44 |
|
| 45 |
# settings |
| 46 |
var propSettings = props.globals.getNode(settings, 1); |
| 47 |
|
| 48 |
var settingTargetAltPressure = propSettings.getNode("target-alt-pressure", 1); |
| 49 |
var settingTargetInterceptAngle = propSettings.getNode("target-intercept-angle", 1); |
| 50 |
var settingTargetPressureRate = propSettings.getNode("target-pressure-rate", 1); |
| 51 |
var settingTargetTurnRate = propSettings.getNode("target-turn-rate", 1); |
| 52 |
var settingTargetAltFt = propSettings.getNode("target-alt-ft", 1); |
| 53 |
var settingBaroSettingInhg = propSettings.getNode("baro-setting-inhg", 1); |
| 54 |
var settingBaroSettingHpa = propSettings.getNode("baro-setting-hpa", 1); |
| 55 |
var settingAutoPitchTrim = propSettings.getNode("auto-pitch-trim", 1); |
| 56 |
|
| 57 |
#annunciators |
| 58 |
var propAnnunciators = props.globals.getNode(annunciators, 1); |
| 59 |
|
| 60 |
var annunciatorRol = propAnnunciators.getNode("rol", 1); |
| 61 |
var annunciatorHdg = propAnnunciators.getNode("hdg", 1); |
| 62 |
var annunciatorNav = propAnnunciators.getNode("nav", 1); |
| 63 |
var annunciatorNavArm = propAnnunciators.getNode("nav-arm", 1); |
| 64 |
var annunciatorApr = propAnnunciators.getNode("apr", 1); |
| 65 |
var annunciatorAprArm = propAnnunciators.getNode("apr-arm", 1); |
| 66 |
var annunciatorRev = propAnnunciators.getNode("rev", 1); |
| 67 |
var annunciatorRevArm = propAnnunciators.getNode("rev-arm", 1); |
| 68 |
var annunciatorVs = propAnnunciators.getNode("vs", 1); |
| 69 |
var annunciatorVsNumber = propAnnunciators.getNode("vs-number", 1); |
| 70 |
var annunciatorFpm = propAnnunciators.getNode("fpm", 1); |
| 71 |
var annunciatorAlt = propAnnunciators.getNode("alt", 1); |
| 72 |
var annunciatorAltArm = propAnnunciators.getNode("alt-arm", 1); |
| 73 |
var annunciatorAltNumber = propAnnunciators.getNode("alt-number", 1); |
| 74 |
var annunciatorAltAlert = propAnnunciators.getNode("alt-alert", 1); |
| 75 |
var annunciatorApr = propAnnunciators.getNode("apr", 1); |
| 76 |
var annunciatorGs = propAnnunciators.getNode("gs", 1); |
| 77 |
var annunciatorGsArm = propAnnunciators.getNode("gs-arm", 1); |
| 78 |
var annunciatorPtUp = propAnnunciators.getNode("pt-up", 1); |
| 79 |
var annunciatorPtDn = propAnnunciators.getNode("pt-dn", 1); |
| 80 |
var annunciatorBsHpaNumber = propAnnunciators.getNode("bs-hpa-number", 1); |
| 81 |
var annunciatorBsInhgNumber = propAnnunciators.getNode("bs-inhg-number", 1); |
| 82 |
var annunciatorAp = propAnnunciators.getNode("ap", 1); |
| 83 |
var annunciatorBeep = propAnnunciators.getNode("beep", 1); |
| 84 |
|
| 85 |
#flashers |
| 86 |
var altAlertBeeper = aircraft.light.new(annunciatorBeep, [0.5, 0.25]).switch(0); |
| 87 |
var altAlertFlasher = aircraft.light.new(annunciatorAltAlert, [0.5, 0.25]).switch(0); |
| 88 |
var hdgFlasher = aircraft.light.new(annunciatorHdg, [0.5, 0.25]).switch(0); |
| 89 |
var apFlasher = aircraft.light.new(annunciatorAp, [1.0, 0.5]).switch(0); |
| 90 |
|
| 91 |
#Flight controls |
| 92 |
var propFlightControls = props.globals.getNode(flightControls, 0); |
| 93 |
|
| 94 |
var elevatorControl = propFlightControls.getNode("elevator", 0); |
| 95 |
var elevatorTrimControl = propFlightControls.getNode("elevator-trim", 0); |
| 96 |
|
| 97 |
var navHeadingValid = "/instrumentation/nav/in-range"; |
| 98 |
var navGSValid = "/instrumentation/nav/gs-in-range"; |
| 99 |
var headingNeedleDeflection = "/instrumentation/nav/heading-needle-deflection"; |
| 100 |
var gsNeedleDeflection = "/instrumentation/nav/gs-needle-deflection-norm"; |
| 101 |
var staticPressure = "systems/static/pressure-inhg"; |
| 102 |
|
| 103 |
var pressureUnits = { "inHg" : 0, "hPa" : 1 }; |
| 104 |
var baroSettingUnit = pressureUnits["inHg"]; |
| 105 |
var baroSettingInhg = 29.92; |
| 106 |
var baroSettingHpa = baroSettingInhg * 33.86389; |
| 107 |
var baroSettingAdjusting = 0; |
| 108 |
var baroButtonDown = 0; |
| 109 |
var baroTimerRunning = 0; |
| 110 |
|
| 111 |
var altPreselect = 0; |
| 112 |
var altButtonTimerRunning = 0; |
| 113 |
var altButtonTimerIgnore = 0; |
| 114 |
var altAlertOn = 0; |
| 115 |
var altCaptured = 0; |
| 116 |
var altDifference = 0.0; |
| 117 |
|
| 118 |
var valueTest = 0; |
| 119 |
var lastValue = 0; |
| 120 |
var newValue = 0; |
| 121 |
var baroOffset = 0.0; |
| 122 |
var baroChange = 1; |
| 123 |
var minVoltageLimit = 8.0; |
| 124 |
|
| 125 |
|
| 126 |
var ptCheck = func { |
| 127 |
##print("pitch trim check"); |
| 128 |
|
| 129 |
if (lockPitchMode.getValue() == pitchModes["OFF"]) |
| 130 |
{ |
| 131 |
annunciatorPtUp.setBoolValue(0); |
| 132 |
annunciatorPtDn.setBoolValue(0); |
| 133 |
return; |
| 134 |
} |
| 135 |
|
| 136 |
else |
| 137 |
{ |
| 138 |
var autoPitchTrim = settingAutoPitchTrim.getValue(); |
| 139 |
# Flash the pitch trim up annunciator |
| 140 |
if (elevatorControl.getValue() < -0.01) |
| 141 |
{ |
| 142 |
if (annunciatorPtUp.getValue() == 0) |
| 143 |
{ |
| 144 |
annunciatorPtUp.setBoolValue(1); |
| 145 |
} |
| 146 |
elsif (annunciatorPtUp.getValue() == 1) |
| 147 |
{ |
| 148 |
annunciatorPtUp.setBoolValue(0); |
| 149 |
} |
| 150 |
annunciatorPtDn.setBoolValue(0); |
| 151 |
# Automatic pitch trim |
| 152 |
if (autoPitchTrim == 1) |
| 153 |
{ |
| 154 |
elevatorTrimControl.setDoubleValue( |
| 155 |
elevatorTrimControl.getValue() - 0.001); |
| 156 |
} |
| 157 |
} |
| 158 |
# Flash the pitch trim down annunciator |
| 159 |
elsif (elevatorControl.getValue() > 0.01) |
| 160 |
{ |
| 161 |
if (annunciatorPtDn.getValue() == 0) |
| 162 |
{ |
| 163 |
annunciatorPtDn.setBoolValue(1); |
| 164 |
} |
| 165 |
elsif (annunciatorPtDn.getValue() == 1) |
| 166 |
{ |
| 167 |
annunciatorPtDn.setBoolValue(0); |
| 168 |
} |
| 169 |
annunciatorPtUp.setBoolValue(0); |
| 170 |
# Automatic pitch trim |
| 171 |
if (autoPitchTrim == 1) |
| 172 |
{ |
| 173 |
elevatorTrimControl.setDoubleValue( |
| 174 |
elevatorTrimControl.getValue() + 0.001); |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
else |
| 179 |
{ |
| 180 |
annunciatorPtUp.setBoolValue(0); |
| 181 |
annunciatorPtDn.setBoolValue(0); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
settimer(ptCheck, 0.5); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
var apInit = func { |
| 190 |
##print("ap init"); |
| 191 |
|
| 192 |
## |
| 193 |
# Initialises the autopilot. |
| 194 |
## |
| 195 |
|
| 196 |
lockAltHold.setBoolValue(0); |
| 197 |
lockAprHold.setBoolValue(0); |
| 198 |
lockGsHold.setBoolValue(0); |
| 199 |
lockHdgHold.setBoolValue(0); |
| 200 |
lockNavHold.setBoolValue(0); |
| 201 |
lockRevHold.setBoolValue(0); |
| 202 |
lockRollAxis.setBoolValue(0); |
| 203 |
lockRollMode.setIntValue(rollModes["OFF"]); |
| 204 |
lockPitchAxis.setBoolValue(0); |
| 205 |
lockPitchMode.setIntValue(pitchModes["OFF"]); |
| 206 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 207 |
lockPitchArm.setIntValue(pitchArmModes["OFF"]); |
| 208 |
# Reset the memory for power down or power up |
| 209 |
altPreselect = 0; |
| 210 |
baroSettingInhg = 29.92; |
| 211 |
adjustBaroSettingInhg(0.0); |
| 212 |
settingTargetAltFt.setDoubleValue(altPreselect); |
| 213 |
settingTargetAltPressure.setDoubleValue(0.0); |
| 214 |
settingTargetInterceptAngle.setDoubleValue(0.0); |
| 215 |
settingTargetPressureRate.setDoubleValue(0.0); |
| 216 |
settingTargetTurnRate.setDoubleValue(0.0); |
| 217 |
|
| 218 |
annunciatorRol.setBoolValue(0); |
| 219 |
annunciatorHdg.getNode("state").setBoolValue(0); |
| 220 |
annunciatorNav.setBoolValue(0); |
| 221 |
annunciatorNavArm.setBoolValue(0); |
| 222 |
annunciatorApr.setBoolValue(0); |
| 223 |
annunciatorAprArm.setBoolValue(0); |
| 224 |
annunciatorRev.setBoolValue(0); |
| 225 |
annunciatorRevArm.setBoolValue(0); |
| 226 |
annunciatorVs.setBoolValue(0); |
| 227 |
annunciatorVsNumber.setBoolValue(0); |
| 228 |
annunciatorFpm.setBoolValue(0); |
| 229 |
annunciatorAlt.setBoolValue(0); |
| 230 |
annunciatorAltArm.setBoolValue(0); |
| 231 |
annunciatorAltNumber.setBoolValue(0); |
| 232 |
annunciatorGs.setBoolValue(0); |
| 233 |
annunciatorGsArm.setBoolValue(0); |
| 234 |
annunciatorPtUp.setBoolValue(0); |
| 235 |
annunciatorPtDn.setBoolValue(0); |
| 236 |
annunciatorBsHpaNumber.setBoolValue(0); |
| 237 |
annunciatorBsInhgNumber.setBoolValue(0); |
| 238 |
annunciatorAp.getNode("state").setBoolValue(0); |
| 239 |
annunciatorBeep.setBoolValue(0); |
| 240 |
|
| 241 |
# settimer(altAlert, 5.0); |
| 242 |
} |
| 243 |
|
| 244 |
var apPower = func { |
| 245 |
|
| 246 |
## Monitor autopilot power |
| 247 |
## Call apInit if the power is too low |
| 248 |
|
| 249 |
if (getprop(power) < minVoltageLimit) { |
| 250 |
newValue = 0; |
| 251 |
} else { |
| 252 |
newValue = 1; |
| 253 |
} |
| 254 |
|
| 255 |
valueTest = newValue - lastValue; |
| 256 |
# print("v_test = ", v_test); |
| 257 |
if (valueTest > 0.5) { |
| 258 |
# autopilot just powered up |
| 259 |
logprint(3, "KAP140 power up"); |
| 260 |
apInit(); |
| 261 |
altAlert(); |
| 262 |
} elsif (valueTest < -0.5) { |
| 263 |
# autopilot just lost power |
| 264 |
logprint(3, "KAP140 power lost"); |
| 265 |
apInit(); |
| 266 |
annunciatorAltAlert.getNode("state").setBoolValue(0); |
| 267 |
annunciatorBeep.getNode("state").setBoolValue(0); |
| 268 |
# note: all button and knobs disabled in functions below |
| 269 |
} |
| 270 |
lastValue = newValue; |
| 271 |
settimer(apPower, 0.5); |
| 272 |
} |
| 273 |
|
| 274 |
var apButton = func { |
| 275 |
##print("apButton"); |
| 276 |
# Disable button if too little power |
| 277 |
if (getprop(power) < minVoltageLimit) { return; } |
| 278 |
|
| 279 |
## |
| 280 |
# Engages the autopilot in Wings level mode (ROL) and Vertical speed hold |
| 281 |
# mode (VS). |
| 282 |
## |
| 283 |
if (lockRollMode.getValue() == rollModes["OFF"] and |
| 284 |
lockPitchMode.getValue() == pitchModes["OFF"]) |
| 285 |
{ |
| 286 |
|
| 287 |
lockAltHold.setBoolValue(0); |
| 288 |
lockAprHold.setBoolValue(0); |
| 289 |
lockGsHold.setBoolValue(0); |
| 290 |
lockHdgHold.setBoolValue(0); |
| 291 |
lockNavHold.setBoolValue(0); |
| 292 |
lockRevHold.setBoolValue(0); |
| 293 |
lockRollAxis.setBoolValue(1); |
| 294 |
lockRollMode.setIntValue(rollModes["ROL"]); |
| 295 |
lockPitchAxis.setBoolValue(1); |
| 296 |
lockPitchMode.setIntValue(pitchModes["VS"]); |
| 297 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 298 |
lockPitchArm.setIntValue(pitchArmModes["OFF"]); |
| 299 |
|
| 300 |
annunciatorRol.setBoolValue(1); |
| 301 |
annunciatorVs.setBoolValue(1); |
| 302 |
annunciatorVsNumber.setBoolValue(1); |
| 303 |
|
| 304 |
settingTargetTurnRate.setDoubleValue(0.0); |
| 305 |
|
| 306 |
ptCheck(); |
| 307 |
|
| 308 |
var pressureRate = getprop(internal, "pressure-rate"); |
| 309 |
#print(pressureRate); |
| 310 |
var fpm = -pressureRate * 58000; |
| 311 |
#print(fpm); |
| 312 |
if (fpm > 0.0) |
| 313 |
{ |
| 314 |
fpm = int(fpm/100 + 0.5) * 100; |
| 315 |
} |
| 316 |
else |
| 317 |
{ |
| 318 |
fpm = int(fpm/100 - 0.5) * 100; |
| 319 |
} |
| 320 |
#print(fpm); |
| 321 |
|
| 322 |
settingTargetPressureRate.setDoubleValue(-fpm / 58000); |
| 323 |
|
| 324 |
if (altButtonTimerRunning == 0) |
| 325 |
{ |
| 326 |
settimer(altButtonTimer, 3.0); |
| 327 |
altButtonTimerRunning = 1; |
| 328 |
altButtonTimerIgnore = 0; |
| 329 |
annunciatorAltNumber.setBoolValue(0); |
| 330 |
} |
| 331 |
} |
| 332 |
## |
| 333 |
# Disengages all modes. |
| 334 |
## |
| 335 |
elsif (lockRollMode.getValue() != rollModes["OFF"] and |
| 336 |
lockPitchMode.getValue() != pitchModes["OFF"]) |
| 337 |
{ |
| 338 |
|
| 339 |
lockAltHold.setBoolValue(0); |
| 340 |
lockAprHold.setBoolValue(0); |
| 341 |
lockGsHold.setBoolValue(0); |
| 342 |
lockHdgHold.setBoolValue(0); |
| 343 |
lockNavHold.setBoolValue(0); |
| 344 |
lockRevHold.setBoolValue(0); |
| 345 |
lockRollAxis.setBoolValue(0); |
| 346 |
lockRollMode.setIntValue(rollModes["OFF"]); |
| 347 |
lockPitchAxis.setBoolValue(0); |
| 348 |
lockPitchMode.setIntValue(pitchModes["OFF"]); |
| 349 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 350 |
lockPitchArm.setIntValue(pitchArmModes["OFF"]); |
| 351 |
|
| 352 |
settingTargetAltPressure.setDoubleValue(0.0); |
| 353 |
settingTargetInterceptAngle.setDoubleValue(0.0); |
| 354 |
settingTargetPressureRate.setDoubleValue(0.0); |
| 355 |
settingTargetTurnRate.setDoubleValue(0.0); |
| 356 |
|
| 357 |
annunciatorRol.setBoolValue(0); |
| 358 |
annunciatorHdg.getNode("state").setBoolValue(0); |
| 359 |
annunciatorNav.setBoolValue(0); |
| 360 |
annunciatorNavArm.setBoolValue(0); |
| 361 |
annunciatorApr.setBoolValue(0); |
| 362 |
annunciatorAprArm.setBoolValue(0); |
| 363 |
annunciatorRev.setBoolValue(0); |
| 364 |
annunciatorRevArm.setBoolValue(0); |
| 365 |
annunciatorVs.setBoolValue(0); |
| 366 |
annunciatorVsNumber.setBoolValue(0); |
| 367 |
annunciatorAlt.setBoolValue(0); |
| 368 |
annunciatorAltArm.setBoolValue(0); |
| 369 |
annunciatorAltNumber.setBoolValue(0); |
| 370 |
annunciatorApr.setBoolValue(0); |
| 371 |
annunciatorGs.setBoolValue(0); |
| 372 |
annunciatorGsArm.setBoolValue(0); |
| 373 |
annunciatorPtUp.setBoolValue(0); |
| 374 |
annunciatorPtDn.setBoolValue(0); |
| 375 |
|
| 376 |
apFlasher.blink(5).switch(0).switch(1); |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
var hdgButton = func { |
| 382 |
##print("hdgButton"); |
| 383 |
# Disable button if too little power |
| 384 |
if (getprop(power) < minVoltageLimit) { return; } |
| 385 |
|
| 386 |
## |
| 387 |
# Engages the heading mode (HDG) and vertical speed hold mode (VS). The |
| 388 |
# commanded vertical speed is set to the vertical speed present at button |
| 389 |
# press. |
| 390 |
## |
| 391 |
if (lockRollMode.getValue() == rollModes["OFF"] and |
| 392 |
lockPitchMode.getValue() == pitchModes["OFF"]) |
| 393 |
{ |
| 394 |
lockAltHold.setBoolValue(0); |
| 395 |
lockAprHold.setBoolValue(0); |
| 396 |
lockRevHold.setBoolValue(0); |
| 397 |
lockGsHold.setBoolValue(0); |
| 398 |
lockHdgHold.setBoolValue(1); |
| 399 |
lockNavHold.setBoolValue(0); |
| 400 |
lockRollAxis.setBoolValue(1); |
| 401 |
lockRollMode.setIntValue(rollModes["HDG"]); |
| 402 |
lockPitchAxis.setBoolValue(1); |
| 403 |
lockPitchMode.setIntValue(pitchModes["VS"]); |
| 404 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 405 |
lockPitchArm.setIntValue(pitchArmModes["OFF"]); |
| 406 |
|
| 407 |
annunciatorHdg.getNode("state").setBoolValue(1); |
| 408 |
annunciatorAlt.setBoolValue(0); |
| 409 |
annunciatorApr.setBoolValue(0); |
| 410 |
annunciatorGs.setBoolValue(0); |
| 411 |
annunciatorNav.setBoolValue(0); |
| 412 |
annunciatorVs.setBoolValue(1); |
| 413 |
annunciatorVsNumber.setBoolValue(1); |
| 414 |
|
| 415 |
settingTargetInterceptAngle.setDoubleValue(0.0); |
| 416 |
|
| 417 |
ptCheck(); |
| 418 |
|
| 419 |
var pressureRate = getprop(internal, "pressure-rate"); |
| 420 |
var fpm = -pressureRate * 58000; |
| 421 |
#print(fpm); |
| 422 |
if (fpm > 0.0) |
| 423 |
{ |
| 424 |
fpm = int(fpm/100 + 0.5) * 100; |
| 425 |
} |
| 426 |
else |
| 427 |
{ |
| 428 |
fpm = int(fpm/100 - 0.5) * 100; |
| 429 |
} |
| 430 |
#print(fpm); |
| 431 |
|
| 432 |
settingTargetPressureRate.setDoubleValue(-fpm / 58000); |
| 433 |
|
| 434 |
if (altButtonTimerRunning == 0) |
| 435 |
{ |
| 436 |
settimer(altButtonTimer, 3.0); |
| 437 |
altButtonTimerRunning = 1; |
| 438 |
altButtonTimerIgnore = 0; |
| 439 |
annunciatorAltNumber.setBoolValue(0); |
| 440 |
} |
| 441 |
} |
| 442 |
## |
| 443 |
# Switch from ROL to HDG mode, but don't change pitch mode. |
| 444 |
## |
| 445 |
elsif (lockRollMode.getValue() == rollModes["ROL"]) |
| 446 |
{ |
| 447 |
lockAprHold.setBoolValue(0); |
| 448 |
lockRevHold.setBoolValue(0); |
| 449 |
lockGsHold.setBoolValue(0); |
| 450 |
lockHdgHold.setBoolValue(1); |
| 451 |
lockNavHold.setBoolValue(0); |
| 452 |
lockRollAxis.setBoolValue(1); |
| 453 |
lockRollMode.setIntValue(rollModes["HDG"]); |
| 454 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 455 |
|
| 456 |
annunciatorApr.setBoolValue(0); |
| 457 |
annunciatorGs.setBoolValue(0); |
| 458 |
annunciatorHdg.getNode("state").setBoolValue(1); |
| 459 |
annunciatorNav.setBoolValue(0); |
| 460 |
annunciatorRol.setBoolValue(0); |
| 461 |
annunciatorRev.setBoolValue(0); |
| 462 |
annunciatorNavArm.setBoolValue(0); |
| 463 |
annunciatorAprArm.setBoolValue(0); |
| 464 |
annunciatorRevArm.setBoolValue(0); |
| 465 |
|
| 466 |
settingTargetInterceptAngle.setDoubleValue(0.0); |
| 467 |
} |
| 468 |
## |
| 469 |
# Switch to HDG mode, but don't change pitch mode. |
| 470 |
## |
| 471 |
elsif ( (lockRollMode.getValue() == rollModes["NAV"] or |
| 472 |
lockRollArm.getValue() == rollArmModes["NAV"] or |
| 473 |
lockRollMode.getValue() == rollModes["REV"] or |
| 474 |
lockRollArm.getValue() == rollArmModes["REV"]) and |
| 475 |
!hdgFlasher.count) |
| 476 |
{ |
| 477 |
lockAprHold.setBoolValue(0); |
| 478 |
lockRevHold.setBoolValue(0); |
| 479 |
lockGsHold.setBoolValue(0); |
| 480 |
lockHdgHold.setBoolValue(1); |
| 481 |
lockNavHold.setBoolValue(0); |
| 482 |
lockRollAxis.setBoolValue(1); |
| 483 |
lockRollMode.setIntValue(rollModes["HDG"]); |
| 484 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 485 |
|
| 486 |
annunciatorApr.setBoolValue(0); |
| 487 |
annunciatorGs.setBoolValue(0); |
| 488 |
annunciatorHdg.getNode("state").setBoolValue(1); |
| 489 |
annunciatorNav.setBoolValue(0); |
| 490 |
annunciatorRol.setBoolValue(0); |
| 491 |
annunciatorRev.setBoolValue(0); |
| 492 |
annunciatorNavArm.setBoolValue(0); |
| 493 |
annunciatorAprArm.setBoolValue(0); |
| 494 |
annunciatorRevArm.setBoolValue(0); |
| 495 |
|
| 496 |
settingTargetInterceptAngle.setDoubleValue(0.0); |
| 497 |
} |
| 498 |
## |
| 499 |
# If we already are in HDG mode switch to ROL mode. Again don't touch pitch |
| 500 |
# mode. |
| 501 |
## |
| 502 |
elsif (lockRollMode.getValue() == rollModes["HDG"]) |
| 503 |
{ |
| 504 |
lockAprHold.setBoolValue(0); |
| 505 |
lockGsHold.setBoolValue(0); |
| 506 |
lockHdgHold.setBoolValue(0); |
| 507 |
lockRevHold.setBoolValue(0); |
| 508 |
lockNavHold.setBoolValue(0); |
| 509 |
lockRollAxis.setBoolValue(1); |
| 510 |
lockRollMode.setIntValue(rollModes["ROL"]); |
| 511 |
|
| 512 |
annunciatorApr.setBoolValue(0); |
| 513 |
annunciatorGs.setBoolValue(0); |
| 514 |
annunciatorHdg.getNode("state").setBoolValue(0); |
| 515 |
annunciatorNav.setBoolValue(0); |
| 516 |
annunciatorRol.setBoolValue(1); |
| 517 |
|
| 518 |
settingTargetTurnRate.setDoubleValue(0.0); |
| 519 |
} |
| 520 |
## |
| 521 |
# If we are in APR mode we also have to change pitch mode. |
| 522 |
# TODO: Should we switch to VS or ALT mode? (currently VS) |
| 523 |
## |
| 524 |
elsif ( (lockRollMode.getValue() == rollModes["APR"] or |
| 525 |
lockRollArm.getValue() == rollArmModes["APR"] or |
| 526 |
lockPitchMode.getValue() == pitchModes["GS"] or |
| 527 |
lockPitchArm.getValue() == pitchArmModes["GS"]) and |
| 528 |
!hdgFlasher.count) |
| 529 |
{ |
| 530 |
lockAltHold.setBoolValue(0); |
| 531 |
lockAprHold.setBoolValue(0); |
| 532 |
lockGsHold.setBoolValue(0); |
| 533 |
lockHdgHold.setBoolValue(1); |
| 534 |
lockNavHold.setBoolValue(0); |
| 535 |
lockRollAxis.setBoolValue(1); |
| 536 |
lockRollMode.setIntValue(rollModes["HDG"]); |
| 537 |
lockPitchAxis.setBoolValue(1); |
| 538 |
lockPitchMode.setIntValue(pitchModes["VS"]); |
| 539 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 540 |
lockPitchArm.setIntValue(pitchArmModes["OFF"]); |
| 541 |
|
| 542 |
annunciatorAlt.setBoolValue(0); |
| 543 |
annunciatorAltArm.setBoolValue(0); |
| 544 |
annunciatorHdg.getNode("state").setBoolValue(1); |
| 545 |
annunciatorRol.setBoolValue(0); |
| 546 |
annunciatorNav.setBoolValue(0); |
| 547 |
annunciatorApr.setBoolValue(0); |
| 548 |
annunciatorAprArm.setBoolValue(0); |
| 549 |
annunciatorGs.setBoolValue(0); |
| 550 |
annunciatorGsArm.setBoolValue(0); |
| 551 |
annunciatorVs.setBoolValue(1); |
| 552 |
annunciatorVsNumber.setBoolValue(1); |
| 553 |
|
| 554 |
settingTargetInterceptAngle.setDoubleValue(0.0); |
| 555 |
|
| 556 |
var pressureRate = getprop(internal, "pressure-rate"); |
| 557 |
#print(pressureRate); |
| 558 |
var fpm = -pressureRate * 58000; |
| 559 |
#print(fpm); |
| 560 |
if (fpm > 0.0) |
| 561 |
{ |
| 562 |
fpm = int(fpm/100 + 0.5) * 100; |
| 563 |
} |
| 564 |
else |
| 565 |
{ |
| 566 |
fpm = int(fpm/100 - 0.5) * 100; |
| 567 |
} |
| 568 |
#print(fpm); |
| 569 |
|
| 570 |
settingTargetPressureRate.setDoubleValue(-fpm / 58000); |
| 571 |
|
| 572 |
if (altButtonTimerRunning == 0) |
| 573 |
{ |
| 574 |
settimer(altButtonTimer, 3.0); |
| 575 |
altButtonTimerRunning = 1; |
| 576 |
altButtonTimerIgnore = 0; |
| 577 |
annunciatorAltNumber.setBoolValue(0); |
| 578 |
} |
| 579 |
} |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
var navButton = func { |
| 584 |
##print("navButton"); |
| 585 |
# Disable button if too little power |
| 586 |
if (getprop(power) < minVoltageLimit) { return; } |
| 587 |
|
| 588 |
if (lockPitchArm.getValue() == pitchArmModes["GS"]) { |
| 589 |
lockPitchArm.setIntValue(pitchArmModes["OFF"]); |
| 590 |
} |
| 591 |
|
| 592 |
## |
| 593 |
# If we are in HDG (or radial) mode we switch to the 45 degree angle intercept NAV mode |
| 594 |
## |
| 595 |
if (lockRollMode.getValue() == rollModes["HDG"] |
| 596 |
or lockRollMode.getValue() == rollModes["APR"] |
| 597 |
or lockRollMode.getValue() == rollModes["REV"]) |
| 598 |
{ |
| 599 |
hdgFlasher.blink(8, 1).switch(0).switch(1); |
| 600 |
|
| 601 |
lockAprHold.setBoolValue(0); |
| 602 |
lockGsHold.setBoolValue(0); |
| 603 |
lockRevHold.setBoolValue(0); |
| 604 |
lockHdgHold.setBoolValue(1); |
| 605 |
lockNavHold.setBoolValue(0); |
| 606 |
lockRollAxis.setBoolValue(1); |
| 607 |
lockRollArm.setIntValue(rollArmModes["NAV"]); |
| 608 |
lockRollMode.setIntValue(rollModes["NAV"]); |
| 609 |
|
| 610 |
annunciatorNavArm.setBoolValue(1); |
| 611 |
annunciatorAprArm.setBoolValue(0); |
| 612 |
annunciatorRevArm.setBoolValue(0); |
| 613 |
annunciatorGsArm.setBoolValue(0); |
| 614 |
annunciatorNav.setBoolValue(0); |
| 615 |
annunciatorRol.setBoolValue(0); |
| 616 |
annunciatorRev.setBoolValue(0); |
| 617 |
annunciatorApr.setBoolValue(0); |
| 618 |
annunciatorGs.setBoolValue(0); |
| 619 |
|
| 620 |
navArmFromHdg(); |
| 621 |
} |
| 622 |
## |
| 623 |
# If we are in ROL mode we switch to the all angle intercept NAV mode. |
| 624 |
## |
| 625 |
elsif (lockRollMode.getValue() == rollModes["ROL"]) |
| 626 |
{ |
| 627 |
hdgFlasher.blink(8).switch(0).switch(1); |
| 628 |
|
| 629 |
lockAprHold.setBoolValue(0); |
| 630 |
lockGsHold.setBoolValue(0); |
| 631 |
lockRevHold.setBoolValue(0); |
| 632 |
lockHdgHold.setBoolValue(0); |
| 633 |
lockNavHold.setBoolValue(0); |
| 634 |
lockRollAxis.setBoolValue(1); |
| 635 |
lockRollArm.setIntValue(rollArmModes["NAV"]); |
| 636 |
lockRollMode.setIntValue(rollModes["NAV"]); |
| 637 |
|
| 638 |
annunciatorNavArm.setBoolValue(1); |
| 639 |
annunciatorAprArm.setBoolValue(0); |
| 640 |
annunciatorRevArm.setBoolValue(0); |
| 641 |
annunciatorGsArm.setBoolValue(0); |
| 642 |
annunciatorNav.setBoolValue(0); |
| 643 |
annunciatorRol.setBoolValue(0); |
| 644 |
annunciatorRev.setBoolValue(0); |
| 645 |
annunciatorApr.setBoolValue(0); |
| 646 |
annunciatorGs.setBoolValue(0); |
| 647 |
|
| 648 |
navArmFromRol(); |
| 649 |
} |
| 650 |
## |
| 651 |
# TODO: |
| 652 |
# NAV mode can only be armed if we are in HDG or ROL mode. |
| 653 |
# Can anyone verify that this is correct? |
| 654 |
## |
| 655 |
} |
| 656 |
|
| 657 |
var navArmFromHdg = func |
| 658 |
{ |
| 659 |
## |
| 660 |
# Abort the NAV-ARM mode if something has changed the arm mode to something |
| 661 |
# else than NAV-ARM. |
| 662 |
## |
| 663 |
if (lockRollArm.getValue() != rollArmModes["NAV"]) |
| 664 |
{ |
| 665 |
annunciatorNavArm.setBoolValue(0); |
| 666 |
return; |
| 667 |
} |
| 668 |
|
| 669 |
#annunciatorNavArm.setBoolValue(1); |
| 670 |
## |
| 671 |
# Wait for the HDG annunciator flashing to finish. |
| 672 |
## |
| 673 |
if (hdgFlasher.count) |
| 674 |
{ |
| 675 |
#print("flashing..."); |
| 676 |
settimer(navArmFromHdg, 2.5); |
| 677 |
return; |
| 678 |
} |
| 679 |
## |
| 680 |
# Activate the nav-hold controller and check the needle deviation. |
| 681 |
## |
| 682 |
lockNavHold.setBoolValue(1); |
| 683 |
deviation = getprop(headingNeedleDeflection); |
| 684 |
var deviationValid = getprop(navHeadingValid); |
| 685 |
## |
| 686 |
# If the deflection is more than 3 degrees wait 5 seconds and check again. |
| 687 |
## |
| 688 |
if (!deviationValid or abs(deviation) > 3.0) |
| 689 |
{ |
| 690 |
#print("deviation"); |
| 691 |
settimer(navArmFromHdg, 5); |
| 692 |
return; |
| 693 |
} |
| 694 |
## |
| 695 |
# If the deviation is less than 3 degrees turn of the NAV-ARM annunciator |
| 696 |
# and show the NAV annunciator. End of NAV-ARM sequence. |
| 697 |
## |
| 698 |
elsif (abs(deviation) < 3.1) |
| 699 |
{ |
| 700 |
#print("capture"); |
| 701 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 702 |
annunciatorNavArm.setBoolValue(0); |
| 703 |
annunciatorHdg.getNode("state").setBoolValue(0); |
| 704 |
annunciatorNav.setBoolValue(1); |
| 705 |
} |
| 706 |
} |
| 707 |
|
| 708 |
var navArmFromRol = func |
| 709 |
{ |
| 710 |
## |
| 711 |
# Abort the NAV-ARM mode if something has changed the arm mode to something |
| 712 |
# else than NAV-ARM. |
| 713 |
## |
| 714 |
if (lockRollArm.getValue() != rollArmModes["NAV"]) |
| 715 |
{ |
| 716 |
annunciatorNavArm.setBoolValue(0); |
| 717 |
return; |
| 718 |
} |
| 719 |
## |
| 720 |
# Wait for the HDG annunciator flashing to finish. |
| 721 |
## |
| 722 |
#annunciatorNavArm.setBoolValue(1); |
| 723 |
if (hdgFlasher.count) |
| 724 |
{ |
| 725 |
#print("flashing..."); |
| 726 |
annunciatorRol.setBoolValue(0); |
| 727 |
settimer(navArmFromRol, 2.5); |
| 728 |
return; |
| 729 |
} |
| 730 |
## |
| 731 |
# Turn the ROL annunciator back on and activate the ROL mode. |
| 732 |
## |
| 733 |
annunciatorRol.setBoolValue(1); |
| 734 |
lockRollAxis.setBoolValue(1); |
| 735 |
settingTargetTurnRate.setDoubleValue(0.0); |
| 736 |
var deviation = getprop(headingNeedleDeflection); |
| 737 |
var deviationValid = getprop(navHeadingValid); |
| 738 |
## |
| 739 |
# If the deflection is more than 3 degrees wait 5 seconds and check again. |
| 740 |
## |
| 741 |
if (!deviationValid or abs(deviation) > 3.0) |
| 742 |
{ |
| 743 |
#print("deviation"); |
| 744 |
settimer(navArmFromRol, 5); |
| 745 |
return; |
| 746 |
} |
| 747 |
## |
| 748 |
# If the deviation is less than 3 degrees turn of the NAV-ARM annunciator |
| 749 |
# and show the NAV annunciator. End of NAV-ARM sequence. |
| 750 |
## |
| 751 |
elsif (abs(deviation) < 3.1) |
| 752 |
{ |
| 753 |
#print("capture"); |
| 754 |
annunciatorRol.setBoolValue(0); |
| 755 |
annunciatorNavArm.setBoolValue(0); |
| 756 |
annunciatorNav.setBoolValue(1); |
| 757 |
|
| 758 |
lockAprHold.setBoolValue(0); |
| 759 |
lockGsHold.setBoolValue(0); |
| 760 |
lockRevHold.setBoolValue(0); |
| 761 |
lockHdgHold.setBoolValue(1); |
| 762 |
lockNavHold.setBoolValue(1); |
| 763 |
lockRollAxis.setBoolValue(1); |
| 764 |
lockRollMode.setIntValue(rollModes["NAV"]); |
| 765 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 766 |
} |
| 767 |
} |
| 768 |
|
| 769 |
var aprButton = func { |
| 770 |
##print("aprButton"); |
| 771 |
# Disable button if too little power |
| 772 |
if (getprop(power) < minVoltageLimit) { return; } |
| 773 |
|
| 774 |
if (lockPitchArm.getValue() == pitchArmModes["GS"]) { |
| 775 |
lockPitchArm.setIntValue(pitchArmModes["OFF"]); |
| 776 |
} |
| 777 |
|
| 778 |
## |
| 779 |
# If we are in HDG (or radial) mode we switch to the 45 degree intercept angle APR mode |
| 780 |
## |
| 781 |
if (lockRollMode.getValue() == rollModes["HDG"] |
| 782 |
or lockRollMode.getValue() == rollModes["NAV"] |
| 783 |
or lockRollMode.getValue() == rollModes["REV"]) |
| 784 |
{ |
| 785 |
hdgFlasher.blink(8, 1).switch(0).switch(1); |
| 786 |
|
| 787 |
lockAprHold.setBoolValue(1); |
| 788 |
lockGsHold.setBoolValue(0); |
| 789 |
lockRevHold.setBoolValue(0); |
| 790 |
lockHdgHold.setBoolValue(1); |
| 791 |
lockNavHold.setBoolValue(0); |
| 792 |
lockRollAxis.setBoolValue(1); |
| 793 |
lockRollArm.setIntValue(rollArmModes["APR"]); |
| 794 |
lockRollMode.setIntValue(rollModes["APR"]); |
| 795 |
|
| 796 |
annunciatorNavArm.setBoolValue(0); |
| 797 |
annunciatorAprArm.setBoolValue(1); |
| 798 |
annunciatorRevArm.setBoolValue(0); |
| 799 |
annunciatorGsArm.setBoolValue(0); |
| 800 |
annunciatorNav.setBoolValue(0); |
| 801 |
annunciatorRol.setBoolValue(0); |
| 802 |
annunciatorRev.setBoolValue(0); |
| 803 |
annunciatorApr.setBoolValue(0); |
| 804 |
annunciatorGs.setBoolValue(0); |
| 805 |
|
| 806 |
aprArmFromHdg(); |
| 807 |
} |
| 808 |
elsif (lockRollMode.getValue() == rollModes["ROL"]) |
| 809 |
{ |
| 810 |
hdgFlasher.blink(8).switch(0).switch(1); |
| 811 |
|
| 812 |
lockAprHold.setBoolValue(0); |
| 813 |
lockGsHold.setBoolValue(0); |
| 814 |
lockRevHold.setBoolValue(0); |
| 815 |
lockHdgHold.setBoolValue(0); |
| 816 |
lockNavHold.setBoolValue(0); |
| 817 |
lockRollAxis.setBoolValue(1); |
| 818 |
lockRollArm.setIntValue(rollArmModes["APR"]); |
| 819 |
lockRollMode.setIntValue(rollModes["APR"]); |
| 820 |
|
| 821 |
annunciatorNavArm.setBoolValue(0); |
| 822 |
annunciatorAprArm.setBoolValue(1); |
| 823 |
annunciatorRevArm.setBoolValue(0); |
| 824 |
annunciatorGsArm.setBoolValue(0); |
| 825 |
annunciatorNav.setBoolValue(0); |
| 826 |
annunciatorRol.setBoolValue(0); |
| 827 |
annunciatorRev.setBoolValue(0); |
| 828 |
annunciatorApr.setBoolValue(0); |
| 829 |
annunciatorGs.setBoolValue(0); |
| 830 |
|
| 831 |
aprArmFromRol(); |
| 832 |
} |
| 833 |
} |
| 834 |
|
| 835 |
var aprArmFromHdg = func |
| 836 |
{ |
| 837 |
## |
| 838 |
# Abort the APR-ARM mode if something has changed the arm mode to something |
| 839 |
# else than APR-ARM. |
| 840 |
## |
| 841 |
if (lockRollArm.getValue() != rollArmModes["APR"]) |
| 842 |
{ |
| 843 |
annunciatorAprArm.setBoolValue(0); |
| 844 |
return; |
| 845 |
} |
| 846 |
|
| 847 |
#annunciatorAprArm.setBoolValue(1); |
| 848 |
## |
| 849 |
# Wait for the HDG annunciator flashing to finish. |
| 850 |
## |
| 851 |
if (hdgFlasher.count) |
| 852 |
{ |
| 853 |
#print("flashing..."); |
| 854 |
settimer(aprArmFromHdg, 2.5); |
| 855 |
return; |
| 856 |
} |
| 857 |
## |
| 858 |
# Activate the apr-hold controller and check the needle deviation. |
| 859 |
## |
| 860 |
lockAprHold.setBoolValue(1); |
| 861 |
var deviation = getprop(headingNeedleDeflection); |
| 862 |
var deviationValid = getprop(navHeadingValid); |
| 863 |
## |
| 864 |
# If the deflection is more than 3 degrees wait 5 seconds and check again. |
| 865 |
## |
| 866 |
if (!deviationValid or abs(deviation) > 3.0) |
| 867 |
{ |
| 868 |
#print("deviation"); |
| 869 |
settimer(aprArmFromHdg, 5); |
| 870 |
return; |
| 871 |
} |
| 872 |
## |
| 873 |
# If the deviation is less than 3 degrees turn of the APR-ARM annunciator |
| 874 |
# and show the APR annunciator. End of APR-ARM sequence. Start the GS-ARM |
| 875 |
# sequence. |
| 876 |
## |
| 877 |
elsif (abs(deviation) < 3.1) |
| 878 |
{ |
| 879 |
#print("capture"); |
| 880 |
annunciatorAprArm.setBoolValue(0); |
| 881 |
annunciatorHdg.getNode("state").setBoolValue(0); |
| 882 |
annunciatorApr.setBoolValue(1); |
| 883 |
lockPitchArm.setIntValue(pitchArmModes["GS"]); |
| 884 |
|
| 885 |
gsArm(); |
| 886 |
} |
| 887 |
} |
| 888 |
|
| 889 |
var aprArmFromRol = func |
| 890 |
{ |
| 891 |
## |
| 892 |
# Abort the APR-ARM mode if something has changed the roll mode to something |
| 893 |
# else than APR-ARM. |
| 894 |
## |
| 895 |
if (lockRollArm.getValue() != rollArmModes["APR"]) |
| 896 |
{ |
| 897 |
annunciatorAprArm.setBoolValue(0); |
| 898 |
return; |
| 899 |
} |
| 900 |
|
| 901 |
#annunciatorAprArm.setBoolValue(1); |
| 902 |
## |
| 903 |
# Wait for the HDG annunciator flashing to finish. |
| 904 |
## |
| 905 |
if (hdgFlasher.count) |
| 906 |
{ |
| 907 |
#print("flashing..."); |
| 908 |
annunciatorRol.setBoolValue(0); |
| 909 |
settimer(aprArmFromRol, 2.5); |
| 910 |
return; |
| 911 |
} |
| 912 |
## |
| 913 |
# Turn the ROL annunciator back on and activate the ROL mode. |
| 914 |
## |
| 915 |
annunciatorRol.setBoolValue(1); |
| 916 |
lockRollAxis.setBoolValue(1); |
| 917 |
settingTargetTurnRate.setDoubleValue(0.0); |
| 918 |
var deviation = getprop(headingNeedleDeflection); |
| 919 |
var deviationValid = getprop(navHeadingValid); |
| 920 |
## |
| 921 |
# If the deflection is more than 3 degrees wait 5 seconds and check again. |
| 922 |
## |
| 923 |
if (!deviationValid or abs(deviation) > 3.0) |
| 924 |
{ |
| 925 |
#print("deviation"); |
| 926 |
settimer(aprArmFromRol, 5); |
| 927 |
return; |
| 928 |
} |
| 929 |
## |
| 930 |
# If the deviation is less than 3 degrees turn of the APR-ARM annunciator |
| 931 |
# and show the APR annunciator. End of APR-ARM sequence. Start the GS-ARM |
| 932 |
# sequence. |
| 933 |
## |
| 934 |
elsif (abs(deviation) < 3.1) |
| 935 |
{ |
| 936 |
#print("capture"); |
| 937 |
annunciatorRol.setBoolValue(0); |
| 938 |
annunciatorAprArm.setBoolValue(0); |
| 939 |
annunciatorApr.setBoolValue(1); |
| 940 |
|
| 941 |
lockAprHold.setBoolValue(1); |
| 942 |
lockGsHold.setBoolValue(0); |
| 943 |
lockRevHold.setBoolValue(0); |
| 944 |
lockHdgHold.setBoolValue(1); |
| 945 |
lockNavHold.setBoolValue(0); |
| 946 |
lockRollAxis.setBoolValue(1); |
| 947 |
lockRollMode.setIntValue(rollModes["APR"]); |
| 948 |
lockPitchArm.setIntValue(pitchArmModes["GS"]); |
| 949 |
|
| 950 |
gsArm(); |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
|
| 955 |
var gsArm = func { |
| 956 |
## |
| 957 |
# Abort the GS-ARM mode if something has changed the arm mode to something |
| 958 |
# else than GS-ARM. |
| 959 |
## |
| 960 |
if (lockPitchArm.getValue() != pitchArmModes["GS"]) |
| 961 |
{ |
| 962 |
annunciatorGsArm.setBoolValue(0); |
| 963 |
return; |
| 964 |
} |
| 965 |
|
| 966 |
annunciatorGsArm.setBoolValue(1); |
| 967 |
|
| 968 |
var deviation = getprop(gsNeedleDeflection); |
| 969 |
var deviationValid = getprop(navGSValid); |
| 970 |
## |
| 971 |
# If the deflection is more than 50% (manual says '2 to 3 dots') |
| 972 |
## |
| 973 |
if (!deviationValid or abs(deviation) > 0.5) |
| 974 |
{ |
| 975 |
#print("deviation"); |
| 976 |
settimer(gsArm, 5); |
| 977 |
return; |
| 978 |
} |
| 979 |
## |
| 980 |
# If the deviation is less than 50% turn off the GS-ARM annunciator |
| 981 |
# and show the GS annunciator. Activate the GS pitch mode. |
| 982 |
## |
| 983 |
else |
| 984 |
{ |
| 985 |
#print("capture"); |
| 986 |
annunciatorAlt.setBoolValue(0); |
| 987 |
annunciatorVs.setBoolValue(0); |
| 988 |
annunciatorVsNumber.setBoolValue(0); |
| 989 |
annunciatorGsArm.setBoolValue(0); |
| 990 |
annunciatorGs.setBoolValue(1); |
| 991 |
|
| 992 |
lockAltHold.setBoolValue(0); |
| 993 |
lockGsHold.setBoolValue(1); |
| 994 |
lockPitchMode.setIntValue(pitchModes["GS"]); |
| 995 |
lockPitchArm.setIntValue(pitchArmModes["OFF"]); |
| 996 |
} |
| 997 |
|
| 998 |
} |
| 999 |
|
| 1000 |
|
| 1001 |
var revButton = func { |
| 1002 |
##print("revButton"); |
| 1003 |
# Disable button if too little power |
| 1004 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1005 |
|
| 1006 |
if (lockPitchArm.getValue() == pitchArmModes["GS"]) { |
| 1007 |
lockPitchArm.setIntValue(pitchArmModes["OFF"]); |
| 1008 |
} |
| 1009 |
|
| 1010 |
## |
| 1011 |
# If we are in HDG (or radial) mode we switch to the 45 degree intercept angle REV mode |
| 1012 |
## |
| 1013 |
if (lockRollMode.getValue() == rollModes["HDG"] |
| 1014 |
or lockRollMode.getValue() == rollModes["NAV"] |
| 1015 |
or lockRollMode.getValue() == rollModes["APR"]) |
| 1016 |
{ |
| 1017 |
hdgFlasher.blink(8, 1).switch(0).switch(1); |
| 1018 |
|
| 1019 |
lockAprHold.setBoolValue(0); |
| 1020 |
lockGsHold.setBoolValue(0); |
| 1021 |
lockRevHold.setBoolValue(0); |
| 1022 |
lockHdgHold.setBoolValue(1); |
| 1023 |
lockNavHold.setBoolValue(0); |
| 1024 |
lockRollAxis.setBoolValue(1); |
| 1025 |
lockRollArm.setIntValue(rollArmModes["REV"]); |
| 1026 |
|
| 1027 |
annunciatorNavArm.setBoolValue(0); |
| 1028 |
annunciatorAprArm.setBoolValue(0); |
| 1029 |
annunciatorRevArm.setBoolValue(1); |
| 1030 |
annunciatorGsArm.setBoolValue(0); |
| 1031 |
annunciatorNav.setBoolValue(0); |
| 1032 |
annunciatorRol.setBoolValue(0); |
| 1033 |
annunciatorRev.setBoolValue(0); |
| 1034 |
annunciatorApr.setBoolValue(0); |
| 1035 |
annunciatorGs.setBoolValue(0); |
| 1036 |
|
| 1037 |
revArmFromHdg(); |
| 1038 |
} |
| 1039 |
elsif (lockRollMode.getValue() == rollModes["ROL"]) |
| 1040 |
{ |
| 1041 |
hdgFlasher.blink(8).switch(0).switch(1); |
| 1042 |
|
| 1043 |
lockAprHold.setBoolValue(0); |
| 1044 |
lockGsHold.setBoolValue(0); |
| 1045 |
lockRevHold.setBoolValue(0); |
| 1046 |
lockHdgHold.setBoolValue(0); |
| 1047 |
lockNavHold.setBoolValue(0); |
| 1048 |
lockRollAxis.setBoolValue(1); |
| 1049 |
lockRollArm.setIntValue(rollArmModes["REV"]); |
| 1050 |
|
| 1051 |
annunciatorNavArm.setBoolValue(0); |
| 1052 |
annunciatorAprArm.setBoolValue(0); |
| 1053 |
annunciatorRevArm.setBoolValue(1); |
| 1054 |
annunciatorGsArm.setBoolValue(0); |
| 1055 |
annunciatorNav.setBoolValue(0); |
| 1056 |
annunciatorRol.setBoolValue(0); |
| 1057 |
annunciatorRev.setBoolValue(0); |
| 1058 |
annunciatorApr.setBoolValue(0); |
| 1059 |
annunciatorGs.setBoolValue(0); |
| 1060 |
|
| 1061 |
revArmFromRol(); |
| 1062 |
} |
| 1063 |
} |
| 1064 |
|
| 1065 |
|
| 1066 |
var revArmFromHdg = func |
| 1067 |
{ |
| 1068 |
## |
| 1069 |
# Abort the REV-ARM mode if something has changed the arm mode to something |
| 1070 |
# else than REV-ARM. |
| 1071 |
## |
| 1072 |
if (lockRollArm.getValue() != rollArmModes["REV"]) |
| 1073 |
{ |
| 1074 |
annunciatorRevArm.setBoolValue(0); |
| 1075 |
return; |
| 1076 |
} |
| 1077 |
|
| 1078 |
#annunciatorRevArm.setBoolValue(1); |
| 1079 |
## |
| 1080 |
# Wait for the HDG annunciator flashing to finish. |
| 1081 |
## |
| 1082 |
if (hdgFlasher.count) |
| 1083 |
{ |
| 1084 |
#print("flashing..."); |
| 1085 |
settimer(revArmFromHdg, 2.5); |
| 1086 |
return; |
| 1087 |
} |
| 1088 |
## |
| 1089 |
# Activate the rev-hold controller and check the needle deviation. |
| 1090 |
## |
| 1091 |
lockRevHold.setBoolValue(1); |
| 1092 |
var deviation = getprop(headingNeedleDeflection); |
| 1093 |
var deviationValid = getprop(navHeadingValid); |
| 1094 |
## |
| 1095 |
# If the deflection is more than 3 degrees wait 5 seconds and check again. |
| 1096 |
## |
| 1097 |
if (!deviationValid or abs(deviation) > 3.0) |
| 1098 |
{ |
| 1099 |
#print("deviation"); |
| 1100 |
settimer(revArmFromHdg, 5); |
| 1101 |
return; |
| 1102 |
} |
| 1103 |
## |
| 1104 |
# If the deviation is less than 3 degrees turn of the REV-ARM annunciator |
| 1105 |
# and show the REV annunciator. End of REV-ARM sequence. |
| 1106 |
## |
| 1107 |
elsif (abs(deviation) < 3.1) |
| 1108 |
{ |
| 1109 |
#print("capture"); |
| 1110 |
annunciatorRevArm.setBoolValue(0); |
| 1111 |
annunciatorHdg.getNode("state").setBoolValue(0); |
| 1112 |
annunciatorRev.setBoolValue(1); |
| 1113 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 1114 |
annunciatorRol.setBoolValue(0); |
| 1115 |
annunciatorRevArm.setBoolValue(0); |
| 1116 |
annunciatorRev.setBoolValue(1); |
| 1117 |
|
| 1118 |
lockAprHold.setBoolValue(0); |
| 1119 |
lockGsHold.setBoolValue(0); |
| 1120 |
lockRevHold.setBoolValue(1); |
| 1121 |
lockHdgHold.setBoolValue(1); |
| 1122 |
lockNavHold.setBoolValue(0); |
| 1123 |
lockRollAxis.setBoolValue(1); |
| 1124 |
lockRollMode.setIntValue(rollModes["REV"]); |
| 1125 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 1126 |
} |
| 1127 |
} |
| 1128 |
|
| 1129 |
|
| 1130 |
var revArmFromRol = func |
| 1131 |
{ |
| 1132 |
## |
| 1133 |
# Abort the REV-ARM mode if something has changed the arm mode to something |
| 1134 |
# else than REV-ARM. |
| 1135 |
## |
| 1136 |
if (lockRollArm.getValue() != rollArmModes["REV"]) |
| 1137 |
{ |
| 1138 |
annunciatorRevArm.setBoolValue(0); |
| 1139 |
return; |
| 1140 |
} |
| 1141 |
|
| 1142 |
#annunciatorRevArm.setBoolValue(1); |
| 1143 |
## |
| 1144 |
# Wait for the HDG annunciator flashing to finish. |
| 1145 |
## |
| 1146 |
if (hdgFlasher.count) |
| 1147 |
{ |
| 1148 |
#print("flashing..."); |
| 1149 |
annunciatorRol.setBoolValue(0); |
| 1150 |
settimer(revArmFromRol, 2.5); |
| 1151 |
return; |
| 1152 |
} |
| 1153 |
## |
| 1154 |
# Turn the ROL annunciator back on and activate the ROL mode. |
| 1155 |
## |
| 1156 |
annunciatorRol.setBoolValue(1); |
| 1157 |
lockRollAxis.setBoolValue(1); |
| 1158 |
settingTargetTurnRate.setDoubleValue(0.0); |
| 1159 |
var deviation = getprop(headingNeedleDeflection); |
| 1160 |
var deviationValid = getprop(navHeadingValid); |
| 1161 |
## |
| 1162 |
# If the deflection is more than 3 degrees wait 5 seconds and check again. |
| 1163 |
## |
| 1164 |
if (!deviationValid or abs(deviation) > 3.0) |
| 1165 |
{ |
| 1166 |
#print("deviation"); |
| 1167 |
settimer(revArmFromRol, 5); |
| 1168 |
return; |
| 1169 |
} |
| 1170 |
## |
| 1171 |
# If the deviation is less than 3 degrees turn of the REV-ARM annunciator |
| 1172 |
# and show the REV annunciator. End of REV-ARM sequence. |
| 1173 |
## |
| 1174 |
elsif (abs(deviation) < 3.1) |
| 1175 |
{ |
| 1176 |
#print("capture"); |
| 1177 |
annunciatorRol.setBoolValue(0); |
| 1178 |
annunciatorRevArm.setBoolValue(0); |
| 1179 |
annunciatorRev.setBoolValue(1); |
| 1180 |
|
| 1181 |
lockAprHold.setBoolValue(0); |
| 1182 |
lockGsHold.setBoolValue(0); |
| 1183 |
lockRevHold.setBoolValue(1); |
| 1184 |
lockHdgHold.setBoolValue(1); |
| 1185 |
lockNavHold.setBoolValue(0); |
| 1186 |
lockRollAxis.setBoolValue(1); |
| 1187 |
lockRollMode.setIntValue(rollModes["REV"]); |
| 1188 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 1189 |
} |
| 1190 |
} |
| 1191 |
|
| 1192 |
|
| 1193 |
var altButtonTimer = func { |
| 1194 |
#print("alt button timer"); |
| 1195 |
#print(altButtonTimerIgnore); |
| 1196 |
|
| 1197 |
if (altButtonTimerIgnore == 0) |
| 1198 |
{ |
| 1199 |
annunciatorVsNumber.setBoolValue(0); |
| 1200 |
annunciatorAltNumber.setBoolValue(1); |
| 1201 |
|
| 1202 |
altButtonTimerRunning = 0; |
| 1203 |
} |
| 1204 |
elsif (altButtonTimerIgnore > 0) |
| 1205 |
{ |
| 1206 |
altButtonTimerIgnore = altButtonTimerIgnore - 1; |
| 1207 |
} |
| 1208 |
} |
| 1209 |
|
| 1210 |
|
| 1211 |
var altButton = func { |
| 1212 |
##print("altButton"); |
| 1213 |
# Disable button if too little power |
| 1214 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1215 |
|
| 1216 |
|
| 1217 |
if (lockPitchMode.getValue() == pitchModes["ALT"]) |
| 1218 |
{ |
| 1219 |
if (altButtonTimerRunning == 0) |
| 1220 |
{ |
| 1221 |
settimer(altButtonTimer, 3.0); |
| 1222 |
altButtonTimerRunning = 1; |
| 1223 |
altButtonTimerIgnore = 0; |
| 1224 |
} |
| 1225 |
lockAltHold.setBoolValue(0); |
| 1226 |
|
| 1227 |
lockPitchAxis.setBoolValue(1); |
| 1228 |
lockPitchMode.setIntValue(pitchModes["VS"]); |
| 1229 |
|
| 1230 |
annunciatorAlt.setBoolValue(0); |
| 1231 |
annunciatorAltNumber.setBoolValue(0); |
| 1232 |
annunciatorVs.setBoolValue(1); |
| 1233 |
annunciatorVsNumber.setBoolValue(1); |
| 1234 |
|
| 1235 |
var pressureRate = getprop(internal, "pressure-rate"); |
| 1236 |
var fpm = -pressureRate * 58000; |
| 1237 |
#print(fpm); |
| 1238 |
if (fpm > 0.0) |
| 1239 |
{ |
| 1240 |
fpm = int(fpm/100 + 0.5) * 100; |
| 1241 |
} |
| 1242 |
else |
| 1243 |
{ |
| 1244 |
fpm = int(fpm/100 - 0.5) * 100; |
| 1245 |
} |
| 1246 |
#print(fpm); |
| 1247 |
|
| 1248 |
settingTargetPressureRate.setDoubleValue(-fpm / 58000); |
| 1249 |
|
| 1250 |
} |
| 1251 |
elsif (lockPitchMode.getValue() == pitchModes["VS"]) |
| 1252 |
{ |
| 1253 |
lockAltHold.setBoolValue(1); |
| 1254 |
lockPitchAxis.setBoolValue(1); |
| 1255 |
lockPitchMode.setIntValue(pitchModes["ALT"]); |
| 1256 |
|
| 1257 |
annunciatorAlt.setBoolValue(1); |
| 1258 |
annunciatorVs.setBoolValue(0); |
| 1259 |
annunciatorVsNumber.setBoolValue(0); |
| 1260 |
annunciatorAltNumber.setBoolValue(1); |
| 1261 |
|
| 1262 |
var altPressure = getprop(staticPressure); |
| 1263 |
settingTargetAltPressure.setDoubleValue(altPressure); |
| 1264 |
} |
| 1265 |
} |
| 1266 |
|
| 1267 |
|
| 1268 |
var downButton = func { |
| 1269 |
##print("downButton");# Disable button if too little power |
| 1270 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1271 |
|
| 1272 |
if (baroTimerRunning == 0) |
| 1273 |
{ |
| 1274 |
if (lockPitchMode.getValue() == pitchModes["VS"]) |
| 1275 |
{ |
| 1276 |
if (altButtonTimerRunning == 0) |
| 1277 |
{ |
| 1278 |
settimer(altButtonTimer, 3.0); |
| 1279 |
altButtonTimerRunning = 1; |
| 1280 |
altButtonTimerIgnore = 0; |
| 1281 |
} |
| 1282 |
elsif (altButtonTimerRunning == 1) |
| 1283 |
{ |
| 1284 |
settimer(altButtonTimer, 3.0); |
| 1285 |
altButtonTimerIgnore = altButtonTimerIgnore + 1; |
| 1286 |
} |
| 1287 |
targetVS = settingTargetPressureRate.getValue(); |
| 1288 |
settingTargetPressureRate.setDoubleValue(targetVS + |
| 1289 |
0.0017241379310345); |
| 1290 |
annunciatorAltNumber.setBoolValue(0); |
| 1291 |
annunciatorVsNumber.setBoolValue(1); |
| 1292 |
} |
| 1293 |
elsif (lockPitchMode.getValue() == pitchModes["ALT"]) |
| 1294 |
{ |
| 1295 |
var targetPressure = getprop(settings, "target-alt-pressure"); |
| 1296 |
settingTargetAltPressure.setDoubleValue(targetPressure + 0.0206); |
| 1297 |
} |
| 1298 |
} |
| 1299 |
} |
| 1300 |
|
| 1301 |
var upButton = func { |
| 1302 |
##print("upButton"); |
| 1303 |
# Disable button if too little power |
| 1304 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1305 |
|
| 1306 |
if (baroTimerRunning == 0) |
| 1307 |
{ |
| 1308 |
if (lockPitchMode.getValue() == pitchModes["VS"]) |
| 1309 |
{ |
| 1310 |
if (altButtonTimerRunning == 0) |
| 1311 |
{ |
| 1312 |
settimer(altButtonTimer, 3.0); |
| 1313 |
altButtonTimerRunning = 1; |
| 1314 |
altButtonTimerIgnore = 0; |
| 1315 |
} |
| 1316 |
elsif (altButtonTimerRunning == 1) |
| 1317 |
{ |
| 1318 |
settimer(altButtonTimer, 3.0); |
| 1319 |
altButtonTimerIgnore = altButtonTimerIgnore + 1; |
| 1320 |
} |
| 1321 |
var targetVS = settingTargetPressureRate.getValue(); |
| 1322 |
settingTargetPressureRate.setDoubleValue(targetVS - |
| 1323 |
0.0017241379310345); |
| 1324 |
annunciatorAltNumber.setBoolValue(0); |
| 1325 |
annunciatorVsNumber.setBoolValue(1); |
| 1326 |
} |
| 1327 |
elsif (lockPitchMode.getValue() == pitchModes["ALT"]) |
| 1328 |
{ |
| 1329 |
var targetPressure = getprop(settings, "target-alt-pressure"); |
| 1330 |
settingTargetAltPressure.setDoubleValue(targetPressure - 0.0206); |
| 1331 |
} |
| 1332 |
} |
| 1333 |
} |
| 1334 |
|
| 1335 |
var armButton = func { |
| 1336 |
#print("arm button"); |
| 1337 |
# Disable button if too little power |
| 1338 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1339 |
|
| 1340 |
# Do nothing if the AP is not turned on |
| 1341 |
if (lockPitchMode.getValue() == pitchModes["OFF"]) { |
| 1342 |
lockPitchMode.setIntValue(pitchArmModes["OFF"]); |
| 1343 |
return; |
| 1344 |
} |
| 1345 |
|
| 1346 |
var pitchArm = lockPitchArm.getValue(); |
| 1347 |
|
| 1348 |
if (pitchArm == pitchArmModes["OFF"]) |
| 1349 |
{ |
| 1350 |
lockPitchArm.setIntValue(pitchArmModes["ALT"]); |
| 1351 |
|
| 1352 |
annunciatorAltArm.setBoolValue(1); |
| 1353 |
} |
| 1354 |
elsif (pitchArm == pitchArmModes["ALT"]) |
| 1355 |
{ |
| 1356 |
lockPitchArm.setIntValue(pitchArmModes["OFF"]); |
| 1357 |
|
| 1358 |
annunciatorAltArm.setBoolValue(0); |
| 1359 |
} |
| 1360 |
} |
| 1361 |
|
| 1362 |
|
| 1363 |
var baroButtonTimer = func { |
| 1364 |
#print("baro button timer"); |
| 1365 |
|
| 1366 |
baroTimerRunning = 0; |
| 1367 |
if (baroButtonDown == 1) |
| 1368 |
{ |
| 1369 |
baroSettingUnit = !baroSettingUnit; |
| 1370 |
baroButtonDown = 0; |
| 1371 |
baroButtonPress(); |
| 1372 |
} |
| 1373 |
elsif (baroButtonDown == 0 and |
| 1374 |
baroSettingAdjusting == 0) |
| 1375 |
{ |
| 1376 |
annunciatorBsHpaNumber.setBoolValue(0); |
| 1377 |
annunciatorBsInhgNumber.setBoolValue(0); |
| 1378 |
annunciatorAltNumber.setBoolValue(1); |
| 1379 |
} |
| 1380 |
elsif (baroSettingAdjusting == 1) |
| 1381 |
{ |
| 1382 |
baroTimerRunning = 1; |
| 1383 |
baroSettingAdjusting = 0; |
| 1384 |
settimer(baroButtonTimer, 3.0); |
| 1385 |
} |
| 1386 |
} |
| 1387 |
|
| 1388 |
var baroButtonPress = func { |
| 1389 |
#print("baro putton press"); |
| 1390 |
# Disable button if too little power |
| 1391 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1392 |
|
| 1393 |
if (baroButtonDown == 0 and |
| 1394 |
baroTimerRunning == 0 and |
| 1395 |
altButtonTimerRunning == 0) |
| 1396 |
{ |
| 1397 |
baroButtonDown = 1; |
| 1398 |
baroTimerRunning = 1; |
| 1399 |
settimer(baroButtonTimer, 3.0); |
| 1400 |
annunciatorAltNumber.setBoolValue(0); |
| 1401 |
|
| 1402 |
if (baroSettingUnit == pressureUnits["inHg"]) |
| 1403 |
{ |
| 1404 |
annunciatorBsInhgNumber.setBoolValue(1); |
| 1405 |
annunciatorBsHpaNumber.setBoolValue(0); |
| 1406 |
} |
| 1407 |
elsif (baroSettingUnit == pressureUnits["hPa"]) |
| 1408 |
{ |
| 1409 |
annunciatorBsHpaNumber.setBoolValue(1); |
| 1410 |
annunciatorBsInhgNumber.setBoolValue(0); |
| 1411 |
} |
| 1412 |
} |
| 1413 |
} |
| 1414 |
|
| 1415 |
|
| 1416 |
var baroButtonRelease = func { |
| 1417 |
#print("baro button release"); |
| 1418 |
# Disable button if too little power |
| 1419 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1420 |
|
| 1421 |
baroButtonDown = 0; |
| 1422 |
} |
| 1423 |
|
| 1424 |
|
| 1425 |
var pow = func(base, exponent) { |
| 1426 |
#print(base,exponent); |
| 1427 |
return math.exp(exponent*math.ln(base)); |
| 1428 |
} |
| 1429 |
|
| 1430 |
|
| 1431 |
var pressureToHeight = func(p, p0) { |
| 1432 |
# |
| 1433 |
# kollsman shift due to baroSettingInhg = |
| 1434 |
# baroOffset = pressureToHeight(baroSettingInhg, 29.921260) |
| 1435 |
# |
| 1436 |
#var p0 = p0; # [Pa] or (p0 and p need to have the same units) |
| 1437 |
#var p = p; # [Pa] or (p0 and p need to have the same units) |
| 1438 |
var t0 = 288.15; # [K] same as in atmosphere.?xx |
| 1439 |
var LR = -0.0065; # [K/m] same as in atmosphere.?xx |
| 1440 |
var g = -9.80665; # [m/s²] same as in atmosphere.?xx |
| 1441 |
var Rd = 287.05307; # [J/kg K] same as in atmosphere.?xx to 8 places |
| 1442 |
var ftTom = 0.3048; |
| 1443 |
var coefficient = t0/LR/ftTom; |
| 1444 |
# coefficient = -145442.156; |
| 1445 |
var exponent = Rd*LR/g; |
| 1446 |
# exponent = 0.1902632365; |
| 1447 |
|
| 1448 |
var z = -coefficient * (1.0-pow((p/p0),exponent)); |
| 1449 |
return z; |
| 1450 |
} |
| 1451 |
|
| 1452 |
|
| 1453 |
var heightToPressure = func(z, p0) { |
| 1454 |
#var p0 = p0; # [Pa] |
| 1455 |
#var z = z; # [m] |
| 1456 |
var t0 = 288.15; # [K] |
| 1457 |
var LR = -0.0065; # [K/m] |
| 1458 |
var g = -9.80665; # [m/s²] |
| 1459 |
var Rd = 287.05307; # [J/kg K] |
| 1460 |
|
| 1461 |
var p = p0 * pow(((t0+LR*z)/t0),(g/(Rd*LR))); |
| 1462 |
return p; |
| 1463 |
} |
| 1464 |
|
| 1465 |
var altAlert = func { |
| 1466 |
#print("alt alert"); |
| 1467 |
# Disable button if too little power |
| 1468 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1469 |
|
| 1470 |
var pressureAltitude = getprop(encoder, "pressure-alt-ft"); |
| 1471 |
|
| 1472 |
if (baroChange) { |
| 1473 |
baroOffset = pressureToHeight(baroSettingInhg, 29.921260); |
| 1474 |
baroChange = 0; |
| 1475 |
} |
| 1476 |
|
| 1477 |
var altFt = pressureAltitude - baroOffset; |
| 1478 |
var prevAltDifference = altDifference; |
| 1479 |
altDifference = abs(altPreselect - altFt); |
| 1480 |
|
| 1481 |
if (altDifference > 1000) |
| 1482 |
{ |
| 1483 |
annunciatorAltAlert.getNode("state").setBoolValue(0); |
| 1484 |
} |
| 1485 |
elsif (altDifference < 1000 and |
| 1486 |
altCaptured == 0) |
| 1487 |
{ |
| 1488 |
if (!altAlertFlasher.count) |
| 1489 |
{ |
| 1490 |
annunciatorAltAlert.getNode("state").setBoolValue(1); |
| 1491 |
} |
| 1492 |
if (!altAlertBeeper.count and prevAltDifference > 1000) |
| 1493 |
{ |
| 1494 |
altAlertBeeper.blink(5).switch(0).switch(1); |
| 1495 |
} |
| 1496 |
if (altDifference < 200) |
| 1497 |
{ |
| 1498 |
if (!altAlertFlasher.count) |
| 1499 |
{ |
| 1500 |
annunciatorAltAlert.getNode("state").setBoolValue(0); |
| 1501 |
} |
| 1502 |
if (altDifference < 20) |
| 1503 |
{ |
| 1504 |
#print("altCapture()"); |
| 1505 |
altCaptured = 1; |
| 1506 |
|
| 1507 |
if (lockPitchArm.getValue() == pitchArmModes["ALT"]) |
| 1508 |
{ |
| 1509 |
lockAltHold.setBoolValue(1); |
| 1510 |
lockPitchAxis.setBoolValue(1); |
| 1511 |
lockPitchMode.setIntValue(pitchModes["ALT"]); |
| 1512 |
lockPitchArm.setIntValue(pitchArmModes["OFF"]); |
| 1513 |
|
| 1514 |
annunciatorAlt.setBoolValue(1); |
| 1515 |
annunciatorAltArm.setBoolValue(0); |
| 1516 |
annunciatorVs.setBoolValue(0); |
| 1517 |
annunciatorVsNumber.setBoolValue(0); |
| 1518 |
annunciatorAltNumber.setBoolValue(1); |
| 1519 |
|
| 1520 |
var altPressure = getprop(staticPressure); |
| 1521 |
settingTargetAltPressure.setDoubleValue(altPressure); |
| 1522 |
} |
| 1523 |
|
| 1524 |
altAlertFlasher.blink(1).switch(0).switch(1); |
| 1525 |
} |
| 1526 |
} |
| 1527 |
} |
| 1528 |
elsif (altDifference < 1000 and |
| 1529 |
altCaptured == 1) |
| 1530 |
{ |
| 1531 |
if (altDifference > 200) |
| 1532 |
{ |
| 1533 |
altAlertFlasher.blink(5, 1).switch(0).switch(1); |
| 1534 |
altAlertBeeper.blink(5).switch(0).switch(1); |
| 1535 |
altCaptured = 0; |
| 1536 |
} |
| 1537 |
} |
| 1538 |
settimer(altAlert, 2.0); |
| 1539 |
} |
| 1540 |
|
| 1541 |
var adjustBaroSettingInhg = func(amount) { |
| 1542 |
# Adjust baro setting inHg by amount, |
| 1543 |
# and sync baro setting hPa. |
| 1544 |
baroSettingInhg = baroSettingInhg + amount; |
| 1545 |
baroSettingHpa = baroSettingInhg * 33.86389; |
| 1546 |
|
| 1547 |
settingBaroSettingHpa.setDoubleValue(baroSettingHpa); |
| 1548 |
settingBaroSettingInhg.setDoubleValue(baroSettingInhg); |
| 1549 |
baroChange = 1; |
| 1550 |
} |
| 1551 |
|
| 1552 |
var adjustbaroSettingHpa = func(amount) { |
| 1553 |
# Adjust baro setting hPa by amount, |
| 1554 |
# and sync baro setting inHg. |
| 1555 |
baroSettingHpa = baroSettingHpa + amount; |
| 1556 |
baroSettingInhg = baroSettingHpa / 33.86389; |
| 1557 |
|
| 1558 |
settingBaroSettingHpa.setDoubleValue(baroSettingHpa); |
| 1559 |
settingBaroSettingInhg.setDoubleValue(baroSettingInhg); |
| 1560 |
baroChange = 1; |
| 1561 |
} |
| 1562 |
|
| 1563 |
var knobSmallUp = func { |
| 1564 |
#print("knob small up"); |
| 1565 |
# Disable button if too little power |
| 1566 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1567 |
|
| 1568 |
if (baroTimerRunning == 1) |
| 1569 |
{ |
| 1570 |
baroSettingAdjusting = 1; |
| 1571 |
if (baroSettingUnit == pressureUnits["inHg"]) |
| 1572 |
{ |
| 1573 |
adjustBaroSettingInhg(0.01); |
| 1574 |
} |
| 1575 |
elsif (baroSettingUnit == pressureUnits["hPa"]) |
| 1576 |
{ |
| 1577 |
adjustbaroSettingHpa(1); |
| 1578 |
} |
| 1579 |
} |
| 1580 |
elsif (baroTimerRunning == 0 and |
| 1581 |
altButtonTimerRunning == 0) |
| 1582 |
{ |
| 1583 |
altCaptured = 0; |
| 1584 |
altPreselect = altPreselect + 20; |
| 1585 |
settingTargetAltFt.setDoubleValue(altPreselect); |
| 1586 |
|
| 1587 |
if (lockRollMode.getValue() == rollModes["OFF"] and |
| 1588 |
lockPitchMode.getValue() == pitchModes["OFF"]) |
| 1589 |
{ |
| 1590 |
annunciatorAltNumber.setBoolValue(1); |
| 1591 |
if (altAlertOn == 0) |
| 1592 |
{ |
| 1593 |
altAlertOn = 1; |
| 1594 |
} |
| 1595 |
} |
| 1596 |
elsif (lockPitchArm.getValue() == pitchArmModes["OFF"]) |
| 1597 |
{ |
| 1598 |
lockPitchArm.setIntValue(pitchArmModes["ALT"]); |
| 1599 |
annunciatorAltArm.setBoolValue(1); |
| 1600 |
} |
| 1601 |
} |
| 1602 |
} |
| 1603 |
|
| 1604 |
|
| 1605 |
var knobLargeUp = func { |
| 1606 |
#print("knob large up"); |
| 1607 |
# Disable button if too little power |
| 1608 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1609 |
|
| 1610 |
if (baroTimerRunning == 1) |
| 1611 |
{ |
| 1612 |
baroSettingAdjusting = 1; |
| 1613 |
if (baroSettingUnit == pressureUnits["inHg"]) |
| 1614 |
{ |
| 1615 |
adjustBaroSettingInhg(1.0); |
| 1616 |
} |
| 1617 |
elsif (baroSettingUnit == pressureUnits["hPa"]) |
| 1618 |
{ |
| 1619 |
adjustbaroSettingHpa(100); |
| 1620 |
} |
| 1621 |
} |
| 1622 |
elsif (baroTimerRunning == 0 and |
| 1623 |
altButtonTimerRunning == 0) |
| 1624 |
{ |
| 1625 |
altCaptured = 0; |
| 1626 |
altPreselect = altPreselect + 100; |
| 1627 |
settingTargetAltFt.setDoubleValue(altPreselect); |
| 1628 |
|
| 1629 |
if (lockRollMode.getValue() == rollModes["OFF"] and |
| 1630 |
lockPitchMode.getValue() == pitchModes["OFF"]) |
| 1631 |
{ |
| 1632 |
annunciatorAltNumber.setBoolValue(1); |
| 1633 |
if (altAlertOn == 0) |
| 1634 |
{ |
| 1635 |
altAlertOn = 1; |
| 1636 |
} |
| 1637 |
} |
| 1638 |
elsif (lockPitchArm.getValue() == pitchArmModes["OFF"]) |
| 1639 |
{ |
| 1640 |
lockPitchArm.setIntValue(pitchArmModes["ALT"]); |
| 1641 |
annunciatorAltArm.setBoolValue(1); |
| 1642 |
} |
| 1643 |
} |
| 1644 |
} |
| 1645 |
|
| 1646 |
|
| 1647 |
var knobSmallDown = func { |
| 1648 |
#print("knob small down"); |
| 1649 |
# Disable button if too little power |
| 1650 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1651 |
|
| 1652 |
if (baroTimerRunning == 1) |
| 1653 |
{ |
| 1654 |
baroSettingAdjusting = 1; |
| 1655 |
if (baroSettingUnit == pressureUnits["inHg"]) |
| 1656 |
{ |
| 1657 |
adjustBaroSettingInhg(-0.01); |
| 1658 |
} |
| 1659 |
elsif (baroSettingUnit == pressureUnits["hPa"]) |
| 1660 |
{ |
| 1661 |
adjustbaroSettingHpa(-1); |
| 1662 |
} |
| 1663 |
} |
| 1664 |
elsif (baroTimerRunning == 0 and |
| 1665 |
altButtonTimerRunning == 0) |
| 1666 |
{ |
| 1667 |
altCaptured = 0; |
| 1668 |
altPreselect = altPreselect - 20; |
| 1669 |
settingTargetAltFt.setDoubleValue(altPreselect); |
| 1670 |
|
| 1671 |
if (lockRollMode.getValue() == rollModes["OFF"] and |
| 1672 |
lockPitchMode.getValue() == pitchModes["OFF"]) |
| 1673 |
{ |
| 1674 |
annunciatorAltNumber.setBoolValue(1); |
| 1675 |
if (altAlertOn == 0) |
| 1676 |
{ |
| 1677 |
altAlertOn = 1; |
| 1678 |
} |
| 1679 |
} |
| 1680 |
elsif (lockPitchArm.getValue() == pitchArmModes["OFF"]) |
| 1681 |
{ |
| 1682 |
lockPitchArm.setIntValue(pitchArmModes["ALT"]); |
| 1683 |
annunciatorAltArm.setBoolValue(1); |
| 1684 |
} |
| 1685 |
} |
| 1686 |
} |
| 1687 |
|
| 1688 |
|
| 1689 |
var knobLargeDown = func { |
| 1690 |
#print("knob large down"); |
| 1691 |
# Disable button if too little power |
| 1692 |
if (getprop(power) < minVoltageLimit) { return; } |
| 1693 |
|
| 1694 |
if (baroTimerRunning == 1) |
| 1695 |
{ |
| 1696 |
baroSettingAdjusting = 1; |
| 1697 |
if (baroSettingUnit == pressureUnits["inHg"]) |
| 1698 |
{ |
| 1699 |
adjustBaroSettingInhg(-1.0); |
| 1700 |
} |
| 1701 |
elsif (baroSettingUnit == pressureUnits["hPa"]) |
| 1702 |
{ |
| 1703 |
adjustbaroSettingHpa(-100); |
| 1704 |
} |
| 1705 |
} |
| 1706 |
elsif (baroTimerRunning == 0 and |
| 1707 |
altButtonTimerRunning == 0) |
| 1708 |
{ |
| 1709 |
altCaptured = 0; |
| 1710 |
altPreselect = altPreselect - 100; |
| 1711 |
settingTargetAltFt.setDoubleValue(altPreselect); |
| 1712 |
|
| 1713 |
if (lockRollMode.getValue() == rollModes["OFF"] and |
| 1714 |
lockPitchMode.getValue() == pitchModes["OFF"]) |
| 1715 |
{ |
| 1716 |
annunciatorAltNumber.setBoolValue(1); |
| 1717 |
if (altAlertOn == 0) |
| 1718 |
{ |
| 1719 |
altAlertOn = 1; |
| 1720 |
} |
| 1721 |
} |
| 1722 |
elsif (lockPitchArm.getValue() == pitchArmModes["OFF"]) |
| 1723 |
{ |
| 1724 |
lockPitchArm.setIntValue(pitchArmModes["ALT"]); |
| 1725 |
annunciatorAltArm.setBoolValue(1); |
| 1726 |
} |
| 1727 |
} |
| 1728 |
} |
| 1729 |
|
| 1730 |
var L = setlistener(power, func { |
| 1731 |
apPower(); |
| 1732 |
removelistener(L); |
| 1733 |
}); |