This repository has been archived on 2021-09-26. You can view files and clone it, but cannot push or open issues or pull requests.
IDG-A32X/Nasal/pneumatics.nas

230 lines
8.2 KiB
Text

# A320 Pneumatics System
# Joshua Davidson (it0uchpods) and Jonathan Redpath (legoboyvdlp)
#############
# Init Vars #
#############
var pneu_init = func {
setprop("/controls/pneumatic/switches/bleed1", 0);
setprop("/controls/pneumatic/switches/bleed2", 0);
setprop("/controls/pneumatic/switches/bleedapu", 0);
setprop("/controls/pneumatic/switches/groundair", 0);
setprop("/controls/pneumatic/switches/pack1", 0);
setprop("/controls/pneumatic/switches/pack2", 0);
setprop("/controls/pneumatic/switches/hot-air", 0);
setprop("/controls/pneumatic/switches/ram-air", 0);
setprop("/controls/pneumatic/switches/pack-flo", 9); # LO: 7, NORM: 9, HI: 11.
setprop("/controls/pneumatic/switches/xbleed", 1); # SHUT: 0, AUTO: 1, OPEN: 2. # I will simulate later, once I get the knob animated. -JD
setprop("/systems/pneumatic/bleed1", 0);
setprop("/systems/pneumatic/bleed2", 0);
setprop("/systems/pneumatic/bleedapu", 0);
setprop("/systems/pneumatic/groundair", 0);
setprop("/systems/pneumatic/total-psi", 0);
setprop("/systems/pneumatic/start-psi", 0);
setprop("/systems/pneumatic/pack-psi", 0);
setprop("/systems/pneumatic/pack1", 0);
setprop("/systems/pneumatic/pack2", 0);
setprop("/systems/pneumatic/startpsir", 0);
setprop("/systems/pneumatic/eng1-starter", 0);
setprop("/systems/pneumatic/eng2-starter", 0);
pneu_timer.start();
press_timer.start();
}
var press_init = func {
setprop("/FMGC/internal/dep-arpt", "");
setprop("/systems/pressurization/mode", "GN");
setprop("/systems/pressurization/vs", "0");
setprop("/systems/pressurization/auto", 1);
setprop("/systems/pressurization/deltap", "0");
setprop("/systems/pressurization/outflowpos", "0");
var altitude = getprop("/position/altitude-ft");
setprop("/systems/pressurization/cabinalt", altitude); # initially set altitude
}
##############
# Main Loops #
##############
var master_press = func {
var phase = getprop("/FMGC/status/phase");
var pressmode = getprop("/systems/pressurization/mode");
var state1 = getprop("/systems/thrust/state1");
var state2 = getprop("/systems/thrust/state2");
var wowl = getprop("/gear/gear[1]/wow");
var wowr = getprop("/gear/gear[2]/wow");
var deltap = getprop("/systems/pressurization/deltap");
var outflow = getprop("/systems/pressurization/outflowpos");
var speed = getprop("/velocities/groundspeed-kt");
var cabinalt = getprop("/systems/pressurization/cabinalt");
var dep_apt = getprop("autopilot/route-manager/departure/airport");
var airport_dep_elev_ft = getprop("autopilot/route-manager/departure/field-elevation-ft");
var altitude = getprop("/position/altitude-ft");
var airport_arr_elev_ft = getprop("autopilot/route-manager/destination/field-elevation-ft");
var vs = getprop("/systems/pressurization/vs");
var outflowpos = getprop("/systems/pressurization/outflowpos");
var cabinalt = getprop("/systems/pressurization/cabinalt");
# switch mode to TO
if ((pressmode == "GN") and (pressmode != "CL") and (wowl and wowr) and ((state1 == "MCT") or (state1 == "TOGA")) and ((state2 == "MCT") or (state2 == "TOGA"))) {
setprop("/systems/pressurization/mode", "TO");
}
# prepressurization
var pressmode = getprop("/systems/pressurization/mode");
if (pressmode == "TO") {
if (outflowpos == "0") {
interpolate("/systems/pressurization/outflowpos", 1, 1);
}
if (vs > -500 and (outflowpos != 0.5)) {
interpolate("/systems/pressurization/vs", vs - 50, 0.1);
}
if (dep_apt != "") {
if ((cabinalt > (airport_dep_elev_ft - 1)) and (cabinalt < (airport_dep_elev_ft + 1))) {
interpolate("/systems/pressurization/cabinalt", airport_dep_elev_ft - 187, 10);
}
} else {
if ((cabinalt > (altitude - 1)) and (cabinalt < (altitude + 1))) {
interpolate("/systems/pressurization/cabinalt", altitude - 187, 10);
}
}
if (dep_apt != "") {
if (cabinalt < (airport_dep_elev_ft - 183)) {
if (vs < 0) {
interpolate("/systems/pressurization/vs", 0, 1);
}
if (outflowpos == "1") {
interpolate("/systems/pressurization/outflowpos", 0.5, 1);
}
}
} else {
if (cabinalt < (altitude - 183)) {
if (vs < 0) {
interpolate("/systems/pressurization/vs", vs + 50, 0.1);
}
if (outflowpos == "1") {
interpolate("/systems/pressurization/outflowpos", 0.5, 1);
}
}
}
}
# switch mode to CLB
if (((!wowl) or (!wowr)) and (speed > 100) and (pressmode == "TO")) {
setprop("/systems/pressurization/mode", "CL");
}
}
var master_pneu = func {
var bleed1_sw = getprop("/controls/pneumatic/switches/bleed1");
var bleed2_sw = getprop("/controls/pneumatic/switches/bleed2");
var bleedapu_sw = getprop("/controls/pneumatic/switches/bleedapu");
var pack1_sw = getprop("/controls/pneumatic/switches/pack1");
var pack2_sw = getprop("/controls/pneumatic/switches/pack2");
var hot_air_sw = getprop("/controls/pneumatic/switches/hot-air");
var ram_air_sw = getprop("/controls/pneumatic/switches/ram-air");
var pack_flo_sw = getprop("/controls/pneumatic/switches/pack-flo");
var xbleed_sw = getprop("/controls/pneumatic/switches/xbleed");
var eng1_starter = getprop("/systems/pneumatic/eng1-starter");
var eng2_starter = getprop("/systems/pneumatic/eng2-starter");
var groundair = getprop("/systems/pneumatic/groundair");
var groundair_supp = getprop("/controls/pneumatic/switches/groundair");
var rpmapu = getprop("/systems/apu/rpm");
var stateL = getprop("/engines/engine[0]/state");
var stateR = getprop("/engines/engine[1]/state");
var bleedapu_fail = getprop("/systems/failures/bleed-apu");
var bleedext_fail = getprop("/systems/failures/bleed-ext");
var bleedeng1_fail = getprop("/systems/failures/bleed-eng1");
var bleedeng2_fail = getprop("/systems/failures/bleed-eng2");
var pack1_fail = getprop("/systems/failures/pack1");
var pack2_fail = getprop("/systems/failures/pack2");
# Air Sources/PSI
if (rpmapu >= 94.9 and bleedapu_sw and !bleedapu_fail) {
setprop("/systems/pneumatic/bleedapu", 34);
} else {
setprop("/systems/pneumatic/bleedapu", 0);
}
if (stateL == 3 and bleed1_sw and !bleedeng1_fail) {
setprop("/systems/pneumatic/bleed1", 31);
} else {
setprop("/systems/pneumatic/bleed1", 0);
}
if (stateR == 3 and bleed2_sw and !bleedeng2_fail) {
setprop("/systems/pneumatic/bleed2", 32);
} else {
setprop("/systems/pneumatic/bleed2", 0);
}
var bleed1 = getprop("/systems/pneumatic/bleed1");
var bleed2 = getprop("/systems/pneumatic/bleed2");
var bleedapu = getprop("/systems/pneumatic/bleedapu");
var ground = getprop("/systems/pneumatic/groundair");
if (stateL == 1 or stateR == 1) {
setprop("/systems/pneumatic/start-psi", 18);
} else {
setprop("/systems/pneumatic/start-psi", 0);
}
if (pack1_sw == 1 and (bleed1 >= 20 or bleedapu >= 20 or ground >= 20) and eng1_starter == 0 and eng2_starter == 0 and !pack1_fail) {
setprop("/systems/pneumatic/pack1", pack_flo_sw);
} else {
setprop("/systems/pneumatic/pack1", 0);
}
if (pack2_sw == 1 and (bleed2 >= 20 or bleedapu >= 20 or ground >= 20) and eng1_starter == 0 and eng2_starter == 0 and !pack2_fail) {
setprop("/systems/pneumatic/pack2", pack_flo_sw);
} else {
setprop("/systems/pneumatic/pack2", 0);
}
var pack1 = getprop("/systems/pneumatic/pack1");
var pack2 = getprop("/systems/pneumatic/pack2");
if (pack1_sw == 1 and pack2_sw == 1) {
setprop("/systems/pneumatic/pack-psi", pack1 + pack2);
} else if (pack1_sw == 0 and pack2_sw == 0) {
setprop("/systems/pneumatic/pack-psi", 0);
} else {
setprop("/systems/pneumatic/pack-psi", pack1 + pack2 + 5);
}
var pack_psi = getprop("/systems/pneumatic/pack-psi");
var start_psi = getprop("/systems/pneumatic/start-psi");
if ((bleed1 + bleed2 + bleedapu) > 42) {
setprop("/systems/pneumatic/total-psi", 42);
} else {
var total_psi_calc = ((bleed1 + bleed2 + bleedapu + ground) - start_psi - pack_psi);
setprop("/systems/pneumatic/total-psi", total_psi_calc);
}
if (groundair_supp) {
setprop("/systems/pneumatic/groundair", 39);
} else {
setprop("/systems/pneumatic/groundair", 0);
}
var total_psi = getprop("/systems/pneumatic/total-psi");
}
###################
# Update Function #
###################
var update_pneumatic = func {
master_pneu();
}
var pneu_timer = maketimer(0.2, update_pneumatic);
var update_press = func {
master_press();
}
var press_timer = maketimer(0.1, update_press);