2017-06-10 14:56:11 +00:00
# Airbus A3XX FBW/Flight Control Computer System
# Joshua Davidson (it0uchpods)
2017-04-09 16:46:30 +00:00
2018-12-20 01:55:02 +00:00
# Copyright (c) 2018 Joshua Davidson (it0uchpods)
2017-07-13 17:30:33 +00:00
2017-06-10 15:57:48 +00:00
# If All ELACs Fail, Alternate Law
2017-11-29 04:11:23 +00:00
setprop("/it-fbw/roll-back", 0);
setprop("/it-fbw/spd-hold", 0);
setprop("/it-fbw/protections/overspeed", 0);
setprop("/it-fbw/protections/overspeed-roll-back", 0);
setprop("/it-fbw/speeds/vmo-mmo", 350);
var mmoIAS = 0;
2017-06-10 15:57:48 +00:00
var fctlInit = func {
setprop("/controls/fctl/elac1", 1);
setprop("/controls/fctl/elac2", 1);
setprop("/controls/fctl/sec1", 1);
setprop("/controls/fctl/sec2", 1);
setprop("/controls/fctl/sec3", 1);
setprop("/controls/fctl/fac1", 1);
setprop("/controls/fctl/fac2", 1);
setprop("/systems/fctl/elac1", 0);
setprop("/systems/fctl/elac2", 0);
setprop("/systems/fctl/sec1", 0);
setprop("/systems/fctl/sec2", 0);
2017-07-05 02:20:23 +00:00
setprop("/systems/fctl/sec3", 0);
2017-06-10 15:57:48 +00:00
setprop("/systems/fctl/fac1", 0);
setprop("/systems/fctl/fac2", 0);
2017-07-05 02:20:23 +00:00
setprop("/it-fbw/degrade-law", 0);
2017-11-29 04:11:23 +00:00
setprop("/it-fbw/override", 0);
setprop("/it-fbw/law", 0);
updatet.start();
fbwt.start();
2017-06-10 15:57:48 +00:00
}
2017-05-03 02:16:53 +00:00
var update_loop = func {
2017-06-10 15:57:48 +00:00
var elac1_sw = getprop("/controls/fctl/elac1");
var elac2_sw = getprop("/controls/fctl/elac2");
2018-04-12 16:54:25 +00:00
var sec1_sw = getprop("/controls/fctl/sec1");
var sec2_sw = getprop("/controls/fctl/sec2");
var sec3_sw = getprop("/controls/fctl/sec3");
var fac1_sw = getprop("/controls/fctl/fac1");
var fac2_sw = getprop("/controls/fctl/fac2");
2017-06-10 15:57:48 +00:00
2018-04-12 16:54:25 +00:00
var elac1_fail = getprop("/systems/failures/elac1");
var elac2_fail = getprop("/systems/failures/elac2");
var sec1_fail = getprop("/systems/failures/sec1");
var sec2_fail = getprop("/systems/failures/sec2");
var sec3_fail = getprop("/systems/failures/sec3");
var fac1_fail = getprop("/systems/failures/fac1");
var fac2_fail = getprop("/systems/failures/fac2");
2018-03-24 13:52:19 +00:00
2018-04-12 16:54:25 +00:00
var ac_ess = getprop("/systems/electrical/bus/ac-ess");
var dc_ess = getprop("/systems/electrical/bus/dc-ess");
2018-03-24 13:52:19 +00:00
var dc_ess_shed = getprop("/systems/electrical/bus/dc-ess-shed");
2018-04-12 16:54:25 +00:00
var ac1 = getprop("/systems/electrical/bus/ac1");
var ac2 = getprop("/systems/electrical/bus/ac2");
var dc1 = getprop("/systems/electrical/bus/dc1");
var dc2 = getprop("/systems/electrical/bus/dc2");
2018-03-24 13:52:19 +00:00
var battery1_sw = getprop("/controls/electrical/switches/battery1");
var battery2_sw = getprop("/controls/electrical/switches/battery2");
2018-04-12 16:54:25 +00:00
var elac1_test = getprop("/systems/electrical/elac1-test");
var elac2_test = getprop("/systems/electrical/elac2-test");
2017-06-10 15:57:48 +00:00
2018-03-24 17:43:41 +00:00
if (elac1_sw and !elac1_fail and (dc_ess >= 25 or battery1_sw) and !elac1_test) {
2017-06-10 15:57:48 +00:00
setprop("/systems/fctl/elac1", 1);
2018-03-24 17:43:41 +00:00
setprop("/systems/failures/elac1-fault", 0);
} else if (elac1_sw and (elac1_fail or (dc_ess < 25 and !battery1_sw)) and !elac1_test) {
setprop("/systems/failures/elac1-fault", 1);
2017-06-10 15:57:48 +00:00
setprop("/systems/fctl/elac1", 0);
2018-03-24 17:43:41 +00:00
} else if (!elac1_test) {
setprop("/systems/failures/elac1-fault", 0);
setprop("/systems/fctl/elac1", 1);
2017-06-10 15:57:48 +00:00
}
2018-03-24 17:43:41 +00:00
if (elac2_sw and !elac2_fail and (dc2 >= 25 or battery2_sw) and !elac2_test) {
2017-06-10 15:57:48 +00:00
setprop("/systems/fctl/elac2", 1);
2018-03-24 17:43:41 +00:00
setprop("/systems/failures/elac2-fault", 0);
} else if (elac2_sw and (elac2_fail or (dc2 < 25 and !battery2_sw)) and !elac2_test) {
setprop("/systems/failures/elac2-fault", 1);
2017-06-10 15:57:48 +00:00
setprop("/systems/fctl/elac2", 0);
2018-03-24 17:43:41 +00:00
} else if (!elac2_test) {
setprop("/systems/failures/elac2-fault", 0);
setprop("/systems/fctl/elac2", 1);
2017-06-10 15:57:48 +00:00
}
2017-07-05 04:59:45 +00:00
if (sec1_sw and !sec1_fail and ac_ess >= 110) {
2017-06-10 15:57:48 +00:00
setprop("/systems/fctl/sec1", 1);
2017-07-05 03:37:40 +00:00
setprop("/systems/failures/spoiler-l3", 0);
setprop("/systems/failures/spoiler-r3", 0);
setprop("/systems/failures/spoiler-l4", 0);
setprop("/systems/failures/spoiler-r4", 0);
2017-06-10 15:57:48 +00:00
} else {
setprop("/systems/fctl/sec1", 0);
2017-07-05 03:37:40 +00:00
setprop("/systems/failures/spoiler-l3", 1);
setprop("/systems/failures/spoiler-r3", 1);
setprop("/systems/failures/spoiler-l4", 1);
setprop("/systems/failures/spoiler-r4", 1);
2017-06-10 15:57:48 +00:00
}
2017-07-05 04:59:45 +00:00
if (sec2_sw and !sec2_fail and ac_ess >= 110) {
2017-06-10 15:57:48 +00:00
setprop("/systems/fctl/sec2", 1);
2017-07-05 03:37:40 +00:00
setprop("/systems/failures/spoiler-l5", 0);
setprop("/systems/failures/spoiler-r5", 0);
2017-06-10 15:57:48 +00:00
} else {
setprop("/systems/fctl/sec2", 0);
2017-07-05 03:37:40 +00:00
setprop("/systems/failures/spoiler-l5", 1);
setprop("/systems/failures/spoiler-r5", 1);
2017-06-10 15:57:48 +00:00
}
2017-07-05 04:59:45 +00:00
if (sec3_sw and !sec3_fail and ac_ess >= 110) {
2017-06-10 15:57:48 +00:00
setprop("/systems/fctl/sec3", 1);
2017-07-08 21:28:33 +00:00
setprop("/systems/failures/spoiler-l1", 0);
setprop("/systems/failures/spoiler-r1", 0);
2017-07-05 03:37:40 +00:00
setprop("/systems/failures/spoiler-l2", 0);
setprop("/systems/failures/spoiler-r2", 0);
2017-06-10 15:57:48 +00:00
} else {
setprop("/systems/fctl/sec3", 0);
2017-07-08 21:28:33 +00:00
setprop("/systems/failures/spoiler-l1", 1);
setprop("/systems/failures/spoiler-r1", 1);
2017-07-05 03:37:40 +00:00
setprop("/systems/failures/spoiler-l2", 1);
setprop("/systems/failures/spoiler-r2", 1);
2017-06-10 15:57:48 +00:00
}
2018-03-24 13:52:19 +00:00
if (fac1_sw and !fac1_fail and (ac_ess >= 110 or dc_ess_shed >= 25)) {
2017-06-10 15:57:48 +00:00
setprop("/systems/fctl/fac1", 1);
2017-07-05 03:37:40 +00:00
setprop("/systems/failures/rudder", 0);
2018-03-24 13:52:19 +00:00
setprop("/systems/failures/fac1-fault", 0);
} else if (fac1_sw and (battery1_sw or battery2_sw) and (fac1_fail or ac_ess < 110 or dc_ess_shed < 25)) {
setprop("/systems/failures/fac1-fault", 1);
setprop("/systems/fctl/fac1", 0);
if (!fac2_sw or fac2_fail) {
setprop("/systems/failures/rudder", 1);
}
2017-06-10 15:57:48 +00:00
} else {
2018-03-24 13:52:19 +00:00
setprop("/systems/failures/fac1-fault", 0);
2017-06-10 15:57:48 +00:00
setprop("/systems/fctl/fac1", 0);
2017-07-05 03:37:40 +00:00
if (!fac2_sw or fac2_fail) {
setprop("/systems/failures/rudder", 1);
}
2017-06-10 15:57:48 +00:00
}
2018-03-24 13:52:19 +00:00
if (fac2_sw and !fac2_fail and (ac2 >= 110 or dc2 >= 25)) {
2017-06-10 15:57:48 +00:00
setprop("/systems/fctl/fac2", 1);
2018-03-24 13:52:19 +00:00
setprop("/systems/failures/fac2-fault", 0);
} else if (fac2_sw and (fac2_fail or ac2 < 110 or dc2 < 25)) {
setprop("/systems/failures/fac2-fault", 1);
setprop("/systems/fctl/fac2", 0);
if (!fac1_sw or fac1_fail) {
setprop("/systems/failures/rudder", 1);
}
2017-06-10 15:57:48 +00:00
} else {
setprop("/systems/fctl/fac2", 0);
2018-03-24 13:52:19 +00:00
setprop("/systems/failures/fac2-fault", 0);
2017-07-05 03:37:40 +00:00
if (!fac1_sw or fac1_fail) {
setprop("/systems/failures/rudder", 1);
}
2017-06-10 15:57:48 +00:00
}
2017-07-05 02:20:23 +00:00
var elac1 = getprop("/systems/fctl/elac1");
var elac2 = getprop("/systems/fctl/elac2");
var sec1 = getprop("/systems/fctl/sec1");
var sec2 = getprop("/systems/fctl/sec2");
var sec3 = getprop("/systems/fctl/sec3");
var fac1 = getprop("/systems/fctl/fac1");
var fac2 = getprop("/systems/fctl/fac2");
var law = getprop("/it-fbw/law");
# Degrade logic, all failures which degrade FBW need to go here. -JD
if (getprop("/gear/gear[1]/wow") == 0 and getprop("/gear/gear[2]/wow") == 0) {
if (!elac1 and !elac2) {
if (law == 0) {
setprop("/it-fbw/degrade-law", 1);
}
2017-07-05 04:59:45 +00:00
}
if (getprop("/systems/electrical/bus/ac-ess") >= 110 and getprop("/systems/hydraulic/blue-psi") >= 1500 and getprop("/systems/hydraulic/green-psi") < 1500 and getprop("/systems/hydraulic/yellow-psi") < 1500) {
2017-07-05 02:20:23 +00:00
if (law == 0 or law == 1) {
setprop("/it-fbw/degrade-law", 2);
}
2017-07-05 04:59:45 +00:00
}
if (getprop("/systems/electrical/bus/ac-ess") < 110 or (getprop("/systems/hydraulic/blue-psi") < 1500 and getprop("/systems/hydraulic/green-psi") < 1500 and getprop("/systems/hydraulic/yellow-psi") < 1500)) {
2017-07-05 02:20:23 +00:00
setprop("/it-fbw/degrade-law", 3);
}
}
2017-07-11 00:07:38 +00:00
if (getprop("/controls/gear/gear-down") == 1 and getprop("/it-autoflight/output/ap1") == 0 and getprop("/it-autoflight/output/ap2") == 0) {
2017-07-05 04:59:45 +00:00
if (law == 1) {
setprop("/it-fbw/degrade-law", 2);
}
}
2017-07-05 02:20:23 +00:00
var law = getprop("/it-fbw/law");
# Mech Backup can always return to direct, if it can.
2017-12-26 18:48:52 +00:00
if (law == 3 and getprop("/systems/electrical/bus/ac-ess") >= 110 and (getprop("/systems/hydraulic/green-psi") >= 1500 or getprop("/systems/hydraulic/blue-psi") >= 1500 or getprop("/systems/hydraulic/yellow-psi") >= 1500)) {
2017-07-05 02:20:23 +00:00
setprop("/it-fbw/degrade-law", 2);
}
2017-11-29 04:11:23 +00:00
mmoIAS = (getprop("/instrumentation/airspeed-indicator/indicated-speed-kt") / getprop("/instrumentation/airspeed-indicator/indicated-mach")) * 0.82;
if (mmoIAS < 350) {
setprop("/it-fbw/speeds/vmo-mmo", mmoIAS);
} else {
setprop("/it-fbw/speeds/vmo-mmo", 350);
}
2017-11-29 16:27:25 +00:00
if (getprop("/instrumentation/airspeed-indicator/indicated-speed-kt") > getprop("/it-fbw/speeds/vmo-mmo") + 6 and (law == 0 or law == 1)) {
2017-11-29 04:11:23 +00:00
if (getprop("/it-fbw/protections/overspeed") != 1) {
setprop("/it-fbw/protections/overspeed", 1);
}
if (getprop("/it-autoflight/output/ap1") == 1) {
setprop("/it-autoflight/input/ap1", 0);
}
if (getprop("/it-autoflight/output/ap2") == 1) {
setprop("/it-autoflight/input/ap2", 0);
}
2018-12-07 17:52:42 +00:00
libraries.apOff("hard", 0);
2017-11-29 04:11:23 +00:00
} else {
if (getprop("/it-fbw/protections/overspeed") != 0) {
setprop("/it-fbw/protections/overspeed", 0);
}
}
2017-07-05 02:20:23 +00:00
}
var fbw_loop = func {
2017-04-10 23:08:55 +00:00
var ail = getprop("/controls/flight/aileron");
2017-04-06 19:06:35 +00:00
2018-06-05 02:20:26 +00:00
if (ail > 0.4 and getprop("/orientation/roll-deg") >= -33.5) {
setprop("/it-fbw/roll-lim", "67");
if (getprop("/it-fbw/roll-back") == 1 and getprop("/orientation/roll-deg") <= 33.5 and getprop("/orientation/roll-deg") >= -33.5) {
setprop("/it-fbw/roll-back", 0);
}
if (getprop("/it-fbw/roll-back") == 0 and (getprop("/orientation/roll-deg") > 33.5 or getprop("/orientation/roll-deg") < -33.5)) {
setprop("/it-fbw/roll-back", 1);
}
} else if (ail < -0.4 and getprop("/orientation/roll-deg") <= 33.5) {
2017-06-26 04:34:18 +00:00
setprop("/it-fbw/roll-lim", "67");
2017-06-26 23:38:04 +00:00
if (getprop("/it-fbw/roll-back") == 1 and getprop("/orientation/roll-deg") <= 33.5 and getprop("/orientation/roll-deg") >= -33.5) {
setprop("/it-fbw/roll-back", 0);
}
2017-06-26 04:34:18 +00:00
if (getprop("/it-fbw/roll-back") == 0 and (getprop("/orientation/roll-deg") > 33.5 or getprop("/orientation/roll-deg") < -33.5)) {
setprop("/it-fbw/roll-back", 1);
2017-04-06 19:06:35 +00:00
}
2017-11-29 04:11:23 +00:00
} else if (ail < 0.04 and ail > -0.04) {
2017-06-26 04:34:18 +00:00
setprop("/it-fbw/roll-lim", "33");
if (getprop("/it-fbw/roll-back") == 1 and getprop("/orientation/roll-deg") <= 33.5 and getprop("/orientation/roll-deg") >= -33.5) {
setprop("/it-fbw/roll-back", 0);
2017-04-17 23:02:43 +00:00
}
2017-04-06 19:06:35 +00:00
}
2017-11-29 04:11:23 +00:00
if (ail > 0.04 or ail < -0.04) {
setprop("/it-fbw/protections/overspeed-roll-back", 0);
} else if (ail < 0.04 and ail > -0.04) {
setprop("/it-fbw/protections/overspeed-roll-back", 1);
}
2017-04-07 18:24:11 +00:00
2017-04-17 23:02:43 +00:00
if (getprop("/it-fbw/override") == 0) {
2017-07-05 02:20:23 +00:00
var degrade = getprop("/it-fbw/degrade-law");
if (degrade == 0) {
2017-04-17 23:02:43 +00:00
if (getprop("/it-fbw/law") != 0) {
setprop("/it-fbw/law", 0);
}
2017-07-05 02:20:23 +00:00
} else if (degrade == 1) {
if (getprop("/it-fbw/law") != 1) {
setprop("/it-fbw/law", 1);
}
} else if (degrade == 2) {
2017-05-03 02:16:53 +00:00
if (getprop("/it-fbw/law") != 2) {
setprop("/it-fbw/law", 2);
}
2017-07-05 02:20:23 +00:00
} else if (degrade == 3) {
2017-05-03 00:54:39 +00:00
if (getprop("/it-fbw/law") != 3) {
setprop("/it-fbw/law", 3);
2017-04-17 23:02:43 +00:00
}
2017-04-09 15:30:46 +00:00
}
2017-04-07 18:24:11 +00:00
}
2017-08-05 19:46:37 +00:00
if (getprop("/it-fbw/law") != 0) {
if (getprop("/it-autoflight/output/ap1") == 1) {
setprop("/it-autoflight/input/ap1", 0);
}
if (getprop("/it-autoflight/output/ap2") == 1) {
setprop("/it-autoflight/input/ap2", 0);
}
}
2017-05-03 00:54:39 +00:00
}
2017-04-09 16:46:30 +00:00
2017-07-05 02:20:23 +00:00
var updatet = maketimer(0.1, update_loop);
2017-08-05 19:46:37 +00:00
var fbwt = maketimer(0.03, fbw_loop);