System: Fix AP Master logic

This commit is contained in:
Joshua Davidson 2018-12-07 16:01:01 -05:00
parent 9e12238b9b
commit 931e753ddb
2 changed files with 103 additions and 30 deletions

View file

@ -95,6 +95,14 @@ var APinit = func {
# AP 1 Master System
setlistener("/it-autoflight/input/ap1", func {
var apmas = getprop("/it-autoflight/input/ap1");
var apout = getprop("/it-autoflight/output/ap1");
if (apmas != apout) {
AP1Master();
}
});
var AP1Master = func {
var apmas = getprop("/it-autoflight/input/ap1");
var ac_ess = getprop("/systems/electrical/bus/ac-ess");
var law = getprop("/it-fbw/law");
@ -127,10 +135,24 @@ setlistener("/it-autoflight/input/ap1", func {
fmabox();
}
}
});
var apout = getprop("/it-autoflight/output/ap1");
if (apmas != apout) {
setprop("/it-autoflight/input/ap1", apout);
}
}
# AP 2 Master System
setlistener("/it-autoflight/input/ap2", func {
var apmas = getprop("/it-autoflight/input/ap2");
var apout = getprop("/it-autoflight/output/ap2");
if (apmas != apout) {
AP2Master();
}
});
var AP2Master = func {
var apmas = getprop("/it-autoflight/input/ap2");
var ac_ess = getprop("/systems/electrical/bus/ac-ess");
var law = getprop("/it-fbw/law");
@ -163,44 +185,95 @@ setlistener("/it-autoflight/input/ap2", func {
fmabox();
}
}
var apout = getprop("/it-autoflight/output/ap2");
if (apmas != apout) {
setprop("/it-autoflight/input/ap2", apout);
}
}
# ATHR Master System
setlistener("/it-autoflight/input/athr", func {
var athrmas = getprop("/it-autoflight/input/athr");
var athrout = getprop("/it-autoflight/output/athr");
if (athrmas != athrout) {
ATHRMaster();
}
});
# AT Master System
setlistener("/it-autoflight/input/athr", func {
var atmas = getprop("/it-autoflight/input/athr");
if (atmas == 0) {
var ATHRMaster = func {
var athrmas = getprop("/it-autoflight/input/athr");
if (athrmas == 0) {
setprop("/it-autoflight/output/athr", 0);
} else if (atmas == 1) {
} else if (athrmas == 1) {
thrustmode();
setprop("/it-autoflight/output/athr", 1);
}
});
var athrout = getprop("/it-autoflight/output/athr");
if (athrmas != athrout) {
setprop("/it-autoflight/input/athr", athrout);
}
}
# Flight Director 1 Master System
setlistener("/it-autoflight/input/fd1", func {
var fdmas = getprop("/it-autoflight/input/fd1");
var fdout = getprop("/it-autoflight/output/fd1");
if (fdmas != fdout) {
FD1Master();
}
});
var FD1Master = func {
var fdmas = getprop("/it-autoflight/input/fd1");
if (fdmas == 0) {
setprop("/it-autoflight/output/fd1", 0);
fmabox();
if (getprop("/it-autoflight/output/fd1") == 0 and getprop("/it-autoflight/output/fd2") == 0) {
fmabox();
}
updateTimers();
} else if (fdmas == 1) {
setprop("/it-autoflight/output/fd1", 1);
fmabox();
}
});
var fdout = getprop("/it-autoflight/output/fd1");
if (fdmas != fdout) {
setprop("/it-autoflight/input/fd1", fdout);
}
}
# Flight Director 2 Master System
setlistener("/it-autoflight/input/fd2", func {
var fdmas = getprop("/it-autoflight/input/fd2");
var fdout = getprop("/it-autoflight/output/fd2");
if (fdmas != fdout) {
FD2Master();
}
});
var FD2Master = func {
var fdmas = getprop("/it-autoflight/input/fd2");
if (fdmas == 0) {
setprop("/it-autoflight/output/fd2", 0);
fmabox();
if (getprop("/it-autoflight/output/fd1") == 0 and getprop("/it-autoflight/output/fd2") == 0) {
fmabox();
}
updateTimers();
} else if (fdmas == 1) {
setprop("/it-autoflight/output/fd2", 1);
fmabox();
}
});
var fdout = getprop("/it-autoflight/output/fd2");
if (fdmas != fdout) {
setprop("/it-autoflight/input/fd2", fdout);
}
}
# FMA Boxes and Mode
var fmabox = func {
@ -415,7 +488,7 @@ var vertical = func {
alandt.stop();
alandt1.stop();
mng_sys_stop();
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var alt = getprop("/it-autoflight/internal/alt");
var dif = calt - alt;
vsnow = getprop("/it-autoflight/internal/vert-speed-fpm");
@ -435,7 +508,7 @@ var vertical = func {
setprop("/it-autoflight/output/appr-armed", 0);
var altinput = getprop("/it-autoflight/input/alt");
setprop("/it-autoflight/internal/alt", altinput);
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var alt = getprop("/it-autoflight/internal/alt");
var dif = calt - alt;
if (dif < 250 and dif > -250) {
@ -689,7 +762,7 @@ setlistener("/it-autoflight/input/toga", func {
var togasel = func {
if ((getprop("/gear/gear[1]/wow") == 0) and (getprop("/gear/gear[2]/wow") == 0)) {
var iasnow = math.round(getprop("/instrumentation/airspeed-indicator/indicated-speed-kt"));
var iasnow = math.round(getprop("/instrumentation/airspeed-indicator[0]/indicated-speed-kt"));
setprop("/it-autoflight/input/spd-kts", iasnow);
setprop("/it-autoflight/input/kts-mach", 0);
setprop("/it-autoflight/mode/vert", "G/A CLB");
@ -712,7 +785,7 @@ setlistener("/it-autoflight/mode/vert", func {
});
var toga_reduc = func {
if (getprop("/instrumentation/altimeter/indicated-altitude-ft") >= getprop("/it-autoflight/settings/reduc-agl-ft") and getprop("/gear/gear[1]/wow") == 0 and getprop("/gear/gear[2]/wow") == 0) {
if (getprop("/instrumentation/altimeter[0]/indicated-altitude-ft") >= getprop("/it-autoflight/settings/reduc-agl-ft") and getprop("/gear/gear[1]/wow") == 0 and getprop("/gear/gear[2]/wow") == 0) {
setprop("/it-autoflight/input/vert", 4);
}
}
@ -751,7 +824,7 @@ var altcapt = func {
setprop("/it-autoflight/internal/captvs", math.round(abs(vsnow) / 5, 100));
setprop("/it-autoflight/internal/captvsneg", -1 * math.round(abs(vsnow) / 5, 100));
if ((getprop("/it-autoflight/output/fd1") == 1 or getprop("/it-autoflight/output/fd2") == 1 or getprop("/it-autoflight/output/ap1") == 1 or getprop("/it-autoflight/output/ap2") == 1) and getprop("/it-autoflight/output/vert") != 9) {
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var alt = getprop("/it-autoflight/internal/alt");
var dif = calt - alt;
if (dif < getprop("/it-autoflight/internal/captvs") and dif > getprop("/it-autoflight/internal/captvsneg")) {
@ -772,7 +845,7 @@ var altcapt = func {
# Min and Max Pitch Reset
var minmax = func {
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var alt = getprop("/it-autoflight/internal/alt");
var dif = calt - alt;
if (dif < 50 and dif > -50) {
@ -790,7 +863,7 @@ var minmax = func {
# Thrust Mode Selector
var thrustmode = func {
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var alt = getprop("/it-autoflight/internal/alt");
if (getprop("/it-autoflight/output/vert") == 4) {
if (calt < alt) {
@ -997,7 +1070,7 @@ var mng_run = func {
var mng_alt_wp = getprop("/autopilot/route-manager/route/wp",wp_curr,"altitude-ft");
if ((wptnum - 1) < getprop("/autopilot/route-manager/route/num")) {
var mng_alt_wp_prev = getprop("/autopilot/route-manager/route/wp",wp_curr - 1,"altitude-ft");
var altcurr = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var altcurr = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
if (mng_alt_wp_prev >= 100) {
if (mng_alt_wp_prev > mng_alt_wp) {
mng_des_todt.start();
@ -1031,7 +1104,7 @@ var mng_run = func {
}
if (mng_alt_wp >= 100) {
if (getprop("/it-autoflight/internal/mng-mode") == "CLB") {
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var valt = getprop("/it-autoflight/internal/mng-alt");
var vdif = calt - valt;
if (vdif > 250 or vdif < -250) {
@ -1040,7 +1113,7 @@ var mng_run = func {
mng_alt_sel();
}
} else if (getprop("/it-autoflight/internal/mng-mode") == "DES") {
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var valt = getprop("/it-autoflight/internal/mng-alt");
var vdif = calt - valt;
if (vdif > 250 or vdif < -250) {
@ -1064,7 +1137,7 @@ var mng_des_tod = func {
if (getprop("/autopilot/route-manager/route/num") > 0 and getprop("/autopilot/route-manager/active") == 1) {
var wp_curr = getprop("/autopilot/route-manager/current-wp");
var mng_alt_wp = getprop("/autopilot/route-manager/route/wp",wp_curr,"altitude-ft");
var alt_curr = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var alt_curr = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var dist = getprop("/autopilot/route-manager/wp/dist");
var vdist = dist + 1;
var alttl = abs(alt_curr - mng_alt_wp);
@ -1073,7 +1146,7 @@ var mng_des_tod = func {
mng_des_todt.stop();
var salt = getprop("/it-autoflight/internal/alt");
var valt = getprop("/it-autoflight/internal/alt-const");
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var sdif = abs(calt - salt);
var vdif = abs(calt - valt);
if (sdif <= vdif) {
@ -1081,7 +1154,7 @@ var mng_des_tod = func {
} else if (sdif > vdif) {
setprop("/it-autoflight/internal/mng-alt", getprop("/it-autoflight/internal/alt-const"));
}
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var valt = getprop("/it-autoflight/internal/mng-alt");
var vdif = calt - valt;
if (vdif > 550 or vdif < -550) {
@ -1097,7 +1170,7 @@ var mng_des_tod = func {
var mng_alt_selector = func {
var salt = getprop("/it-autoflight/internal/alt");
var valt = getprop("/it-autoflight/internal/alt-const");
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var sdif = abs(calt - salt);
var vdif = abs(calt - valt);
if (getprop("/it-autoflight/internal/mng-mode") == "CLB") {
@ -1174,7 +1247,7 @@ var mng_altcapt = func {
var MCPalt = getprop("/it-autoflight/internal/alt");
var MNGdif = abs(MNGalt - MCPalt);
if (MNGdif <= 20) {
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var alt = getprop("/it-autoflight/internal/alt");
var dif = calt - alt;
if (dif < getprop("/it-autoflight/internal/captvs") and dif > getprop("/it-autoflight/internal/captvsneg")) {
@ -1187,7 +1260,7 @@ var mng_altcapt = func {
}
}
} else {
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var valt = getprop("/it-autoflight/internal/mng-alt");
var vdif = calt - valt;
if (vdif < getprop("/it-autoflight/internal/captvs") and vdif > getprop("/it-autoflight/internal/captvsneg")) {
@ -1205,7 +1278,7 @@ var mng_capture_alt = func {
vsnow = getprop("/it-autoflight/internal/vert-speed-fpm");
mng_altcaptt.stop();
mng_des_fpmt.stop();
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var alt = getprop("/it-autoflight/internal/alt");
var valt = getprop("/it-autoflight/internal/mng-alt");
if (calt < valt) {
@ -1222,7 +1295,7 @@ var mng_capture_alt = func {
# Managed Min and Max Pitch Reset
var mng_minmax = func {
var calt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
var calt = getprop("/instrumentation/altimeter[0]/indicated-altitude-ft");
var valt = getprop("/it-autoflight/internal/mng-alt");
var vdif = calt - valt;
if (vdif < 50 and vdif > -50) {

View file

@ -1 +1 @@
4705
4707