2019-10-14 16:48:35 +00:00
# A3XX Autobrake
# Joshua Davidson (Octal450)
# Copyright (c) 2019 Joshua Davidson (Octal450)
var thr1 = 0;
var thr2 = 0;
var wow0 = 0;
var gnd_speed = 0;
2020-02-07 16:10:54 +00:00
setprop("controls/autobrake/active", 0);
setprop("controls/autobrake/mode", 0);
setprop("controls/autobrake/decel-rate", 0);
2019-10-14 16:48:35 +00:00
var autobrake_init = func {
2020-02-07 16:10:54 +00:00
setprop("controls/autobrake/active", 0);
setprop("controls/autobrake/mode", 0);
2019-10-14 16:48:35 +00:00
}
# Override FG's generic brake
controls.applyBrakes = func(v, which = 0) {
2020-02-07 16:10:54 +00:00
if (getprop("systems/acconfig/autoconfig-running") != 1) {
2019-10-14 16:48:35 +00:00
if (which <= 0) {
interpolate("/controls/gear/brake-left", v, 0.5);
}
if (which >= 0) {
interpolate("/controls/gear/brake-right", v, 0.5);
}
}
}
# Set autobrake mode
var arm_autobrake = func(mode) {
2020-02-07 16:10:54 +00:00
wow0 = getprop("gear/gear[0]/wow");
gnd_speed = getprop("velocities/groundspeed-kt");
2019-10-14 16:48:35 +00:00
if (mode == 0) { # OFF
absChk.stop();
2020-02-07 16:10:54 +00:00
if (getprop("controls/autobrake/active") == 1) {
setprop("controls/autobrake/active", 0);
setprop("controls/gear/brake-left", 0);
setprop("controls/gear/brake-right", 0);
2019-10-14 16:48:35 +00:00
}
2020-02-07 16:10:54 +00:00
setprop("controls/autobrake/decel-rate", 0);
setprop("controls/autobrake/mode", 0);
2019-10-14 16:48:35 +00:00
} else if (mode == 1 and wow0 != 1) { # LO
2020-02-07 16:10:54 +00:00
setprop("controls/autobrake/decel-rate", 1.7);
setprop("controls/autobrake/mode", 1);
2019-10-14 16:48:35 +00:00
absChk.start();
} else if (mode == 2 and wow0 != 1) { # MED
2020-02-07 16:10:54 +00:00
setprop("controls/autobrake/decel-rate", 3);
setprop("controls/autobrake/mode", 2);
2019-10-14 16:48:35 +00:00
absChk.start();
} else if (mode == 3 and wow0 == 1 and gnd_speed < 40) { # MAX
2020-02-07 16:10:54 +00:00
setprop("controls/autobrake/decel-rate", 6);
setprop("controls/autobrake/mode", 3);
2019-10-14 16:48:35 +00:00
absChk.start();
}
}
# Autobrake loop
var absChk = maketimer(0.2, func {
2020-02-07 16:10:54 +00:00
thr1 = getprop("controls/engines/engine[0]/throttle");
thr2 = getprop("controls/engines/engine[1]/throttle");
wow0 = getprop("gear/gear[0]/wow");
gnd_speed = getprop("velocities/groundspeed-kt");
2019-10-14 16:48:35 +00:00
if (gnd_speed > 72) {
2020-02-07 16:10:54 +00:00
if (getprop("controls/autobrake/mode") != 0 and thr1 < 0.15 and thr2 < 0.15 and wow0 == 1) {
setprop("controls/autobrake/active", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("controls/autobrake/active", 0);
setprop("controls/gear/brake-left", 0);
setprop("controls/gear/brake-right", 0);
2019-10-14 16:48:35 +00:00
}
}
2020-02-07 16:10:54 +00:00
if (getprop("controls/autobrake/mode") == 3 and getprop("controls/gear/gear-down") == 0) {
2019-10-14 16:48:35 +00:00
arm_autobrake(0);
}
2020-02-07 16:10:54 +00:00
if (getprop("controls/autobrake/mode") != 0 and wow0 == 1 and getprop("controls/autobrake/active") == 1 and (getprop("controls/gear/brake-left") > 0.05 or getprop("controls/gear/brake-right") > 0.05)) {
2019-10-14 16:48:35 +00:00
arm_autobrake(0);
}
});