2019-10-14 16:48:35 +00:00
# A3XX Engine Control
# Joshua Davidson (Octal450)
2020-04-18 05:36:46 +00:00
# Copyright (c) 2020 Josh Davidson (Octal450)
2019-10-14 16:48:35 +00:00
2020-05-12 20:47:05 +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 eng_common_init = func {
2020-04-17 22:41:36 +00:00
# nada
2019-10-14 16:48:35 +00:00
}
# Various Other Stuff
var doIdleThrust = func {
2020-02-15 21:30:45 +00:00
# Idle does not respect selected engines, because it is used to respond
# to "Retard" and both engines must be idle for spoilers to deploy
2020-05-12 20:47:05 +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-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[0]") == 1) {
setprop("/controls/engines/engine[0]/throttle", 0.63);
2020-02-15 21:30:45 +00:00
}
2020-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[1]") == 1) {
setprop("/controls/engines/engine[1]/throttle", 0.63);
2020-02-15 21:30:45 +00:00
}
2019-10-14 16:48:35 +00:00
}
var doMCTThrust = func {
2020-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[0]") == 1) {
setprop("/controls/engines/engine[0]/throttle", 0.8);
2020-02-15 21:30:45 +00:00
}
2020-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[1]") == 1) {
setprop("/controls/engines/engine[1]/throttle", 0.8);
2020-02-15 21:30:45 +00:00
}
2019-10-14 16:48:35 +00:00
}
var doTOGAThrust = func {
2020-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[0]") == 1) {
setprop("/controls/engines/engine[0]/throttle", 1.0);
2020-02-15 21:30:45 +00:00
}
2020-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[1]") == 1) {
setprop("/controls/engines/engine[1]/throttle", 1.0);
2020-02-15 21:30:45 +00:00
}
2019-10-14 16:48:35 +00:00
}
# Reverse Thrust System
var toggleFastRevThrust = func {
2020-05-12 20:47:05 +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) {
if (getprop("/sim/input/selected/engine[0]") == 1) {
2020-02-15 22:34:12 +00:00
interpolate("/engines/engine[0]/reverser-pos-norm", 1, 1.4);
2020-05-12 20:47:05 +00:00
setprop("/controls/engines/engine[0]/reverser", 1);
setprop("/controls/engines/engine[0]/throttle-rev", 0.65);
setprop("/fdm/jsbsim/propulsion/engine[0]/reverser-angle-rad", 3.14);
2020-02-15 22:34:12 +00:00
}
2020-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[1]") == 1) {
2020-02-15 22:34:12 +00:00
interpolate("/engines/engine[1]/reverser-pos-norm", 1, 1.4);
2020-05-12 20:47:05 +00:00
setprop("/controls/engines/engine[1]/reverser", 1);
setprop("/controls/engines/engine[1]/throttle-rev", 0.65);
setprop("/fdm/jsbsim/propulsion/engine[1]/reverser-angle-rad", 3.14);
2020-02-15 22:34:12 +00:00
}
2020-05-12 20:47:05 +00:00
} else if ((getprop("/controls/engines/engine[0]/reverser") == "1") or (getprop("/controls/engines/engine[1]/reverser") == "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-05-12 20:47:05 +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-05-12 20:47:05 +00:00
if (getprop("/gear/gear[1]/wow") != 1 and getprop("/gear/gear[2]/wow") != 1) {
2020-02-15 22:34:12 +00:00
# Can't select reverse if not on the ground
return;
}
2020-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[0]") == 1 and getprop("/controls/engines/engine[0]/reverser") == "1") {
var pos = getprop("/controls/engines/engine[0]/throttle-rev");
2020-02-15 22:34:12 +00:00
if (pos < 0.649) {
2020-05-12 20:47:05 +00:00
setprop("/controls/engines/engine[0]/throttle-rev", pos + 0.15);
2019-10-14 16:48:35 +00:00
}
2020-02-15 22:34:12 +00:00
}
2020-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[1]") == 1 and getprop("/controls/engines/engine[1]/reverser") == "1") {
var pos = getprop("/controls/engines/engine[1]/throttle-rev");
2020-02-15 22:34:12 +00:00
if (pos < 0.649) {
2020-05-12 20:47:05 +00:00
setprop("/controls/engines/engine[1]/throttle-rev", pos + 0.15);
2019-10-14 16:48:35 +00:00
}
}
2020-05-12 20:47:05 +00:00
var state1 = getprop("/systems/thrust/state1");
var state2 = getprop("/systems/thrust/state2");
if (getprop("/sim/input/selected/engine[0]") == 1 and state1 == "IDLE" and getprop("/controls/engines/engine[0]/reverser") == "0") {
setprop("/controls/engines/engine[0]/throttle-rev", 0.05);
2019-10-14 16:48:35 +00:00
interpolate("/engines/engine[0]/reverser-pos-norm", 1, 1.4);
2020-05-12 20:47:05 +00:00
setprop("/controls/engines/engine[0]/reverser", 1);
setprop("/fdm/jsbsim/propulsion/engine[0]/reverser-angle-rad", 3.14);
2020-02-15 22:34:12 +00:00
}
2020-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[1]") == 1 and state2 == "IDLE" and getprop("/controls/engines/engine[1]/reverser") == "0") {
setprop("/controls/engines/engine[1]/throttle-rev", 0.05);
2020-02-15 22:34:12 +00:00
interpolate("/engines/engine[1]/reverser-pos-norm", 1, 1.4);
2020-05-12 20:47:05 +00:00
setprop("/controls/engines/engine[1]/reverser", 1);
setprop("/fdm/jsbsim/propulsion/engine[1]/reverser-angle-rad", 3.14);
2019-10-14 16:48:35 +00:00
}
}
var unRevThrust = func {
2020-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[0]") == 1 and getprop("/controls/engines/engine[0]/reverser") == "1") {
var pos = getprop("/controls/engines/engine[0]/throttle-rev");
2020-02-15 22:34:12 +00:00
if (pos > 0.051) {
2020-05-12 20:47:05 +00:00
setprop("/controls/engines/engine[0]/throttle-rev", pos - 0.15);
2019-10-14 16:48:35 +00:00
} else {
2020-05-12 20:47:05 +00:00
setprop("/controls/engines/engine[0]/throttle-rev", 0);
2020-02-15 22:34:12 +00:00
interpolate("/engines/engine[0]/reverser-pos-norm", 0, 1.0);
2020-05-12 20:47:05 +00:00
setprop("/fdm/jsbsim/propulsion/engine[0]/reverser-angle-rad", 0);
setprop("/controls/engines/engine[0]/reverser", 0);
2019-10-14 16:48:35 +00:00
}
2020-02-15 22:34:12 +00:00
}
2020-05-12 20:47:05 +00:00
if (getprop("/sim/input/selected/engine[1]") == 1 and getprop("/controls/engines/engine[1]/reverser") == "1") {
var pos = getprop("/controls/engines/engine[1]/throttle-rev");
2020-02-15 22:34:12 +00:00
if (pos > 0.051) {
2020-05-12 20:47:05 +00:00
setprop("/controls/engines/engine[1]/throttle-rev", pos - 0.15);
2019-10-14 16:48:35 +00:00
} else {
2020-05-12 20:47:05 +00:00
setprop("/controls/engines/engine[1]/throttle-rev", 0);
2020-02-15 22:34:12 +00:00
interpolate("/engines/engine[1]/reverser-pos-norm", 0, 1.0);
2020-05-12 20:47:05 +00:00
setprop("/fdm/jsbsim/propulsion/engine[1]/reverser-angle-rad", 0);
setprop("/controls/engines/engine[1]/reverser", 0);
2019-10-14 16:48:35 +00:00
}
}
}