2007-02-04 12:55:28 +00:00
|
|
|
##
|
|
|
|
# Bendix/King KAP140 Autopilot System
|
|
|
|
# Tries to behave like the Bendix/King KAP140 autopilot
|
|
|
|
# two axis w/altitude preselect.
|
|
|
|
#
|
|
|
|
# One would also need the autopilot configuration file
|
|
|
|
# KAP140.xml and the panel instrument configuration file
|
|
|
|
#
|
|
|
|
# Written by Roy Vegard Ovesen
|
|
|
|
# "Power-check" edits by Dave Perry
|
|
|
|
##
|
|
|
|
|
|
|
|
# Properties
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var locks = "/autopilot/KAP140/locks";
|
|
|
|
var settings = "/autopilot/KAP140/settings";
|
|
|
|
var annunciators = "/autopilot/KAP140/annunciators";
|
|
|
|
var internal = "/autopilot/internal";
|
|
|
|
var power="/systems/electrical/outputs/autopilot";
|
|
|
|
var encoder = "/instrumentation/encoder";
|
|
|
|
var flightControls = "/controls/flight";
|
2007-02-04 12:55:28 +00:00
|
|
|
|
|
|
|
# locks
|
2007-11-28 20:09:59 +00:00
|
|
|
var propLocks = props.globals.getNode(locks, 1);
|
|
|
|
|
|
|
|
var lockAltHold = propLocks.getNode("alt-hold", 1);
|
|
|
|
var lockAprHold = propLocks.getNode("apr-hold", 1);
|
|
|
|
var lockGsHold = propLocks.getNode("gs-hold", 1);
|
|
|
|
var lockHdgHold = propLocks.getNode("hdg-hold", 1);
|
|
|
|
var lockNavHold = propLocks.getNode("nav-hold", 1);
|
|
|
|
var lockRevHold = propLocks.getNode("rev-hold", 1);
|
|
|
|
var lockRollAxis = propLocks.getNode("roll-axis", 1);
|
|
|
|
var lockRollMode = propLocks.getNode("roll-mode", 1);
|
|
|
|
var lockPitchAxis = propLocks.getNode("pitch-axis", 1);
|
|
|
|
var lockPitchMode = propLocks.getNode("pitch-mode", 1);
|
|
|
|
var lockRollArm = propLocks.getNode("roll-arm", 1);
|
|
|
|
var lockPitchArm = propLocks.getNode("pitch-arm", 1);
|
|
|
|
|
|
|
|
|
|
|
|
var rollModes = { "OFF" : 0, "ROL" : 1, "HDG" : 2, "NAV" : 3, "REV" : 4, "APR" : 5 };
|
|
|
|
var pitchModes = { "OFF" : 0, "VS" : 1, "ALT" : 2, "GS" : 3 };
|
|
|
|
var rollArmModes = { "OFF" : 0, "NAV" : 1, "APR" : 2, "REV" : 3 };
|
|
|
|
var pitchArmModes = { "OFF" : 0, "ALT" : 1, "GS" : 2 };
|
2007-02-04 12:55:28 +00:00
|
|
|
|
|
|
|
# settings
|
2007-11-28 20:09:59 +00:00
|
|
|
var propSettings = props.globals.getNode(settings, 1);
|
2007-02-04 12:55:28 +00:00
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var settingTargetAltPressure = propSettings.getNode("target-alt-pressure", 1);
|
|
|
|
var settingTargetInterceptAngle = propSettings.getNode("target-intercept-angle", 1);
|
|
|
|
var settingTargetPressureRate = propSettings.getNode("target-pressure-rate", 1);
|
|
|
|
var settingTargetTurnRate = propSettings.getNode("target-turn-rate", 1);
|
|
|
|
var settingTargetAltFt = propSettings.getNode("target-alt-ft", 1);
|
|
|
|
var settingBaroSettingInhg = propSettings.getNode("baro-setting-inhg", 1);
|
|
|
|
var settingBaroSettingHpa = propSettings.getNode("baro-setting-hpa", 1);
|
|
|
|
var settingAutoPitchTrim = propSettings.getNode("auto-pitch-trim", 1);
|
2007-02-04 12:55:28 +00:00
|
|
|
|
|
|
|
#annunciators
|
2007-11-28 20:09:59 +00:00
|
|
|
var propAnnunciators = props.globals.getNode(annunciators, 1);
|
|
|
|
|
|
|
|
var annunciatorRol = propAnnunciators.getNode("rol", 1);
|
|
|
|
var annunciatorHdg = propAnnunciators.getNode("hdg", 1);
|
|
|
|
var annunciatorNav = propAnnunciators.getNode("nav", 1);
|
|
|
|
var annunciatorNavArm = propAnnunciators.getNode("nav-arm", 1);
|
|
|
|
var annunciatorApr = propAnnunciators.getNode("apr", 1);
|
|
|
|
var annunciatorAprArm = propAnnunciators.getNode("apr-arm", 1);
|
|
|
|
var annunciatorRev = propAnnunciators.getNode("rev", 1);
|
|
|
|
var annunciatorRevArm = propAnnunciators.getNode("rev-arm", 1);
|
|
|
|
var annunciatorVs = propAnnunciators.getNode("vs", 1);
|
|
|
|
var annunciatorVsNumber = propAnnunciators.getNode("vs-number", 1);
|
|
|
|
var annunciatorFpm = propAnnunciators.getNode("fpm", 1);
|
|
|
|
var annunciatorAlt = propAnnunciators.getNode("alt", 1);
|
|
|
|
var annunciatorAltArm = propAnnunciators.getNode("alt-arm", 1);
|
|
|
|
var annunciatorAltNumber = propAnnunciators.getNode("alt-number", 1);
|
|
|
|
var annunciatorAltAlert = propAnnunciators.getNode("alt-alert", 1);
|
|
|
|
var annunciatorApr = propAnnunciators.getNode("apr", 1);
|
|
|
|
var annunciatorGs = propAnnunciators.getNode("gs", 1);
|
|
|
|
var annunciatorGsArm = propAnnunciators.getNode("gs-arm", 1);
|
|
|
|
var annunciatorPtUp = propAnnunciators.getNode("pt-up", 1);
|
|
|
|
var annunciatorPtDn = propAnnunciators.getNode("pt-dn", 1);
|
|
|
|
var annunciatorBsHpaNumber = propAnnunciators.getNode("bs-hpa-number", 1);
|
|
|
|
var annunciatorBsInhgNumber = propAnnunciators.getNode("bs-inhg-number", 1);
|
|
|
|
var annunciatorAp = propAnnunciators.getNode("ap", 1);
|
|
|
|
var annunciatorBeep = propAnnunciators.getNode("beep", 1);
|
2007-02-04 12:55:28 +00:00
|
|
|
|
2007-04-26 18:04:51 +00:00
|
|
|
#flashers
|
2007-11-28 20:09:59 +00:00
|
|
|
var altAlertBeeper = aircraft.light.new(annunciatorBeep, [0.5, 0.25]).switch(0);
|
|
|
|
var altAlertFlasher = aircraft.light.new(annunciatorAltAlert, [0.5, 0.25]).switch(0);
|
|
|
|
var hdgFlasher = aircraft.light.new(annunciatorHdg, [0.5, 0.25]).switch(0);
|
|
|
|
var apFlasher = aircraft.light.new(annunciatorAp, [1.0, 0.5]).switch(0);
|
2007-02-04 12:55:28 +00:00
|
|
|
|
2007-04-26 18:04:51 +00:00
|
|
|
#Flight controls
|
2007-11-28 20:09:59 +00:00
|
|
|
var propFlightControls = props.globals.getNode(flightControls, 0);
|
|
|
|
|
|
|
|
var elevatorControl = propFlightControls.getNode("elevator", 0);
|
|
|
|
var elevatorTrimControl = propFlightControls.getNode("elevator-trim", 0);
|
|
|
|
|
|
|
|
var headingNeedleDeflection = "/instrumentation/nav/heading-needle-deflection";
|
2009-09-09 10:49:36 +00:00
|
|
|
var gsNeedleDeflection = "/instrumentation/nav/gs-needle-deflection-norm";
|
2007-11-28 20:09:59 +00:00
|
|
|
var staticPressure = "systems/static/pressure-inhg";
|
|
|
|
|
|
|
|
var pressureUnits = { "inHg" : 0, "hPa" : 1 };
|
|
|
|
var baroSettingUnit = pressureUnits["inHg"];
|
|
|
|
var baroSettingInhg = 29.92;
|
|
|
|
var baroSettingHpa = baroSettingInhg * 0.03386389;
|
|
|
|
var baroSettingAdjusting = 0;
|
|
|
|
var baroButtonDown = 0;
|
|
|
|
var baroTimerRunning = 0;
|
|
|
|
|
|
|
|
var altPreselect = 0;
|
|
|
|
var altButtonTimerRunning = 0;
|
|
|
|
var altButtonTimerIgnore = 0;
|
|
|
|
var altAlertOn = 0;
|
|
|
|
var altCaptured = 0;
|
|
|
|
var altDifference = 0.0;
|
|
|
|
|
|
|
|
var valueTest = 0;
|
|
|
|
var lastValue = 0;
|
|
|
|
var newValue = 0;
|
|
|
|
var baroOffset = 0.0;
|
|
|
|
var baroChange = 1;
|
|
|
|
var minVoltageLimit = 8.0;
|
|
|
|
|
|
|
|
|
|
|
|
var ptCheck = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
##print("pitch trim check");
|
|
|
|
|
|
|
|
if (lockPitchMode.getValue() == pitchModes["OFF"])
|
|
|
|
{
|
|
|
|
annunciatorPtUp.setBoolValue(0);
|
|
|
|
annunciatorPtDn.setBoolValue(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2007-11-28 20:09:59 +00:00
|
|
|
var autoPitchTrim = settingAutoPitchTrim.getValue();
|
2007-02-04 12:55:28 +00:00
|
|
|
# Flash the pitch trim up annunciator
|
2007-04-26 18:04:51 +00:00
|
|
|
if (elevatorControl.getValue() < -0.01)
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
if (annunciatorPtUp.getValue() == 0)
|
|
|
|
{
|
|
|
|
annunciatorPtUp.setBoolValue(1);
|
|
|
|
}
|
|
|
|
elsif (annunciatorPtUp.getValue() == 1)
|
|
|
|
{
|
|
|
|
annunciatorPtUp.setBoolValue(0);
|
|
|
|
}
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorPtDn.setBoolValue(0);
|
|
|
|
# Automatic pitch trim
|
|
|
|
if (autoPitchTrim == 1)
|
|
|
|
{
|
|
|
|
elevatorTrimControl.setDoubleValue(
|
|
|
|
elevatorTrimControl.getValue() - 0.001);
|
|
|
|
}
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
# Flash the pitch trim down annunciator
|
2007-04-26 18:04:51 +00:00
|
|
|
elsif (elevatorControl.getValue() > 0.01)
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
if (annunciatorPtDn.getValue() == 0)
|
|
|
|
{
|
|
|
|
annunciatorPtDn.setBoolValue(1);
|
|
|
|
}
|
|
|
|
elsif (annunciatorPtDn.getValue() == 1)
|
|
|
|
{
|
|
|
|
annunciatorPtDn.setBoolValue(0);
|
|
|
|
}
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorPtUp.setBoolValue(0);
|
|
|
|
# Automatic pitch trim
|
|
|
|
if (autoPitchTrim == 1)
|
|
|
|
{
|
|
|
|
elevatorTrimControl.setDoubleValue(
|
|
|
|
elevatorTrimControl.getValue() + 0.001);
|
|
|
|
}
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
annunciatorPtUp.setBoolValue(0);
|
|
|
|
annunciatorPtDn.setBoolValue(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
settimer(ptCheck, 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var apInit = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
##print("ap init");
|
|
|
|
|
|
|
|
##
|
|
|
|
# Initialises the autopilot.
|
|
|
|
##
|
|
|
|
|
|
|
|
lockAltHold.setBoolValue(0);
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(0);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(0);
|
|
|
|
lockRollMode.setIntValue(rollModes["OFF"]);
|
|
|
|
lockPitchAxis.setBoolValue(0);
|
|
|
|
lockPitchMode.setIntValue(pitchModes["OFF"]);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["OFF"]);
|
|
|
|
# Reset the memory for power down or power up
|
|
|
|
altPreselect = 0;
|
|
|
|
baroSettingInhg = 29.92;
|
2007-04-26 18:04:51 +00:00
|
|
|
adjustBaroSettingInhg(0.0);
|
2007-02-04 12:55:28 +00:00
|
|
|
settingTargetAltFt.setDoubleValue(altPreselect);
|
|
|
|
settingTargetAltPressure.setDoubleValue(0.0);
|
|
|
|
settingTargetInterceptAngle.setDoubleValue(0.0);
|
|
|
|
settingTargetPressureRate.setDoubleValue(0.0);
|
|
|
|
settingTargetTurnRate.setDoubleValue(0.0);
|
|
|
|
|
|
|
|
annunciatorRol.setBoolValue(0);
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorHdg.getNode("state").setBoolValue(0);
|
2007-02-04 12:55:28 +00:00
|
|
|
annunciatorNav.setBoolValue(0);
|
|
|
|
annunciatorNavArm.setBoolValue(0);
|
|
|
|
annunciatorApr.setBoolValue(0);
|
|
|
|
annunciatorAprArm.setBoolValue(0);
|
|
|
|
annunciatorRev.setBoolValue(0);
|
|
|
|
annunciatorRevArm.setBoolValue(0);
|
|
|
|
annunciatorVs.setBoolValue(0);
|
|
|
|
annunciatorVsNumber.setBoolValue(0);
|
|
|
|
annunciatorFpm.setBoolValue(0);
|
|
|
|
annunciatorAlt.setBoolValue(0);
|
|
|
|
annunciatorAltArm.setBoolValue(0);
|
|
|
|
annunciatorAltNumber.setBoolValue(0);
|
|
|
|
annunciatorGs.setBoolValue(0);
|
|
|
|
annunciatorGsArm.setBoolValue(0);
|
|
|
|
annunciatorPtUp.setBoolValue(0);
|
|
|
|
annunciatorPtDn.setBoolValue(0);
|
|
|
|
annunciatorBsHpaNumber.setBoolValue(0);
|
|
|
|
annunciatorBsInhgNumber.setBoolValue(0);
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorAp.getNode("state").setBoolValue(0);
|
2007-02-04 12:55:28 +00:00
|
|
|
annunciatorBeep.setBoolValue(0);
|
|
|
|
|
|
|
|
# settimer(altAlert, 5.0);
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var apPower = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
|
|
|
|
## Monitor autopilot power
|
|
|
|
## Call apInit if the power is too low
|
|
|
|
|
|
|
|
if (getprop(power) < minVoltageLimit) {
|
|
|
|
newValue = 0;
|
|
|
|
} else {
|
|
|
|
newValue = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
valueTest = newValue - lastValue;
|
|
|
|
# print("v_test = ", v_test);
|
2007-03-31 09:38:18 +00:00
|
|
|
if (valueTest > 0.5) {
|
2007-02-04 12:55:28 +00:00
|
|
|
# autopilot just powered up
|
2012-07-01 09:00:56 +00:00
|
|
|
print("KAP140 power up");
|
2007-02-04 12:55:28 +00:00
|
|
|
apInit();
|
|
|
|
altAlert();
|
|
|
|
} elsif (valueTest < -0.5) {
|
|
|
|
# autopilot just lost power
|
2012-07-01 09:00:56 +00:00
|
|
|
print("KAP140 power lost");
|
2007-02-04 12:55:28 +00:00
|
|
|
apInit();
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorAltAlert.getNode("state").setBoolValue(0);
|
|
|
|
annunciatorBeep.getNode("state").setBoolValue(0);
|
2007-02-04 12:55:28 +00:00
|
|
|
# note: all button and knobs disabled in functions below
|
|
|
|
}
|
|
|
|
lastValue = newValue;
|
|
|
|
settimer(apPower, 0.5);
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var apButton = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
##print("apButton");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
##
|
|
|
|
# Engages the autopilot in Wings level mode (ROL) and Vertical speed hold
|
|
|
|
# mode (VS).
|
|
|
|
##
|
|
|
|
if (lockRollMode.getValue() == rollModes["OFF"] and
|
|
|
|
lockPitchMode.getValue() == pitchModes["OFF"])
|
|
|
|
{
|
|
|
|
|
|
|
|
lockAltHold.setBoolValue(0);
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(0);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollMode.setIntValue(rollModes["ROL"]);
|
|
|
|
lockPitchAxis.setBoolValue(1);
|
|
|
|
lockPitchMode.setIntValue(pitchModes["VS"]);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["OFF"]);
|
|
|
|
|
|
|
|
annunciatorRol.setBoolValue(1);
|
|
|
|
annunciatorVs.setBoolValue(1);
|
|
|
|
annunciatorVsNumber.setBoolValue(1);
|
|
|
|
|
|
|
|
settingTargetTurnRate.setDoubleValue(0.0);
|
|
|
|
|
|
|
|
ptCheck();
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var pressureRate = getprop(internal, "pressure-rate");
|
2007-02-04 12:55:28 +00:00
|
|
|
#print(pressureRate);
|
2007-11-28 20:09:59 +00:00
|
|
|
var fpm = -pressureRate * 58000;
|
2007-02-04 12:55:28 +00:00
|
|
|
#print(fpm);
|
|
|
|
if (fpm > 0.0)
|
|
|
|
{
|
|
|
|
fpm = int(fpm/100 + 0.5) * 100;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fpm = int(fpm/100 - 0.5) * 100;
|
|
|
|
}
|
|
|
|
#print(fpm);
|
|
|
|
|
|
|
|
settingTargetPressureRate.setDoubleValue(-fpm / 58000);
|
|
|
|
|
|
|
|
if (altButtonTimerRunning == 0)
|
|
|
|
{
|
|
|
|
settimer(altButtonTimer, 3.0);
|
|
|
|
altButtonTimerRunning = 1;
|
|
|
|
altButtonTimerIgnore = 0;
|
|
|
|
annunciatorAltNumber.setBoolValue(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# Disengages all modes.
|
|
|
|
##
|
|
|
|
elsif (lockRollMode.getValue() != rollModes["OFF"] and
|
|
|
|
lockPitchMode.getValue() != pitchModes["OFF"])
|
|
|
|
{
|
|
|
|
|
|
|
|
lockAltHold.setBoolValue(0);
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(0);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(0);
|
|
|
|
lockRollMode.setIntValue(rollModes["OFF"]);
|
|
|
|
lockPitchAxis.setBoolValue(0);
|
|
|
|
lockPitchMode.setIntValue(pitchModes["OFF"]);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["OFF"]);
|
|
|
|
|
|
|
|
settingTargetAltPressure.setDoubleValue(0.0);
|
|
|
|
settingTargetInterceptAngle.setDoubleValue(0.0);
|
|
|
|
settingTargetPressureRate.setDoubleValue(0.0);
|
|
|
|
settingTargetTurnRate.setDoubleValue(0.0);
|
|
|
|
|
|
|
|
annunciatorRol.setBoolValue(0);
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorHdg.getNode("state").setBoolValue(0);
|
2007-02-04 12:55:28 +00:00
|
|
|
annunciatorNav.setBoolValue(0);
|
|
|
|
annunciatorNavArm.setBoolValue(0);
|
|
|
|
annunciatorApr.setBoolValue(0);
|
|
|
|
annunciatorAprArm.setBoolValue(0);
|
|
|
|
annunciatorRev.setBoolValue(0);
|
|
|
|
annunciatorRevArm.setBoolValue(0);
|
|
|
|
annunciatorVs.setBoolValue(0);
|
|
|
|
annunciatorVsNumber.setBoolValue(0);
|
|
|
|
annunciatorAlt.setBoolValue(0);
|
|
|
|
annunciatorAltArm.setBoolValue(0);
|
|
|
|
annunciatorAltNumber.setBoolValue(0);
|
|
|
|
annunciatorApr.setBoolValue(0);
|
|
|
|
annunciatorGs.setBoolValue(0);
|
|
|
|
annunciatorGsArm.setBoolValue(0);
|
|
|
|
annunciatorPtUp.setBoolValue(0);
|
|
|
|
annunciatorPtDn.setBoolValue(0);
|
|
|
|
|
2007-04-26 18:04:51 +00:00
|
|
|
apFlasher.blink(5).switch(0).switch(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var hdgButton = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
##print("hdgButton");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
##
|
|
|
|
# Engages the heading mode (HDG) and vertical speed hold mode (VS). The
|
|
|
|
# commanded vertical speed is set to the vertical speed present at button
|
|
|
|
# press.
|
|
|
|
##
|
|
|
|
if (lockRollMode.getValue() == rollModes["OFF"] and
|
|
|
|
lockPitchMode.getValue() == pitchModes["OFF"])
|
|
|
|
{
|
|
|
|
lockAltHold.setBoolValue(0);
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(1);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollMode.setIntValue(rollModes["HDG"]);
|
|
|
|
lockPitchAxis.setBoolValue(1);
|
|
|
|
lockPitchMode.setIntValue(pitchModes["VS"]);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["OFF"]);
|
|
|
|
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorHdg.getNode("state").setBoolValue(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
annunciatorAlt.setBoolValue(0);
|
|
|
|
annunciatorApr.setBoolValue(0);
|
|
|
|
annunciatorGs.setBoolValue(0);
|
|
|
|
annunciatorNav.setBoolValue(0);
|
|
|
|
annunciatorVs.setBoolValue(1);
|
|
|
|
annunciatorVsNumber.setBoolValue(1);
|
|
|
|
|
|
|
|
settingTargetInterceptAngle.setDoubleValue(0.0);
|
|
|
|
|
|
|
|
ptCheck();
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var pressureRate = getprop(internal, "pressure-rate");
|
|
|
|
var fpm = -pressureRate * 58000;
|
2007-02-04 12:55:28 +00:00
|
|
|
#print(fpm);
|
|
|
|
if (fpm > 0.0)
|
|
|
|
{
|
|
|
|
fpm = int(fpm/100 + 0.5) * 100;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fpm = int(fpm/100 - 0.5) * 100;
|
|
|
|
}
|
|
|
|
#print(fpm);
|
|
|
|
|
|
|
|
settingTargetPressureRate.setDoubleValue(-fpm / 58000);
|
|
|
|
|
|
|
|
if (altButtonTimerRunning == 0)
|
|
|
|
{
|
|
|
|
settimer(altButtonTimer, 3.0);
|
|
|
|
altButtonTimerRunning = 1;
|
|
|
|
altButtonTimerIgnore = 0;
|
|
|
|
annunciatorAltNumber.setBoolValue(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# Switch from ROL to HDG mode, but don't change pitch mode.
|
|
|
|
##
|
|
|
|
elsif (lockRollMode.getValue() == rollModes["ROL"])
|
|
|
|
{
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(1);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollMode.setIntValue(rollModes["HDG"]);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
|
|
|
|
annunciatorApr.setBoolValue(0);
|
|
|
|
annunciatorGs.setBoolValue(0);
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorHdg.getNode("state").setBoolValue(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
annunciatorNav.setBoolValue(0);
|
|
|
|
annunciatorRol.setBoolValue(0);
|
|
|
|
annunciatorRev.setBoolValue(0);
|
|
|
|
|
|
|
|
settingTargetInterceptAngle.setDoubleValue(0.0);
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# Switch to HDG mode, but don't change pitch mode.
|
|
|
|
##
|
|
|
|
elsif ( (lockRollMode.getValue() == rollModes["NAV"] or
|
|
|
|
lockRollArm.getValue() == rollArmModes["NAV"] or
|
|
|
|
lockRollMode.getValue() == rollModes["REV"] or
|
|
|
|
lockRollArm.getValue() == rollArmModes["REV"]) and
|
2007-04-26 18:04:51 +00:00
|
|
|
!hdgFlasher.count)
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(1);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollMode.setIntValue(rollModes["HDG"]);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
|
|
|
|
annunciatorApr.setBoolValue(0);
|
|
|
|
annunciatorGs.setBoolValue(0);
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorHdg.getNode("state").setBoolValue(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
annunciatorNav.setBoolValue(0);
|
|
|
|
annunciatorRol.setBoolValue(0);
|
|
|
|
annunciatorRev.setBoolValue(0);
|
|
|
|
annunciatorNavArm.setBoolValue(0);
|
|
|
|
|
|
|
|
settingTargetInterceptAngle.setDoubleValue(0.0);
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# If we already are in HDG mode switch to ROL mode. Again don't touch pitch
|
|
|
|
# mode.
|
|
|
|
##
|
|
|
|
elsif (lockRollMode.getValue() == rollModes["HDG"])
|
|
|
|
{
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollMode.setIntValue(rollModes["ROL"]);
|
|
|
|
|
|
|
|
annunciatorApr.setBoolValue(0);
|
|
|
|
annunciatorGs.setBoolValue(0);
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorHdg.getNode("state").setBoolValue(0);
|
2007-02-04 12:55:28 +00:00
|
|
|
annunciatorNav.setBoolValue(0);
|
|
|
|
annunciatorRol.setBoolValue(1);
|
|
|
|
|
|
|
|
settingTargetTurnRate.setDoubleValue(0.0);
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# If we are in APR mode we also have to change pitch mode.
|
|
|
|
# TODO: Should we switch to VS or ALT mode? (currently VS)
|
|
|
|
##
|
|
|
|
elsif ( (lockRollMode.getValue() == rollModes["APR"] or
|
|
|
|
lockRollArm.getValue() == rollArmModes["APR"] or
|
|
|
|
lockPitchMode.getValue() == pitchModes["GS"] or
|
|
|
|
lockPitchArm.getValue() == pitchArmModes["GS"]) and
|
2007-04-26 18:04:51 +00:00
|
|
|
!hdgFlasher.count)
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
lockAltHold.setBoolValue(0);
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(1);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollMode.setIntValue(rollModes["HDG"]);
|
|
|
|
lockPitchAxis.setBoolValue(1);
|
|
|
|
lockPitchMode.setIntValue(pitchModes["VS"]);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["OFF"]);
|
|
|
|
|
|
|
|
annunciatorAlt.setBoolValue(0);
|
|
|
|
annunciatorAltArm.setBoolValue(0);
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorHdg.getNode("state").setBoolValue(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
annunciatorRol.setBoolValue(0);
|
|
|
|
annunciatorNav.setBoolValue(0);
|
|
|
|
annunciatorApr.setBoolValue(0);
|
|
|
|
annunciatorAprArm.setBoolValue(0);
|
|
|
|
annunciatorGs.setBoolValue(0);
|
|
|
|
annunciatorGsArm.setBoolValue(0);
|
|
|
|
annunciatorVs.setBoolValue(1);
|
|
|
|
annunciatorVsNumber.setBoolValue(1);
|
|
|
|
|
|
|
|
settingTargetInterceptAngle.setDoubleValue(0.0);
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var pressureRate = getprop(internal, "pressure-rate");
|
2007-02-04 12:55:28 +00:00
|
|
|
#print(pressureRate);
|
2007-11-28 20:09:59 +00:00
|
|
|
var fpm = -pressureRate * 58000;
|
2007-02-04 12:55:28 +00:00
|
|
|
#print(fpm);
|
|
|
|
if (fpm > 0.0)
|
|
|
|
{
|
|
|
|
fpm = int(fpm/100 + 0.5) * 100;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fpm = int(fpm/100 - 0.5) * 100;
|
|
|
|
}
|
|
|
|
#print(fpm);
|
|
|
|
|
|
|
|
settingTargetPressureRate.setDoubleValue(-fpm / 58000);
|
|
|
|
|
|
|
|
if (altButtonTimerRunning == 0)
|
|
|
|
{
|
|
|
|
settimer(altButtonTimer, 3.0);
|
|
|
|
altButtonTimerRunning = 1;
|
|
|
|
altButtonTimerIgnore = 0;
|
|
|
|
annunciatorAltNumber.setBoolValue(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var navButton = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
##print("navButton");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
##
|
|
|
|
# If we are in HDG mode we switch to the 45 degree angle intercept NAV mode
|
|
|
|
##
|
|
|
|
if (lockRollMode.getValue() == rollModes["HDG"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
hdgFlasher.blink(8, 1).switch(0).switch(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(1);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["NAV"]);
|
|
|
|
lockRollMode.setIntValue(rollModes["NAV"]);
|
|
|
|
|
|
|
|
annunciatorNavArm.setBoolValue(1);
|
|
|
|
|
|
|
|
navArmFromHdg();
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# If we are in ROL mode we switch to the all angle intercept NAV mode.
|
|
|
|
##
|
|
|
|
elsif (lockRollMode.getValue() == rollModes["ROL"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
hdgFlasher.blink(8).switch(0).switch(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(0);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["NAV"]);
|
|
|
|
lockRollMode.setIntValue(rollModes["NAV"]);
|
|
|
|
|
|
|
|
annunciatorNavArm.setBoolValue(1);
|
|
|
|
|
|
|
|
navArmFromRol();
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# TODO:
|
|
|
|
# NAV mode can only be armed if we are in HDG or ROL mode.
|
|
|
|
# Can anyone verify that this is correct?
|
|
|
|
##
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var navArmFromHdg = func
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
##
|
|
|
|
# Abort the NAV-ARM mode if something has changed the arm mode to something
|
|
|
|
# else than NAV-ARM.
|
|
|
|
##
|
|
|
|
if (lockRollArm.getValue() != rollArmModes["NAV"])
|
|
|
|
{
|
|
|
|
annunciatorNavArm.setBoolValue(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#annunciatorNavArm.setBoolValue(1);
|
|
|
|
##
|
|
|
|
# Wait for the HDG annunciator flashing to finish.
|
|
|
|
##
|
2007-04-26 18:04:51 +00:00
|
|
|
if (hdgFlasher.count)
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
#print("flashing...");
|
|
|
|
settimer(navArmFromHdg, 2.5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# Activate the nav-hold controller and check the needle deviation.
|
|
|
|
##
|
|
|
|
lockNavHold.setBoolValue(1);
|
2007-04-26 18:04:51 +00:00
|
|
|
deviation = getprop(headingNeedleDeflection);
|
2007-02-04 12:55:28 +00:00
|
|
|
##
|
|
|
|
# If the deflection is more than 3 degrees wait 5 seconds and check again.
|
|
|
|
##
|
|
|
|
if (abs(deviation) > 3.0)
|
|
|
|
{
|
|
|
|
#print("deviation");
|
|
|
|
settimer(navArmFromHdg, 5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# If the deviation is less than 3 degrees turn of the NAV-ARM annunciator
|
|
|
|
# and show the NAV annunciator. End of NAV-ARM sequence.
|
|
|
|
##
|
|
|
|
elsif (abs(deviation) < 3.1)
|
|
|
|
{
|
|
|
|
#print("capture");
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
annunciatorNavArm.setBoolValue(0);
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorHdg.getNode("state").setBoolValue(0);
|
2007-02-04 12:55:28 +00:00
|
|
|
annunciatorNav.setBoolValue(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var navArmFromRol = func
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
##
|
|
|
|
# Abort the NAV-ARM mode if something has changed the arm mode to something
|
|
|
|
# else than NAV-ARM.
|
|
|
|
##
|
|
|
|
if (lockRollArm.getValue() != rollArmModes["NAV"])
|
|
|
|
{
|
|
|
|
annunciatorNavArm.setBoolValue(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# Wait for the HDG annunciator flashing to finish.
|
|
|
|
##
|
|
|
|
#annunciatorNavArm.setBoolValue(1);
|
2007-04-26 18:04:51 +00:00
|
|
|
if (hdgFlasher.count)
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
#print("flashing...");
|
|
|
|
annunciatorRol.setBoolValue(0);
|
|
|
|
settimer(navArmFromRol, 2.5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# Turn the ROL annunciator back on and activate the ROL mode.
|
|
|
|
##
|
|
|
|
annunciatorRol.setBoolValue(1);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
settingTargetTurnRate.setDoubleValue(0.0);
|
2007-11-28 20:09:59 +00:00
|
|
|
var deviation = getprop(headingNeedleDeflection);
|
2007-02-04 12:55:28 +00:00
|
|
|
##
|
|
|
|
# If the deflection is more than 3 degrees wait 5 seconds and check again.
|
|
|
|
##
|
|
|
|
if (abs(deviation) > 3.0)
|
|
|
|
{
|
|
|
|
#print("deviation");
|
|
|
|
settimer(navArmFromRol, 5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# If the deviation is less than 3 degrees turn of the NAV-ARM annunciator
|
|
|
|
# and show the NAV annunciator. End of NAV-ARM sequence.
|
|
|
|
##
|
|
|
|
elsif (abs(deviation) < 3.1)
|
|
|
|
{
|
|
|
|
#print("capture");
|
|
|
|
annunciatorRol.setBoolValue(0);
|
|
|
|
annunciatorNavArm.setBoolValue(0);
|
|
|
|
annunciatorNav.setBoolValue(1);
|
|
|
|
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(1);
|
|
|
|
lockNavHold.setBoolValue(1);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollMode.setIntValue(rollModes["NAV"]);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var aprButton = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
##print("aprButton");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
##
|
|
|
|
# If we are in HDG mode we switch to the 45 degree intercept angle APR mode
|
|
|
|
##
|
|
|
|
if (lockRollMode.getValue() == rollModes["HDG"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
hdgFlasher.blink(8, 1).switch(0).switch(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
|
|
|
|
lockAprHold.setBoolValue(1);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(1);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["APR"]);
|
|
|
|
lockRollMode.setIntValue(rollModes["APR"]);
|
|
|
|
|
|
|
|
annunciatorAprArm.setBoolValue(1);
|
|
|
|
|
|
|
|
aprArmFromHdg();
|
|
|
|
}
|
|
|
|
elsif (lockRollMode.getValue() == rollModes["ROL"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
hdgFlasher.blink(8).switch(0).switch(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(0);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["APR"]);
|
|
|
|
lockRollMode.setIntValue(rollModes["APR"]);
|
|
|
|
|
|
|
|
annunciatorAprArm.setBoolValue(1);
|
|
|
|
|
|
|
|
aprArmFromRol();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var aprArmFromHdg = func
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
##
|
|
|
|
# Abort the APR-ARM mode if something has changed the arm mode to something
|
|
|
|
# else than APR-ARM.
|
|
|
|
##
|
|
|
|
if (lockRollArm.getValue() != rollArmModes["APR"])
|
|
|
|
{
|
|
|
|
annunciatorAprArm.setBoolValue(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#annunciatorAprArm.setBoolValue(1);
|
|
|
|
##
|
|
|
|
# Wait for the HDG annunciator flashing to finish.
|
|
|
|
##
|
2007-04-26 18:04:51 +00:00
|
|
|
if (hdgFlasher.count)
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
#print("flashing...");
|
|
|
|
settimer(aprArmFromHdg, 2.5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# Activate the apr-hold controller and check the needle deviation.
|
|
|
|
##
|
|
|
|
lockAprHold.setBoolValue(1);
|
2007-11-28 20:09:59 +00:00
|
|
|
var deviation = getprop(headingNeedleDeflection);
|
2007-02-04 12:55:28 +00:00
|
|
|
##
|
|
|
|
# If the deflection is more than 3 degrees wait 5 seconds and check again.
|
|
|
|
##
|
|
|
|
if (abs(deviation) > 3.0)
|
|
|
|
{
|
|
|
|
#print("deviation");
|
|
|
|
settimer(aprArmFromHdg, 5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# If the deviation is less than 3 degrees turn of the APR-ARM annunciator
|
|
|
|
# and show the APR annunciator. End of APR-ARM sequence. Start the GS-ARM
|
|
|
|
# sequence.
|
|
|
|
##
|
|
|
|
elsif (abs(deviation) < 3.1)
|
|
|
|
{
|
|
|
|
#print("capture");
|
|
|
|
annunciatorAprArm.setBoolValue(0);
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorHdg.getNode("state").setBoolValue(0);
|
2007-02-04 12:55:28 +00:00
|
|
|
annunciatorApr.setBoolValue(1);
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["GS"]);
|
|
|
|
|
|
|
|
gsArm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var aprArmFromRol = func
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
##
|
|
|
|
# Abort the APR-ARM mode if something has changed the roll mode to something
|
|
|
|
# else than APR-ARM.
|
|
|
|
##
|
|
|
|
if (lockRollArm.getValue() != rollArmModes["APR"])
|
|
|
|
{
|
|
|
|
annunciatorAprArm.setBoolValue(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#annunciatorAprArm.setBoolValue(1);
|
|
|
|
##
|
|
|
|
# Wait for the HDG annunciator flashing to finish.
|
|
|
|
##
|
2007-04-26 18:04:51 +00:00
|
|
|
if (hdgFlasher.count)
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
#print("flashing...");
|
|
|
|
annunciatorRol.setBoolValue(0);
|
|
|
|
settimer(aprArmFromRol, 2.5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# Turn the ROL annunciator back on and activate the ROL mode.
|
|
|
|
##
|
|
|
|
annunciatorRol.setBoolValue(1);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
settingTargetTurnRate.setDoubleValue(0.0);
|
2007-11-28 20:09:59 +00:00
|
|
|
var deviation = getprop(headingNeedleDeflection);
|
2007-02-04 12:55:28 +00:00
|
|
|
##
|
|
|
|
# If the deflection is more than 3 degrees wait 5 seconds and check again.
|
|
|
|
##
|
|
|
|
if (abs(deviation) > 3.0)
|
|
|
|
{
|
|
|
|
#print("deviation");
|
|
|
|
settimer(aprArmFromRol, 5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# If the deviation is less than 3 degrees turn of the APR-ARM annunciator
|
|
|
|
# and show the APR annunciator. End of APR-ARM sequence. Start the GS-ARM
|
|
|
|
# sequence.
|
|
|
|
##
|
|
|
|
elsif (abs(deviation) < 3.1)
|
|
|
|
{
|
|
|
|
#print("capture");
|
|
|
|
annunciatorRol.setBoolValue(0);
|
|
|
|
annunciatorAprArm.setBoolValue(0);
|
|
|
|
annunciatorApr.setBoolValue(1);
|
|
|
|
|
|
|
|
lockAprHold.setBoolValue(1);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(1);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollMode.setIntValue(rollModes["APR"]);
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["GS"]);
|
|
|
|
|
|
|
|
gsArm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var gsArm = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
##
|
|
|
|
# Abort the GS-ARM mode if something has changed the arm mode to something
|
|
|
|
# else than GS-ARM.
|
|
|
|
##
|
|
|
|
if (lockPitchArm.getValue() != pitchArmModes["GS"])
|
|
|
|
{
|
|
|
|
annunciatorGsArm.setBoolValue(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
annunciatorGsArm.setBoolValue(1);
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var deviation = getprop(gsNeedleDeflection);
|
2007-02-04 12:55:28 +00:00
|
|
|
##
|
2009-09-09 10:49:36 +00:00
|
|
|
# If the deflection is more than 50% (manual says '2 to 3 dots')
|
2007-02-04 12:55:28 +00:00
|
|
|
##
|
2009-09-09 10:49:36 +00:00
|
|
|
if (abs(deviation) > 0.5)
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
#print("deviation");
|
|
|
|
settimer(gsArm, 5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
2009-09-09 10:49:36 +00:00
|
|
|
# If the deviation is less than 50% turn off the GS-ARM annunciator
|
2007-02-04 12:55:28 +00:00
|
|
|
# and show the GS annunciator. Activate the GS pitch mode.
|
|
|
|
##
|
2009-09-09 10:49:36 +00:00
|
|
|
else
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
#print("capture");
|
|
|
|
annunciatorAlt.setBoolValue(0);
|
|
|
|
annunciatorVs.setBoolValue(0);
|
|
|
|
annunciatorVsNumber.setBoolValue(0);
|
|
|
|
annunciatorGsArm.setBoolValue(0);
|
|
|
|
annunciatorGs.setBoolValue(1);
|
|
|
|
|
|
|
|
lockAltHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(1);
|
|
|
|
lockPitchMode.setIntValue(pitchModes["GS"]);
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["OFF"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var revButton = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
##print("revButton");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
##
|
|
|
|
# If we are in HDG mode we switch to the 45 degree intercept angle REV mode
|
|
|
|
##
|
|
|
|
if (lockRollMode.getValue() == rollModes["HDG"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
hdgFlasher.blink(8, 1).switch(0).switch(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(1);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["REV"]);
|
|
|
|
|
|
|
|
annunciatorRevArm.setBoolValue(1);
|
|
|
|
|
|
|
|
revArmFromHdg();
|
|
|
|
}
|
|
|
|
elsif (lockRollMode.getValue() == rollModes["ROL"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
hdgFlasher.blink(8).switch(0).switch(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(0);
|
|
|
|
lockHdgHold.setBoolValue(0);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["REV"]);
|
|
|
|
|
|
|
|
annunciatorRevArm.setBoolValue(1);
|
|
|
|
|
|
|
|
revArmFromRol();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var revArmFromHdg = func
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
##
|
|
|
|
# Abort the REV-ARM mode if something has changed the arm mode to something
|
|
|
|
# else than REV-ARM.
|
|
|
|
##
|
|
|
|
if (lockRollArm.getValue() != rollArmModes["REV"])
|
|
|
|
{
|
|
|
|
annunciatorRevArm.setBoolValue(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#annunciatorRevArm.setBoolValue(1);
|
|
|
|
##
|
|
|
|
# Wait for the HDG annunciator flashing to finish.
|
|
|
|
##
|
2007-04-26 18:04:51 +00:00
|
|
|
if (hdgFlasher.count)
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
#print("flashing...");
|
|
|
|
settimer(revArmFromHdg, 2.5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# Activate the rev-hold controller and check the needle deviation.
|
|
|
|
##
|
|
|
|
lockRevHold.setBoolValue(1);
|
2007-11-28 20:09:59 +00:00
|
|
|
var deviation = getprop(headingNeedleDeflection);
|
2007-02-04 12:55:28 +00:00
|
|
|
##
|
|
|
|
# If the deflection is more than 3 degrees wait 5 seconds and check again.
|
|
|
|
##
|
|
|
|
if (abs(deviation) > 3.0)
|
|
|
|
{
|
|
|
|
#print("deviation");
|
|
|
|
settimer(revArmFromHdg, 5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# If the deviation is less than 3 degrees turn of the REV-ARM annunciator
|
|
|
|
# and show the REV annunciator. End of REV-ARM sequence.
|
|
|
|
##
|
|
|
|
elsif (abs(deviation) < 3.1)
|
|
|
|
{
|
|
|
|
#print("capture");
|
|
|
|
annunciatorRevArm.setBoolValue(0);
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorHdg.getNode("state").setBoolValue(0);
|
2007-02-04 12:55:28 +00:00
|
|
|
annunciatorRev.setBoolValue(1);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
annunciatorRol.setBoolValue(0);
|
|
|
|
annunciatorRevArm.setBoolValue(0);
|
|
|
|
annunciatorRev.setBoolValue(1);
|
|
|
|
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(1);
|
|
|
|
lockHdgHold.setBoolValue(1);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollMode.setIntValue(rollModes["REV"]);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var revArmFromRol = func
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
##
|
|
|
|
# Abort the REV-ARM mode if something has changed the arm mode to something
|
|
|
|
# else than REV-ARM.
|
|
|
|
##
|
|
|
|
if (lockRollArm.getValue() != rollArmModes["REV"])
|
|
|
|
{
|
|
|
|
annunciatorRevArm.setBoolValue(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#annunciatorRevArm.setBoolValue(1);
|
|
|
|
##
|
|
|
|
# Wait for the HDG annunciator flashing to finish.
|
|
|
|
##
|
2007-04-26 18:04:51 +00:00
|
|
|
if (hdgFlasher.count)
|
2007-02-04 12:55:28 +00:00
|
|
|
{
|
|
|
|
#print("flashing...");
|
|
|
|
annunciatorRol.setBoolValue(0);
|
|
|
|
settimer(revArmFromRol, 2.5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# Turn the ROL annunciator back on and activate the ROL mode.
|
|
|
|
##
|
|
|
|
annunciatorRol.setBoolValue(1);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
settingTargetTurnRate.setDoubleValue(0.0);
|
2007-11-28 20:09:59 +00:00
|
|
|
var deviation = getprop(headingNeedleDeflection);
|
2007-02-04 12:55:28 +00:00
|
|
|
##
|
|
|
|
# If the deflection is more than 3 degrees wait 5 seconds and check again.
|
|
|
|
##
|
|
|
|
if (abs(deviation) > 3.0)
|
|
|
|
{
|
|
|
|
#print("deviation");
|
|
|
|
settimer(revArmFromRol, 5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
##
|
|
|
|
# If the deviation is less than 3 degrees turn of the REV-ARM annunciator
|
|
|
|
# and show the REV annunciator. End of REV-ARM sequence.
|
|
|
|
##
|
|
|
|
elsif (abs(deviation) < 3.1)
|
|
|
|
{
|
|
|
|
#print("capture");
|
|
|
|
annunciatorRol.setBoolValue(0);
|
|
|
|
annunciatorRevArm.setBoolValue(0);
|
|
|
|
annunciatorRev.setBoolValue(1);
|
|
|
|
|
|
|
|
lockAprHold.setBoolValue(0);
|
|
|
|
lockGsHold.setBoolValue(0);
|
|
|
|
lockRevHold.setBoolValue(1);
|
|
|
|
lockHdgHold.setBoolValue(1);
|
|
|
|
lockNavHold.setBoolValue(0);
|
|
|
|
lockRollAxis.setBoolValue(1);
|
|
|
|
lockRollMode.setIntValue(rollModes["REV"]);
|
|
|
|
lockRollArm.setIntValue(rollArmModes["OFF"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var altButtonTimer = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
#print("alt button timer");
|
|
|
|
#print(altButtonTimerIgnore);
|
|
|
|
|
|
|
|
if (altButtonTimerIgnore == 0)
|
|
|
|
{
|
|
|
|
annunciatorVsNumber.setBoolValue(0);
|
|
|
|
annunciatorAltNumber.setBoolValue(1);
|
|
|
|
|
|
|
|
altButtonTimerRunning = 0;
|
|
|
|
}
|
|
|
|
elsif (altButtonTimerIgnore > 0)
|
|
|
|
{
|
|
|
|
altButtonTimerIgnore = altButtonTimerIgnore - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var altButton = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
##print("altButton");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
if (lockPitchMode.getValue() == pitchModes["ALT"])
|
|
|
|
{
|
|
|
|
if (altButtonTimerRunning == 0)
|
|
|
|
{
|
|
|
|
settimer(altButtonTimer, 3.0);
|
|
|
|
altButtonTimerRunning = 1;
|
|
|
|
altButtonTimerIgnore = 0;
|
|
|
|
}
|
|
|
|
lockAltHold.setBoolValue(0);
|
|
|
|
|
|
|
|
lockPitchAxis.setBoolValue(1);
|
|
|
|
lockPitchMode.setIntValue(pitchModes["VS"]);
|
|
|
|
|
|
|
|
annunciatorAlt.setBoolValue(0);
|
|
|
|
annunciatorAltNumber.setBoolValue(0);
|
|
|
|
annunciatorVs.setBoolValue(1);
|
|
|
|
annunciatorVsNumber.setBoolValue(1);
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var pressureRate = getprop(internal, "pressure-rate");
|
|
|
|
var fpm = -pressureRate * 58000;
|
2007-02-04 12:55:28 +00:00
|
|
|
#print(fpm);
|
|
|
|
if (fpm > 0.0)
|
|
|
|
{
|
|
|
|
fpm = int(fpm/100 + 0.5) * 100;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fpm = int(fpm/100 - 0.5) * 100;
|
|
|
|
}
|
|
|
|
#print(fpm);
|
|
|
|
|
|
|
|
settingTargetPressureRate.setDoubleValue(-fpm / 58000);
|
|
|
|
|
|
|
|
}
|
|
|
|
elsif (lockPitchMode.getValue() == pitchModes["VS"])
|
|
|
|
{
|
|
|
|
lockAltHold.setBoolValue(1);
|
|
|
|
lockPitchAxis.setBoolValue(1);
|
|
|
|
lockPitchMode.setIntValue(pitchModes["ALT"]);
|
|
|
|
|
|
|
|
annunciatorAlt.setBoolValue(1);
|
|
|
|
annunciatorVs.setBoolValue(0);
|
|
|
|
annunciatorVsNumber.setBoolValue(0);
|
|
|
|
annunciatorAltNumber.setBoolValue(1);
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var altPressure = getprop(staticPressure);
|
2007-02-04 12:55:28 +00:00
|
|
|
settingTargetAltPressure.setDoubleValue(altPressure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var downButton = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
##print("downButton");# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
if (baroTimerRunning == 0)
|
|
|
|
{
|
|
|
|
if (lockPitchMode.getValue() == pitchModes["VS"])
|
|
|
|
{
|
|
|
|
if (altButtonTimerRunning == 0)
|
|
|
|
{
|
|
|
|
settimer(altButtonTimer, 3.0);
|
|
|
|
altButtonTimerRunning = 1;
|
|
|
|
altButtonTimerIgnore = 0;
|
|
|
|
}
|
|
|
|
elsif (altButtonTimerRunning == 1)
|
|
|
|
{
|
|
|
|
settimer(altButtonTimer, 3.0);
|
|
|
|
altButtonTimerIgnore = altButtonTimerIgnore + 1;
|
|
|
|
}
|
2007-11-28 20:09:59 +00:00
|
|
|
targetVS = settingTargetPressureRate.getValue();
|
2007-02-04 12:55:28 +00:00
|
|
|
settingTargetPressureRate.setDoubleValue(targetVS +
|
|
|
|
0.0017241379310345);
|
|
|
|
annunciatorAltNumber.setBoolValue(0);
|
|
|
|
annunciatorVsNumber.setBoolValue(1);
|
|
|
|
}
|
|
|
|
elsif (lockPitchMode.getValue() == pitchModes["ALT"])
|
|
|
|
{
|
2007-11-28 20:09:59 +00:00
|
|
|
var targetPressure = getprop(settings, "target-alt-pressure");
|
2007-02-04 12:55:28 +00:00
|
|
|
settingTargetAltPressure.setDoubleValue(targetPressure + 0.0206);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var upButton = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
##print("upButton");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
if (baroTimerRunning == 0)
|
|
|
|
{
|
|
|
|
if (lockPitchMode.getValue() == pitchModes["VS"])
|
|
|
|
{
|
|
|
|
if (altButtonTimerRunning == 0)
|
|
|
|
{
|
|
|
|
settimer(altButtonTimer, 3.0);
|
|
|
|
altButtonTimerRunning = 1;
|
|
|
|
altButtonTimerIgnore = 0;
|
|
|
|
}
|
|
|
|
elsif (altButtonTimerRunning == 1)
|
|
|
|
{
|
|
|
|
settimer(altButtonTimer, 3.0);
|
|
|
|
altButtonTimerIgnore = altButtonTimerIgnore + 1;
|
|
|
|
}
|
2007-11-28 20:09:59 +00:00
|
|
|
var targetVS = settingTargetPressureRate.getValue();
|
2007-02-04 12:55:28 +00:00
|
|
|
settingTargetPressureRate.setDoubleValue(targetVS -
|
|
|
|
0.0017241379310345);
|
|
|
|
annunciatorAltNumber.setBoolValue(0);
|
|
|
|
annunciatorVsNumber.setBoolValue(1);
|
|
|
|
}
|
|
|
|
elsif (lockPitchMode.getValue() == pitchModes["ALT"])
|
|
|
|
{
|
2007-11-28 20:09:59 +00:00
|
|
|
var targetPressure = getprop(settings, "target-alt-pressure");
|
2007-02-04 12:55:28 +00:00
|
|
|
settingTargetAltPressure.setDoubleValue(targetPressure - 0.0206);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var armButton = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
#print("arm button");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var pitchArm = lockPitchArm.getValue();
|
2007-02-04 12:55:28 +00:00
|
|
|
|
|
|
|
if (pitchArm == pitchArmModes["OFF"])
|
|
|
|
{
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["ALT"]);
|
|
|
|
|
|
|
|
annunciatorAltArm.setBoolValue(1);
|
|
|
|
}
|
|
|
|
elsif (pitchArm == pitchArmModes["ALT"])
|
|
|
|
{
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["OFF"]);
|
|
|
|
|
|
|
|
annunciatorAltArm.setBoolValue(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var baroButtonTimer = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
#print("baro button timer");
|
|
|
|
|
|
|
|
baroTimerRunning = 0;
|
|
|
|
if (baroButtonDown == 1)
|
|
|
|
{
|
|
|
|
baroSettingUnit = !baroSettingUnit;
|
|
|
|
baroButtonDown = 0;
|
|
|
|
baroButtonPress();
|
|
|
|
}
|
|
|
|
elsif (baroButtonDown == 0 and
|
|
|
|
baroSettingAdjusting == 0)
|
|
|
|
{
|
|
|
|
annunciatorBsHpaNumber.setBoolValue(0);
|
|
|
|
annunciatorBsInhgNumber.setBoolValue(0);
|
|
|
|
annunciatorAltNumber.setBoolValue(1);
|
|
|
|
}
|
|
|
|
elsif (baroSettingAdjusting == 1)
|
|
|
|
{
|
|
|
|
baroTimerRunning = 1;
|
|
|
|
baroSettingAdjusting = 0;
|
|
|
|
settimer(baroButtonTimer, 3.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var baroButtonPress = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
#print("baro putton press");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
if (baroButtonDown == 0 and
|
|
|
|
baroTimerRunning == 0 and
|
|
|
|
altButtonTimerRunning == 0)
|
|
|
|
{
|
|
|
|
baroButtonDown = 1;
|
|
|
|
baroTimerRunning = 1;
|
|
|
|
settimer(baroButtonTimer, 3.0);
|
|
|
|
annunciatorAltNumber.setBoolValue(0);
|
|
|
|
|
|
|
|
if (baroSettingUnit == pressureUnits["inHg"])
|
|
|
|
{
|
|
|
|
annunciatorBsInhgNumber.setBoolValue(1);
|
|
|
|
annunciatorBsHpaNumber.setBoolValue(0);
|
|
|
|
}
|
|
|
|
elsif (baroSettingUnit == pressureUnits["hPa"])
|
|
|
|
{
|
|
|
|
annunciatorBsHpaNumber.setBoolValue(1);
|
|
|
|
annunciatorBsInhgNumber.setBoolValue(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var baroButtonRelease = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
#print("baro button release");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
baroButtonDown = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var pow = func(base, exponent) {
|
2007-04-26 18:04:51 +00:00
|
|
|
#print(base,exponent);
|
|
|
|
return math.exp(exponent*math.ln(base));
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var pressureToHeight = func(p, p0) {
|
2007-03-31 09:38:18 +00:00
|
|
|
#
|
|
|
|
# kollsman shift due to baroSettingInhg =
|
|
|
|
# baroOffset = pressureToHeight(baroSettingInhg, 29.921260)
|
|
|
|
#
|
2007-11-28 20:09:59 +00:00
|
|
|
#var p0 = p0; # [Pa] or (p0 and p need to have the same units)
|
|
|
|
#var p = p; # [Pa] or (p0 and p need to have the same units)
|
|
|
|
var t0 = 288.15; # [K] same as in atmosphere.?xx
|
|
|
|
var LR = -0.0065; # [K/m] same as in atmosphere.?xx
|
|
|
|
var g = -9.80665; # [m/s²] same as in atmosphere.?xx
|
|
|
|
var Rd = 287.05307; # [J/kg K] same as in atmosphere.?xx to 8 places
|
|
|
|
var ftTom = 0.3048;
|
|
|
|
var coefficient = t0/LR/ftTom;
|
2007-03-31 09:38:18 +00:00
|
|
|
# coefficient = -145442.156;
|
2007-11-28 20:09:59 +00:00
|
|
|
var exponent = Rd*LR/g;
|
2007-03-31 09:38:18 +00:00
|
|
|
# exponent = 0.1902632365;
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var z = -coefficient * (1.0-pow((p/p0),exponent));
|
2007-02-04 12:55:28 +00:00
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-11 18:22:00 +00:00
|
|
|
var heightToPressure = func(z, p0) {
|
2007-11-28 20:09:59 +00:00
|
|
|
#var p0 = p0; # [Pa]
|
|
|
|
#var z = z; # [m]
|
|
|
|
var t0 = 288.15; # [K]
|
|
|
|
var LR = -0.0065; # [K/m]
|
|
|
|
var g = -9.80665; # [m/s²]
|
|
|
|
var Rd = 287.05307; # [J/kg K]
|
|
|
|
|
|
|
|
var p = p0 * pow(((t0+LR*z)/t0),(g/(Rd*LR)));
|
2007-02-04 12:55:28 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var altAlert = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
#print("alt alert");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var pressureAltitude = getprop(encoder, "pressure-alt-ft");
|
2007-03-31 09:38:18 +00:00
|
|
|
|
|
|
|
if (baroChange) {
|
|
|
|
baroOffset = pressureToHeight(baroSettingInhg, 29.921260);
|
|
|
|
baroChange = 0;
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var altFt = pressureAltitude - baroOffset;
|
|
|
|
var prevAltDifference = altDifference;
|
2007-02-04 12:55:28 +00:00
|
|
|
altDifference = abs(altPreselect - altFt);
|
|
|
|
|
|
|
|
if (altDifference > 1000)
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
annunciatorAltAlert.getNode("state").setBoolValue(0);
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
elsif (altDifference < 1000 and
|
|
|
|
altCaptured == 0)
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
if (!altAlertFlasher.count)
|
|
|
|
{
|
|
|
|
annunciatorAltAlert.getNode("state").setBoolValue(1);
|
|
|
|
}
|
|
|
|
if (!altAlertBeeper.count and prevAltDifference > 1000)
|
|
|
|
{
|
|
|
|
altAlertBeeper.blink(5).switch(0).switch(1);
|
|
|
|
}
|
2007-02-04 12:55:28 +00:00
|
|
|
if (altDifference < 200)
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
if (!altAlertFlasher.count)
|
|
|
|
{
|
|
|
|
annunciatorAltAlert.getNode("state").setBoolValue(0);
|
|
|
|
}
|
2007-02-04 12:55:28 +00:00
|
|
|
if (altDifference < 20)
|
|
|
|
{
|
|
|
|
#print("altCapture()");
|
|
|
|
altCaptured = 1;
|
|
|
|
|
|
|
|
if (lockPitchArm.getValue() == pitchArmModes["ALT"])
|
|
|
|
{
|
|
|
|
lockAltHold.setBoolValue(1);
|
|
|
|
lockPitchAxis.setBoolValue(1);
|
|
|
|
lockPitchMode.setIntValue(pitchModes["ALT"]);
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["OFF"]);
|
|
|
|
|
|
|
|
annunciatorAlt.setBoolValue(1);
|
|
|
|
annunciatorAltArm.setBoolValue(0);
|
|
|
|
annunciatorVs.setBoolValue(0);
|
|
|
|
annunciatorVsNumber.setBoolValue(0);
|
|
|
|
annunciatorAltNumber.setBoolValue(1);
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var altPressure = getprop(staticPressure);
|
2007-02-04 12:55:28 +00:00
|
|
|
settingTargetAltPressure.setDoubleValue(altPressure);
|
|
|
|
}
|
|
|
|
|
2007-04-26 18:04:51 +00:00
|
|
|
altAlertFlasher.blink(1).switch(0).switch(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (altDifference < 1000 and
|
|
|
|
altCaptured == 1)
|
|
|
|
{
|
|
|
|
if (altDifference > 200)
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
altAlertFlasher.blink(5, 1).switch(0).switch(1);
|
|
|
|
altAlertBeeper.blink(5).switch(0).switch(1);
|
2007-02-04 12:55:28 +00:00
|
|
|
altCaptured = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settimer(altAlert, 2.0);
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var adjustBaroSettingInhg = func(amount) {
|
2007-04-26 18:04:51 +00:00
|
|
|
# Adjust baro setting inHg by amount,
|
|
|
|
# and sync baro setting hPa.
|
|
|
|
baroSettingInhg = baroSettingInhg + amount;
|
|
|
|
baroSettingHpa = baroSettingInhg * 0.03386389;
|
|
|
|
|
|
|
|
settingBaroSettingHpa.setDoubleValue(baroSettingHpa);
|
|
|
|
settingBaroSettingInhg.setDoubleValue(baroSettingInhg);
|
|
|
|
baroChange = 1;
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var adjustbaroSettingHpa = func(amount) {
|
2007-04-26 18:04:51 +00:00
|
|
|
# Adjust baro setting hPa by amount,
|
|
|
|
# and sync baro setting inHg.
|
|
|
|
baroSettingHpa = baroSettingHpa + amount;
|
|
|
|
baroSettingInhg = baroSettingHpa / 0.03386389;
|
|
|
|
|
|
|
|
settingBaroSettingHpa.setDoubleValue(baroSettingHpa);
|
|
|
|
settingBaroSettingInhg.setDoubleValue(baroSettingInhg);
|
|
|
|
baroChange = 1;
|
|
|
|
}
|
2007-02-04 12:55:28 +00:00
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var knobSmallUp = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
#print("knob small up");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
if (baroTimerRunning == 1)
|
|
|
|
{
|
|
|
|
baroSettingAdjusting = 1;
|
|
|
|
if (baroSettingUnit == pressureUnits["inHg"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
adjustBaroSettingInhg(0.01);
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
elsif (baroSettingUnit == pressureUnits["hPa"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
adjustbaroSettingHpa(0.001);
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (baroTimerRunning == 0 and
|
|
|
|
altButtonTimerRunning == 0)
|
|
|
|
{
|
|
|
|
altCaptured = 0;
|
|
|
|
altPreselect = altPreselect + 20;
|
|
|
|
settingTargetAltFt.setDoubleValue(altPreselect);
|
|
|
|
|
|
|
|
if (lockRollMode.getValue() == rollModes["OFF"] and
|
|
|
|
lockPitchMode.getValue() == pitchModes["OFF"])
|
|
|
|
{
|
|
|
|
annunciatorAltNumber.setBoolValue(1);
|
|
|
|
if (altAlertOn == 0)
|
|
|
|
{
|
|
|
|
altAlertOn = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (lockPitchArm.getValue() == pitchArmModes["OFF"])
|
|
|
|
{
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["ALT"]);
|
|
|
|
annunciatorAltArm.setBoolValue(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var knobLargeUp = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
#print("knob large up");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
if (baroTimerRunning == 1)
|
|
|
|
{
|
|
|
|
baroSettingAdjusting = 1;
|
|
|
|
if (baroSettingUnit == pressureUnits["inHg"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
adjustBaroSettingInhg(1.0);
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
elsif (baroSettingUnit == pressureUnits["hPa"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
adjustbaroSettingHpa(0.1);
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (baroTimerRunning == 0 and
|
|
|
|
altButtonTimerRunning == 0)
|
|
|
|
{
|
|
|
|
altCaptured = 0;
|
|
|
|
altPreselect = altPreselect + 100;
|
|
|
|
settingTargetAltFt.setDoubleValue(altPreselect);
|
|
|
|
|
|
|
|
if (lockRollMode.getValue() == rollModes["OFF"] and
|
|
|
|
lockPitchMode.getValue() == pitchModes["OFF"])
|
|
|
|
{
|
|
|
|
annunciatorAltNumber.setBoolValue(1);
|
|
|
|
if (altAlertOn == 0)
|
|
|
|
{
|
|
|
|
altAlertOn = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (lockPitchArm.getValue() == pitchArmModes["OFF"])
|
|
|
|
{
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["ALT"]);
|
|
|
|
annunciatorAltArm.setBoolValue(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var knobSmallDown = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
#print("knob small down");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
if (baroTimerRunning == 1)
|
|
|
|
{
|
|
|
|
baroSettingAdjusting = 1;
|
|
|
|
if (baroSettingUnit == pressureUnits["inHg"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
adjustBaroSettingInhg(-0.01);
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
elsif (baroSettingUnit == pressureUnits["hPa"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
adjustbaroSettingHpa(-0.001);
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (baroTimerRunning == 0 and
|
|
|
|
altButtonTimerRunning == 0)
|
|
|
|
{
|
|
|
|
altCaptured = 0;
|
|
|
|
altPreselect = altPreselect - 20;
|
|
|
|
settingTargetAltFt.setDoubleValue(altPreselect);
|
|
|
|
|
|
|
|
if (lockRollMode.getValue() == rollModes["OFF"] and
|
|
|
|
lockPitchMode.getValue() == pitchModes["OFF"])
|
|
|
|
{
|
|
|
|
annunciatorAltNumber.setBoolValue(1);
|
|
|
|
if (altAlertOn == 0)
|
|
|
|
{
|
|
|
|
altAlertOn = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (lockPitchArm.getValue() == pitchArmModes["OFF"])
|
|
|
|
{
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["ALT"]);
|
|
|
|
annunciatorAltArm.setBoolValue(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-28 20:09:59 +00:00
|
|
|
var knobLargeDown = func {
|
2007-02-04 12:55:28 +00:00
|
|
|
#print("knob large down");
|
|
|
|
# Disable button if too little power
|
|
|
|
if (getprop(power) < minVoltageLimit) { return; }
|
|
|
|
|
|
|
|
if (baroTimerRunning == 1)
|
|
|
|
{
|
|
|
|
baroSettingAdjusting = 1;
|
|
|
|
if (baroSettingUnit == pressureUnits["inHg"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
adjustBaroSettingInhg(-1.0);
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
elsif (baroSettingUnit == pressureUnits["hPa"])
|
|
|
|
{
|
2007-04-26 18:04:51 +00:00
|
|
|
adjustbaroSettingHpa(-0.1);
|
2007-02-04 12:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (baroTimerRunning == 0 and
|
|
|
|
altButtonTimerRunning == 0)
|
|
|
|
{
|
|
|
|
altCaptured = 0;
|
|
|
|
altPreselect = altPreselect - 100;
|
|
|
|
settingTargetAltFt.setDoubleValue(altPreselect);
|
|
|
|
|
|
|
|
if (lockRollMode.getValue() == rollModes["OFF"] and
|
|
|
|
lockPitchMode.getValue() == pitchModes["OFF"])
|
|
|
|
{
|
|
|
|
annunciatorAltNumber.setBoolValue(1);
|
|
|
|
if (altAlertOn == 0)
|
|
|
|
{
|
|
|
|
altAlertOn = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (lockPitchArm.getValue() == pitchArmModes["OFF"])
|
|
|
|
{
|
|
|
|
lockPitchArm.setIntValue(pitchArmModes["ALT"]);
|
|
|
|
annunciatorAltArm.setBoolValue(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var L = setlistener(power, func {
|
|
|
|
apPower();
|
|
|
|
removelistener(L);
|
|
|
|
});
|