2017-05-29 16:39:03 +00:00
# A3XX FMGC
2017-05-13 13:24:02 +00:00
# Joshua Davidson (it0uchpods) and Jonathan Redpath (legoboyvdlp)
2017-05-08 01:34:45 +00:00
2017-05-13 14:45:26 +00:00
##################
# Init Functions #
##################
setprop("/position/gear-agl-ft", 0);
2017-05-13 13:24:02 +00:00
var FMGCinit = func {
2017-05-13 14:45:26 +00:00
setprop("/FMGC/status/to-state", 0);
setprop("/FMGC/status/phase", "0"); # 0 is preflight 1 takeoff 2 climb 3 cruise 4 descent 5 approach 6 go around 7 done
2017-05-15 16:14:56 +00:00
setprop("/FMGC/internal/tropo", 36090);
2017-05-13 14:45:26 +00:00
phasecheck.start();
2017-05-27 04:15:06 +00:00
various.start();
2017-05-13 13:24:02 +00:00
}
2017-05-08 01:34:45 +00:00
2017-05-13 14:45:26 +00:00
#############
# TO Status #
#############
2017-05-08 01:34:45 +00:00
setlistener("/gear/gear[1]/wow", func {
2017-05-11 22:58:16 +00:00
flarecheck();
2017-05-08 01:34:45 +00:00
});
setlistener("/gear/gear[2]/wow", func {
2017-05-11 22:58:16 +00:00
flarecheck();
2017-05-08 01:34:45 +00:00
});
2017-05-11 22:58:16 +00:00
var flarecheck = func {
2017-05-08 01:34:45 +00:00
var gear1 = getprop("/gear/gear[1]/wow");
var gear2 = getprop("/gear/gear[2]/wow");
var state1 = getprop("/systems/thrust/state1");
var state2 = getprop("/systems/thrust/state2");
var flaps = getprop("/controls/flight/flap-pos");
2017-05-13 14:45:26 +00:00
if (gear1 == 1 and gear2 == 1 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA") and flaps < 4) {
2017-05-08 01:34:45 +00:00
setprop("/FMGC/status/to-state", 1);
}
if (getprop("/position/gear-agl-ft") >= 55) {
setprop("/FMGC/status/to-state", 0);
}
if (gear1 == 1 and gear2 == 1 and getprop("/FMGC/status/to-state") == 0 and flaps >= 4) {
setprop("/controls/flight/elevator-trim", -0.15);
}
2017-05-13 13:24:02 +00:00
}
2017-05-21 17:20:14 +00:00
###############
# MCDU Inputs #
###############
var updateARPT = func {
var dep = getprop("/FMGC/internal/dep-arpt");
var arr = getprop("/FMGC/internal/arr-arpt");
setprop("/autopilot/route-manager/departure/airport", dep);
setprop("/autopilot/route-manager/destination/airport", arr);
}
setlistener("/FMGC/internal/cruise-ft", func {
setprop("/autopilot/route-manager/cruise/altitude-ft", getprop("/FMGC/internal/cruise-ft"));
});
2017-05-13 14:45:26 +00:00
################
# Flight Phase #
################
2017-05-27 04:15:06 +00:00
var phasecheck = maketimer(0.2, func {
2017-05-13 13:24:02 +00:00
var n1_left = getprop("/engines/engine[0]/n1");
var n1_right = getprop("/engines/engine[1]/n1");
var flaps = getprop("/controls/flight/flap-pos");
var mode = getprop("/modes/pfd/fma/pitch-mode");
var gs = getprop("/velocities/groundspeed-kt");
var alt = getprop("/instrumentation/altimeter/indicated-altitude-ft");
2017-05-18 18:41:33 +00:00
var cruisefl = getprop("/FMGC/internal/cruise-ft");
2017-05-13 14:45:26 +00:00
var newcruise = getprop("/it-autoflight/internal/alt");
2017-05-13 13:24:02 +00:00
var phase = getprop("/FMGC/status/phase");
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");
2017-05-13 14:45:26 +00:00
var targetalt = getprop("/it-autoflight/internal/alt");
2017-05-13 13:24:02 +00:00
var targetvs = getprop("/it-autoflight/input/vs");
var targetfpa = getprop("/it-autoflight/input/fpa");
2017-05-13 13:58:01 +00:00
var vertmode = getprop("/modes/pfd/fma/pitch-mode");
2017-05-13 13:24:02 +00:00
if ((((n1_left >= 85) and (n1_right >= 85)) or (gs > 90 )) and flaps < 4 and (mode == "SRS")) {
setprop("/FMGC/status/phase", "1");
2017-06-02 14:31:17 +00:00
setprop("/systems/pressurization/mode", "TO");
2017-05-13 13:24:02 +00:00
}
2017-05-18 13:19:56 +00:00
if ((alt >= 3000) and (alt <= cruisefl) and (phase == "1") and (phase != "4") and (mode != "SRS")) {
2017-05-13 13:24:02 +00:00
setprop("/FMGC/status/phase", "2");
}
if ((alt >= cruisefl) and (phase == "2") and (mode != "SRS")) {
2017-06-02 14:31:17 +00:00
setprop("/FMGC/status/phase", "3");
setprop("/systems/pressurization/mode", "CR");
2017-05-13 13:24:02 +00:00
}
if ((alt <= cruisefl) and (phase == "3")) { # for now it will have to be when we begin descent.
setprop("/FMGC/status/phase", "4");
2017-06-02 14:31:17 +00:00
setprop("/systems/pressurization/mode", "DE");
2017-05-13 13:24:02 +00:00
}
if (getprop("/FMGC/status/to-state") == 0 and flaps >= 4 and ((phase == "4") or (phase == "2"))) { # add man activation of approach phase in MCDU or DECEL when those things are simulated
setprop("/FMGC/status/phase", "5");
}
if ((phase == "5") and (state1 == "TOGA") and (state2 == "TOGA")) { # this is the only fully correct one to FCOM
setprop("/FMGC/status/phase", "6");
2017-05-26 17:50:53 +00:00
setprop("/it-autoflight/input/toga", 1);
2017-05-13 13:24:02 +00:00
}
# forget transition from APP to climb for now because it would be too complex
2017-05-13 13:58:01 +00:00
if ((phase == "6") and ((vertmode == "G/A CLB") or (vertmode == "SPD CLB") or (vertmode == "CLB") or ((vertmode == "V/S") and (targetvs > 0)) or ((vertmode == "FPA") and (targetfpa > 0))) and (alt <= targetalt)) {
2017-05-13 13:24:02 +00:00
setprop("/FMGC/status/phase", "2"); # going to CLIMB mode from GA
}
2017-05-27 04:15:06 +00:00
if ((wowl and wowr) and (gs < 20) and (phase == "5")) {
2017-05-13 13:24:02 +00:00
setprop("/FMGC/status/phase", "7");
2017-05-27 19:11:48 +00:00
var fd1 = getprop("/it-autoflight/input/fd1");
var fd2 = getprop("/it-autoflight/input/fd2");
itaf.ap_init();
FMGCinit();
mcdu1.MCDU_reset();
mcdu2.MCDU_reset();
setprop("/it-autoflight/input/fd1", fd1);
setprop("/it-autoflight/input/fd2", fd2);
2017-06-02 14:31:17 +00:00
press_init();
2017-05-13 13:24:02 +00:00
}
});
2017-05-27 04:15:06 +00:00
var various = maketimer(1, func {
if (getprop("/engines/engine[0]/state") == 3 and getprop("/engines/engine[1]/state") != 3) {
setprop("/it-autoflight/settings/reduc-agl-ft", getprop("/FMGC/internal/eng-out-reduc"));
} else if (getprop("/engines/engine[0]/state") != 3 and getprop("/engines/engine[1]/state") == 3) {
setprop("/it-autoflight/settings/reduc-agl-ft", getprop("/FMGC/internal/eng-out-reduc"));
} else {
setprop("/it-autoflight/settings/reduc-agl-ft", getprop("/FMGC/internal/reduc-agl-ft"));
}
});
2017-05-18 13:19:56 +00:00