1
0
Fork 0
A320-family/Nasal/Systems/fuel.nas

253 lines
9.3 KiB
Text
Raw Normal View History

2019-10-14 16:48:35 +00:00
# A3XX Fuel System
# 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
var FUEL = {
2019-11-08 18:22:29 +00:00
offset1: 0,
offset2: 0,
2019-11-07 21:47:16 +00:00
timeEngStart: 0,
2020-02-07 16:10:54 +00:00
cmdCtrOn: props.globals.getNode("systems/fuel/ctr-pump-cmd-on-eng-start"),
refuelling: props.globals.getNode("systems/fuel/refuel/refuelling"),
2019-11-07 21:47:16 +00:00
Fail: {
},
Switches: {
2020-02-07 16:10:54 +00:00
centerTkMode: props.globals.getNode("controls/fuel/switches/center-mode"),
crossfeed: props.globals.getNode("controls/fuel/switches/crossfeed"),
pumpLeft1: props.globals.getNode("controls/fuel/switches/pump-left-1"),
pumpLeft2: props.globals.getNode("controls/fuel/switches/pump-left-2"),
pumpCenter1: props.globals.getNode("controls/fuel/switches/pump-center-1"),
pumpCenter2: props.globals.getNode("controls/fuel/switches/pump-center-2"),
pumpRight1: props.globals.getNode("controls/fuel/switches/pump-right-1"),
pumpRight2: props.globals.getNode("controls/fuel/switches/pump-right-2"),
2019-11-07 21:47:16 +00:00
},
Pumps: {
2020-02-07 16:10:54 +00:00
apu: props.globals.getNode("systems/fuel/pumps/apu-operate"),
allOff: props.globals.getNode("systems/fuel/pumps/all-eng-pump-off"),
},
2019-11-07 21:47:16 +00:00
Valves: {
2020-04-17 20:56:12 +00:00
apu: props.globals.getNode("systems/fuel/valves/apu-lp-valve"),
2020-02-07 16:10:54 +00:00
crossfeed: props.globals.getNode("systems/fuel/valves/crossfeed-valve"),
lpValve1: props.globals.getNode("systems/fuel/valves/engine-1-lp-valve"),
lpValve2: props.globals.getNode("systems/fuel/valves/engine-2-lp-valve"),
transfer1: props.globals.getNode("systems/fuel/valves/outer-inner-transfer-valve-1"),
transfer2: props.globals.getNode("systems/fuel/valves/outer-inner-transfer-valve-2"),
refuelLeft: props.globals.getNode("systems/fuel/refuel/left-valve"),
refuelCenter: props.globals.getNode("systems/fuel/refuel/center-valve"),
refuelRight: props.globals.getNode("systems/fuel/refuel/right-valve"),
2019-11-07 21:47:16 +00:00
},
Quantity: {
2020-02-07 16:10:54 +00:00
leftOuter: props.globals.getNode("consumables/fuel/tank[0]/level-lbs"),
leftOuterPct: props.globals.getNode("consumables/fuel/tank[0]/level-norm"),
leftInner: props.globals.getNode("consumables/fuel/tank[1]/level-lbs"),
leftInnerPct: props.globals.getNode("consumables/fuel/tank[1]/level-norm"),
center: props.globals.getNode("consumables/fuel/tank[2]/level-lbs"),
centerPct: props.globals.getNode("consumables/fuel/tank[2]/level-norm"),
rightInner: props.globals.getNode("consumables/fuel/tank[3]/level-lbs"),
rightInnerPct: props.globals.getNode("consumables/fuel/tank[3]/level-norm"),
rightOuter: props.globals.getNode("consumables/fuel/tank[4]/level-lbs"),
rightOuterPct: props.globals.getNode("consumables/fuel/tank[4]/level-norm"),
usedLeft: props.globals.getNode("systems/fuel/fuel-used-1"),
usedRight: props.globals.getNode("systems/fuel/fuel-used-2"),
2019-11-07 21:47:16 +00:00
},
resetFail: func() {
},
init: func() {
},
loop: func() {
systems.FUEL.Quantity.usedLeft.setValue(pts.Fdm.JSBsim.Propulsion.Engine.fuelUsed[0].getValue() + me.offset1);
systems.FUEL.Quantity.usedRight.setValue(pts.Fdm.JSBsim.Propulsion.Engine.fuelUsed[1].getValue() + me.offset2);
2019-11-07 21:47:16 +00:00
},
2019-11-08 18:22:29 +00:00
setOffset: func() {
me.offset1 = me.offset1 -(pts.Fdm.JSBsim.Propulsion.Engine.fuelUsed[0].getValue());
me.offset2 = me.offset2 -(pts.Fdm.JSBsim.Propulsion.Engine.fuelUsed[1].getValue());
2019-11-08 18:22:29 +00:00
}
2019-11-07 21:47:16 +00:00
};
setlistener("/engines/engine[0]/state", func() {
2020-04-27 13:58:38 +00:00
if (pts.Engines.Engine.state[0].getValue() == 3) {
2019-11-07 21:47:16 +00:00
FUEL.timeEngStart = pts.Sim.Time.elapsedSec.getValue();
FUEL.cmdCtrOn.setValue(1);
ctrTkTimer.start();
}
}, 0, 0);
setlistener("/engines/engine[1]/state", func() {
2020-04-27 13:58:38 +00:00
if (pts.Engines.Engine.state[1].getValue() == 3) {
2019-11-07 21:47:16 +00:00
FUEL.timeEngStart = pts.Sim.Time.elapsedSec.getValue();
FUEL.cmdCtrOn.setValue(1);
ctrTkTimer.start();
}
}, 0, 0);
var FUELx = {
2019-10-14 16:48:35 +00:00
init: func() {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/gravityfeedL", 0);
setprop("systems/fuel/gravityfeedR", 0);
setprop("systems/fuel/gravityfeedL-output", 0);
setprop("systems/fuel/gravityfeedR-output", 0);
setprop("controls/fuel/x-feed", 0);
setprop("controls/fuel/tank0pump1", 0);
setprop("controls/fuel/tank0pump2", 0);
setprop("controls/fuel/tank1pump1", 0);
setprop("controls/fuel/tank1pump2", 0);
setprop("controls/fuel/tank2pump1", 0);
setprop("controls/fuel/tank2pump2", 0);
setprop("controls/fuel/mode", 1);
setprop("systems/fuel/valves/crossfeed-valve", 0);
setprop("systems/fuel/tank[0]/feed", 0);
setprop("systems/fuel/tank[1]/feed", 0);
setprop("systems/fuel/tank[2]/feed", 0);
setprop("systems/fuel/only-use-ctr-tank", 0);
setprop("systems/fuel/tank0pump1-fault", 0);
setprop("systems/fuel/tank0pump2-fault", 0);
setprop("systems/fuel/tank1pump1-fault", 0);
setprop("systems/fuel/tank1pump2-fault", 0);
setprop("systems/fuel/tank2pump1-fault", 0);
setprop("systems/fuel/tank2pump2-fault", 0);
setprop("systems/fuel/mode-fault", 0);
2019-10-14 16:48:35 +00:00
},
loop: func() {
2020-02-07 16:10:54 +00:00
xfeed_sw = getprop("controls/fuel/x-feed");
tank0pump1_sw = getprop("controls/fuel/tank0pump1");
tank0pump2_sw = getprop("controls/fuel/tank0pump2");
tank1pump1_sw = getprop("controls/fuel/tank1pump1");
tank1pump2_sw = getprop("controls/fuel/tank1pump2");
tank2pump1_sw = getprop("controls/fuel/tank2pump1");
tank2pump2_sw = getprop("controls/fuel/tank2pump2");
mode_sw = getprop("controls/fuel/mode");
xfeed = getprop("systems/fuel/valves/crossfeed-valve");
ac1 = getprop("systems/electrical/bus/ac-1");
ac2 = getprop("systems/electrical/bus/ac-2");
gravityfeedL = getprop("systems/fuel/gravityfeedL");
gravityfeedR = getprop("systems/fuel/gravityfeedR");
gload = getprop("accelerations/pilot-gdamped");
tank0pump1_fail = getprop("systems/failures/tank0pump1");
tank0pump2_fail = getprop("systems/failures/tank0pump2");
tank1pump1_fail = getprop("systems/failures/tank1pump1");
tank1pump2_fail = getprop("systems/failures/tank1pump2");
tank2pump1_fail = getprop("systems/failures/tank2pump1");
tank2pump2_fail = getprop("systems/failures/tank2pump2");
2019-10-14 16:48:35 +00:00
if (gload >= 0.7 and gravityfeedL) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/gravityfeedL-output", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/gravityfeedL-output", 0);
2019-10-14 16:48:35 +00:00
}
if (gload >= 0.7 and gravityfeedR) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/gravityfeedR-output", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/gravityfeedR-output", 0);
2019-10-14 16:48:35 +00:00
}
2020-02-07 16:10:54 +00:00
gravityfeedL_output = getprop("systems/fuel/gravityfeedL-output");
gravityfeedR_output = getprop("systems/fuel/gravityfeedR-output");
2019-10-14 16:48:35 +00:00
if ((ac1 >= 110 or ac2 >= 110) and tank0pump1_sw and !tank0pump1_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank[0]/feed", 1);
2019-10-14 16:48:35 +00:00
} else if ((ac1 >= 110 or ac2 >= 110) and tank0pump2_sw and !tank0pump2_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank[0]/feed", 1);
2019-10-14 16:48:35 +00:00
} else if (gravityfeedL_output) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank[0]/feed", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank[0]/feed", 0);
2019-10-14 16:48:35 +00:00
}
if ((ac1 >= 110 or ac2 >= 110) and tank1pump1_sw and !tank1pump1_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank[1]/feed", 1);
2019-10-14 16:48:35 +00:00
} else if ((ac1 >= 110 or ac2 >= 110) and tank1pump2_sw and !tank1pump2_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank[1]/feed", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank[1]/feed", 0);
2019-10-14 16:48:35 +00:00
}
if ((ac1 >= 110 or ac2 >= 110) and tank2pump1_sw and !tank2pump1_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank[2]/feed", 1);
2019-10-14 16:48:35 +00:00
} else if ((ac1 >= 110 or ac2 >= 110) and tank2pump2_sw and !tank2pump2_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank[2]/feed", 1);
2019-10-14 16:48:35 +00:00
} else if (gravityfeedR_output) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank[2]/feed", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank[2]/feed", 0);
2019-10-14 16:48:35 +00:00
}
if ((ac1 >= 110 or ac2 >= 110) and xfeed_sw) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/valves/crossfeed-valve", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/valves/crossfeed-valve", 0);
2019-10-14 16:48:35 +00:00
}
2020-02-07 16:10:54 +00:00
tank0 = getprop("systems/fuel/tank[0]/feed");
tank1 = getprop("systems/fuel/tank[1]/feed");
tank2 = getprop("systems/fuel/tank[2]/feed");
2019-10-14 16:48:35 +00:00
if ((ac1 >= 110 or ac2 >= 110) and (tank0pump1_sw or tank0pump2_sw)) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/gravityfeedL", 0);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/gravityfeedL", 1);
2019-10-14 16:48:35 +00:00
}
if ((ac1 >= 110 or ac2 >= 110) and (tank2pump1_sw or tank2pump2_sw)) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/gravityfeedR", 0);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/gravityfeedR", 1);
2019-10-14 16:48:35 +00:00
}
2020-02-07 16:10:54 +00:00
gravityfeedL = getprop("systems/fuel/gravityfeedL");
gravityfeedR = getprop("systems/fuel/gravityfeedR");
2019-10-14 16:48:35 +00:00
2020-02-07 16:10:54 +00:00
if ((getprop("fdm/jsbsim/propulsion/tank[1]/contents-lbs") >= 50) and (tank1pump1_sw or tank1pump2_sw) and !gravityfeedL and !gravityfeedR) {
setprop("systems/fuel/only-use-ctr-tank", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/only-use-ctr-tank", 0);
2019-10-14 16:48:35 +00:00
}
# Fault lights
if (tank0pump1_sw and tank0pump1_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank0pump1-fault", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank0pump1-fault", 0);
2019-10-14 16:48:35 +00:00
}
if (tank0pump2_sw and tank0pump2_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank0pump2-fault", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank0pump2-fault", 0);
2019-10-14 16:48:35 +00:00
}
if (tank1pump1_sw and tank1pump1_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank1pump1-fault", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank1pump1-fault", 0);
2019-10-14 16:48:35 +00:00
}
if (tank1pump2_sw and tank1pump2_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank1pump2-fault", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank1pump2-fault", 0);
2019-10-14 16:48:35 +00:00
}
if (tank2pump1_sw and tank2pump1_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank2pump1-fault", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank2pump1-fault", 0);
2019-10-14 16:48:35 +00:00
}
if (tank2pump2_sw and tank2pump2_fail) {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank2pump2-fault", 1);
2019-10-14 16:48:35 +00:00
} else {
2020-02-07 16:10:54 +00:00
setprop("systems/fuel/tank2pump2-fault", 0);
2019-10-14 16:48:35 +00:00
}
},
};
2019-11-07 21:47:16 +00:00
var ctrTkTimer = maketimer(0.5, func() {
if (pts.Sim.Time.elapsedSec.getValue() > (FUEL.timeEngStart + 120)) {
FUEL.cmdCtrOn.setValue(0);
ctrTkTimer.stop()
}
});