2017-10-04 19:53:07 +00:00
# A3XX Autobrake
# Joshua Davidson (it0uchpods)
2017-11-16 19:29:08 +00:00
##############################################
# Copyright (c) Joshua Davidson (it0uchpods) #
##############################################
2017-10-04 19:53:07 +00:00
setprop("/controls/autobrake/active", 0);
setprop("/controls/autobrake/mode", 0);
2017-12-03 14:38:57 +00:00
setprop("/controls/autobrake/decel-rate", 0);
2017-10-04 19:53:07 +00:00
setlistener("/sim/signals/fdm-initialized", func {
var thr1 = 0;
var thr2 = 0;
2017-11-12 02:36:40 +00:00
var wow0 = getprop("/gear/gear[0]/wow");
2017-10-04 19:53:07 +00:00
var gnd_speed = getprop("/velocities/groundspeed-kt");
});
var autobrake_init = func {
setprop("/controls/autobrake/active", 0);
setprop("/controls/autobrake/mode", 0);
}
2018-03-09 16:10:13 +00:00
# Override FG's generic brake
2017-10-04 19:53:07 +00:00
controls.applyBrakes = func(v, which = 0) {
2017-10-05 14:53:24 +00:00
if (getprop("/systems/acconfig/autoconfig-running") != 1) {
if (which <= 0) {
interpolate("/controls/gear/brake-left", v, 0.5);
}
if (which >= 0) {
interpolate("/controls/gear/brake-right", v, 0.5);
}
2017-10-04 19:53:07 +00:00
}
}
# Set autobrake mode
var arm_autobrake = func(mode) {
2017-11-18 16:06:32 +00:00
wow0 = getprop("/gear/gear[0]/wow");
2018-08-22 19:50:55 +00:00
gnd_speed = getprop("/velocities/groundspeed-kt");
2017-10-04 19:53:07 +00:00
if (mode == 0) { # OFF
absChk.stop();
if (getprop("/controls/autobrake/active") == 1) {
setprop("/controls/autobrake/active", 0);
setprop("/controls/gear/brake-left", 0);
setprop("/controls/gear/brake-right", 0);
}
2017-12-03 14:38:57 +00:00
setprop("/controls/autobrake/decel-rate", 0);
2017-10-04 19:53:07 +00:00
setprop("/controls/autobrake/mode", 0);
2017-11-18 16:06:32 +00:00
} else if (mode == 1 and wow0 != 1) { # LO
2017-12-03 14:38:57 +00:00
setprop("/controls/autobrake/decel-rate", 1.7);
2017-10-04 19:53:07 +00:00
setprop("/controls/autobrake/mode", 1);
absChk.start();
2017-11-18 16:06:32 +00:00
} else if (mode == 2 and wow0 != 1) { # MED
2017-12-03 14:38:57 +00:00
setprop("/controls/autobrake/decel-rate", 3);
2017-10-04 19:53:07 +00:00
setprop("/controls/autobrake/mode", 2);
absChk.start();
2018-08-22 19:50:55 +00:00
} else if (mode == 3 and wow0 == 1 and gnd_speed < 40) { # MAX
2017-12-03 14:38:57 +00:00
setprop("/controls/autobrake/decel-rate", 6);
2017-10-04 19:53:07 +00:00
setprop("/controls/autobrake/mode", 3);
absChk.start();
}
}
2018-03-09 16:10:13 +00:00
# Autobrake loop
2017-10-04 19:53:07 +00:00
var absChk = maketimer(0.2, func {
thr1 = getprop("/controls/engines/engine[0]/throttle");
thr2 = getprop("/controls/engines/engine[1]/throttle");
2017-11-12 02:36:40 +00:00
wow0 = getprop("/gear/gear[0]/wow");
2017-10-04 19:53:07 +00:00
gnd_speed = getprop("/velocities/groundspeed-kt");
2017-12-03 14:09:43 +00:00
if (gnd_speed > 72) {
2017-11-18 16:06:32 +00:00
if (getprop("/controls/autobrake/mode") != 0 and thr1 < 0.15 and thr2 < 0.15 and wow0 == 1) {
2017-10-04 19:53:07 +00:00
setprop("/controls/autobrake/active", 1);
} else {
setprop("/controls/autobrake/active", 0);
setprop("/controls/gear/brake-left", 0);
setprop("/controls/gear/brake-right", 0);
}
}
2017-12-30 16:33:28 +00:00
if (getprop("/controls/autobrake/mode") == 3 and getprop("/controls/gear/gear-down") == 0) {
arm_autobrake(0);
}
2018-03-09 16:10:13 +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)) {
arm_autobrake(0);
}
2017-10-04 19:53:07 +00:00
});