2017-05-26 20:40:23 +00:00
# A3XX FADEC/Throttle Control System by Joshua Davidson (it0uchpods)
# V2.0.0
2017-05-19 19:13:28 +00:00
setprop("/systems/thrust/alpha-floor", 0);
setprop("/systems/thrust/toga-lk", 0);
2016-11-05 03:39:28 +00:00
2017-05-26 20:40:23 +00:00
setprop("/systems/thrust/epr/toga-lim", 0.0);
setprop("/systems/thrust/epr/mct-lim", 0.0);
2017-05-27 00:37:11 +00:00
setprop("/systems/thrust/epr/flx-lim", 0.0);
2017-05-26 20:40:23 +00:00
setprop("/systems/thrust/epr/clb-lim", 0.0);
2017-05-27 00:37:11 +00:00
setprop("/systems/thrust/n1/flx-lim", 0.0);
setprop("/engines/flx-thr", 0.0);
2017-05-26 20:40:23 +00:00
2016-11-05 03:39:28 +00:00
setlistener("/sim/signals/fdm-initialized", func {
2017-04-25 17:13:15 +00:00
setprop("/controls/engines/thrust-limit", "TOGA");
2017-04-25 18:41:13 +00:00
setprop("/controls/engines/epr-limit", 1.308);
2017-05-26 20:40:23 +00:00
setprop("/controls/engines/n1-limit", 101.8);
2016-11-05 03:39:28 +00:00
setprop("/systems/thrust/state1", "IDLE");
setprop("/systems/thrust/state2", "IDLE");
setprop("/systems/thrust/lvrclb", "0");
2017-05-16 18:22:40 +00:00
setprop("/systems/thrust/clbreduc-ft", "1500");
2017-05-26 20:40:23 +00:00
setprop("/systems/thrust/toga-lim", 0.0);
setprop("/systems/thrust/mct-lim", 0.0);
setprop("/systems/thrust/clb-lim", 0.0);
2017-05-26 17:50:53 +00:00
setprop("/systems/thrust/lim-flex", 0);
2017-06-15 18:45:59 +00:00
setprop("/engines/flex-derate", 0);
2017-04-25 18:41:13 +00:00
thrustt.start();
2016-11-05 03:39:28 +00:00
});
2017-04-07 18:09:40 +00:00
setlistener("/controls/engines/engine[0]/throttle-pos", func {
var thrr = getprop("/controls/engines/engine[0]/throttle-pos");
2017-05-19 19:13:28 +00:00
if (getprop("/systems/thrust/alpha-floor") == 0 and getprop("/systems/thrust/toga-lk") == 0) {
if (thrr < 0.01) {
setprop("/systems/thrust/state1", "IDLE");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
atoff_request();
} else if (thrr >= 0.01 and thrr < 0.60) {
setprop("/systems/thrust/state1", "MAN");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
} else if (thrr >= 0.60 and thrr < 0.65) {
setprop("/systems/thrust/state1", "CL");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
} else if (thrr >= 0.65 and thrr < 0.78) {
setprop("/systems/thrust/state1", "MAN THR");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
} else if (thrr >= 0.78 and thrr < 0.83) {
setprop("/it-autoflight/input/athr", 1);
2017-05-27 00:37:11 +00:00
if (getprop("/controls/engines/thrust-limit") == "FLX") {
var derate = getprop("/engines/flex-derate");
setprop("/controls/engines/engine[0]/throttle-fdm", 0.95 - derate);
} else {
setprop("/controls/engines/engine[0]/throttle-fdm", 0.90);
}
2017-05-19 19:13:28 +00:00
setprop("/systems/thrust/state1", "MCT");
} else if (thrr >= 0.83 and thrr < 0.95) {
setprop("/it-autoflight/input/athr", 1);
setprop("/systems/thrust/state1", "MAN THR");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
} else if (thrr >= 0.95) {
setprop("/it-autoflight/input/athr", 1);
setprop("/controls/engines/engine[0]/throttle-fdm", 0.95);
setprop("/systems/thrust/state1", "TOGA");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
}
} else {
if (thrr < 0.01) {
setprop("/systems/thrust/state1", "IDLE");
} else if (thrr >= 0.01 and thrr < 0.60) {
setprop("/systems/thrust/state1", "MAN");
} else if (thrr >= 0.60 and thrr < 0.65) {
setprop("/systems/thrust/state1", "CL");
} else if (thrr >= 0.65 and thrr < 0.78) {
setprop("/systems/thrust/state1", "MAN THR");
} else if (thrr >= 0.78 and thrr < 0.83) {
setprop("/systems/thrust/state1", "MCT");
} else if (thrr >= 0.83 and thrr < 0.95) {
setprop("/systems/thrust/state1", "MAN THR");
} else if (thrr >= 0.95) {
setprop("/systems/thrust/state1", "TOGA");
}
2016-12-10 16:26:57 +00:00
setprop("/controls/engines/engine[0]/throttle-fdm", 0.95);
2016-11-05 03:39:28 +00:00
}
});
2017-04-07 18:09:40 +00:00
setlistener("/controls/engines/engine[1]/throttle-pos", func {
var thrr = getprop("/controls/engines/engine[1]/throttle-pos");
2017-05-19 19:13:28 +00:00
if (getprop("/systems/thrust/alpha-floor") == 0 and getprop("/systems/thrust/toga-lk") == 0) {
if (thrr < 0.01) {
setprop("/systems/thrust/state2", "IDLE");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
atoff_request();
} else if (thrr >= 0.01 and thrr < 0.60) {
setprop("/systems/thrust/state2", "MAN");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
} else if (thrr >= 0.60 and thrr < 0.65) {
setprop("/systems/thrust/state2", "CL");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
} else if (thrr >= 0.65 and thrr < 0.78) {
setprop("/systems/thrust/state2", "MAN THR");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
} else if (thrr >= 0.78 and thrr < 0.83) {
setprop("/it-autoflight/input/athr", 1);
2017-05-27 00:37:11 +00:00
if (getprop("/controls/engines/thrust-limit") == "FLX") {
var derate = getprop("/engines/flex-derate");
setprop("/controls/engines/engine[1]/throttle-fdm", 0.95 - derate);
} else {
setprop("/controls/engines/engine[1]/throttle-fdm", 0.90);
}
2017-05-19 19:13:28 +00:00
setprop("/systems/thrust/state2", "MCT");
} else if (thrr >= 0.83 and thrr < 0.95) {
setprop("/it-autoflight/input/athr", 1);
setprop("/systems/thrust/state2", "MAN THR");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
} else if (thrr >= 0.95) {
setprop("/it-autoflight/input/athr", 1);
setprop("/controls/engines/engine[1]/throttle-fdm", 0.95);
setprop("/systems/thrust/state2", "TOGA");
2017-05-26 17:50:53 +00:00
unflex();
2017-05-19 19:13:28 +00:00
}
} else {
if (thrr < 0.01) {
setprop("/systems/thrust/state2", "IDLE");
} else if (thrr >= 0.01 and thrr < 0.60) {
setprop("/systems/thrust/state2", "MAN");
} else if (thrr >= 0.60 and thrr < 0.65) {
setprop("/systems/thrust/state2", "CL");
} else if (thrr >= 0.65 and thrr < 0.78) {
setprop("/systems/thrust/state2", "MAN THR");
} else if (thrr >= 0.78 and thrr < 0.83) {
setprop("/systems/thrust/state2", "MCT");
} else if (thrr >= 0.83 and thrr < 0.95) {
setprop("/systems/thrust/state2", "MAN THR");
} else if (thrr >= 0.95) {
setprop("/systems/thrust/state2", "TOGA");
}
2016-12-10 16:26:57 +00:00
setprop("/controls/engines/engine[1]/throttle-fdm", 0.95);
2017-05-19 19:13:28 +00:00
}
});
# Alpha Floor and Toga Lock
setlistener("/it-autoflight/input/athr", func {
if (getprop("/systems/thrust/alpha-floor") == 1) {
setprop("/it-autoflight/input/athr", 1);
} else {
setprop("/systems/thrust/toga-lk", 0);
2016-11-05 03:39:28 +00:00
}
});
# Checks if all throttles are in the IDLE position, before tuning off the A/THR.
var atoff_request = func {
var state1 = getprop("/systems/thrust/state1");
var state2 = getprop("/systems/thrust/state2");
2017-05-19 19:13:28 +00:00
if ((state1 == "IDLE") and (state2 == "IDLE") and (getprop("/systems/thrust/alpha-floor") == 0) and (getprop("/systems/thrust/toga-lk") == 0)) {
2016-12-05 20:20:56 +00:00
setprop("/it-autoflight/input/athr", 0);
2016-11-05 03:39:28 +00:00
}
}
2017-04-25 18:41:13 +00:00
setlistener("/systems/thrust/state1", func {
thrust_lim();
});
setlistener("/systems/thrust/state2", func {
thrust_lim();
});
var thrust_lim = func {
var state1 = getprop("/systems/thrust/state1");
var state2 = getprop("/systems/thrust/state2");
var thr1 = getprop("/controls/engines/engine[0]/throttle-pos");
var thr2 = getprop("/controls/engines/engine[0]/throttle-pos");
2017-05-27 00:37:11 +00:00
var eprtoga = getprop("/systems/thrust/epr/toga-lim");
var eprmct = getprop("/systems/thrust/epr/mct-lim");
var eprflx = getprop("/systems/thrust/epr/flx-lim");
var eprclb = getprop("/systems/thrust/epr/clb-lim");
var n1flx = getprop("/systems/thrust/n1/flx-lim");
2017-04-25 18:41:13 +00:00
if (getprop("/gear/gear[1]/wow") == 0 and getprop("/gear/gear[2]/wow") == 0) {
2017-05-19 19:13:28 +00:00
if ((state1 == "TOGA" or state2 == "TOGA" or (state1 == "MAN THR" and thr1 >= 0.83) or (state2 == "MAN THR" and thr2 >= 0.83)) or getprop("/systems/thrust/alpha-floor") == 1 or getprop("/systems/thrust/toga-lk") == 1) {
2017-04-25 18:41:13 +00:00
setprop("/controls/engines/thrust-limit", "TOGA");
2017-05-26 20:40:23 +00:00
setprop("/controls/engines/epr-limit", eprtoga);
2017-04-25 18:41:13 +00:00
setprop("/controls/engines/n1-limit", 101.8);
2017-05-26 17:50:53 +00:00
} else if ((state1 == "MCT" or state2 == "MCT" or (state1 == "MAN THR" and thr1 < 0.83) or (state2 == "MAN THR" and thr2 < 0.83)) and getprop("/systems/thrust/lim-flex") == 0) {
2017-04-25 18:41:13 +00:00
setprop("/controls/engines/thrust-limit", "MCT");
2017-05-26 20:40:23 +00:00
setprop("/controls/engines/epr-limit", eprmct);
2017-04-25 18:41:13 +00:00
setprop("/controls/engines/n1-limit", 97.7);
2017-05-26 17:50:53 +00:00
} else if ((state1 == "MCT" or state2 == "MCT" or (state1 == "MAN THR" and thr1 < 0.83) or (state2 == "MAN THR" and thr2 < 0.83)) and getprop("/systems/thrust/lim-flex") == 1) {
setprop("/controls/engines/thrust-limit", "FLX");
2017-05-26 20:40:23 +00:00
setprop("/controls/engines/epr-limit", eprmct);
2017-05-26 17:50:53 +00:00
setprop("/controls/engines/n1-limit", 97.7);
2017-04-25 18:41:13 +00:00
} else if (state1 == "CL" or state2 == "CL" or state1 == "MAN" or state2 == "MAN" or state1 == "IDLE" or state2 == "IDLE") {
setprop("/controls/engines/thrust-limit", "CLB");
2017-05-26 20:40:23 +00:00
setprop("/controls/engines/epr-limit", eprclb);
2017-04-25 18:41:13 +00:00
setprop("/controls/engines/n1-limit", 91.9);
}
2017-05-26 17:50:53 +00:00
} else if (getprop("/FMGC/internal/flex-set") == 1) {
setprop("/systems/thrust/lim-flex", 1);
setprop("/controls/engines/thrust-limit", "FLX");
2017-05-27 00:37:11 +00:00
setprop("/controls/engines/epr-limit", eprflx);
setprop("/controls/engines/n1-limit", n1flx);
2017-04-25 18:41:13 +00:00
} else {
setprop("/controls/engines/thrust-limit", "TOGA");
2017-05-26 20:40:23 +00:00
setprop("/controls/engines/epr-limit", eprtoga);
setprop("/controls/engines/n1-limit", 101.8);
2017-04-25 18:41:13 +00:00
}
}
2017-05-26 17:50:53 +00:00
var unflex = func {
var state1 = getprop("/systems/thrust/state1");
var state2 = getprop("/systems/thrust/state2");
if (state1 != "MCT" and state2 != "MCT" and getprop("/gear/gear[1]/wow") == 0 and getprop("/gear/gear[2]/wow") == 0) {
setprop("/systems/thrust/lim-flex", 0);
}
}
2017-04-25 18:41:13 +00:00
var thrust_loop = func {
2017-05-27 00:37:11 +00:00
var derate = getprop("/engines/flex-derate");
setprop("/engines/flx-thr", 0.95 - derate);
2016-11-05 03:39:28 +00:00
var state1 = getprop("/systems/thrust/state1");
var state2 = getprop("/systems/thrust/state2");
2016-12-05 20:20:56 +00:00
if ((state1 == "CL") and (state2 == "CL")) {
2016-11-05 03:39:28 +00:00
setprop("/systems/thrust/lvrclb", "0");
} else {
var status = getprop("/systems/thrust/lvrclb");
if (status == 0) {
2017-04-17 19:44:59 +00:00
if (getprop("/systems/thrust/state1") == "MAN" or getprop("/systems/thrust/state2") == "MAN") {
2016-11-05 03:39:28 +00:00
setprop("/systems/thrust/lvrclb", "1");
} else {
2017-04-25 18:41:13 +00:00
if (getprop("/position/gear-agl-ft") >= getprop("/systems/thrust/clbreduc-ft")) {
2017-04-17 19:44:59 +00:00
setprop("/systems/thrust/lvrclb", "1");
} else {
setprop("/systems/thrust/lvrclb", "0");
}
2016-11-05 03:39:28 +00:00
}
} else if (status == 1) {
setprop("/systems/thrust/lvrclb", "0");
}
}
2017-05-26 20:40:23 +00:00
# Disabled until FDE AoA and stall characteristics are correct.
2017-05-19 19:13:28 +00:00
# var AoA = getprop("/fdm/jsbsim/aero/alpha-deg");
# var flaps = getprop("/controls/flight/flap-lever");
# if (getprop("/gear/gear[1]/wow") == 0 and getprop("/gear/gear[2]/wow") == 0 and getprop("/it-fbw/law") == 0) {
# if (AoA >= 6.0 and flaps == 0) {
# setprop("/systems/thrust/alpha-floor", 1);
# setprop("/systems/thrust/toga-lk", 0);
# setprop("/it-autoflight/input/athr", 1);
# } else if (AoA >= 8.0 and (flaps == 1 or flaps == 2)) {
# setprop("/systems/thrust/alpha-floor", 1);
# setprop("/systems/thrust/toga-lk", 0);
# setprop("/it-autoflight/input/athr", 1);
# } else if (AoA >= 8.0 and flaps == 3) {
# setprop("/systems/thrust/alpha-floor", 1);
# setprop("/systems/thrust/toga-lk", 0);
# setprop("/it-autoflight/input/athr", 1);
# } else if (AoA >= 7.5 and flaps == 4) {
# setprop("/systems/thrust/alpha-floor", 1);
# setprop("/systems/thrust/toga-lk", 0);
# setprop("/it-autoflight/input/athr", 1);
# } else if (getprop("/systems/thrust/alpha-floor") == 1) {
# setprop("/systems/thrust/alpha-floor", 0);
# setprop("/it-autoflight/input/athr", 1);
# setprop("/systems/thrust/toga-lk", 1);
# }
# } else {
# setprop("/systems/thrust/alpha-floor", 0);
# setprop("/systems/thrust/toga-lk", 0);
# }
2017-04-07 18:09:40 +00:00
}
2017-04-17 19:44:59 +00:00
# Timers
2017-04-25 18:41:13 +00:00
var thrustt = maketimer(0.5, thrust_loop);