2019-10-14 16:48:35 +00:00
# A3XX Engine Control
# Joshua Davidson (Octal450)
# Copyright (c) 2019 Joshua Davidson (Octal450)
2020-02-07 16:10:54 +00:00
if (getprop("options/eng") == "IAE") {
2019-10-14 16:48:35 +00:00
io.include("engines-iae.nas");
} else {
io.include("engines-cfm.nas");
}
var spinup_time = 49;
var apu_max = 100;
var apu_egt_min = 352;
var apu_egt_max = 704;
2020-02-07 16:10:54 +00:00
setprop("systems/apu/rpm", 0);
setprop("systems/apu/egt", 42);
setprop("systems/apu/bleed-used", 0);
setprop("systems/apu/bleed-counting", 0);
setprop("systems/apu/bleed-time", 0);
2019-10-14 16:48:35 +00:00
var eng_common_init = func {
2020-02-07 16:10:54 +00:00
setprop("systems/apu/bleed-used", 0);
2019-10-14 16:48:35 +00:00
}
# Start APU
setlistener("/controls/APU/start", func {
2020-02-07 16:10:54 +00:00
if (getprop("controls/APU/master") == 1 and getprop("controls/APU/start") == 1) {
2019-10-14 16:48:35 +00:00
apuBleedChk.stop();
2020-02-07 16:10:54 +00:00
setprop("systems/apu/bleed-counting", 0);
if (getprop("systems/acconfig/autoconfig-running") == 0) {
2019-10-14 16:48:35 +00:00
interpolate("/systems/apu/rpm", apu_max, spinup_time);
apu_egt_check.start();
2020-02-07 16:10:54 +00:00
} else if (getprop("systems/acconfig/autoconfig-running") == 1) {
2019-10-14 16:48:35 +00:00
interpolate("/systems/apu/rpm", apu_max, 5);
interpolate("/systems/apu/egt", apu_egt_min, 5);
}
2020-02-07 16:10:54 +00:00
} else if (getprop("controls/APU/master") == 0) {
2019-10-14 16:48:35 +00:00
apu_egt_check.stop();
apu_stop();
}
});
var apu_egt_check = maketimer(0.5, func {
2020-02-07 16:10:54 +00:00
if (getprop("systems/apu/rpm") >= 28) {
2019-10-14 16:48:35 +00:00
apu_egt_check.stop();
interpolate("/systems/apu/egt", apu_egt_max, 5);
apu_egt2_check.start();
}
});
var apu_egt2_check = maketimer(0.5, func {
2020-02-07 16:10:54 +00:00
if (getprop("systems/apu/egt") >= 701) {
2019-10-14 16:48:35 +00:00
apu_egt2_check.stop();
interpolate("/systems/apu/egt", apu_egt_min, 30);
}
});
# Stop APU
setlistener("/controls/APU/master", func {
2020-02-07 16:10:54 +00:00
if (getprop("controls/APU/master") == 0) {
setprop("controls/APU/start", 0);
2019-10-14 16:48:35 +00:00
apu_egt_check.stop();
apu_egt2_check.stop();
apu_stop();
2020-02-07 16:10:54 +00:00
} else if (getprop("controls/APU/master") == 1) {
2019-10-14 16:48:35 +00:00
apuBleedChk.stop();
2020-02-07 16:10:54 +00:00
setprop("systems/apu/bleed-counting", 0);
setprop("systems/apu/bleed-used", 0);
2019-10-14 16:48:35 +00:00
}
});
var apu_stop = func {
2020-02-07 16:10:54 +00:00
if (getprop("systems/apu/bleed-used") == 1 and getprop("systems/apu/bleed-counting") != 1 and getprop("systems/acconfig/autoconfig-running") != 1) {
setprop("systems/apu/bleed-counting", 1);
setprop("systems/apu/bleed-time", getprop("sim/time/elapsed-sec"));
2019-10-14 16:48:35 +00:00
}
2020-02-07 16:10:54 +00:00
if (getprop("systems/apu/bleed-used") == 1 and getprop("systems/apu/bleed-counting") == 1 and getprop("systems/acconfig/autoconfig-running") != 1) {
2019-10-14 16:48:35 +00:00
apuBleedChk.start();
} else {
apuBleedChk.stop();
interpolate("/systems/apu/rpm", 0, 30);
interpolate("/systems/apu/egt", 42, 40);
2020-02-07 16:10:54 +00:00
setprop("systems/apu/bleed-counting", 0);
setprop("systems/apu/bleed-used", 0);
2019-10-14 16:48:35 +00:00
}
}
var apuBleedChk = maketimer(0.1, func {
2020-02-07 16:10:54 +00:00
if (getprop("systems/apu/bleed-used") == 1 and getprop("systems/apu/bleed-counting") == 1) {
if (getprop("systems/apu/bleed-time") + 60 <= getprop("sim/time/elapsed-sec")) {
2019-10-14 16:48:35 +00:00
apuBleedChk.stop();
interpolate("/systems/apu/rpm", 0, 30);
interpolate("/systems/apu/egt", 42, 40);
2020-02-07 16:10:54 +00:00
setprop("systems/apu/bleed-counting", 0);
setprop("systems/apu/bleed-used", 0);
2019-10-14 16:48:35 +00:00
}
}
});
# Various Other Stuff
var doIdleThrust = func {
2020-02-07 16:10:54 +00:00
setprop("controls/engines/engine[0]/throttle", 0.0);
setprop("controls/engines/engine[1]/throttle", 0.0);
2019-10-14 16:48:35 +00:00
}
var doCLThrust = func {
2020-02-07 16:10:54 +00:00
setprop("controls/engines/engine[0]/throttle", 0.63);
setprop("controls/engines/engine[1]/throttle", 0.63);
2019-10-14 16:48:35 +00:00
}
var doMCTThrust = func {
2020-02-07 16:10:54 +00:00
setprop("controls/engines/engine[0]/throttle", 0.8);
setprop("controls/engines/engine[1]/throttle", 0.8);
2019-10-14 16:48:35 +00:00
}
var doTOGAThrust = func {
2020-02-07 16:10:54 +00:00
setprop("controls/engines/engine[0]/throttle", 1.0);
setprop("controls/engines/engine[1]/throttle", 1.0);
2019-10-14 16:48:35 +00:00
}
# Reverse Thrust System
var toggleFastRevThrust = func {
2020-02-07 16:10:54 +00:00
var state1 = getprop("systems/thrust/state1");
var state2 = getprop("systems/thrust/state2");
if (state1 == "IDLE" and state2 == "IDLE" and getprop("controls/engines/engine[0]/reverser") == "0" and getprop("controls/engines/engine[1]/reverser") == "0" and getprop("gear/gear[1]/wow") == 1 and getprop("gear/gear[2]/wow") == 1) {
2019-10-14 16:48:35 +00:00
interpolate("/engines/engine[0]/reverser-pos-norm", 1, 1.4);
interpolate("/engines/engine[1]/reverser-pos-norm", 1, 1.4);
2020-02-07 16:10:54 +00:00
setprop("controls/engines/engine[0]/reverser", 1);
setprop("controls/engines/engine[1]/reverser", 1);
setprop("controls/engines/engine[0]/throttle-rev", 0.65);
setprop("controls/engines/engine[1]/throttle-rev", 0.65);
setprop("fdm/jsbsim/propulsion/engine[0]/reverser-angle-rad", 3.14);
setprop("fdm/jsbsim/propulsion/engine[1]/reverser-angle-rad", 3.14);
} else if ((getprop("controls/engines/engine[0]/reverser") == "1") or (getprop("controls/engines/engine[1]/reverser") == "1") and (getprop("gear/gear[1]/wow") == 1) and (getprop("gear/gear[2]/wow") == 1)) {
setprop("controls/engines/engine[0]/throttle-rev", 0);
setprop("controls/engines/engine[1]/throttle-rev", 0);
2019-10-14 16:48:35 +00:00
interpolate("/engines/engine[0]/reverser-pos-norm", 0, 1.0);
interpolate("/engines/engine[1]/reverser-pos-norm", 0, 1.0);
2020-02-07 16:10:54 +00:00
setprop("fdm/jsbsim/propulsion/engine[0]/reverser-angle-rad", 0);
setprop("fdm/jsbsim/propulsion/engine[1]/reverser-angle-rad", 0);
setprop("controls/engines/engine[0]/reverser", 0);
setprop("controls/engines/engine[1]/reverser", 0);
2019-10-14 16:48:35 +00:00
}
}
var doRevThrust = func {
2020-02-07 16:10:54 +00:00
if (getprop("controls/engines/engine[0]/reverser") == "1" and getprop("controls/engines/engine[1]/reverser") == "1" and getprop("gear/gear[1]/wow") == 1 and getprop("gear/gear[2]/wow") == 1) {
var pos1 = getprop("controls/engines/engine[0]/throttle-rev");
var pos2 = getprop("controls/engines/engine[1]/throttle-rev");
2019-10-14 16:48:35 +00:00
if (pos1 < 0.649) {
2020-02-07 16:10:54 +00:00
setprop("controls/engines/engine[0]/throttle-rev", pos1 + 0.15);
2019-10-14 16:48:35 +00:00
}
if (pos2 < 0.649) {
2020-02-07 16:10:54 +00:00
setprop("controls/engines/engine[1]/throttle-rev", pos2 + 0.15);
2019-10-14 16:48:35 +00:00
}
}
2020-02-07 16:10:54 +00:00
var state1 = getprop("systems/thrust/state1");
var state2 = getprop("systems/thrust/state2");
if (state1 == "IDLE" and state2 == "IDLE" and getprop("controls/engines/engine[0]/reverser") == "0" and getprop("controls/engines/engine[1]/reverser") == "0" and getprop("gear/gear[1]/wow") == 1 and getprop("gear/gear[2]/wow") == 1) {
setprop("controls/engines/engine[0]/throttle-rev", 0.05);
setprop("controls/engines/engine[1]/throttle-rev", 0.05);
2019-10-14 16:48:35 +00:00
interpolate("/engines/engine[0]/reverser-pos-norm", 1, 1.4);
interpolate("/engines/engine[1]/reverser-pos-norm", 1, 1.4);
2020-02-07 16:10:54 +00:00
setprop("controls/engines/engine[0]/reverser", 1);
setprop("controls/engines/engine[1]/reverser", 1);
setprop("fdm/jsbsim/propulsion/engine[0]/reverser-angle-rad", 3.14);
setprop("fdm/jsbsim/propulsion/engine[1]/reverser-angle-rad", 3.14);
2019-10-14 16:48:35 +00:00
}
}
var unRevThrust = func {
2020-02-07 16:10:54 +00:00
if (getprop("controls/engines/engine[0]/reverser") == "1" or getprop("controls/engines/engine[1]/reverser") == "1") {
var pos1 = getprop("controls/engines/engine[0]/throttle-rev");
var pos2 = getprop("controls/engines/engine[1]/throttle-rev");
2019-10-14 16:48:35 +00:00
if (pos1 > 0.051) {
2020-02-07 16:10:54 +00:00
setprop("controls/engines/engine[0]/throttle-rev", pos1 - 0.15);
2019-10-14 16:48:35 +00:00
} else {
unRevThrust_b();
}
if (pos2 > 0.051) {
2020-02-07 16:10:54 +00:00
setprop("controls/engines/engine[1]/throttle-rev", pos2 - 0.15);
2019-10-14 16:48:35 +00:00
} else {
unRevThrust_b();
}
}
}
var unRevThrust_b = func {
2020-02-07 16:10:54 +00:00
setprop("controls/engines/engine[0]/throttle-rev", 0);
setprop("controls/engines/engine[1]/throttle-rev", 0);
2019-10-14 16:48:35 +00:00
interpolate("/engines/engine[0]/reverser-pos-norm", 0, 1.0);
interpolate("/engines/engine[1]/reverser-pos-norm", 0, 1.0);
2020-02-07 16:10:54 +00:00
setprop("fdm/jsbsim/propulsion/engine[0]/reverser-angle-rad", 0);
setprop("fdm/jsbsim/propulsion/engine[1]/reverser-angle-rad", 0);
setprop("controls/engines/engine[0]/reverser", 0);
setprop("controls/engines/engine[1]/reverser", 0);
2019-10-14 16:48:35 +00:00
}