From b4e59e15b85c282cbecda6285cad9798009359db Mon Sep 17 00:00:00 2001 From: Inuyaksa Date: Sat, 5 Jun 2021 14:59:50 +0200 Subject: [PATCH 01/11] some logic optiomizing --- Models/Instruments/MCDU/MCDU.nas | 81 ++++++---- Nasal/FMGC/FMGC.nas | 248 ++++++++++++++++++++----------- Nasal/FMGC/flightplan.nas | 5 + 3 files changed, 214 insertions(+), 120 deletions(-) diff --git a/Models/Instruments/MCDU/MCDU.nas b/Models/Instruments/MCDU/MCDU.nas index f9e09f1c..44194563 100644 --- a/Models/Instruments/MCDU/MCDU.nas +++ b/Models/Instruments/MCDU/MCDU.nas @@ -410,9 +410,14 @@ var canvas_MCDU_base = { } } return irsstatus; + }, + onPageUpdate: func(p) { + }, updateCommon: func(i) { page = pageProp[i].getValue(); + var phase = fmgc.FMGCInternal.phase; + if (page != "NOTIFICATION") { me["NOTIFY"].hide(); me["NOTIFY_FLTNBR"].hide(); @@ -2114,7 +2119,7 @@ var canvas_MCDU_base = { me.colorRightS("wht", "wht", "wht", "wht", "grn", "wht"); me.colorRightArrow("wht", "wht", "wht", "wht", "wht", "wht"); - if (fmgc.FMGCInternal.phase == 0 or fmgc.FMGCInternal.phase == 7) { # only on preflight and done phases + if (phase == 0 or phase == 7) { # only on preflight and done phases me["Simple_L5S"].setText("CHG CODE"); me["Simple_L5S"].show(); me["Simple_L5"].setText("[ ]"); @@ -2164,7 +2169,7 @@ var canvas_MCDU_base = { me["arrow5R"].setColor(getprop("/MCDUC/colors/blu/r"),getprop("/MCDUC/colors/blu/g"),getprop("/MCDUC/colors/blu/b")); } - if (fmgc.FMGCInternal.phase == 0 or fmgc.FMGCInternal.phase == 7) { + if (phase == 0 or phase == 7) { me["Simple_L5"].show(); me["Simple_L5S"].show(); } else { @@ -2476,7 +2481,7 @@ var canvas_MCDU_base = { } } - if (fmgc.FMGCInternal.phase == 7) { # DONE phase + if (phase == 7) { # DONE phase if (fmgc.FMGCInternal.arrApt != nil and fmgc.flightPlanController.flightplans[2].departure_runway != nil) { me["Simple_R1S"].setText(sprintf("DRIFT AT %7s ",fmgc.FMGCInternal.arrApt ~ fmgc.flightPlanController.flightplans[2].departure_runway.id)); } @@ -2828,7 +2833,7 @@ var canvas_MCDU_base = { } me["Simple_R6S"].setText("GND TEMP"); - if (fmgc.FMGCInternal.phase == 0 and !fmgc.FMGCInternal.gndTempSet) { + if (phase == 0 and !fmgc.FMGCInternal.gndTempSet) { fmgc.FMGCInternal.gndTemp = 15 - (2 * getprop("/position/gear-agl-ft") / 1000); me["Simple_R6"].setText(sprintf("%.0fg", fmgc.FMGCInternal.gndTemp)); me["Simple_R6"].setFontSize(small); @@ -3834,25 +3839,25 @@ var canvas_MCDU_base = { } else if (page == "PROGPREF" or page == "PROGTO" or page == "PROGCLB" or page == "PROGCRZ" or page == "PROGDES" or page == "PROGAPPR" or page == "PROGDONE") { - if (fmgc.FMGCInternal.phase == 0) { + if (phase == 0) { setprop("/MCDU[" ~ i ~ "]/page", "PROGPREF"); page = "PROGPREF"; - } else if (fmgc.FMGCInternal.phase == 1) { + } else if (phase == 1) { setprop("/MCDU[" ~ i ~ "]/page", "PROGTO"); page = "PROGTO"; - } else if (fmgc.FMGCInternal.phase == 2) { + } else if (phase == 2) { setprop("/MCDU[" ~ i ~ "]/page", "PROGCLB"); page = "PROGCLB"; - } else if (fmgc.FMGCInternal.phase == 3) { + } else if (phase == 3) { setprop("/MCDU[" ~ i ~ "]/page", "PROGCRZ"); page = "PROGCRZ"; - } else if (fmgc.FMGCInternal.phase == 4) { + } else if (phase == 4) { setprop("/MCDU[" ~ i ~ "]/page", "PROGDES"); page = "PROGDES"; - } else if (fmgc.FMGCInternal.phase == 5 or fmgc.FMGCInternal.phase == 6) { + } else if (phase == 5 or phase == 6) { setprop("/MCDU[" ~ i ~ "]/page", "PROGAPPR"); page = "PROGAPPR"; - } else if (fmgc.FMGCInternal.phase == 7) { + } else if (phase == 7) { setprop("/MCDU[" ~ i ~ "]/page", "PROGDONE"); page = "PROGDONE"; } @@ -4131,7 +4136,7 @@ var canvas_MCDU_base = { me["Simple_L4"].setFontSize(small); } - if (fmgc.FMGCInternal.phase == 0 or fmgc.FMGCInternal.phase == 7) { + if (phase == 0 or phase == 7) { me["Simple_L6_Arrow"].show(); me["Simple_L6"].show(); me["Simple_L6S"].show(); @@ -4141,7 +4146,7 @@ var canvas_MCDU_base = { me["Simple_L6S"].hide(); } - if (fmgc.FMGCInternal.phase == 1) { # GREEN title and not modifiable on TO phase + if (phase == 1) { # GREEN title and not modifiable on TO phase me["Simple_Title"].setColor(GREEN); me.colorLeft("grn", "grn", "grn", "blu", "grn", "wht"); me.colorRight("grn", "blu", "grn", "grn", "grn", "wht"); @@ -4221,7 +4226,7 @@ var canvas_MCDU_base = { me["Simple_R5"].setFontSize(small); } - if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or fmgc.FMGCInternal.phase == 1) { + if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or phase == 1) { me["Simple_C1"].setText(sprintf("%3.0f", fmgc.FMGCInternal.flap2_to)); me["Simple_C2"].setText(sprintf("%3.0f", fmgc.FMGCInternal.slat_to)); me["Simple_C3"].setText(sprintf("%3.0f", fmgc.FMGCInternal.clean_to)); @@ -4280,7 +4285,7 @@ var canvas_MCDU_base = { pageSwitch[i].setBoolValue(1); } - if (fmgc.FMGCInternal.phase == 2) { + if (phase == 2) { me["Simple_Title"].setColor(GREEN); me.showLeft(0, 0, 0, 0, 1, 0); me.showLeftS(0, 0, 0, 0, 1, 0); @@ -4310,7 +4315,7 @@ var canvas_MCDU_base = { me.colorLeft("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftS("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftArrow("ack", "ack", "ack", "ack", "ack", "amb"); - } else if (fmgc.FMGCInternal.phase == 5) { + } else if (phase == 5) { me["Simple_L6S"].setText(""); me["Simple_L6"].setText(""); me.colorLeft("ack", "ack", "ack", "ack", "ack", "blu"); @@ -4434,7 +4439,7 @@ var canvas_MCDU_base = { pageSwitch[i].setBoolValue(1); } - if (fmgc.FMGCInternal.phase == 3) { + if (phase == 3) { me["Simple_Title"].setColor(GREEN); if (managedSpeed.getValue() == 1) { @@ -4458,7 +4463,7 @@ var canvas_MCDU_base = { me.colorLeft("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftS("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftArrow("ack", "ack", "ack", "ack", "ack", "amb"); - } else if (fmgc.FMGCInternal.phase == 5) { + } else if (phase == 5) { me["Simple_L6S"].setText(""); me["Simple_L6"].setText(""); me.colorLeft("ack", "ack", "ack", "ack", "ack", "blu"); @@ -4572,7 +4577,7 @@ var canvas_MCDU_base = { pageSwitch[i].setBoolValue(1); } - if (fmgc.FMGCInternal.phase == 4) { + if (phase == 4) { me["Simple_Title"].setColor(GREEN); me.showLeft(0, 0, 0, 0, 1, 0); me.showRight(0, 1, 0, 1, 0, 0); @@ -4601,7 +4606,7 @@ var canvas_MCDU_base = { me.colorLeft("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftS("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftArrow("ack", "ack", "ack", "ack", "ack", "amb"); - } else if (fmgc.FMGCInternal.phase == 5) { + } else if (phase == 5) { me["Simple_L6S"].setText(""); me["Simple_L6"].setText(""); me.colorLeft("ack", "ack", "ack", "ack", "ack", "blu"); @@ -4729,7 +4734,7 @@ var canvas_MCDU_base = { pageSwitch[i].setBoolValue(1); } - if (fmgc.FMGCInternal.phase == 5) { + if (phase == 5) { me["Simple_Title"].setColor(GREEN); } else { me["Simple_Title"].setColor(WHITE); @@ -4837,7 +4842,7 @@ var canvas_MCDU_base = { me["Simple_R6"].setText("PHASE "); me["Simple_L5S"].setText(" VAPP"); - if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or fmgc.FMGCInternal.phase == 5) { + if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or phase == 5) { me["Simple_C1"].setText(sprintf("%3.0f", fmgc.FMGCInternal.flap2_appr)); me["Simple_C2"].setText(sprintf("%3.0f", fmgc.FMGCInternal.slat_appr)); me["Simple_C3"].setText(sprintf("%3.0f", fmgc.FMGCInternal.clean_appr)); @@ -4913,7 +4918,7 @@ var canvas_MCDU_base = { pageSwitch[i].setBoolValue(1); } - if (fmgc.FMGCInternal.phase == 6) { + if (phase == 6) { me["Simple_Title"].setColor(GREEN); } else { me["Simple_Title"].setColor(WHITE); @@ -4937,7 +4942,7 @@ var canvas_MCDU_base = { me["Simple_R5"].setText(sprintf("%3.0f", engOutAcc.getValue())); me["Simple_R5S"].setText("ENG OUT ACC"); - if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or fmgc.FMGCInternal.phase == 6) { + if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or phase == 6) { me["Simple_C1"].setText(sprintf("%3.0f", fmgc.FMGCInternal.flap2_appr)); me["Simple_C2"].setText(sprintf("%3.0f", fmgc.FMGCInternal.slat_appr)); me["Simple_C3"].setText(sprintf("%3.0f", fmgc.FMGCInternal.clean_appr)); @@ -6592,13 +6597,32 @@ setlistener("/sim/signals/fdm-initialized", func { mcdu.mcdu_message(0, "SELECT DESIRED SYSTEM"); mcdu.mcdu_message(1, "SELECT DESIRED SYSTEM"); - + + #setlistener("/MCDU[0]/page", func(v) { + # pageSwitch[0].setBoolValue(0); + # MCDU_1.onPageChanged(0); + #}, 1, 0); + + #setlistener("/MCDU[1]/page", func(v) { + # pageSwitch[1].setBoolValue(0); + # MCDU_2.onPageChanged(1); + #}, 1, 0); + MCDU_update.start(); + }); var MCDU_update = maketimer(0.125, func { canvas_MCDU_base.update(); }); + +var MCDU1_update = maketimer(0.125, func { + MCDU1.update(); +}); + +var MCDU2_update = maketimer(0.125, func { + MCDU2.update(); +}); var showMCDU1 = func { gui.showDialog("mcdu1"); @@ -6608,10 +6632,3 @@ var showMCDU2 = func { gui.showDialog("mcdu2"); } -setlistener("/MCDU[0]/page", func { - pageSwitch[0].setBoolValue(0); -}, 0, 0); - -setlistener("/MCDU[1]/page", func { - pageSwitch[1].setBoolValue(0); -}, 0, 0); diff --git a/Nasal/FMGC/FMGC.nas b/Nasal/FMGC/FMGC.nas index a106e8b1..96f189e5 100644 --- a/Nasal/FMGC/FMGC.nas +++ b/Nasal/FMGC/FMGC.nas @@ -84,6 +84,7 @@ var FMGCinit = func { FMGCInternal.minspeed = 0; FMGCInternal.maxspeed = 338; FMGCInternal.phase = 0; # 0 is Preflight 1 is Takeoff 2 is Climb 3 is Cruise 4 is Descent 5 is Decel/Approach 6 is Go Around 7 is Done + FMGCNodes.phase.setValue(0); FMGCInternal.mngSpd = 157; FMGCInternal.mngSpdCmd = 157; FMGCInternal.mngKtsMach = 0; @@ -257,6 +258,7 @@ var FMGCNodes = { toState: props.globals.initNode("/FMGC/internal/to-state", 0, "BOOL"), v1: props.globals.initNode("/FMGC/internal/v1", 0, "DOUBLE"), v1set: props.globals.initNode("/FMGC/internal/v1-set", 0, "BOOL"), + phase: props.globals.initNode("/FMGC/internal/phase", 0, "INT"), }; ############ @@ -601,92 +603,15 @@ var radios = maketimer(1, func() { adf1(); }); -var masterFMGC = maketimer(0.2, func { - n1_left = pts.Engines.Engine.n1Actual[0].getValue(); - n1_right = pts.Engines.Engine.n1Actual[1].getValue(); - modelat = Modes.PFD.FMA.rollMode.getValue(); - mode = Modes.PFD.FMA.pitchMode.getValue(); - gs = pts.Velocities.groundspeed.getValue(); - alt = pts.Instrumentation.Altimeter.indicatedFt.getValue(); - # cruiseft = FMGCInternal.crzFt; - # cruiseft_b = FMGCInternal.crzFt - 200; - state1 = pts.Systems.Thrust.state[0].getValue(); - state2 = pts.Systems.Thrust.state[1].getValue(); - accel_agl_ft = Setting.reducAglFt.getValue(); - gear0 = pts.Gear.wow[0].getBoolValue(); - altSel = Input.alt.getValue(); - - if ((n1_left < 85 or n1_right < 85) and gs < 90 and mode == " " and gear0 and FMGCInternal.phase == 1) { # rejected takeoff - FMGCInternal.phase = 0; - systems.PNEU.pressMode.setValue("GN"); - } - - if (gear0 and FMGCInternal.phase == 0 and ((n1_left >= 85 and n1_right >= 85 and mode == "SRS") or gs >= 90)) { - FMGCInternal.phase = 1; - systems.PNEU.pressMode.setValue("TO"); - } - - if (FMGCInternal.phase == 1 and ((mode != "SRS" and mode != " ") or alt >= accel_agl_ft)) { - FMGCInternal.phase = 2; - systems.PNEU.pressMode.setValue("TO"); - } - - if (FMGCInternal.phase == 2 and (mode == "ALT CRZ" or mode == "ALT CRZ*")) { - FMGCInternal.phase = 3; - systems.PNEU.pressMode.setValue("CR"); - } - - if (FMGCInternal.crzFl >= 200) { - if (FMGCInternal.phase == 3 and (flightPlanController.arrivalDist <= 200 or altSel < 20000)) { - FMGCInternal.phase = 4; - systems.PNEU.pressMode.setValue("DE"); - } - } else { - if (FMGCInternal.phase == 3 and (flightPlanController.arrivalDist <= 200 or altSel < (FMGCInternal.crzFl * 100))) { # todo - not sure about crzFl condition, investigate what happens! - FMGCInternal.phase = 4; - systems.PNEU.pressMode.setValue("DE"); - } - } - - if (FMGCInternal.phase == 4) { - if (getprop("/FMGC/internal/decel")) { - FMGCInternal.phase = 5; - } - else if (altSel == (FMGCInternal.crzFl * 100)) { # back to CRZ state - FMGCInternal.phase = 3; - systems.PNEU.pressMode.setValue("CR"); - } - } - - 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 pts.Position.gearAglFt.getValue() < 9500) { #todo decel pseudo waypoint - setprop("/FMGC/internal/decel", 1); - } else if (getprop("/FMGC/internal/decel") == 1 and (FMGCInternal.phase == 0 or FMGCInternal.phase == 6)) { - setprop("/FMGC/internal/decel", 0); - } - - if ((FMGCInternal.phase == 5) and state1 == "TOGA" and state2 == "TOGA") { - FMGCInternal.phase = 6; - systems.PNEU.pressMode.setValue("TO"); - Input.toga.setValue(1); - } - - if (FMGCInternal.phase == 6 and alt >= accel_agl_ft) { # todo when insert altn or new dest - FMGCInternal.phase = 2; - } - - if (getprop("/systems/navigation/adr/computation/overspeed-vfe-spd") != 1024) { - FMGCInternal.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) { - FMGCInternal.maxspeed = 284; - } else { - FMGCInternal.maxspeed = fmgc.FMGCInternal.vmo_mmo; - } - +var fuelUpdateFMGC = maketime(0.5, func { ############################ # fuel ############################ updateFuel(); - +}); + +var windUpdateFMGC = maketime(1, func { + ############################ # wind ############################ @@ -730,6 +655,141 @@ var masterFMGC = maketimer(0.2, func { fmgc.windController.write(); } } + +}); + +var prop_n1_left = pts.Engines.Engine.n1Actual[0]; +var prop_n1_right = pts.Engines.Engine.n1Actual[1]; +var prop_nmodelat = Modes.PFD.FMA.rollMode; +var prop_mode = Modes.PFD.FMA.pitchMode; +var prop_gs = pts.Velocities.groundspeed; +var prop_alt = pts.Instrumentation.Altimeter.indicatedFt; +var prop_state1 = pts.Systems.Thrust.state[0]; +var prop_state2 = pts.Systems.Thrust.state[1]; +var prop_accel_agl_ft = Setting.reducAglFt; +var prop_gear0 = pts.Gear.wow[0]; +var prop_altSel = Input.alt; + +var masterFMGC = maketimer(0.2, func { + n1_left = prop_n1_left.getValue(); + n1_right = prop_n1_right.getValue(); + modelat = prop_nmodelat.getValue(); + mode = prop_mode.getValue(); + gs = prop_gs.getValue(); + alt = prop_alt.getValue(); + # cruiseft = FMGCInternal.crzFt; + # cruiseft_b = FMGCInternal.crzFt - 200; + state1 = prop_state1.getValue(); + state2 = prop_state2.getValue(); + accel_agl_ft = prop_accel_agl_ft.getValue(); + gear0 = prop_gear0.getBoolValue(); + altSel = prop_altSel.getValue(); + + var phase = FMGCInternal.phase; + var newphase = phase; + + if (phase == 0) { + + if (gear0 and ((n1_left >= 85 and n1_right >= 85 and mode == "SRS") or gs >= 90)) { + newphase = 1; + systems.PNEU.pressMode.setValue("TO"); + } + + } + + else if (phase == 1) { + + if (gear0) { + + if ((n1_left < 85 or n1_right < 85) and gs < 90 and mode == " ") { # rejected takeoff + newphase = 0; + systems.PNEU.pressMode.setValue("GN"); + } + + } + else if (((mode != "SRS" and mode != " ") or alt >= accel_agl_ft)) { + newphase = 2; + systems.PNEU.pressMode.setValue("TO"); + } + + } + + else if (phase == 2) { + + if ((mode == "ALT CRZ" or mode == "ALT CRZ*")) { + newphase = 3; + systems.PNEU.pressMode.setValue("CR"); + } + + } + + else if (phase == 3) { + + if (FMGCInternal.crzFl >= 200) { + if ((flightPlanController.arrivalDist <= 200 or altSel < 20000)) { + newphase = 4; + systems.PNEU.pressMode.setValue("DE"); + } + } else { + if ((flightPlanController.arrivalDist <= 200 or altSel < (FMGCInternal.crzFl * 100))) { # todo - not sure about crzFl condition, investigate what happens! + newphase = 4; + systems.PNEU.pressMode.setValue("DE"); + } + } + + } + + else if (phase == 4) { + + if (getprop("/FMGC/internal/decel")) { + newphase = 5; + } + else if (altSel == (FMGCInternal.crzFl * 100)) { # back to CRZ state + newphase = 3; + systems.PNEU.pressMode.setValue("CR"); + } + + } + + else if (phase == 5) { + + if (state1 == "TOGA" and state2 == "TOGA") { + newphase = 6; + systems.PNEU.pressMode.setValue("TO"); + Input.toga.setValue(1); + } + + } + + else if (phase == 6) { + + if (alt >= accel_agl_ft) { # todo when insert altn or new dest + newphase = 2; + } + + } + + + 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 pts.Position.gearAglFt.getValue() < 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); + } + + + if (getprop("/systems/navigation/adr/computation/overspeed-vfe-spd") != 1024) { + FMGCInternal.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) { + FMGCInternal.maxspeed = 284; + } else { + FMGCInternal.maxspeed = fmgc.FMGCInternal.vmo_mmo; + } + + if (newphase != phase) { # phase changed + FMGCInternal.phase = newphase; + FMGCNodes.phase.setValue(newphase); + } ############################ # calculate speeds @@ -771,7 +831,7 @@ var masterFMGC = maketimer(0.2, func { } # predicted takeoff speeds - if (FMGCInternal.phase == 1) { + if (phase == 1) { FMGCInternal.clean_to = FMGCInternal.clean; FMGCInternal.vs1g_clean_to = FMGCInternal.vs1g_clean; FMGCInternal.vs1g_conf_2_to = FMGCInternal.vs1g_conf_2; @@ -793,7 +853,7 @@ var masterFMGC = maketimer(0.2, func { } # predicted approach (temp go-around) speeds - if (FMGCInternal.phase == 5 or FMGCInternal.phase == 6) { + if (phase == 5 or phase == 6) { FMGCInternal.clean_appr = FMGCInternal.clean; FMGCInternal.vs1g_clean_appr = FMGCInternal.vs1g_clean; FMGCInternal.vs1g_conf_2_appr = FMGCInternal.vs1g_conf_2; @@ -914,7 +974,8 @@ var masterFMGC = maketimer(0.2, func { } } - if (gear0 and pts.Controls.Flight.flapsPos.getValue() < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { + #if (gear0 and pts.Controls.Flight.flapsPos.getValue() < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { + if (gear0 and flaps < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { if (!FMGCInternal.takeoffState) { fmgc.FMGCNodes.toState.setValue(1); } @@ -930,9 +991,15 @@ var masterFMGC = maketimer(0.2, func { #handle radios, runways, v1/vr/v2 ############################ +}); + +var updateAirportRadios = func { + + var phase = FMGCInternal.phase; + departure_rwy = fmgc.flightPlanController.flightplans[2].departure_runway; destination_rwy = fmgc.flightPlanController.flightplans[2].destination_runway; - if (destination_rwy != nil and FMGCInternal.phase >= 2) { + if (destination_rwy != nil and phase >= 2) { var airport = airportinfo(FMGCInternal.arrApt); setprop("/FMGC/internal/ldg-elev", airport.elevation * M2FT); # eventually should be runway elevation magnetic_hdg = geo.normdeg(destination_rwy.heading - getprop("/environment/magnetic-variation-deg")); @@ -947,7 +1014,7 @@ var masterFMGC = maketimer(0.2, func { } else if (!getprop("/FMGC/internal/ils1crs-set")) { setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); } - } else if (departure_rwy != nil and FMGCInternal.phase <= 1) { + } else if (departure_rwy != nil and phase <= 1) { magnetic_hdg = geo.normdeg(departure_rwy.heading - getprop("/environment/magnetic-variation-deg")); runway_ils = departure_rwy.ils_frequency_mhz; if (runway_ils != nil and !getprop("/FMGC/internal/ils1freq-set") and !getprop("/FMGC/internal/ils1crs-set")) { @@ -961,10 +1028,15 @@ var masterFMGC = maketimer(0.2, func { setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); } } -}); + +}; + +setlistener(FMGCNodes.phase, updateAirportRadios); +setlistener(flightPlanController.changed, updateAirportRadios); var reset_FMGC = func { FMGCInternal.phase = 0; + FMGCNodes.phase.serValue(0); fd1 = Input.fd1.getValue(); fd2 = Input.fd2.getValue(); spd = Input.kts.getValue(); diff --git a/Nasal/FMGC/flightplan.nas b/Nasal/FMGC/flightplan.nas index cb71f578..b072de4e 100644 --- a/Nasal/FMGC/flightplan.nas +++ b/Nasal/FMGC/flightplan.nas @@ -32,6 +32,8 @@ var flightPlanController = { # These flags are only for the main flgiht-plan active: props.globals.initNode("/FMGC/flightplan[2]/active", 0, "BOOL"), + + changed: props.globals.initNode("/FMGC/flightplan[2]/changed", 0, "BOOL"), currentToWpt: nil, # container for the current TO waypoint ghost currentToWptIndex: props.globals.initNode("/FMGC/flightplan[2]/current-wp", 0, "INT"), @@ -765,6 +767,9 @@ var flightPlanController = { fmgc.FMGCInternal.fuelCalculating = 1; fmgc.fuelCalculating.setValue(1); } + + if (n == 2) flightPlanController.changed.setBoolValue(1); + canvas_nd.A3XXRouteDriver.triggerSignal("fp-added"); }, From 69a4678e16377f811516a704abb24ab87a57ca37 Mon Sep 17 00:00:00 2001 From: Inuyaksa Date: Sun, 6 Jun 2021 22:25:52 +0200 Subject: [PATCH 02/11] Revert "some logic optiomizing" This reverts commit b4e59e15b85c282cbecda6285cad9798009359db. --- Models/Instruments/MCDU/MCDU.nas | 81 ++++------ Nasal/FMGC/FMGC.nas | 248 +++++++++++-------------------- Nasal/FMGC/flightplan.nas | 5 - 3 files changed, 120 insertions(+), 214 deletions(-) diff --git a/Models/Instruments/MCDU/MCDU.nas b/Models/Instruments/MCDU/MCDU.nas index 44194563..f9e09f1c 100644 --- a/Models/Instruments/MCDU/MCDU.nas +++ b/Models/Instruments/MCDU/MCDU.nas @@ -410,14 +410,9 @@ var canvas_MCDU_base = { } } return irsstatus; - }, - onPageUpdate: func(p) { - }, updateCommon: func(i) { page = pageProp[i].getValue(); - var phase = fmgc.FMGCInternal.phase; - if (page != "NOTIFICATION") { me["NOTIFY"].hide(); me["NOTIFY_FLTNBR"].hide(); @@ -2119,7 +2114,7 @@ var canvas_MCDU_base = { me.colorRightS("wht", "wht", "wht", "wht", "grn", "wht"); me.colorRightArrow("wht", "wht", "wht", "wht", "wht", "wht"); - if (phase == 0 or phase == 7) { # only on preflight and done phases + if (fmgc.FMGCInternal.phase == 0 or fmgc.FMGCInternal.phase == 7) { # only on preflight and done phases me["Simple_L5S"].setText("CHG CODE"); me["Simple_L5S"].show(); me["Simple_L5"].setText("[ ]"); @@ -2169,7 +2164,7 @@ var canvas_MCDU_base = { me["arrow5R"].setColor(getprop("/MCDUC/colors/blu/r"),getprop("/MCDUC/colors/blu/g"),getprop("/MCDUC/colors/blu/b")); } - if (phase == 0 or phase == 7) { + if (fmgc.FMGCInternal.phase == 0 or fmgc.FMGCInternal.phase == 7) { me["Simple_L5"].show(); me["Simple_L5S"].show(); } else { @@ -2481,7 +2476,7 @@ var canvas_MCDU_base = { } } - if (phase == 7) { # DONE phase + if (fmgc.FMGCInternal.phase == 7) { # DONE phase if (fmgc.FMGCInternal.arrApt != nil and fmgc.flightPlanController.flightplans[2].departure_runway != nil) { me["Simple_R1S"].setText(sprintf("DRIFT AT %7s ",fmgc.FMGCInternal.arrApt ~ fmgc.flightPlanController.flightplans[2].departure_runway.id)); } @@ -2833,7 +2828,7 @@ var canvas_MCDU_base = { } me["Simple_R6S"].setText("GND TEMP"); - if (phase == 0 and !fmgc.FMGCInternal.gndTempSet) { + if (fmgc.FMGCInternal.phase == 0 and !fmgc.FMGCInternal.gndTempSet) { fmgc.FMGCInternal.gndTemp = 15 - (2 * getprop("/position/gear-agl-ft") / 1000); me["Simple_R6"].setText(sprintf("%.0fg", fmgc.FMGCInternal.gndTemp)); me["Simple_R6"].setFontSize(small); @@ -3839,25 +3834,25 @@ var canvas_MCDU_base = { } else if (page == "PROGPREF" or page == "PROGTO" or page == "PROGCLB" or page == "PROGCRZ" or page == "PROGDES" or page == "PROGAPPR" or page == "PROGDONE") { - if (phase == 0) { + if (fmgc.FMGCInternal.phase == 0) { setprop("/MCDU[" ~ i ~ "]/page", "PROGPREF"); page = "PROGPREF"; - } else if (phase == 1) { + } else if (fmgc.FMGCInternal.phase == 1) { setprop("/MCDU[" ~ i ~ "]/page", "PROGTO"); page = "PROGTO"; - } else if (phase == 2) { + } else if (fmgc.FMGCInternal.phase == 2) { setprop("/MCDU[" ~ i ~ "]/page", "PROGCLB"); page = "PROGCLB"; - } else if (phase == 3) { + } else if (fmgc.FMGCInternal.phase == 3) { setprop("/MCDU[" ~ i ~ "]/page", "PROGCRZ"); page = "PROGCRZ"; - } else if (phase == 4) { + } else if (fmgc.FMGCInternal.phase == 4) { setprop("/MCDU[" ~ i ~ "]/page", "PROGDES"); page = "PROGDES"; - } else if (phase == 5 or phase == 6) { + } else if (fmgc.FMGCInternal.phase == 5 or fmgc.FMGCInternal.phase == 6) { setprop("/MCDU[" ~ i ~ "]/page", "PROGAPPR"); page = "PROGAPPR"; - } else if (phase == 7) { + } else if (fmgc.FMGCInternal.phase == 7) { setprop("/MCDU[" ~ i ~ "]/page", "PROGDONE"); page = "PROGDONE"; } @@ -4136,7 +4131,7 @@ var canvas_MCDU_base = { me["Simple_L4"].setFontSize(small); } - if (phase == 0 or phase == 7) { + if (fmgc.FMGCInternal.phase == 0 or fmgc.FMGCInternal.phase == 7) { me["Simple_L6_Arrow"].show(); me["Simple_L6"].show(); me["Simple_L6S"].show(); @@ -4146,7 +4141,7 @@ var canvas_MCDU_base = { me["Simple_L6S"].hide(); } - if (phase == 1) { # GREEN title and not modifiable on TO phase + if (fmgc.FMGCInternal.phase == 1) { # GREEN title and not modifiable on TO phase me["Simple_Title"].setColor(GREEN); me.colorLeft("grn", "grn", "grn", "blu", "grn", "wht"); me.colorRight("grn", "blu", "grn", "grn", "grn", "wht"); @@ -4226,7 +4221,7 @@ var canvas_MCDU_base = { me["Simple_R5"].setFontSize(small); } - if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or phase == 1) { + if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or fmgc.FMGCInternal.phase == 1) { me["Simple_C1"].setText(sprintf("%3.0f", fmgc.FMGCInternal.flap2_to)); me["Simple_C2"].setText(sprintf("%3.0f", fmgc.FMGCInternal.slat_to)); me["Simple_C3"].setText(sprintf("%3.0f", fmgc.FMGCInternal.clean_to)); @@ -4285,7 +4280,7 @@ var canvas_MCDU_base = { pageSwitch[i].setBoolValue(1); } - if (phase == 2) { + if (fmgc.FMGCInternal.phase == 2) { me["Simple_Title"].setColor(GREEN); me.showLeft(0, 0, 0, 0, 1, 0); me.showLeftS(0, 0, 0, 0, 1, 0); @@ -4315,7 +4310,7 @@ var canvas_MCDU_base = { me.colorLeft("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftS("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftArrow("ack", "ack", "ack", "ack", "ack", "amb"); - } else if (phase == 5) { + } else if (fmgc.FMGCInternal.phase == 5) { me["Simple_L6S"].setText(""); me["Simple_L6"].setText(""); me.colorLeft("ack", "ack", "ack", "ack", "ack", "blu"); @@ -4439,7 +4434,7 @@ var canvas_MCDU_base = { pageSwitch[i].setBoolValue(1); } - if (phase == 3) { + if (fmgc.FMGCInternal.phase == 3) { me["Simple_Title"].setColor(GREEN); if (managedSpeed.getValue() == 1) { @@ -4463,7 +4458,7 @@ var canvas_MCDU_base = { me.colorLeft("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftS("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftArrow("ack", "ack", "ack", "ack", "ack", "amb"); - } else if (phase == 5) { + } else if (fmgc.FMGCInternal.phase == 5) { me["Simple_L6S"].setText(""); me["Simple_L6"].setText(""); me.colorLeft("ack", "ack", "ack", "ack", "ack", "blu"); @@ -4577,7 +4572,7 @@ var canvas_MCDU_base = { pageSwitch[i].setBoolValue(1); } - if (phase == 4) { + if (fmgc.FMGCInternal.phase == 4) { me["Simple_Title"].setColor(GREEN); me.showLeft(0, 0, 0, 0, 1, 0); me.showRight(0, 1, 0, 1, 0, 0); @@ -4606,7 +4601,7 @@ var canvas_MCDU_base = { me.colorLeft("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftS("ack", "ack", "ack", "ack", "ack", "amb"); me.colorLeftArrow("ack", "ack", "ack", "ack", "ack", "amb"); - } else if (phase == 5) { + } else if (fmgc.FMGCInternal.phase == 5) { me["Simple_L6S"].setText(""); me["Simple_L6"].setText(""); me.colorLeft("ack", "ack", "ack", "ack", "ack", "blu"); @@ -4734,7 +4729,7 @@ var canvas_MCDU_base = { pageSwitch[i].setBoolValue(1); } - if (phase == 5) { + if (fmgc.FMGCInternal.phase == 5) { me["Simple_Title"].setColor(GREEN); } else { me["Simple_Title"].setColor(WHITE); @@ -4842,7 +4837,7 @@ var canvas_MCDU_base = { me["Simple_R6"].setText("PHASE "); me["Simple_L5S"].setText(" VAPP"); - if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or phase == 5) { + if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or fmgc.FMGCInternal.phase == 5) { me["Simple_C1"].setText(sprintf("%3.0f", fmgc.FMGCInternal.flap2_appr)); me["Simple_C2"].setText(sprintf("%3.0f", fmgc.FMGCInternal.slat_appr)); me["Simple_C3"].setText(sprintf("%3.0f", fmgc.FMGCInternal.clean_appr)); @@ -4918,7 +4913,7 @@ var canvas_MCDU_base = { pageSwitch[i].setBoolValue(1); } - if (phase == 6) { + if (fmgc.FMGCInternal.phase == 6) { me["Simple_Title"].setColor(GREEN); } else { me["Simple_Title"].setColor(WHITE); @@ -4942,7 +4937,7 @@ var canvas_MCDU_base = { me["Simple_R5"].setText(sprintf("%3.0f", engOutAcc.getValue())); me["Simple_R5S"].setText("ENG OUT ACC"); - if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or phase == 6) { + if ((fmgc.FMGCInternal.zfwSet and fmgc.FMGCInternal.blockSet) or fmgc.FMGCInternal.phase == 6) { me["Simple_C1"].setText(sprintf("%3.0f", fmgc.FMGCInternal.flap2_appr)); me["Simple_C2"].setText(sprintf("%3.0f", fmgc.FMGCInternal.slat_appr)); me["Simple_C3"].setText(sprintf("%3.0f", fmgc.FMGCInternal.clean_appr)); @@ -6597,32 +6592,13 @@ setlistener("/sim/signals/fdm-initialized", func { mcdu.mcdu_message(0, "SELECT DESIRED SYSTEM"); mcdu.mcdu_message(1, "SELECT DESIRED SYSTEM"); - - #setlistener("/MCDU[0]/page", func(v) { - # pageSwitch[0].setBoolValue(0); - # MCDU_1.onPageChanged(0); - #}, 1, 0); - - #setlistener("/MCDU[1]/page", func(v) { - # pageSwitch[1].setBoolValue(0); - # MCDU_2.onPageChanged(1); - #}, 1, 0); - + MCDU_update.start(); - }); var MCDU_update = maketimer(0.125, func { canvas_MCDU_base.update(); }); - -var MCDU1_update = maketimer(0.125, func { - MCDU1.update(); -}); - -var MCDU2_update = maketimer(0.125, func { - MCDU2.update(); -}); var showMCDU1 = func { gui.showDialog("mcdu1"); @@ -6632,3 +6608,10 @@ var showMCDU2 = func { gui.showDialog("mcdu2"); } +setlistener("/MCDU[0]/page", func { + pageSwitch[0].setBoolValue(0); +}, 0, 0); + +setlistener("/MCDU[1]/page", func { + pageSwitch[1].setBoolValue(0); +}, 0, 0); diff --git a/Nasal/FMGC/FMGC.nas b/Nasal/FMGC/FMGC.nas index 96f189e5..a106e8b1 100644 --- a/Nasal/FMGC/FMGC.nas +++ b/Nasal/FMGC/FMGC.nas @@ -84,7 +84,6 @@ var FMGCinit = func { FMGCInternal.minspeed = 0; FMGCInternal.maxspeed = 338; FMGCInternal.phase = 0; # 0 is Preflight 1 is Takeoff 2 is Climb 3 is Cruise 4 is Descent 5 is Decel/Approach 6 is Go Around 7 is Done - FMGCNodes.phase.setValue(0); FMGCInternal.mngSpd = 157; FMGCInternal.mngSpdCmd = 157; FMGCInternal.mngKtsMach = 0; @@ -258,7 +257,6 @@ var FMGCNodes = { toState: props.globals.initNode("/FMGC/internal/to-state", 0, "BOOL"), v1: props.globals.initNode("/FMGC/internal/v1", 0, "DOUBLE"), v1set: props.globals.initNode("/FMGC/internal/v1-set", 0, "BOOL"), - phase: props.globals.initNode("/FMGC/internal/phase", 0, "INT"), }; ############ @@ -603,15 +601,92 @@ var radios = maketimer(1, func() { adf1(); }); -var fuelUpdateFMGC = maketime(0.5, func { +var masterFMGC = maketimer(0.2, func { + n1_left = pts.Engines.Engine.n1Actual[0].getValue(); + n1_right = pts.Engines.Engine.n1Actual[1].getValue(); + modelat = Modes.PFD.FMA.rollMode.getValue(); + mode = Modes.PFD.FMA.pitchMode.getValue(); + gs = pts.Velocities.groundspeed.getValue(); + alt = pts.Instrumentation.Altimeter.indicatedFt.getValue(); + # cruiseft = FMGCInternal.crzFt; + # cruiseft_b = FMGCInternal.crzFt - 200; + state1 = pts.Systems.Thrust.state[0].getValue(); + state2 = pts.Systems.Thrust.state[1].getValue(); + accel_agl_ft = Setting.reducAglFt.getValue(); + gear0 = pts.Gear.wow[0].getBoolValue(); + altSel = Input.alt.getValue(); + + if ((n1_left < 85 or n1_right < 85) and gs < 90 and mode == " " and gear0 and FMGCInternal.phase == 1) { # rejected takeoff + FMGCInternal.phase = 0; + systems.PNEU.pressMode.setValue("GN"); + } + + if (gear0 and FMGCInternal.phase == 0 and ((n1_left >= 85 and n1_right >= 85 and mode == "SRS") or gs >= 90)) { + FMGCInternal.phase = 1; + systems.PNEU.pressMode.setValue("TO"); + } + + if (FMGCInternal.phase == 1 and ((mode != "SRS" and mode != " ") or alt >= accel_agl_ft)) { + FMGCInternal.phase = 2; + systems.PNEU.pressMode.setValue("TO"); + } + + if (FMGCInternal.phase == 2 and (mode == "ALT CRZ" or mode == "ALT CRZ*")) { + FMGCInternal.phase = 3; + systems.PNEU.pressMode.setValue("CR"); + } + + if (FMGCInternal.crzFl >= 200) { + if (FMGCInternal.phase == 3 and (flightPlanController.arrivalDist <= 200 or altSel < 20000)) { + FMGCInternal.phase = 4; + systems.PNEU.pressMode.setValue("DE"); + } + } else { + if (FMGCInternal.phase == 3 and (flightPlanController.arrivalDist <= 200 or altSel < (FMGCInternal.crzFl * 100))) { # todo - not sure about crzFl condition, investigate what happens! + FMGCInternal.phase = 4; + systems.PNEU.pressMode.setValue("DE"); + } + } + + if (FMGCInternal.phase == 4) { + if (getprop("/FMGC/internal/decel")) { + FMGCInternal.phase = 5; + } + else if (altSel == (FMGCInternal.crzFl * 100)) { # back to CRZ state + FMGCInternal.phase = 3; + systems.PNEU.pressMode.setValue("CR"); + } + } + + 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 pts.Position.gearAglFt.getValue() < 9500) { #todo decel pseudo waypoint + setprop("/FMGC/internal/decel", 1); + } else if (getprop("/FMGC/internal/decel") == 1 and (FMGCInternal.phase == 0 or FMGCInternal.phase == 6)) { + setprop("/FMGC/internal/decel", 0); + } + + if ((FMGCInternal.phase == 5) and state1 == "TOGA" and state2 == "TOGA") { + FMGCInternal.phase = 6; + systems.PNEU.pressMode.setValue("TO"); + Input.toga.setValue(1); + } + + if (FMGCInternal.phase == 6 and alt >= accel_agl_ft) { # todo when insert altn or new dest + FMGCInternal.phase = 2; + } + + if (getprop("/systems/navigation/adr/computation/overspeed-vfe-spd") != 1024) { + FMGCInternal.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) { + FMGCInternal.maxspeed = 284; + } else { + FMGCInternal.maxspeed = fmgc.FMGCInternal.vmo_mmo; + } + ############################ # fuel ############################ updateFuel(); -}); - -var windUpdateFMGC = maketime(1, func { - + ############################ # wind ############################ @@ -655,141 +730,6 @@ var windUpdateFMGC = maketime(1, func { fmgc.windController.write(); } } - -}); - -var prop_n1_left = pts.Engines.Engine.n1Actual[0]; -var prop_n1_right = pts.Engines.Engine.n1Actual[1]; -var prop_nmodelat = Modes.PFD.FMA.rollMode; -var prop_mode = Modes.PFD.FMA.pitchMode; -var prop_gs = pts.Velocities.groundspeed; -var prop_alt = pts.Instrumentation.Altimeter.indicatedFt; -var prop_state1 = pts.Systems.Thrust.state[0]; -var prop_state2 = pts.Systems.Thrust.state[1]; -var prop_accel_agl_ft = Setting.reducAglFt; -var prop_gear0 = pts.Gear.wow[0]; -var prop_altSel = Input.alt; - -var masterFMGC = maketimer(0.2, func { - n1_left = prop_n1_left.getValue(); - n1_right = prop_n1_right.getValue(); - modelat = prop_nmodelat.getValue(); - mode = prop_mode.getValue(); - gs = prop_gs.getValue(); - alt = prop_alt.getValue(); - # cruiseft = FMGCInternal.crzFt; - # cruiseft_b = FMGCInternal.crzFt - 200; - state1 = prop_state1.getValue(); - state2 = prop_state2.getValue(); - accel_agl_ft = prop_accel_agl_ft.getValue(); - gear0 = prop_gear0.getBoolValue(); - altSel = prop_altSel.getValue(); - - var phase = FMGCInternal.phase; - var newphase = phase; - - if (phase == 0) { - - if (gear0 and ((n1_left >= 85 and n1_right >= 85 and mode == "SRS") or gs >= 90)) { - newphase = 1; - systems.PNEU.pressMode.setValue("TO"); - } - - } - - else if (phase == 1) { - - if (gear0) { - - if ((n1_left < 85 or n1_right < 85) and gs < 90 and mode == " ") { # rejected takeoff - newphase = 0; - systems.PNEU.pressMode.setValue("GN"); - } - - } - else if (((mode != "SRS" and mode != " ") or alt >= accel_agl_ft)) { - newphase = 2; - systems.PNEU.pressMode.setValue("TO"); - } - - } - - else if (phase == 2) { - - if ((mode == "ALT CRZ" or mode == "ALT CRZ*")) { - newphase = 3; - systems.PNEU.pressMode.setValue("CR"); - } - - } - - else if (phase == 3) { - - if (FMGCInternal.crzFl >= 200) { - if ((flightPlanController.arrivalDist <= 200 or altSel < 20000)) { - newphase = 4; - systems.PNEU.pressMode.setValue("DE"); - } - } else { - if ((flightPlanController.arrivalDist <= 200 or altSel < (FMGCInternal.crzFl * 100))) { # todo - not sure about crzFl condition, investigate what happens! - newphase = 4; - systems.PNEU.pressMode.setValue("DE"); - } - } - - } - - else if (phase == 4) { - - if (getprop("/FMGC/internal/decel")) { - newphase = 5; - } - else if (altSel == (FMGCInternal.crzFl * 100)) { # back to CRZ state - newphase = 3; - systems.PNEU.pressMode.setValue("CR"); - } - - } - - else if (phase == 5) { - - if (state1 == "TOGA" and state2 == "TOGA") { - newphase = 6; - systems.PNEU.pressMode.setValue("TO"); - Input.toga.setValue(1); - } - - } - - else if (phase == 6) { - - if (alt >= accel_agl_ft) { # todo when insert altn or new dest - newphase = 2; - } - - } - - - 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 pts.Position.gearAglFt.getValue() < 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); - } - - - if (getprop("/systems/navigation/adr/computation/overspeed-vfe-spd") != 1024) { - FMGCInternal.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) { - FMGCInternal.maxspeed = 284; - } else { - FMGCInternal.maxspeed = fmgc.FMGCInternal.vmo_mmo; - } - - if (newphase != phase) { # phase changed - FMGCInternal.phase = newphase; - FMGCNodes.phase.setValue(newphase); - } ############################ # calculate speeds @@ -831,7 +771,7 @@ var masterFMGC = maketimer(0.2, func { } # predicted takeoff speeds - if (phase == 1) { + if (FMGCInternal.phase == 1) { FMGCInternal.clean_to = FMGCInternal.clean; FMGCInternal.vs1g_clean_to = FMGCInternal.vs1g_clean; FMGCInternal.vs1g_conf_2_to = FMGCInternal.vs1g_conf_2; @@ -853,7 +793,7 @@ var masterFMGC = maketimer(0.2, func { } # predicted approach (temp go-around) speeds - if (phase == 5 or phase == 6) { + if (FMGCInternal.phase == 5 or FMGCInternal.phase == 6) { FMGCInternal.clean_appr = FMGCInternal.clean; FMGCInternal.vs1g_clean_appr = FMGCInternal.vs1g_clean; FMGCInternal.vs1g_conf_2_appr = FMGCInternal.vs1g_conf_2; @@ -974,8 +914,7 @@ var masterFMGC = maketimer(0.2, func { } } - #if (gear0 and pts.Controls.Flight.flapsPos.getValue() < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { - if (gear0 and flaps < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { + if (gear0 and pts.Controls.Flight.flapsPos.getValue() < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { if (!FMGCInternal.takeoffState) { fmgc.FMGCNodes.toState.setValue(1); } @@ -991,15 +930,9 @@ var masterFMGC = maketimer(0.2, func { #handle radios, runways, v1/vr/v2 ############################ -}); - -var updateAirportRadios = func { - - var phase = FMGCInternal.phase; - departure_rwy = fmgc.flightPlanController.flightplans[2].departure_runway; destination_rwy = fmgc.flightPlanController.flightplans[2].destination_runway; - if (destination_rwy != nil and phase >= 2) { + if (destination_rwy != nil and FMGCInternal.phase >= 2) { var airport = airportinfo(FMGCInternal.arrApt); setprop("/FMGC/internal/ldg-elev", airport.elevation * M2FT); # eventually should be runway elevation magnetic_hdg = geo.normdeg(destination_rwy.heading - getprop("/environment/magnetic-variation-deg")); @@ -1014,7 +947,7 @@ var updateAirportRadios = func { } else if (!getprop("/FMGC/internal/ils1crs-set")) { setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); } - } else if (departure_rwy != nil and phase <= 1) { + } else if (departure_rwy != nil and FMGCInternal.phase <= 1) { magnetic_hdg = geo.normdeg(departure_rwy.heading - getprop("/environment/magnetic-variation-deg")); runway_ils = departure_rwy.ils_frequency_mhz; if (runway_ils != nil and !getprop("/FMGC/internal/ils1freq-set") and !getprop("/FMGC/internal/ils1crs-set")) { @@ -1028,15 +961,10 @@ var updateAirportRadios = func { setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); } } - -}; - -setlistener(FMGCNodes.phase, updateAirportRadios); -setlistener(flightPlanController.changed, updateAirportRadios); +}); var reset_FMGC = func { FMGCInternal.phase = 0; - FMGCNodes.phase.serValue(0); fd1 = Input.fd1.getValue(); fd2 = Input.fd2.getValue(); spd = Input.kts.getValue(); diff --git a/Nasal/FMGC/flightplan.nas b/Nasal/FMGC/flightplan.nas index b072de4e..cb71f578 100644 --- a/Nasal/FMGC/flightplan.nas +++ b/Nasal/FMGC/flightplan.nas @@ -32,8 +32,6 @@ var flightPlanController = { # These flags are only for the main flgiht-plan active: props.globals.initNode("/FMGC/flightplan[2]/active", 0, "BOOL"), - - changed: props.globals.initNode("/FMGC/flightplan[2]/changed", 0, "BOOL"), currentToWpt: nil, # container for the current TO waypoint ghost currentToWptIndex: props.globals.initNode("/FMGC/flightplan[2]/current-wp", 0, "INT"), @@ -767,9 +765,6 @@ var flightPlanController = { fmgc.FMGCInternal.fuelCalculating = 1; fmgc.fuelCalculating.setValue(1); } - - if (n == 2) flightPlanController.changed.setBoolValue(1); - canvas_nd.A3XXRouteDriver.triggerSignal("fp-added"); }, From d18b1212238c82ff663d33738c368412b8b5eb8e Mon Sep 17 00:00:00 2001 From: Inuyaksa Date: Sun, 6 Jun 2021 23:21:58 +0200 Subject: [PATCH 03/11] rework fix --- Nasal/FMGC/FMGC.nas | 249 ++++++++++++++++++++++------------ Nasal/FMGC/flightplan.nas | 5 + Nasal/Libraries/libraries.nas | 4 +- 3 files changed, 168 insertions(+), 90 deletions(-) diff --git a/Nasal/FMGC/FMGC.nas b/Nasal/FMGC/FMGC.nas index a106e8b1..b72f980f 100644 --- a/Nasal/FMGC/FMGC.nas +++ b/Nasal/FMGC/FMGC.nas @@ -84,6 +84,7 @@ var FMGCinit = func { FMGCInternal.minspeed = 0; FMGCInternal.maxspeed = 338; FMGCInternal.phase = 0; # 0 is Preflight 1 is Takeoff 2 is Climb 3 is Cruise 4 is Descent 5 is Decel/Approach 6 is Go Around 7 is Done + FMGCNodes.phase.setValue(0); FMGCInternal.mngSpd = 157; FMGCInternal.mngSpdCmd = 157; FMGCInternal.mngKtsMach = 0; @@ -257,6 +258,7 @@ var FMGCNodes = { toState: props.globals.initNode("/FMGC/internal/to-state", 0, "BOOL"), v1: props.globals.initNode("/FMGC/internal/v1", 0, "DOUBLE"), v1set: props.globals.initNode("/FMGC/internal/v1-set", 0, "BOOL"), + phase: props.globals.initNode("/FMGC/internal/phase", 0, "INT"), }; ############ @@ -601,92 +603,15 @@ var radios = maketimer(1, func() { adf1(); }); -var masterFMGC = maketimer(0.2, func { - n1_left = pts.Engines.Engine.n1Actual[0].getValue(); - n1_right = pts.Engines.Engine.n1Actual[1].getValue(); - modelat = Modes.PFD.FMA.rollMode.getValue(); - mode = Modes.PFD.FMA.pitchMode.getValue(); - gs = pts.Velocities.groundspeed.getValue(); - alt = pts.Instrumentation.Altimeter.indicatedFt.getValue(); - # cruiseft = FMGCInternal.crzFt; - # cruiseft_b = FMGCInternal.crzFt - 200; - state1 = pts.Systems.Thrust.state[0].getValue(); - state2 = pts.Systems.Thrust.state[1].getValue(); - accel_agl_ft = Setting.reducAglFt.getValue(); - gear0 = pts.Gear.wow[0].getBoolValue(); - altSel = Input.alt.getValue(); - - if ((n1_left < 85 or n1_right < 85) and gs < 90 and mode == " " and gear0 and FMGCInternal.phase == 1) { # rejected takeoff - FMGCInternal.phase = 0; - systems.PNEU.pressMode.setValue("GN"); - } - - if (gear0 and FMGCInternal.phase == 0 and ((n1_left >= 85 and n1_right >= 85 and mode == "SRS") or gs >= 90)) { - FMGCInternal.phase = 1; - systems.PNEU.pressMode.setValue("TO"); - } - - if (FMGCInternal.phase == 1 and ((mode != "SRS" and mode != " ") or alt >= accel_agl_ft)) { - FMGCInternal.phase = 2; - systems.PNEU.pressMode.setValue("TO"); - } - - if (FMGCInternal.phase == 2 and (mode == "ALT CRZ" or mode == "ALT CRZ*")) { - FMGCInternal.phase = 3; - systems.PNEU.pressMode.setValue("CR"); - } - - if (FMGCInternal.crzFl >= 200) { - if (FMGCInternal.phase == 3 and (flightPlanController.arrivalDist <= 200 or altSel < 20000)) { - FMGCInternal.phase = 4; - systems.PNEU.pressMode.setValue("DE"); - } - } else { - if (FMGCInternal.phase == 3 and (flightPlanController.arrivalDist <= 200 or altSel < (FMGCInternal.crzFl * 100))) { # todo - not sure about crzFl condition, investigate what happens! - FMGCInternal.phase = 4; - systems.PNEU.pressMode.setValue("DE"); - } - } - - if (FMGCInternal.phase == 4) { - if (getprop("/FMGC/internal/decel")) { - FMGCInternal.phase = 5; - } - else if (altSel == (FMGCInternal.crzFl * 100)) { # back to CRZ state - FMGCInternal.phase = 3; - systems.PNEU.pressMode.setValue("CR"); - } - } - - 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 pts.Position.gearAglFt.getValue() < 9500) { #todo decel pseudo waypoint - setprop("/FMGC/internal/decel", 1); - } else if (getprop("/FMGC/internal/decel") == 1 and (FMGCInternal.phase == 0 or FMGCInternal.phase == 6)) { - setprop("/FMGC/internal/decel", 0); - } - - if ((FMGCInternal.phase == 5) and state1 == "TOGA" and state2 == "TOGA") { - FMGCInternal.phase = 6; - systems.PNEU.pressMode.setValue("TO"); - Input.toga.setValue(1); - } - - if (FMGCInternal.phase == 6 and alt >= accel_agl_ft) { # todo when insert altn or new dest - FMGCInternal.phase = 2; - } - - if (getprop("/systems/navigation/adr/computation/overspeed-vfe-spd") != 1024) { - FMGCInternal.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) { - FMGCInternal.maxspeed = 284; - } else { - FMGCInternal.maxspeed = fmgc.FMGCInternal.vmo_mmo; - } - +var fuelUpdateFMGC = maketimer(0.5, func { ############################ # fuel ############################ updateFuel(); - +}); + +var windUpdateFMGC = maketimer(1, func { + ############################ # wind ############################ @@ -730,6 +655,142 @@ var masterFMGC = maketimer(0.2, func { fmgc.windController.write(); } } + +}); + +var prop_n1_left = pts.Engines.Engine.n1Actual[0]; +var prop_n1_right = pts.Engines.Engine.n1Actual[1]; +#var prop_nmodelat = Modes.PFD.FMA.rollMode; +#var prop_mode = Modes.PFD.FMA.pitchMode; +var prop_gs = pts.Velocities.groundspeed; +var prop_alt = pts.Instrumentation.Altimeter.indicatedFt; +var prop_state1 = pts.Systems.Thrust.state[0]; +var prop_state2 = pts.Systems.Thrust.state[1]; +#var prop_accel_agl_ft = Setting.reducAglFt; +var prop_gear0 = pts.Gear.wow[0]; +#var prop_altSel = Input.alt; + +var masterFMGC = maketimer(0.2, func { + + n1_left = prop_n1_left.getValue(); + n1_right = prop_n1_right.getValue(); + modelat = Modes.PFD.FMA.rollMode.getValue(); + mode = Modes.PFD.FMA.pitchMode.getValue(); + gs = prop_gs.getValue(); + alt = prop_alt.getValue(); + # cruiseft = FMGCInternal.crzFt; + # cruiseft_b = FMGCInternal.crzFt - 200; + state1 = prop_state1.getValue(); + state2 = prop_state2.getValue(); + accel_agl_ft = Setting.reducAglFt.getValue(); + gear0 = prop_gear0.getBoolValue(); + altSel = Input.alt.getValue(); + + var phase = FMGCInternal.phase; + var newphase = phase; + + if (phase == 0) { + + if (gear0 and ((n1_left >= 85 and n1_right >= 85 and mode == "SRS") or gs >= 90)) { + newphase = 1; + systems.PNEU.pressMode.setValue("TO"); + } + + } + + else if (phase == 1) { + + if (gear0) { + + if ((n1_left < 85 or n1_right < 85) and gs < 90 and mode == " ") { # rejected takeoff + newphase = 0; + systems.PNEU.pressMode.setValue("GN"); + } + + } + else if (((mode != "SRS" and mode != " ") or alt >= accel_agl_ft)) { + newphase = 2; + systems.PNEU.pressMode.setValue("TO"); + } + + } + + else if (phase == 2) { + + if ((mode == "ALT CRZ" or mode == "ALT CRZ*")) { + newphase = 3; + systems.PNEU.pressMode.setValue("CR"); + } + + } + + else if (phase == 3) { + + if (FMGCInternal.crzFl >= 200) { + if ((flightPlanController.arrivalDist <= 200 or altSel < 20000)) { + newphase = 4; + systems.PNEU.pressMode.setValue("DE"); + } + } else { + if ((flightPlanController.arrivalDist <= 200 or altSel < (FMGCInternal.crzFl * 100))) { # todo - not sure about crzFl condition, investigate what happens! + newphase = 4; + systems.PNEU.pressMode.setValue("DE"); + } + } + + } + + else if (phase == 4) { + + if (getprop("/FMGC/internal/decel")) { + newphase = 5; + } + else if (altSel == (FMGCInternal.crzFl * 100)) { # back to CRZ state + newphase = 3; + systems.PNEU.pressMode.setValue("CR"); + } + + } + + else if (phase == 5) { + + if (state1 == "TOGA" and state2 == "TOGA") { + newphase = 6; + systems.PNEU.pressMode.setValue("TO"); + Input.toga.setValue(1); + } + + } + + else if (phase == 6) { + + if (alt >= accel_agl_ft) { # todo when insert altn or new dest + newphase = 2; + } + + } + + + 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 pts.Position.gearAglFt.getValue() < 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); + } + + + if (getprop("/systems/navigation/adr/computation/overspeed-vfe-spd") != 1024) { + FMGCInternal.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) { + FMGCInternal.maxspeed = 284; + } else { + FMGCInternal.maxspeed = fmgc.FMGCInternal.vmo_mmo; + } + + if (newphase != phase) { # phase changed + FMGCInternal.phase = newphase; + FMGCNodes.phase.setValue(newphase); + } ############################ # calculate speeds @@ -771,7 +832,7 @@ var masterFMGC = maketimer(0.2, func { } # predicted takeoff speeds - if (FMGCInternal.phase == 1) { + if (phase == 1) { FMGCInternal.clean_to = FMGCInternal.clean; FMGCInternal.vs1g_clean_to = FMGCInternal.vs1g_clean; FMGCInternal.vs1g_conf_2_to = FMGCInternal.vs1g_conf_2; @@ -793,7 +854,7 @@ var masterFMGC = maketimer(0.2, func { } # predicted approach (temp go-around) speeds - if (FMGCInternal.phase == 5 or FMGCInternal.phase == 6) { + if (phase == 5 or phase == 6) { FMGCInternal.clean_appr = FMGCInternal.clean; FMGCInternal.vs1g_clean_appr = FMGCInternal.vs1g_clean; FMGCInternal.vs1g_conf_2_appr = FMGCInternal.vs1g_conf_2; @@ -914,7 +975,8 @@ var masterFMGC = maketimer(0.2, func { } } - if (gear0 and pts.Controls.Flight.flapsPos.getValue() < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { + #if (gear0 and pts.Controls.Flight.flapsPos.getValue() < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { + if (gear0 and flap < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { if (!FMGCInternal.takeoffState) { fmgc.FMGCNodes.toState.setValue(1); } @@ -930,9 +992,15 @@ var masterFMGC = maketimer(0.2, func { #handle radios, runways, v1/vr/v2 ############################ +}); + +var updateAirportRadios = func { + + var phase = FMGCInternal.phase; + departure_rwy = fmgc.flightPlanController.flightplans[2].departure_runway; destination_rwy = fmgc.flightPlanController.flightplans[2].destination_runway; - if (destination_rwy != nil and FMGCInternal.phase >= 2) { + if (destination_rwy != nil and phase >= 2) { var airport = airportinfo(FMGCInternal.arrApt); setprop("/FMGC/internal/ldg-elev", airport.elevation * M2FT); # eventually should be runway elevation magnetic_hdg = geo.normdeg(destination_rwy.heading - getprop("/environment/magnetic-variation-deg")); @@ -947,7 +1015,7 @@ var masterFMGC = maketimer(0.2, func { } else if (!getprop("/FMGC/internal/ils1crs-set")) { setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); } - } else if (departure_rwy != nil and FMGCInternal.phase <= 1) { + } else if (departure_rwy != nil and phase <= 1) { magnetic_hdg = geo.normdeg(departure_rwy.heading - getprop("/environment/magnetic-variation-deg")); runway_ils = departure_rwy.ils_frequency_mhz; if (runway_ils != nil and !getprop("/FMGC/internal/ils1freq-set") and !getprop("/FMGC/internal/ils1crs-set")) { @@ -961,10 +1029,15 @@ var masterFMGC = maketimer(0.2, func { setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); } } -}); + +}; + +setlistener(FMGCNodes.phase, updateAirportRadios); +setlistener(flightPlanController.changed, updateAirportRadios); var reset_FMGC = func { FMGCInternal.phase = 0; + FMGCNodes.phase.serValue(0); fd1 = Input.fd1.getValue(); fd2 = Input.fd2.getValue(); spd = Input.kts.getValue(); diff --git a/Nasal/FMGC/flightplan.nas b/Nasal/FMGC/flightplan.nas index cb71f578..b072de4e 100644 --- a/Nasal/FMGC/flightplan.nas +++ b/Nasal/FMGC/flightplan.nas @@ -32,6 +32,8 @@ var flightPlanController = { # These flags are only for the main flgiht-plan active: props.globals.initNode("/FMGC/flightplan[2]/active", 0, "BOOL"), + + changed: props.globals.initNode("/FMGC/flightplan[2]/changed", 0, "BOOL"), currentToWpt: nil, # container for the current TO waypoint ghost currentToWptIndex: props.globals.initNode("/FMGC/flightplan[2]/current-wp", 0, "INT"), @@ -765,6 +767,9 @@ var flightPlanController = { fmgc.FMGCInternal.fuelCalculating = 1; fmgc.fuelCalculating.setValue(1); } + + if (n == 2) flightPlanController.changed.setBoolValue(1); + canvas_nd.A3XXRouteDriver.triggerSignal("fp-added"); }, diff --git a/Nasal/Libraries/libraries.nas b/Nasal/Libraries/libraries.nas index 0e15b916..b0662140 100644 --- a/Nasal/Libraries/libraries.nas +++ b/Nasal/Libraries/libraries.nas @@ -250,8 +250,8 @@ setlistener("/instrumentation/mk-viii/inputs/discretes/ta-tcf-inhibit", func{ # Replay var replayState = props.globals.getNode("/sim/replay/replay-state"); -setlistener("/sim/replay/replay-state", func() { - if (replayState.getBoolValue()) { +setlistener(replayState, func(v) { + if (v.getBoolValue()) { } else { acconfig.colddark(); gui.popupTip("Replay Ended: Setting Cold and Dark state..."); From 8c470e641c8bf48e2b7e9c812ca3f28d26440fb5 Mon Sep 17 00:00:00 2001 From: Inuyaksa Date: Fri, 11 Jun 2021 19:34:00 +0200 Subject: [PATCH 04/11] MCDU web moved as webpanel - MCDU as webpanel (not visible on PHI) - New menu to access MCDU web - Open via browser or QRCode - Fixed MCDU web text selection #230 --- A320-main.xml | 10 +++ mcdu.html => WebPanel/mcdu.html | 50 ++++++++---- gui/dialogs/mcduweb.xml | 137 ++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+), 15 deletions(-) rename mcdu.html => WebPanel/mcdu.html (76%) create mode 100644 gui/dialogs/mcduweb.xml diff --git a/A320-main.xml b/A320-main.xml index 0283c7f9..1d253efc 100644 --- a/A320-main.xml +++ b/A320-main.xml @@ -457,6 +457,16 @@ ]]> + + + + nasal + + + diff --git a/mcdu.html b/WebPanel/mcdu.html similarity index 76% rename from mcdu.html rename to WebPanel/mcdu.html index ec2904ad..55c0ed67 100644 --- a/mcdu.html +++ b/WebPanel/mcdu.html @@ -1,12 +1,18 @@ - + MCDU + + + + + - + - @@ -245,7 +265,7 @@ - +


Z / SPOVFY
OVFY
CLR
@@ -283,11 +303,11 @@ . 0 + style="font-size: 3vw; width: 33.333333333333333333333333333333333333333333333333333333333333333333333%; /* :) */" class="disabled"> +/- - + \ No newline at end of file diff --git a/gui/dialogs/mcduweb.xml b/gui/dialogs/mcduweb.xml new file mode 100644 index 00000000..f4cd077b --- /dev/null +++ b/gui/dialogs/mcduweb.xml @@ -0,0 +1,137 @@ + + + + + + + + + mcdu-web + vbox + 480 + + + hbox + + left + + + + + + + + + + vbox + + + left + + + + /sim/http/running + 0 + + + + + left + + + + /sim/http/running + 0 + + + + + + + + vbox + + + center + + + + + + + + vbox + + center + + + + center + + + + + + + mcduwebqr + center + center + false + 320 + 320 + + + + + + + + + + + + vbox + + center + + + + + + From c4036fc40784229c7865660a2d73b6802ee4f0a2 Mon Sep 17 00:00:00 2001 From: Inuyaksa Date: Sat, 12 Jun 2021 15:42:41 +0200 Subject: [PATCH 05/11] autoland light, phase as a nodes optimzed fmgc phase loop --- Models/FlightDeck/a320.flightdeck.xml | 25 +++- Models/Instruments/PFD/PFD.nas | 3 + Nasal/FMGC/FMGC.nas | 200 +++++++++++++++++--------- Systems/a320-adr.xml | 11 ++ Systems/a320-fwc.xml | 38 ++++- 5 files changed, 210 insertions(+), 67 deletions(-) diff --git a/Models/FlightDeck/a320.flightdeck.xml b/Models/FlightDeck/a320.flightdeck.xml index c45e4ec1..c352a650 100644 --- a/Models/FlightDeck/a320.flightdeck.xml +++ b/Models/FlightDeck/a320.flightdeck.xml @@ -1206,7 +1206,7 @@ audio_call_vhf2_led audio_call_vhf3_led audio_mech_sgn - autoland_light_on + ecam_c_b_led ecam_el_dc_led ecam_sts_led @@ -6158,6 +6158,29 @@ + + select + autoland_light_on + + + + controls/switches/annun-test + 1 + + + + instrumentation/pfd/lights/autoland-armed + 1 + + + instrumentation/pfd/lights/autoland-on + 1 + + + + + + select diff --git a/Models/Instruments/PFD/PFD.nas b/Models/Instruments/PFD/PFD.nas index 78e62441..d39738ac 100644 --- a/Models/Instruments/PFD/PFD.nas +++ b/Models/Instruments/PFD/PFD.nas @@ -164,6 +164,9 @@ var amberFlash1 = props.globals.initNode("/instrumentation/pfd/flash-indicators/ var amberFlash2 = props.globals.initNode("/instrumentation/pfd/flash-indicators/amber-flash-2", 0, "BOOL"); var dhFlash = props.globals.initNode("/instrumentation/pfd/flash-indicators/dh-flash", 0, "BOOL"); +var light_autoland_armed = props.globals.initNode("/instrumentation/pfd/lights/autoland-armed", 0, "BOOL"); +var light_autoland_on = props.globals.initNode("/instrumentation/pfd/lights/autoland-on", 0, "BOOL"); + var canvas_PFD_base = { init: func(canvas_group, file) { var font_mapper = func(family, weight) { diff --git a/Nasal/FMGC/FMGC.nas b/Nasal/FMGC/FMGC.nas index b771d080..a65f6fe6 100644 --- a/Nasal/FMGC/FMGC.nas +++ b/Nasal/FMGC/FMGC.nas @@ -86,6 +86,7 @@ var FMGCinit = func { FMGCInternal.minspeed = 0; FMGCInternal.maxspeed = 338; FMGCInternal.phase = 0; # 0 is Preflight 1 is Takeoff 2 is Climb 3 is Cruise 4 is Descent 5 is Decel/Approach 6 is Go Around 7 is Done + FMGCNodes.phase.setValue(0); FMGCInternal.mngSpd = 157; FMGCInternal.mngSpdCmd = 157; FMGCInternal.mngKtsMach = 0; @@ -259,6 +260,7 @@ var FMGCNodes = { toState: props.globals.initNode("/FMGC/internal/to-state", 0, "BOOL"), v1: props.globals.initNode("/FMGC/internal/v1", 0, "DOUBLE"), v1set: props.globals.initNode("/FMGC/internal/v1-set", 0, "BOOL"), + phase: props.globals.initNode("/FMGC/internal/phase", 0, "INT"), }; ############ @@ -603,88 +605,144 @@ var radios = maketimer(1, func() { adf1(); }); + + +var prop_n1_left = pts.Engines.Engine.n1Actual[0]; +var prop_n1_right = pts.Engines.Engine.n1Actual[1]; +#var prop_nmodelat = Modes.PFD.FMA.rollMode; +#var prop_mode = Modes.PFD.FMA.pitchMode; +var prop_gs = pts.Velocities.groundspeed; +var prop_alt = pts.Instrumentation.Altimeter.indicatedFt; +var prop_state1 = pts.Systems.Thrust.state[0]; +var prop_state2 = pts.Systems.Thrust.state[1]; +#var prop_accel_agl_ft = Setting.reducAglFt; +var prop_gear0 = pts.Gear.wow[0]; +#var prop_altSel = Input.alt; + var masterFMGC = maketimer(0.2, func { - n1_left = pts.Engines.Engine.n1Actual[0].getValue(); - n1_right = pts.Engines.Engine.n1Actual[1].getValue(); + + n1_left = prop_n1_left.getValue(); + n1_right = prop_n1_right.getValue(); modelat = Modes.PFD.FMA.rollMode.getValue(); mode = Modes.PFD.FMA.pitchMode.getValue(); - gs = pts.Velocities.groundspeed.getValue(); - alt = pts.Instrumentation.Altimeter.indicatedFt.getValue(); + gs = prop_gs.getValue(); + alt = prop_alt.getValue(); # cruiseft = FMGCInternal.crzFt; # cruiseft_b = FMGCInternal.crzFt - 200; - state1 = pts.Systems.Thrust.state[0].getValue(); - state2 = pts.Systems.Thrust.state[1].getValue(); + state1 = prop_state1.getValue(); + state2 = prop_state2.getValue(); accel_agl_ft = Setting.reducAglFt.getValue(); - gear0 = pts.Gear.wow[0].getBoolValue(); + gear0 = prop_gear0.getBoolValue(); altSel = Input.alt.getValue(); - if ((n1_left < 85 or n1_right < 85) and gs < 90 and mode == " " and gear0 and FMGCInternal.phase == 1) { # rejected takeoff - FMGCInternal.phase = 0; - systems.PNEU.pressMode.setValue("GN"); - } - - if (gear0 and FMGCInternal.phase == 0 and ((n1_left >= 85 and n1_right >= 85 and mode == "SRS") or gs >= 90)) { - FMGCInternal.phase = 1; - systems.PNEU.pressMode.setValue("TO"); - } - - if (FMGCInternal.phase == 1 and ((mode != "SRS" and mode != " ") or alt >= accel_agl_ft)) { - FMGCInternal.phase = 2; - systems.PNEU.pressMode.setValue("TO"); - } - - if (FMGCInternal.phase == 2 and (mode == "ALT CRZ" or mode == "ALT CRZ*")) { - FMGCInternal.phase = 3; - systems.PNEU.pressMode.setValue("CR"); - } - - if (FMGCInternal.crzFl >= 200) { - if (FMGCInternal.phase == 3 and (flightPlanController.arrivalDist <= 200 or altSel < 20000)) { - FMGCInternal.phase = 4; - systems.PNEU.pressMode.setValue("DE"); + var phase = FMGCInternal.phase; + var newphase = phase; + + if (phase == 0) { + + if (gear0 and ((n1_left >= 85 and n1_right >= 85 and mode == "SRS") or gs >= 90)) { + newphase = 1; + systems.PNEU.pressMode.setValue("TO"); } - } else { - if (FMGCInternal.phase == 3 and (flightPlanController.arrivalDist <= 200 or altSel < (FMGCInternal.crzFl * 100))) { # todo - not sure about crzFl condition, investigate what happens! - FMGCInternal.phase = 4; - systems.PNEU.pressMode.setValue("DE"); + + } + + else if (phase == 1) { + + if (gear0) { + + if ((n1_left < 85 or n1_right < 85) and gs < 90 and mode == " ") { # rejected takeoff + newphase = 0; + systems.PNEU.pressMode.setValue("GN"); + } + + } + else if (((mode != "SRS" and mode != " ") or alt >= accel_agl_ft)) { + newphase = 2; + systems.PNEU.pressMode.setValue("TO"); } + } - if (FMGCInternal.phase == 4) { - if (getprop("/FMGC/internal/decel")) { - FMGCInternal.phase = 5; - } - else if (altSel == (FMGCInternal.crzFl * 100)) { # back to CRZ state - FMGCInternal.phase = 3; + else if (phase == 2) { + + if ((mode == "ALT CRZ" or mode == "ALT CRZ*")) { + newphase = 3; systems.PNEU.pressMode.setValue("CR"); } + + } + + else if (phase == 3) { + + if (FMGCInternal.crzFl >= 200) { + if ((flightPlanController.arrivalDist <= 200 or altSel < 20000)) { + newphase = 4; + systems.PNEU.pressMode.setValue("DE"); + } + } else { + if ((flightPlanController.arrivalDist <= 200 and altSel < (FMGCInternal.crzFl * 100))) { # todo - not sure about crzFl condition, investigate what happens! + newphase = 4; + systems.PNEU.pressMode.setValue("DE"); + } + } + + } + + else if (phase == 4) { + + if (getprop("/FMGC/internal/decel")) { + newphase = 5; + } + else if (altSel == (FMGCInternal.crzFl * 100)) { # back to CRZ state + newphase = 3; + systems.PNEU.pressMode.setValue("CR"); + } + } - 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 pts.Position.gearAglFt.getValue() < 9500) { #todo decel pseudo waypoint + else if (phase == 5) { + + if (state1 == "TOGA" and state2 == "TOGA") { + newphase = 6; + systems.PNEU.pressMode.setValue("TO"); + Input.toga.setValue(1); + } + + } + + else if (phase == 6) { + + if (alt >= accel_agl_ft) { # todo when insert altn or new dest + newphase = 2; + } + + } + + + 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 pts.Position.gearAglFt.getValue() < 9500) { #todo decel pseudo waypoint setprop("/FMGC/internal/decel", 1); - } else if (getprop("/FMGC/internal/decel") == 1 and (FMGCInternal.phase == 0 or FMGCInternal.phase == 6)) { + } else if (getprop("/FMGC/internal/decel") == 1 and (phase == 0 or phase == 6)) { setprop("/FMGC/internal/decel", 0); } - if ((FMGCInternal.phase == 5) and state1 == "TOGA" and state2 == "TOGA") { - FMGCInternal.phase = 6; - systems.PNEU.pressMode.setValue("TO"); - Input.toga.setValue(1); - } - if (FMGCInternal.phase == 6 and alt >= accel_agl_ft) { # todo when insert altn or new dest - FMGCInternal.phase = 2; - } - - tempOverspeed = systems.ADIRS.overspeedVFE.getValue(); - if (tempOverspeed != 1024) { - FMGCInternal.maxspeed = tempOverspeed - 4; + if (getprop("/systems/navigation/adr/computation/overspeed-vfe-spd") != 1024) { + FMGCInternal.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) { FMGCInternal.maxspeed = 284; } else { FMGCInternal.maxspeed = fmgc.FMGCInternal.vmo_mmo; } + if (newphase != phase) { # phase changed + FMGCInternal.phase = newphase; + FMGCNodes.phase.setValue(newphase); + } + + + ############################ # fuel ############################ @@ -774,7 +832,7 @@ var masterFMGC = maketimer(0.2, func { } # predicted takeoff speeds - if (FMGCInternal.phase == 1) { + if (phase == 1) { FMGCInternal.clean_to = FMGCInternal.clean; FMGCInternal.vs1g_clean_to = FMGCInternal.vs1g_clean; FMGCInternal.vs1g_conf_2_to = FMGCInternal.vs1g_conf_2; @@ -796,7 +854,7 @@ var masterFMGC = maketimer(0.2, func { } # predicted approach (temp go-around) speeds - if (FMGCInternal.phase == 5 or FMGCInternal.phase == 6) { + if (phase == 5 or phase == 6) { FMGCInternal.clean_appr = FMGCInternal.clean; FMGCInternal.vs1g_clean_appr = FMGCInternal.vs1g_clean; FMGCInternal.vs1g_conf_2_appr = FMGCInternal.vs1g_conf_2; @@ -917,7 +975,8 @@ var masterFMGC = maketimer(0.2, func { } } - if (gear0 and pts.Controls.Flight.flapsPos.getValue() < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { + #if (gear0 and pts.Controls.Flight.flapsPos.getValue() < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { + if (gear0 and flap < 5 and (state1 == "MCT" or state1 == "MAN THR" or state1 == "TOGA") and (state2 == "MCT" or state2 == "MAN THR" or state2 == "TOGA")) { if (!FMGCInternal.takeoffState) { fmgc.FMGCNodes.toState.setValue(1); } @@ -929,13 +988,21 @@ var masterFMGC = maketimer(0.2, func { FMGCInternal.takeoffState = 0; } - ############################ - #handle radios, runways, v1/vr/v2 - ############################ +}); + +############################ +#handle radios, runways, v1/vr/v2 +############################ + +var updateAirportRadios = func { + + var phase = FMGCInternal.phase; + print("# Update airport radios"); + departure_rwy = fmgc.flightPlanController.flightplans[2].departure_runway; destination_rwy = fmgc.flightPlanController.flightplans[2].destination_runway; - if (destination_rwy != nil and FMGCInternal.phase >= 2) { + if (phase >= 2 and destination_rwy != nil) { var airport = airportinfo(FMGCInternal.arrApt); setprop("/FMGC/internal/ldg-elev", airport.elevation * M2FT); # eventually should be runway elevation magnetic_hdg = geo.normdeg(destination_rwy.heading - getprop("/environment/magnetic-variation-deg")); @@ -950,7 +1017,7 @@ var masterFMGC = maketimer(0.2, func { } else if (!getprop("/FMGC/internal/ils1crs-set")) { setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); } - } else if (departure_rwy != nil and FMGCInternal.phase <= 1) { + } else if (phase <= 1 and departure_rwy != nil) { magnetic_hdg = geo.normdeg(departure_rwy.heading - getprop("/environment/magnetic-variation-deg")); runway_ils = departure_rwy.ils_frequency_mhz; if (runway_ils != nil and !getprop("/FMGC/internal/ils1freq-set") and !getprop("/FMGC/internal/ils1crs-set")) { @@ -964,10 +1031,15 @@ var masterFMGC = maketimer(0.2, func { setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); } } -}); + +}; + +setlistener(FMGCNodes.phase, updateAirportRadios); +setlistener(flightPlanController.changed, updateAirportRadios); var reset_FMGC = func { FMGCInternal.phase = 0; + FMGCNodes.phase.serValue(0); fd1 = Input.fd1.getValue(); fd2 = Input.fd2.getValue(); spd = Input.kts.getValue(); diff --git a/Systems/a320-adr.xml b/Systems/a320-adr.xml index 2a125dcf..9896d49b 100644 --- a/Systems/a320-adr.xml +++ b/Systems/a320-adr.xml @@ -922,6 +922,17 @@ 5000 + + + + + + /instrumentation/radar-altimeter[0]/radar-altitude-ft-corrected + /instrumentation/radar-altimeter[1]/radar-altitude-ft-corrected + + + + diff --git a/Systems/a320-fwc.xml b/Systems/a320-fwc.xml index 1c08f6c3..09ab1065 100644 --- a/Systems/a320-fwc.xml +++ b/Systems/a320-fwc.xml @@ -2211,7 +2211,7 @@ /ECAM/warnings/logic/stall/phase-flipflop eq 1 - + @@ -2300,7 +2300,41 @@ /ECAM/warnings/logic/stall/stall-warn-inhibit eq 0 - + + + + + + + /modes/pfd/ILS1 eq 1 + /instrumentation/radar-altimeter[0]/radar-altitude-ft-corrected le 200 + + + /modes/pfd/ILS2 eq 1 + /instrumentation/radar-altimeter[1]/radar-altitude-ft-corrected le 200 + + + + + + + + + /instrumentation/pfd/lights/autoland-armed eq 1 + + + /it-autoflight/output/ap1 eq 0 + /it-autoflight/output/ap2 eq 0 + + /instrumentation/radar-altimeter-difference gt 15 + + + + + From 23369f854b9cc1c703e94fcb7aee5ae0006a0d2a Mon Sep 17 00:00:00 2001 From: Inuyaksa Date: Sat, 12 Jun 2021 15:46:08 +0200 Subject: [PATCH 06/11] property /instrumentation/radar-altimeter-difference-ft Difference from 2 radar altimeter (corrected) in ft --- Systems/a320-adr.xml | 2 +- Systems/a320-fwc.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Systems/a320-adr.xml b/Systems/a320-adr.xml index 9896d49b..b1ef10f0 100644 --- a/Systems/a320-adr.xml +++ b/Systems/a320-adr.xml @@ -923,7 +923,7 @@ - + diff --git a/Systems/a320-fwc.xml b/Systems/a320-fwc.xml index 09ab1065..de676136 100644 --- a/Systems/a320-fwc.xml +++ b/Systems/a320-fwc.xml @@ -2326,7 +2326,7 @@ /it-autoflight/output/ap1 eq 0 /it-autoflight/output/ap2 eq 0 - /instrumentation/radar-altimeter-difference gt 15 + /instrumentation/radar-altimeter-difference-ft gt 15