From 5417101ca0f5580fff06d0c15445bfb838b195c5 Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Thu, 16 Apr 2020 13:25:06 +0100 Subject: [PATCH] Add experimental vertical flightplan phases, allow user to set cruise flight level in descent phase --- Nasal/FMGC/FMGC.nas | 74 +++++++++++++++++++++++++----------------- Nasal/MCDU/MCDU.nas | 5 +++ Nasal/MCDU/PROGDES.nas | 2 +- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/Nasal/FMGC/FMGC.nas b/Nasal/FMGC/FMGC.nas index aa9c3c0a..fa95669e 100644 --- a/Nasal/FMGC/FMGC.nas +++ b/Nasal/FMGC/FMGC.nas @@ -37,7 +37,7 @@ var wowr = 0; var targetalt = 0; var targetvs = 0; var targetfpa = 0; -var reduc_agl_ft = 0; +var accel_agl_ft = 0; var locarm = 0; var apprarm = 0; var gear0 = 0; @@ -95,6 +95,8 @@ var newvert = 0; var newvertarm = 0; var thr1 = 0; var thr2 = 0; +var altsel = 0; +var crzFl = 0; setprop("FMGC/internal/maxspeed", 0); setprop("FMGC/internal/minspeed", 0); setprop("position/gear-agl-ft", 0); @@ -127,6 +129,7 @@ var FMGCinit = func { setprop("FMGC/internal/decel", 0); setprop("FMGC/internal/loc-source", "NAV0"); setprop("FMGC/internal/optalt", 0); + setprop("FMGC/internal/landing-time", -99); masterFMGC.start(); various.start(); various2.start(); @@ -193,7 +196,7 @@ var masterFMGC = maketimer(0.2, func { targetalt = getprop("it-autoflight/internal/alt"); targetvs = getprop("it-autoflight/input/vs"); targetfpa = getprop("it-autoflight/input/fpa"); - reduc_agl_ft = getprop("it-autoflight/settings/accel-agl-ft"); + accel_agl_ft = getprop("it-autoflight/settings/accel-agl-ft"); locarm = getprop("it-autopilot/output/loc-armed"); apprarm = getprop("it-autopilot/output/appr-armed"); gear0 = getprop("gear/gear[0]/wow"); @@ -210,71 +213,65 @@ var masterFMGC = maketimer(0.2, func { gear0 = getprop("gear/gear[0]/wow"); state1 = getprop("systems/thrust/state1"); state2 = getprop("systems/thrust/state2"); + altSel = getprop("it-autoflight/input/alt"); + crzFl = getprop("FMGC/internal/cruise-fl"); if (getprop("gear/gear[0]/wow") != getprop("gear/gear[0]/wow-fmgc")) { setprop("gear/gear[0]/wow-fmgc", getprop("gear/gear[0]/wow")); } - if ((n1_left < 70 or n1_right < 70) and gs < 90 and mode == " " and gear0 == 1 and phase == 1) { + if ((n1_left < 85 or n1_right < 85) and gs < 90 and mode == " " and gear0 == 1 and phase == 1) { # rejected takeoff setprop("FMGC/status/phase", 0); setprop("systems/pressurization/mode", "GN"); } - if (gear0 == 1 and phase == 0 and ((n1_left >= 70 and n1_right >= 70) or gs >= 90) and (state1 == "TOGA" or state2 == "TOGA") or (flx == 1 and (state1 == "MCT" or state2 == "MCT")) or (flx == 1 and ((state1 == "MAN THR" and thr1 >= 0.83) or - (state2 == "MAN THR" and thr2 >= 0.83)))) { + if (gear0 == 1 and phase == 0 and ((n1_left >= 85 and n1_right >= 85) or gs >= 90) and mode == "SRS") { setprop("FMGC/status/phase", 1); setprop("systems/pressurization/mode", "TO"); } - if (phase == 1 and ((mode != "SRS" and mode != " ") or alt >= reduc_agl_ft)) { + if (phase == 1 and ((mode != "SRS" and mode != " ") or alt >= accel_agl_ft)) { setprop("FMGC/status/phase", 2); setprop("systems/pressurization/mode", "TO"); } - if ((phase == 3 or phase == 4) and (mode == "OP CLB" or mode == "CLB" or (modeI == "V/S" and getprop("it-autoflight/input/vs") >= 100) or (modeI == "FPA" and getprop("it-autoflight/input/fpa") >= 0.1))) { - setprop("FMGC/status/phase", 2); - setprop("systems/pressurization/mode", "TO"); - } - - if ((phase == 2 or phase == 4) and (mode == "ALT" or mode == "ALT CRZ" or mode == "ALT CST")) { + if (phase == 2 and (mode == "ALT CRZ" or mode == "ALT CRZ*")) { setprop("FMGC/status/phase", 3); setprop("systems/pressurization/mode", "CR"); } - if ((phase == 2 or phase == 3) and (mode == "OP DES" or mode == "DES" or (modeI == "V/S" and getprop("it-autoflight/input/vs") <= -100) or (modeI == "FPA" and getprop("it-autoflight/input/fpa") <= -0.1))) { - setprop("FMGC/status/phase", 4); - setprop("systems/pressurization/mode", "DE"); + if (crzFl >= 20000) { + if ((phase == 2 or phase == 3) and (flightPlanController.arrivalDist <= 200 or altSel < 20000)) { + setprop("FMGC/status/phase", 4); + setprop("systems/pressurization/mode", "DE"); + } + } else { + if ((phase == 2 or phase == 3) and (flightPlanController.arrivalDist <= 200 or altSel < crzFl)) { # todo - not sure about crzFl condition, investigate what happens! + setprop("FMGC/status/phase", 4); + setprop("systems/pressurization/mode", "DE"); + } } - if (!wowl and !wowr and aglalt < 7200 and (phase == "4" or mode == "G/S" or mode == "LAND" or mode == "FLARE")) { + if (getprop("/FMGC/internal/decel")) { setprop("FMGC/status/phase", 5); } - if (flightPlanController.num[2].getValue() > 0 and getprop("/FMGC/flightplan[2]/active") == 1 and flightPlanController.arrivalDist <= 15) { + if (flightPlanController.num[2].getValue() > 0 and getprop("/FMGC/flightplan[2]/active") == 1 and flightPlanController.arrivalDist <= 15 and (modelat == "NAV" or modelat == "LOC" or modelat == "LOC*") and aglalt < 9500) { #todo decel pseudo waypoint setprop("/FMGC/internal/decel", 1); } else if (getprop("/FMGC/internal/decel") == 1 and (phase == 0 or phase == 6)) { setprop("/FMGC/internal/decel", 0); } - #handle go-around - if ((phase == "5" or phase == "7") and state1 == "TOGA" and state2 == "TOGA") { + if ((phase == "5") and state1 == "TOGA" and state2 == "TOGA") { setprop("FMGC/status/phase", 6); setprop("systems/pressurization/mode", "TO"); setprop("it-autoflight/input/toga", 1); } - if (phase == "6" and alt >= reduc_agl_ft) { + if (phase == "6" and alt >= accel_agl_ft) { # todo when insert altn or new dest setprop("FMGC/status/phase", 2); } - if (wowl and wowr and (phase == "2" or phase == "3" or phase == "4" or phase == "5" or phase == "6")) { - setprop("FMGC/status/phase", 7); - } - - if (wowl and wowr and gs <= 40 and phase == "7" and ap1 == 0 and ap2 == 0) { - reset_FMGC(); - } - if (getprop("systems/navigation/adr/computation/overspeed-vfe-spd") != 1024) { setprop("FMGC/internal/maxspeed", getprop("systems/navigation/adr/computation/overspeed-vfe-spd") - 4); } elsif (pts.Gear.position[0].getValue() != 0 or pts.Gear.position[1].getValue() != 0 or pts.Gear.position[2].getValue() != 0) { @@ -751,4 +748,23 @@ var switchDatabase = func { setprop("FMGC/internal/navdatabase2", database1); setprop("FMGC/internal/navdatabasecode", code2); setprop("FMGC/internal/navdatabasecode2", code1); -} \ No newline at end of file +} + +setlistener("gear/gear[1]/wow", func() { + if (timer30secLandingstart.isRunning) { + timer30secLandingstart.stop(); + } + + if (getprop("gear/gear[1]/wow") == 1 and getprop("FMGC/internal/landing-time") == -99) { + timer30secLandingstart(); + setprop("FMGC/internal/landing-time", pts.Sim.Time.elapsedSec.getValue()); + } +}, 0, 0); + +var timer30secLandingstart = maketimer(0.1, func() { + if (pts.Sim.Time.elapsedSec.getValue() > getprop("FMGC/internal/landing-time") + 30) { + setprop("FMGC/status/phase", 7); + setprop("FMGC/internal/landing-time", -99); + timer30secLandingstart.stop(); + } +}); \ No newline at end of file diff --git a/Nasal/MCDU/MCDU.nas b/Nasal/MCDU/MCDU.nas index 7d5fb483..676e674b 100644 --- a/Nasal/MCDU/MCDU.nas +++ b/Nasal/MCDU/MCDU.nas @@ -674,8 +674,13 @@ var pagebutton = func(btn, i) { setprop("MCDU[" ~ i ~ "]/page", "PERFAPPR"); } else if (getprop("FMGC/status/phase") == 6) { setprop("MCDU[" ~ i ~ "]/page", "PERFGA"); + } else if (getprop("FMGC/status/phase") == 7) { + reset_FMGC(); } } else if (btn == "init") { + if (getprop("FMGC/status/phase") == 7) { + reset_FMGC(); + } setprop("MCDU[" ~ i ~ "]/page", "INITA"); } else if (btn == "data") { setprop("MCDU[" ~ i ~ "]/page", "DATA"); diff --git a/Nasal/MCDU/PROGDES.nas b/Nasal/MCDU/PROGDES.nas index 6af9365c..23d9d5b8 100644 --- a/Nasal/MCDU/PROGDES.nas +++ b/Nasal/MCDU/PROGDES.nas @@ -16,7 +16,7 @@ var progDESInput = func(key, i) { if (crzs >= 1 and crzs <= 3 and scratchpad > 0 and scratchpad <= 430 and altSet.getValue() <= scratchpad * 100) { setprop("FMGC/internal/cruise-fl-prog", scratchpad); setprop("MCDU[" ~ i ~ "]/scratchpad", ""); - if (getprop("FMGC/status/phase") == 5 or getprop("FMGC/status/phase") == 6) { + if (getprop("FMGC/status/phase") == 4 or getprop("FMGC/status/phase") == 5 or getprop("FMGC/status/phase") == 6) { setprop("FMGC/status/phase", 3); setprop("FMGC/internal/activate-once", 0); setprop("FMGC/internal/activate-twice", 0);