From d65fde37263e0700b0142b192aa61690275dfb51 Mon Sep 17 00:00:00 2001 From: Jonathan Redpath Date: Tue, 28 Jun 2022 20:31:01 +0100 Subject: [PATCH] Add top of climb / level off symbols to the navdisplay --- .../Instruments/ND/canvas/res/airbus_tc.svg | 73 ------------------- Models/Instruments/ND/canvas/style.nas | 51 +++++++------ Nasal/FMGC/flightplan.nas | 49 +++++++++++++ 3 files changed, 74 insertions(+), 99 deletions(-) delete mode 100644 Models/Instruments/ND/canvas/res/airbus_tc.svg diff --git a/Models/Instruments/ND/canvas/res/airbus_tc.svg b/Models/Instruments/ND/canvas/res/airbus_tc.svg deleted file mode 100644 index 353ce25d..00000000 --- a/Models/Instruments/ND/canvas/res/airbus_tc.svg +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - - - - diff --git a/Models/Instruments/ND/canvas/style.nas b/Models/Instruments/ND/canvas/style.nas index 052bab9a..8ab0593d 100644 --- a/Models/Instruments/ND/canvas/style.nas +++ b/Models/Instruments/ND/canvas/style.nas @@ -181,7 +181,7 @@ canvas.NDStyles["Airbus"] = { { name: "ALT-profile", isMapStructure: 1, - update_on: ["toggle_display_mode","toggle_range",{rate_hz: 2}], + update_on: ["toggle_display_mode","toggle_range", {rate_hz: 0.5}], predicate: func(nd, layer) { var visible = nd.in_mode("toggle_display_mode", ["MAP", "PLAN"]) and (nd.adirs_property.getValue() == 1 or (adirs_3.getValue() == 1 and att_switch.getValue() == nd.attitude_heading_setting)); layer.group.setVisible( visible ); @@ -205,7 +205,6 @@ canvas.NDStyles["Airbus"] = { # /autopilot/route-manager/vnav/td/ # Each node should have the latitude-deg and longitude-deg properties. # Available nodes are: - # tc (top of climb) # td (top of descent) # ec (end of climb) # ed (end of descent) @@ -214,14 +213,13 @@ canvas.NDStyles["Airbus"] = { # If ec and ed are altitude constraints, their node should have the # boolean "alt-cstr" property set to 1. vnav_node: "/autopilot/route-manager/vnav/", - types: ["tc", "td", "ec", "ed","sc","sd"], + types: ["ec","ed","sc","sd","td"], svg_path: { - tc: get_local_path("res/airbus_tc.svg"), - td: get_local_path("res/airbus_td.svg"), ec: get_local_path("res/airbus_ec.svg"), ed: get_local_path("res/airbus_ed.svg"), sc: get_local_path("res/airbus_sc.svg"), - sd: get_local_path("res/airbus_sd.svg") + sd: get_local_path("res/airbus_sd.svg"), + td: get_local_path("res/airbus_td.svg") }, listen: [ "fplan_active", @@ -233,31 +231,32 @@ canvas.NDStyles["Airbus"] = { draw_callback: func(){ var name = me.model.getName(); var grp = me.element.getElementById(name~"_symbol"); - if(grp == nil) return; - var dfcolor = me.getStyle("default_color"); - var armed_color = me.getStyle("armed_color"); - var managed_color = me.getStyle("managed_color"); - #print("Draw: -> " ~ name); - if(name == "td" or name == "sd" or name == "sc"){ - var vnav_armed = me.model.getValue("vnav-armed"); - if(vnav_armed and name != "td") - grp.setColor(armed_color); - else - grp.setColor(dfcolor); + if (grp == nil) return; + + if (me.model.getValue("show")) { + grp.show(); + } else { + grp.hide(); } - elsif(name == "ed" or name == "ec"){ - var is_cstr = me.model.getValue("alt-cstr"); - if(is_cstr) - grp.setColor(managed_color); - else - grp.setColor(armed_color); + + if (name == "ed" or name == "ec") { + if (me.model.getValue("alt-cstr")) { + grp.setColor(me.getStyle("managed_color")); + } else { + grp.setColor(me.getStyle("armed_color")); + } + } elsif(name == "td" or name == "sd" or name == "sc"){ + if (me.model.getValue("vnav-armed") and name != "td") { + grp.setColor(me.getStyle("armed_color")); + } else { + grp.setColor(me.getStyle("default_color")); + } } }, init_after_callback: func{ var name = me.model.getName(); - var grp = me.element.getElementById(name~"_symbol"); - if(name != "td" and name != "sd" and name != "sc"){ - grp.setTranslation(-66,0); + if (name != "td" and name != "sd" and name != "sc") { + me.element.getElementById(name~"_symbol").setTranslation(-66,0); } } } diff --git a/Nasal/FMGC/flightplan.nas b/Nasal/FMGC/flightplan.nas index 8760962f..53178d3e 100644 --- a/Nasal/FMGC/flightplan.nas +++ b/Nasal/FMGC/flightplan.nas @@ -45,6 +45,7 @@ var flightPlanController = { _timeTemp: nil, _altTemp: nil, decelPoint: nil, + lvlOffPoint: nil, init: func() { me.resetFlightplan(2); @@ -60,8 +61,18 @@ var flightPlanController = { me.resetFlightplan(0); me.resetFlightplan(1); me.resetFlightplan(2); + me.decelPoint = nil; setprop("/instrumentation/nd/symbols/decel/show", 0); + + me.lvlOffPoint = nil; + setprop("/autopilot/route-manager/vnav/ec/latitude-deg", 0); # necessary to prevent canvas glitching out because properties don't exist + setprop("/autopilot/route-manager/vnav/ed/latitude-deg", 0); + setprop("/autopilot/route-manager/vnav/ec/longitude-deg", 0); + setprop("/autopilot/route-manager/vnav/ed/longitude-deg", 0); + setprop("/autopilot/route-manager/vnav/ec/show", 0); + setprop("/autopilot/route-manager/vnav/ed/show", 0); + me.flightplans[2].activate(); }, @@ -763,6 +774,36 @@ var flightPlanController = { setprop("/instrumentation/nd/symbols/decel/index", me.indexTemp); }, + + calculateLvlOffPoint: func(deltaAltitude) { + me.distLvl = (deltaAltitude * pts.Velocities.groundspeedKt.getValue()) / (fmgc.Internal.vs.getValue() * 60); + + if (fmgc.Output.lat.getValue() == 1) { # NAV + me.lvlOffPoint = me.flightplans[2].pathGeod(me.currentToWptIndex.getValue() - 1, me.flightplans[2].getWP(me.currentToWptIndex.getValue()).leg_distance - me.distToWpt.getValue() + abs(me.distLvl)); + } elsif (fmgc.Output.lat.getValue() == 0) { # HDG TRK + #var coord = geo.aircraft_position(); + #coord.apply_course_distance(fmgc.Internal.hdg.getValue(), me.distLvl * FT2M); + #me.lvlOffPoint = {lat: coord.lat(), lon: coord.lon()}; + me.lvlOffPoint = me.flightplans[2].pathGeod(me.currentToWptIndex.getValue(), 10); + } else { + setprop("/autopilot/route-manager/vnav/ec/show", 0); + setprop("/autopilot/route-manager/vnav/ed/show", 0); + me.lvlOffPoint = nil; + } + + if (deltaAltitude >= 100 and me.lvlOffPoint != nil) { + setprop("/autopilot/route-manager/vnav/ec/latitude-deg", me.lvlOffPoint.lat); + setprop("/autopilot/route-manager/vnav/ec/longitude-deg", me.lvlOffPoint.lon); + setprop("/autopilot/route-manager/vnav/ec/show", 1); + setprop("/autopilot/route-manager/vnav/ed/show", 0); + } elsif (deltaAltitude <= -100 and me.lvlOffPoint != nil) { + setprop("/autopilot/route-manager/vnav/ed/latitude-deg", me.lvlOffPoint.lat); + setprop("/autopilot/route-manager/vnav/ed/longitude-deg", me.lvlOffPoint.lon); + setprop("/autopilot/route-manager/vnav/ec/show", 0); + setprop("/autopilot/route-manager/vnav/ed/show", 1); + } + }, + # insertPlaceBearingDistance - insert PBD waypoint at specified index, # at some specified bearing, distance from a specified location # args: wp, index, plan @@ -898,6 +939,14 @@ var flightPlanController = { me.calculateDecelPoint(); } + var deltaAltitude = fmgc.Input.alt.getValue() - pts.Instrumentation.Altimeter.indicatedFt.getValue(); + if (abs(deltaAltitude) >= 100) { + me.calculateLvlOffPoint(deltaAltitude); + } else { + setprop("/autopilot/route-manager/vnav/ec/show", 0); + setprop("/autopilot/route-manager/vnav/ed/show", 0); + } + for (var i = 0; i <= 1; i += 1) { if (canvas_mcdu.myFpln[i] != nil) { canvas_mcdu.myFpln[i].updatePlan();