2019-10-14 16:48:35 +00:00
# A3XX IAE V2500 Engine
# Joshua Davidson (Octal450)
2022-01-11 02:17:41 +00:00
# Copyright (c) 2022 Josh Davidson (Octal450)
2019-10-14 16:48:35 +00:00
#####################
# Initializing Vars #
#####################
2020-02-07 16:10:54 +00:00
var engines = props.globals.getNode("engines").getChildren("engine");
2019-10-14 16:48:35 +00:00
var egt_min = 434;
var egt_start = 587;
var egt_max = 712;
var start_time = 10;
var egt_lightup_time = 4;
var egt_lightdn_time = 10;
var shutdown_time = 20;
var egt_shutdown_time = 20;
var eng_init = func {
eng_common_init();
}
# Trigger Startups and Stops
setlistener("/controls/engines/engine[0]/cutoff-switch", func {
2020-11-22 22:00:21 +00:00
if (!pts.Controls.Engines.Engine.cutoffSw[0].getValue()) {
if (pts.Acconfig.running.getValue()) {
2019-10-14 16:48:35 +00:00
fast_start_one();
} else {
2020-11-22 22:00:21 +00:00
if (!manStart[0].getValue()) {
2019-10-14 16:48:35 +00:00
start_one_check();
2020-11-22 22:00:21 +00:00
} else {
2019-10-14 16:48:35 +00:00
eng_one_man_start.start();
}
}
2020-11-22 22:00:21 +00:00
} else if (pts.Controls.Engines.Engine.cutoffSw[0].getValue()) {
2019-10-14 16:48:35 +00:00
cutoff_one();
}
2020-11-22 22:00:21 +00:00
}, 0, 0);
2019-10-14 16:48:35 +00:00
var cutoff_one = func {
eng_one_auto_start.stop();
eng_one_man_start.stop();
eng_one_n2_check.stop();
2020-11-22 22:00:21 +00:00
igniterA[0].setValue(0);
igniterB[0].setValue(0);
manStart[0].setValue(0);
systems.PNEU.Valves.starter1.setValue(0);
pts.Controls.Engines.Engine.starter[0].setValue(0);
pts.Controls.Engines.Engine.cutoff[0].setValue(1);
pts.Engines.Engine.state[0].setValue(0);
2019-10-14 16:48:35 +00:00
interpolate(engines[0].getNode("egt-actual"), 0, egt_shutdown_time);
eng_one_n2_check.stop();
}
var fast_start_one = func {
2020-11-22 22:00:21 +00:00
pts.Controls.Engines.Engine.cutoff[0].setValue(0);
2020-05-12 20:47:05 +00:00
setprop("/engines/engine[0]/out-of-fuel", 0);
setprop("/engines/engine[0]/run", 1);
2019-10-14 16:48:35 +00:00
2020-05-12 20:47:05 +00:00
setprop("/engines/engine[0]/cutoff", 0);
setprop("/engines/engine[0]/starter", 0);
2019-10-14 16:48:35 +00:00
2020-05-12 20:47:05 +00:00
setprop("/fdm/jsbsim/propulsion/set-running", 0);
2019-10-14 16:48:35 +00:00
2020-11-22 22:00:21 +00:00
pts.Engines.Engine.state[0].setValue(3);
systems.PNEU.Valves.starter1.setValue(0);
2019-10-14 16:48:35 +00:00
}
setlistener("/controls/engines/engine[0]/man-start", func {
start_one_mancheck();
2020-11-22 22:00:21 +00:00
}, 0, 0);
2019-10-14 16:48:35 +00:00
var start_one_mancheck = func {
2020-11-22 22:00:21 +00:00
if (manStart[0].getValue()) {
if (pts.Controls.Engines.startSw.getValue() == 2 and (pts.Controls.Engines.Engine.cutoffSw[0].getValue() == 1)) {
systems.PNEU.Valves.starter1.setValue(1);
2019-10-14 16:48:35 +00:00
settimer(start_one_mancheck_b, 0.5);
}
} else {
2020-10-07 17:24:23 +00:00
if (pts.Engines.Engine.state[0].getValue() == 1 or pts.Engines.Engine.state[0].getValue() == 2) {
2020-11-22 22:00:21 +00:00
systems.PNEU.Valves.starter1.setValue(0);
pts.Engines.Engine.state[0].setValue(0);
pts.Controls.Engines.Engine.starter[0].setValue(0);
2019-10-14 16:48:35 +00:00
}
}
}
var start_one_mancheck_b = func {
2020-05-12 21:03:29 +00:00
if (systems.PNEU.Psi.engine1.getValue() >= 25) {
2020-11-22 22:00:21 +00:00
pts.Engines.Engine.state[0].setValue(1);
pts.Controls.Engines.Engine.starter[0].setValue(1);
2019-10-14 16:48:35 +00:00
}
}
var start_one_check = func {
2020-11-22 22:00:21 +00:00
if (pts.Controls.Engines.startSw.getValue() == 2 and pts.Controls.Engines.Engine.cutoffSw[0].getValue() == 0) {
systems.PNEU.Valves.starter1.setValue(1);
2019-10-14 16:48:35 +00:00
settimer(start_one_check_b, 0.5);
}
}
var start_one_check_b = func {
2020-11-22 22:00:21 +00:00
if (pts.Controls.Engines.startSw.getValue() == 2 and systems.PNEU.Psi.engine1.getValue() >= 25and !pts.Controls.Engines.Engine.cutoffSw[0].getValue()) {
2019-10-14 16:48:35 +00:00
auto_start_one();
}
}
setlistener("/controls/engines/engine[1]/cutoff-switch", func {
2020-11-22 22:00:21 +00:00
if (!pts.Controls.Engines.Engine.cutoffSw[1].getValue()) {
if (pts.Acconfig.running.getValue()) {
2019-10-14 16:48:35 +00:00
fast_start_two();
} else {
2020-11-22 22:00:21 +00:00
if (!manStart[1].getValue()) {
2019-10-14 16:48:35 +00:00
start_two_check();
2020-11-22 22:00:21 +00:00
} else {
2019-10-14 16:48:35 +00:00
eng_two_man_start.start();
}
}
2020-11-22 22:00:21 +00:00
} else if (pts.Controls.Engines.Engine.cutoffSw[1].getValue()) {
2019-10-14 16:48:35 +00:00
cutoff_two();
}
2020-11-22 22:00:21 +00:00
}, 0, 0);
2019-10-14 16:48:35 +00:00
var cutoff_two = func {
eng_two_auto_start.stop();
eng_two_man_start.stop();
eng_two_n2_check.stop();
2020-11-22 22:00:21 +00:00
igniterA[1].setValue(0);
igniterB[1].setValue(0);
manStart[1].setValue(0);
systems.PNEU.Valves.starter2.setValue(0);
pts.Controls.Engines.Engine.starter[1].setValue(0);
pts.Controls.Engines.Engine.cutoff[1].setValue(1);
pts.Engines.Engine.state[1].setValue(0);
2019-10-14 16:48:35 +00:00
interpolate(engines[1].getNode("egt-actual"), 0, egt_shutdown_time);
}
var fast_start_two = func {
2020-11-22 22:00:21 +00:00
pts.Controls.Engines.Engine.cutoff[1].setValue(0);
2020-05-12 20:47:05 +00:00
setprop("/engines/engine[1]/out-of-fuel", 0);
setprop("/engines/engine[1]/run", 1);
2019-10-14 16:48:35 +00:00
2020-05-12 20:47:05 +00:00
setprop("/engines/engine[1]/cutoff", 0);
setprop("/engines/engine[1]/starter", 0);
2019-10-14 16:48:35 +00:00
2020-05-12 20:47:05 +00:00
setprop("/fdm/jsbsim/propulsion/set-running", 1);
2019-10-14 16:48:35 +00:00
2020-11-22 22:00:21 +00:00
pts.Engines.Engine.state[1].setValue(3);
systems.PNEU.Valves.starter2.setValue(0);
2019-10-14 16:48:35 +00:00
}
setlistener("/controls/engines/engine[1]/man-start", func {
start_two_mancheck();
2020-11-22 22:00:21 +00:00
}, 0, 0);
2019-10-14 16:48:35 +00:00
var start_two_mancheck = func {
2020-11-22 22:00:21 +00:00
if (manStart[1].getValue() == 1) {
if (pts.Controls.Engines.startSw.getValue() == 2 and (pts.Controls.Engines.Engine.cutoffSw[1].getValue() == 1)) {
systems.PNEU.Valves.starter2.setValue(1);
2019-10-14 16:48:35 +00:00
settimer(start_two_mancheck_b, 0.5);
}
} else {
2020-10-07 17:24:23 +00:00
if (pts.Engines.Engine.state[1].getValue() == 1 or pts.Engines.Engine.state[1].getValue() == 2) {
2020-11-22 22:00:21 +00:00
systems.PNEU.Valves.starter2.setValue(0);
pts.Engines.Engine.state[1].setValue(0);
pts.Controls.Engines.Engine.starter[1].setValue(0);
2019-10-14 16:48:35 +00:00
}
}
}
var start_two_mancheck_b = func {
2020-05-12 21:03:29 +00:00
if (systems.PNEU.Psi.engine2.getValue() >= 25) {
2020-11-22 22:00:21 +00:00
pts.Engines.Engine.state[1].setValue(1);
pts.Controls.Engines.Engine.starter[1].setValue(1);
2019-10-14 16:48:35 +00:00
}
}
var start_two_check = func {
2020-11-22 22:00:21 +00:00
if (pts.Controls.Engines.startSw.getValue() == 2 and pts.Controls.Engines.Engine.cutoffSw[1].getValue() == 0) {
systems.PNEU.Valves.starter2.setValue(1);
2019-10-14 16:48:35 +00:00
settimer(start_two_check_b, 0.5);
}
}
var start_two_check_b = func {
2020-11-22 22:00:21 +00:00
if (pts.Controls.Engines.startSw.getValue() == 2 and systems.PNEU.Psi.engine2.getValue() >= 25 and !pts.Controls.Engines.Engine.cutoffSw[1].getValue()) {
2019-10-14 16:48:35 +00:00
auto_start_two();
}
}
# Start Engine One
var auto_start_one = func {
2020-11-22 22:00:21 +00:00
pts.Engines.Engine.state[0].setValue(1);
pts.Controls.Engines.Engine.starter[0].setValue(1);
2019-10-14 16:48:35 +00:00
eng_one_auto_start.start();
}
var eng_one_auto_start = maketimer(0.5, func {
2021-10-16 15:48:25 +00:00
if (pts.Engines.Engine.n2Actual[0].getValue() >= 21) {
2019-10-14 16:48:35 +00:00
eng_one_auto_start.stop();
2020-11-22 22:00:21 +00:00
pts.Engines.Engine.state[0].setValue(2);
pts.Controls.Engines.Engine.cutoff[0].setValue(0);
if (lastIgniter[0].getValue() == "B") {
igniterA[0].setValue(1);
igniterB[0].setValue(0);
lastIgniter[0].setValue("A");
} else if (lastIgniter[0].getValue() == "A") {
igniterA[0].setValue(0);
igniterB[0].setValue(1);
lastIgniter[0].setValue("B");
2019-10-14 16:48:35 +00:00
}
interpolate(engines[0].getNode("egt-actual"), egt_start, egt_lightup_time);
eng_one_egt_check.start();
eng_one_n2_check.start();
}
});
var eng_one_man_start = maketimer(0.5, func {
2020-10-03 09:59:43 +00:00
if (pts.Engines.Engine.n2Actual[0].getValue() >= 16.7) {
2019-10-14 16:48:35 +00:00
eng_one_man_start.stop();
2020-11-22 22:00:21 +00:00
pts.Engines.Engine.state[0].setValue(2);
pts.Controls.Engines.Engine.cutoff[0].setValue(0);
igniterA[0].setValue(1);
igniterB[0].setValue(1);
2019-10-14 16:48:35 +00:00
interpolate(engines[0].getNode("egt-actual"), egt_start, egt_lightup_time);
eng_one_egt_check.start();
eng_one_n2_check.start();
}
});
var eng_one_egt_check = maketimer(0.5, func {
2020-11-22 22:00:21 +00:00
if (pts.Engines.Engine.egtActual[0].getValue() >= egt_start) {
2019-10-14 16:48:35 +00:00
eng_one_egt_check.stop();
interpolate(engines[0].getNode("egt-actual"), egt_min, egt_lightdn_time);
}
});
var eng_one_n2_check = maketimer(0.5, func {
2020-10-03 09:59:43 +00:00
if (pts.Engines.Engine.n2Actual[0].getValue() >= 43.0) {
2020-11-22 22:00:21 +00:00
if (igniterA[0].getValue() != 0) {
igniterA[0].setValue(0);
2019-10-14 16:48:35 +00:00
}
2020-11-22 22:00:21 +00:00
if (igniterB[0].getValue() != 0) {
igniterB[0].setValue(0);
2019-10-14 16:48:35 +00:00
}
}
2020-10-03 09:59:43 +00:00
if (pts.Engines.Engine.n2Actual[0].getValue() >= 57.0) {
2019-10-14 16:48:35 +00:00
eng_one_n2_check.stop();
2020-11-22 22:00:21 +00:00
systems.PNEU.Valves.starter1.setValue(0);
pts.Engines.Engine.state[0].setValue(3);
2019-10-14 16:48:35 +00:00
}
});
# Start Engine Two
var auto_start_two = func {
2020-11-22 22:00:21 +00:00
pts.Engines.Engine.state[1].setValue(1);
pts.Controls.Engines.Engine.starter[1].setValue(1);
2019-10-14 16:48:35 +00:00
eng_two_auto_start.start();
}
var eng_two_auto_start = maketimer(0.5, func {
2021-10-16 15:48:25 +00:00
if (pts.Engines.Engine.n2Actual[1].getValue() >= 21) {
2019-10-14 16:48:35 +00:00
eng_two_auto_start.stop();
2020-11-22 22:00:21 +00:00
pts.Engines.Engine.state[1].setValue(2);
pts.Controls.Engines.Engine.cutoff[1].setValue(0);
if (lastIgniter[1].getValue() == "B") {
igniterA[1].setValue(1);
igniterB[1].setValue(0);
lastIgniter[1].setValue("A");
} else if (lastIgniter[1].getValue() == "A") {
igniterA[1].setValue(0);
igniterB[1].setValue(1);
lastIgniter[1].setValue("B");
2019-10-14 16:48:35 +00:00
}
interpolate(engines[1].getNode("egt-actual"), egt_start, egt_lightup_time);
eng_two_egt_check.start();
eng_two_n2_check.start();
}
});
var eng_two_man_start = maketimer(0.5, func {
2020-10-03 09:59:43 +00:00
if (pts.Engines.Engine.n2Actual[1].getValue() >= 16.7) {
2019-10-14 16:48:35 +00:00
eng_two_man_start.stop();
2020-11-22 22:00:21 +00:00
pts.Engines.Engine.state[1].setValue(2);
pts.Controls.Engines.Engine.cutoff[1].setValue(0);
igniterA[1].setValue(1);
igniterB[1].setValue(1);
2019-10-14 16:48:35 +00:00
interpolate(engines[1].getNode("egt-actual"), egt_start, egt_lightup_time);
eng_two_egt_check.start();
eng_two_n2_check.start();
}
});
var eng_two_egt_check = maketimer(0.5, func {
2020-11-22 22:00:21 +00:00
if (pts.Engines.Engine.egtActual[1].getValue() >= egt_start) {
2019-10-14 16:48:35 +00:00
eng_two_egt_check.stop();
interpolate(engines[1].getNode("egt-actual"), egt_min, egt_lightdn_time);
}
});
var eng_two_n2_check = maketimer(0.5, func {
2020-10-03 09:59:43 +00:00
if (pts.Engines.Engine.n2Actual[1].getValue() >= 50.0) {
2020-11-22 22:00:21 +00:00
if (igniterA[1].getValue() != 0) {
igniterA[1].setValue(0);
2019-10-14 16:48:35 +00:00
}
2020-11-22 22:00:21 +00:00
if (igniterB[1].getValue() != 0) {
igniterB[1].setValue(0);
2019-10-14 16:48:35 +00:00
}
}
2020-10-03 09:59:43 +00:00
if (pts.Engines.Engine.n2Actual[1].getValue() >= 57.0) {
2019-10-14 16:48:35 +00:00
eng_two_n2_check.stop();
2020-11-22 22:00:21 +00:00
systems.PNEU.Valves.starter2.setValue(0);
pts.Engines.Engine.state[1].setValue(3);
2019-10-14 16:48:35 +00:00
}
});
# Various Other Stuff
setlistener("/controls/engines/engine-start-switch", func {
2020-10-07 17:24:23 +00:00
if (pts.Engines.Engine.state[0].getValue() == 0) {
2019-10-14 16:48:35 +00:00
start_one_check();
start_one_mancheck();
}
2020-10-07 17:24:23 +00:00
if (pts.Engines.Engine.state[1].getValue() == 0) {
2019-10-14 16:48:35 +00:00
start_two_check();
start_two_mancheck();
}
2020-11-22 22:00:21 +00:00
if ((pts.Controls.Engines.startSw.getValue() == 0) or (pts.Controls.Engines.startSw.getValue() == 1)) {
2020-10-07 17:24:23 +00:00
if (pts.Engines.Engine.state[0].getValue() == 1 or pts.Engines.Engine.state[0].getValue() == 2) {
2020-11-22 22:00:21 +00:00
pts.Controls.Engines.Engine.starter[0].setValue(0);
pts.Controls.Engines.Engine.cutoff[0].setValue(1);
systems.PNEU.Valves.starter1.setValue(0);
pts.Engines.Engine.state[0].setValue(0);
2019-10-14 16:48:35 +00:00
interpolate(engines[0].getNode("egt-actual"), 0, egt_shutdown_time);
}
2020-10-07 17:24:23 +00:00
if (pts.Engines.Engine.state[1].getValue() == 1 or pts.Engines.Engine.state[1].getValue() == 2) {
2020-11-22 22:00:21 +00:00
pts.Controls.Engines.Engine.starter[1].setValue(0);
pts.Controls.Engines.Engine.cutoff[1].setValue(1);
systems.PNEU.Valves.starter2.setValue(0);
pts.Engines.Engine.state[1].setValue(0);
2019-10-14 16:48:35 +00:00
interpolate(engines[1].getNode("egt-actual"), 0, egt_shutdown_time);
}
}
2020-11-22 22:00:21 +00:00
}, 0, 0);
2019-10-14 16:48:35 +00:00
2020-05-12 20:47:05 +00:00
setlistener("/systems/pneumatics/psi/engine-1-psi", func {
2020-05-12 21:03:29 +00:00
if (systems.PNEU.Psi.engine1.getValue() < 24.5) {
2020-10-07 17:24:23 +00:00
if (pts.Engines.Engine.state[0].getValue() == 1 or pts.Engines.Engine.state[0].getValue() == 2) {
2020-11-22 22:00:21 +00:00
pts.Controls.Engines.Engine.starter[0].setValue(0);
pts.Controls.Engines.Engine.cutoff[0].setValue(1);
systems.PNEU.Valves.starter1.setValue(0);
pts.Engines.Engine.state[0].setValue(0);
2019-10-14 16:48:35 +00:00
interpolate(engines[0].getNode("egt-actual"), 0, egt_shutdown_time);
}
2020-05-12 20:47:05 +00:00
}
}, 0, 0);
setlistener("/systems/pneumatics/psi/engine-2-psi", func {
2020-05-12 21:03:29 +00:00
if (systems.PNEU.Psi.engine2.getValue() < 24.5) {
2020-10-07 17:24:23 +00:00
if (pts.Engines.Engine.state[1].getValue() == 1 or pts.Engines.Engine.state[1].getValue() == 2) {
2020-11-22 22:00:21 +00:00
pts.Controls.Engines.Engine.starter[1].setValue(0);
pts.Controls.Engines.Engine.cutoff[1].setValue(1);
systems.PNEU.Valves.starter2.setValue(0);
pts.Engines.Engine.state[1].setValue(0);
2019-10-14 16:48:35 +00:00
interpolate(engines[1].getNode("egt-actual"), 0, egt_shutdown_time);
}
}
2020-05-12 20:47:05 +00:00
}, 0, 0);
2020-07-25 20:04:38 +00:00
setlistener("/engines/engine[0]/state", func() {
2020-10-07 17:24:23 +00:00
setprop("/sim/sound/shutdown[0]", pts.Engines.Engine.state[0].getValue());
2020-07-25 20:04:38 +00:00
}, 0, 0);
setlistener("/engines/engine[1]/state", func() {
2020-10-07 17:24:23 +00:00
setprop("/sim/sound/shutdown[1]", pts.Engines.Engine.state[1].getValue());
2020-07-25 20:04:38 +00:00
}, 0, 0);