2019-10-14 16:48:35 +00:00
# A3XX FMGC/Autoflight
2020-07-08 20:14:55 +00:00
# Copyright (c) 2020 Josh Davidson (Octal450), Jonathan Redpath (legoboyvdlp), and Matthew Maring (mattmaring)
2019-10-14 16:48:35 +00:00
##################
# Init Functions #
##################
var gear0 = 0;
var state1 = 0;
var state2 = 0;
var dep = "";
var arr = "";
var n1_left = 0;
var n1_right = 0;
2021-06-12 16:53:54 +00:00
var modelat = "";
2019-10-14 16:48:35 +00:00
var mode = 0;
var gs = 0;
var cruiseft = 0;
var cruiseft_b = 0;
var state1 = 0;
var state2 = 0;
2020-04-16 12:25:06 +00:00
var accel_agl_ft = 0;
2019-10-14 16:48:35 +00:00
var fd1 = 0;
var fd2 = 0;
var spd = 0;
var hdg = 0;
var alt = 0;
var altitude = 0;
var flap = 0;
2021-06-13 18:41:53 +00:00
var flaps = 0;
2019-10-14 16:48:35 +00:00
var ias = 0;
var mach = 0;
var ktsmach = 0;
var kts_sel = 0;
var mach_sel = 0;
var srsSPD = 0;
var decel = 0;
var mng_alt_spd = 0;
var mng_alt_mach = 0;
2020-04-16 12:25:06 +00:00
var altsel = 0;
var crzFl = 0;
2020-10-05 18:18:10 +00:00
var windHdg = 0;
var windSpeed = 0;
2020-11-28 12:24:24 +00:00
var windsDidChange = 0;
2021-06-10 15:38:16 +00:00
var tempOverspeed = nil;
2021-12-27 11:44:08 +00:00
setprop("/position/gear-agl-ft", 0);
2020-07-09 22:59:11 +00:00
setprop("/it-autoflight/settings/accel-agl-ft", 1500); #eventually set to 1500 above runway
setprop("/it-autoflight/internal/vert-speed-fpm", 0);
setprop("/it-autoflight/output/fma-pwr", 0);
2021-06-13 18:29:25 +00:00
setprop("/instrumentation/nav[0]/nav-id", "XXX");
setprop("/instrumentation/nav[1]/nav-id", "XXX");
2019-10-14 16:48:35 +00:00
2021-06-12 23:24:46 +00:00
var FMGCAlignDone = [props.globals.initNode("/FMGC/internal/align1-done", 0, "BOOL"), props.globals.initNode("/FMGC/internal/align2-done", 0, "BOOL"), props.globals.initNode("/FMGC/internal/align3-done", 0, "BOOL")];
var FMGCAlignTime = [props.globals.initNode("/FMGC/internal/align1-time", 0, "DOUBLE"), props.globals.initNode("/FMGC/internal/align2-time", 0, "DOUBLE"), props.globals.initNode("/FMGC/internal/align3-time", 0, "DOUBLE")];
2021-06-11 23:27:46 +00:00
var adirsSkip = props.globals.getNode("/systems/acconfig/options/adirs-skip");
2020-10-03 11:34:29 +00:00
var blockCalculating = props.globals.initNode("/FMGC/internal/block-calculating", 0, "BOOL");
var fuelCalculating = props.globals.initNode("/FMGC/internal/fuel-calculating", 0, "BOOL");
2019-10-14 16:48:35 +00:00
var FMGCinit = func {
2020-08-01 16:49:54 +00:00
FMGCInternal.takeoffState = 0;
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
2021-06-12 13:42:41 +00:00
FMGCNodes.phase.setValue(0);
2020-10-05 18:18:10 +00:00
FMGCInternal.mngSpd = 157;
FMGCInternal.mngSpdCmd = 157;
FMGCInternal.mngKtsMach = 0;
FMGCInternal.machSwitchover = 0;
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/optalt", 0);
2021-12-28 12:59:08 +00:00
FMGCInternal.landingTime = -99;
FMGCInternal.blockFuelTime = -99;
FMGCInternal.fuelPredTime = -99;
2021-06-13 18:29:25 +00:00
FMGCAlignTime[0].setValue(-99);
FMGCAlignTime[1].setValue(-99);
FMGCAlignTime[2].setValue(-99);
2019-10-14 16:48:35 +00:00
masterFMGC.start();
2020-07-12 18:27:04 +00:00
radios.start();
2019-10-14 16:48:35 +00:00
}
2020-05-16 14:48:26 +00:00
var FMGCInternal = {
2020-07-10 21:15:37 +00:00
# phase logic
phase: 0,
2020-07-11 19:13:21 +00:00
minspeed: 0,
maxspeed: 0,
takeoffState: 0,
# speeds
alpha_prot: 0,
alpha_max: 0,
vmo_mmo: 0,
2020-08-01 16:49:54 +00:00
vsw: 0,
vls_min: 0,
clean: 0,
vs1g_clean: 0,
vs1g_conf_1: 0,
vs1g_conf_1f: 0,
vs1g_conf_2: 0,
vs1g_conf_3: 0,
vs1g_conf_full: 0,
slat: 0,
flap2: 0,
flap3: 0,
vls: 0,
vapp: 0,
clean_to: 0,
vs1g_clean_to: 0,
vs1g_conf_2_to: 0,
vs1g_conf_3_to: 0,
vs1g_conf_full_to: 0,
slat_to: 0,
flap2_to: 0,
clean_appr: 0,
vs1g_clean_appr: 0,
vs1g_conf_2_appr: 0,
vs1g_conf_3_appr: 0,
vs1g_conf_full_appr: 0,
slat_appr: 0,
flap2_appr: 0,
vls_appr: 0,
vapp_appr: 0,
2020-09-28 19:15:19 +00:00
vappSpeedSet: 0,
2020-07-10 21:15:37 +00:00
2020-07-10 00:09:19 +00:00
# PERF
2020-07-29 23:24:03 +00:00
transAlt: 18000,
transAltSet: 0,
# PERF TO
2020-07-09 22:59:11 +00:00
v1: 0,
v1set: 0,
vr: 0,
vrset: 0,
v2: 0,
v2set: 0,
2020-07-29 23:24:03 +00:00
# PERF APPR
destMag: 0,
destMagSet: 0,
destWind: 0,
destWindSet: 0,
2020-09-28 19:15:19 +00:00
radioNo: 0,
ldgConfig3: 0,
ldgConfigFull: 0,
2020-07-10 00:09:19 +00:00
# INIT A
2020-07-10 19:54:13 +00:00
altAirport: "",
altAirportSet: 0,
altSelected: 0,
arrApt: "",
2020-12-31 20:03:47 +00:00
coRoute: "",
coRouteSet: 0,
2020-07-10 19:54:13 +00:00
costIndex: 0,
costIndexSet: 0,
2020-07-10 00:09:19 +00:00
crzFt: 10000,
crzFl: 0,
crzSet: 0,
crzTemp: 15,
crzTempSet: 0,
flightNum: "",
flightNumSet: 0,
2020-07-10 19:54:13 +00:00
gndTemp: 15,
gndTempSet: 0,
2020-07-10 19:28:17 +00:00
depApt: "",
2020-07-10 19:54:13 +00:00
tropo: 36090,
tropoSet: 0,
2020-07-10 19:28:17 +00:00
toFromSet: 0,
2020-08-01 13:57:19 +00:00
# INIT B
zfw: 0,
zfwSet: 0,
zfwcg: 25.0,
zfwcgSet: 0,
block: 0.0,
blockSet: 0,
2020-10-03 09:59:43 +00:00
blockCalculating: 0,
blockConfirmed: 0,
fuelCalculating: 0,
fuelRequest: 0,
2020-08-01 13:57:19 +00:00
taxiFuel: 0.4,
taxiFuelSet: 0,
tripFuel: 0,
tripTime: "0000",
rteRsv: 0,
rteRsvSet: 0,
rtePercent: 5.0,
rtePercentSet: 0,
altFuel: 0,
altFuelSet: 0,
altTime: "0000",
finalFuel: 0,
finalFuelSet: 0,
finalTime: "0030",
finalTimeSet: 0,
minDestFob: 0,
minDestFobSet: 0,
tow: 0,
lw: 0,
tripWind: "HD000",
tripWindValue: 0,
fffqSensor: "FF+FQ",
extraFuel: 0,
extraTime: "0000",
# FUELPRED
priUtc: "0000",
altUtc: "0000",
priEfob: 0,
altEfob: 0,
fob: 0,
fuelPredGw: 0,
cg: 0,
2020-10-05 18:18:10 +00:00
# Managed Speed
machSwitchover: 0,
mngKtsMach: 0,
mngSpd: 0,
mngSpdCmd: 0,
2021-12-27 11:44:08 +00:00
2022-01-04 17:24:49 +00:00
# This can't be init to -98, because we don't want it to run until WOW has gone to false and back to true
landingTime: -98,
2021-12-28 12:59:08 +00:00
blockFuelTime: -99,
fuelPredTime: -99,
2021-12-27 11:44:08 +00:00
# RADNAV
ADF1: {
freqSet: 0,
mcdu: "XXX/999.99"
},
ADF2: {
freqSet: 0,
mcdu: "999.99/XXX"
},
ILS: {
crsSet: 0,
freqCalculated: 0,
freqSet: 0,
mcdu: "XXX/999.99"
},
VOR1: {
crsSet: 0,
freqSet: 0,
mcdu: "XXX/999.99"
},
VOR2: {
crsSet: 0,
freqSet: 0,
mcdu: "999.99/XXX"
},
2020-05-16 14:48:26 +00:00
};
2020-07-10 00:09:19 +00:00
var postInit = func() {
# Some properties had setlistener -- so to make sure all is o.k., we call function immediately like so:
altvert();
updateRouteManagerAlt();
mcdu.updateCrzLvlCallback();
}
2020-07-09 22:59:11 +00:00
var FMGCNodes = {
2020-07-10 19:54:13 +00:00
costIndex: props.globals.initNode("/FMGC/internal/cost-index", 0, "DOUBLE"),
2020-09-20 19:52:54 +00:00
flexSet: props.globals.initNode("/FMGC/internal/flex-set", 0, "BOOL"),
2020-10-27 21:35:17 +00:00
flexTemp: props.globals.initNode("/FMGC/internal/flex", 0, "INT"),
2020-10-05 18:18:10 +00:00
mngSpdAlt: props.globals.getNode("/FMGC/internal/mng-alt-spd"),
mngMachAlt: props.globals.getNode("/FMGC/internal/mng-alt-mach"),
2020-07-10 19:54:13 +00:00
toFromSet: props.globals.initNode("/FMGC/internal/tofrom-set", 0, "BOOL"),
2020-10-05 18:18:10 +00:00
toState: props.globals.initNode("/FMGC/internal/to-state", 0, "BOOL"),
2020-07-09 22:59:11 +00:00
v1: props.globals.initNode("/FMGC/internal/v1", 0, "DOUBLE"),
v1set: props.globals.initNode("/FMGC/internal/v1-set", 0, "BOOL"),
2021-06-12 13:42:41 +00:00
phase: props.globals.initNode("/FMGC/internal/phase", 0, "INT"),
2021-06-16 13:40:15 +00:00
vlsMin: props.globals.initNode("/FMGC/internal/vls-min", 0, "DOUBLE"),
vmax: props.globals.initNode("/FMGC/internal/vmax", 0, "DOUBLE"),
2020-07-09 22:59:11 +00:00
};
2019-10-14 16:48:35 +00:00
############
# FBW Trim #
############
2020-07-10 21:15:37 +00:00
setlistener("/gear/gear[0]/wow", func {
2019-10-14 16:48:35 +00:00
trimReset();
2020-07-10 21:15:37 +00:00
}, 0, 0);
2019-10-14 16:48:35 +00:00
var trimReset = func {
2020-10-03 09:59:43 +00:00
flaps = pts.Controls.Flight.flapsPos.getValue();
if (pts.Gear.wow[0].getBoolValue() and !FMGCInternal.takeoffState and (flaps >= 5 or (flaps >= 4 and pts.Instrumentation.MKVII.Inputs.Discretes.flap3Override.getValue() == 1))) {
2019-10-14 16:48:35 +00:00
interpolate("/controls/flight/elevator-trim", 0.0, 1.5);
}
}
###############
# MCDU Inputs #
###############
var updateARPT = func {
2021-06-10 15:38:16 +00:00
setprop("/autopilot/route-manager/departure/airport", FMGCInternal.depApt);
setprop("/autopilot/route-manager/destination/airport", FMGCInternal.arrApt);
setprop("/autopilot/route-manager/alternate/airport", FMGCInternal.altAirport);
2020-05-01 16:46:53 +00:00
if (getprop("/autopilot/route-manager/active") != 1) {
2019-10-14 16:48:35 +00:00
fgcommand("activate-flightplan", props.Node.new({"activate": 1}));
}
}
2020-08-01 15:30:16 +00:00
var updateArptLatLon = func {
#ref lat
dms = getprop("/FMGC/flightplan[2]/wp[0]/lat");
degrees = int(dms);
minutes = sprintf("%.1f",abs((dms - degrees) * 60));
sign = degrees >= 0 ? "N" : "S";
setprop("/FMGC/internal/align-ref-lat-degrees", degrees);
setprop("/FMGC/internal/align-ref-lat-minutes", minutes);
setprop("/FMGC/internal/align-ref-lat-sign", sign);
#ref long
dms = getprop("/FMGC/flightplan[2]/wp[0]/lon");
degrees = int(dms);
minutes = sprintf("%.1f",abs((dms - degrees) * 60));
sign = degrees >= 0 ? "E" : "W";
setprop("/FMGC/internal/align-ref-long-degrees", degrees);
setprop("/FMGC/internal/align-ref-long-minutes", minutes);
setprop("/FMGC/internal/align-ref-long-sign", sign);
#ref edit
setprop("/FMGC/internal/align-ref-lat-edit", 0);
setprop("/FMGC/internal/align-ref-long-edit", 0);
}
2020-07-10 00:09:19 +00:00
updateRouteManagerAlt = func() {
2021-06-10 15:38:16 +00:00
setprop("/autopilot/route-manager/cruise/altitude-ft", FMGCInternal.crzFt);
2020-12-31 20:03:47 +00:00
# TODO - update FMGCInternal.phase when DES to re-enter in CLIMB/CRUIZE
2020-07-10 00:09:19 +00:00
};
2019-10-14 16:48:35 +00:00
2020-05-01 19:59:47 +00:00
########
# FUEL #
########
2020-05-03 16:52:38 +00:00
# Calculations maintained at https://github.com/mattmaring/A320-family-fuel-model
# Copyright (c) 2020 Matthew Maring (mattmaring)
#
2020-05-01 19:59:47 +00:00
var updateFuel = func {
2020-05-02 18:12:44 +00:00
# Calculate (final) holding fuel
2020-08-01 13:57:19 +00:00
if (FMGCInternal.finalFuelSet) {
final_fuel = 1000 * FMGCInternal.finalFuel;
zfw = 1000 * FMGCInternal.zfw;
2020-05-09 18:33:55 +00:00
final_time = final_fuel / (2.0 * ((zfw*zfw*-2e-10) + (zfw*0.0003) + 2.8903)); # x2 for 2 engines
2020-05-09 18:08:08 +00:00
if (final_time < 0) {
final_time = 0;
2021-06-13 18:29:25 +00:00
} elsif (final_time > 480) {
2020-05-18 19:51:09 +00:00
final_time = 480;
2020-05-09 18:08:08 +00:00
}
if (num(final_time) >= 60) {
final_min = int(math.mod(final_time, 60));
final_hour = int((final_time - final_min) / 60);
2020-08-01 13:57:19 +00:00
FMGCInternal.finalTime = sprintf("%02d", final_hour) ~ sprintf("%02d", final_min);
2020-05-09 18:08:08 +00:00
} else {
2020-08-01 13:57:19 +00:00
FMGCInternal.finalTime = sprintf("%04d", final_time);
2020-05-09 18:08:08 +00:00
}
} else {
2020-08-01 13:57:19 +00:00
if (!FMGCInternal.finalTimeSet) {
FMGCInternal.finalTime = "0030";
2020-05-09 18:08:08 +00:00
}
2020-08-01 13:57:19 +00:00
final_time = int(FMGCInternal.finalTime);
2020-05-09 18:08:08 +00:00
if (final_time >= 100) {
final_time = final_time - 100 + 60; # can't be set above 90 (0130)
}
2020-08-01 13:57:19 +00:00
zfw = 1000 * FMGCInternal.zfw;
2020-05-09 18:27:21 +00:00
final_fuel = final_time * 2.0 * ((zfw*zfw*-2e-10) + (zfw*0.0003) + 2.8903); # x2 for 2 engines
2020-05-09 18:08:08 +00:00
if (final_fuel < 0) {
final_fuel = 0;
2021-06-13 18:29:25 +00:00
} elsif (final_fuel > 80000) {
2020-05-18 19:51:09 +00:00
final_fuel = 80000;
2020-05-09 18:08:08 +00:00
}
2020-08-01 13:57:19 +00:00
FMGCInternal.finalFuel = final_fuel / 1000;
2020-05-02 18:12:44 +00:00
}
# Calculate alternate fuel
2020-08-01 13:57:19 +00:00
if (!FMGCInternal.altFuelSet and FMGCInternal.altAirportSet) {
2020-05-02 18:12:44 +00:00
#calc
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.altFuelSet and FMGCInternal.altAirportSet) {
2020-05-13 22:26:08 +00:00
#dummy calc for now
2020-08-01 13:57:19 +00:00
alt_fuel = 1000 * num(FMGCInternal.altFuel);
zfw = 1000 * FMGCInternal.zfw;
2020-05-13 22:26:08 +00:00
alt_time = alt_fuel / (2.0 * ((zfw*zfw*-2e-10) + (zfw*0.0003) + 2.8903)); # x2 for 2 engines
if (alt_time < 0) {
alt_time = 0;
2021-06-13 18:29:25 +00:00
} elsif (alt_time > 480) {
2020-05-18 19:51:09 +00:00
alt_time = 480;
2020-05-13 22:26:08 +00:00
}
if (num(alt_time) >= 60) {
alt_min = int(math.mod(alt_time, 60));
alt_hour = int((alt_time - alt_min) / 60);
2020-08-01 13:57:19 +00:00
FMGCInternal.altTime = sprintf("%02d", alt_hour) ~ sprintf("%02d", alt_min);
2020-05-13 22:26:08 +00:00
} else {
2020-08-01 13:57:19 +00:00
FMGCInternal.altTime = sprintf("%04d", alt_time);
2020-05-13 22:26:08 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif (!FMGCInternal.altFuelSet) {
2020-08-01 13:57:19 +00:00
FMGCInternal.altFuel = 0.0;
FMGCInternal.altTime = "0000";
2020-05-02 18:12:44 +00:00
}
# Calculate min dest fob (final + alternate)
2020-08-01 13:57:19 +00:00
if (!FMGCInternal.minDestFobSet) {
FMGCInternal.minDestFob = num(FMGCInternal.altFuel + FMGCInternal.finalFuel);
2020-05-02 18:12:44 +00:00
}
2020-08-01 13:57:19 +00:00
if (FMGCInternal.zfwSet) {
FMGCInternal.lw = num(FMGCInternal.zfw + FMGCInternal.altFuel + FMGCInternal.finalFuel);
2020-05-05 02:39:06 +00:00
}
2020-05-02 18:12:44 +00:00
# Calculate trip fuel
2020-08-01 13:57:19 +00:00
if (FMGCInternal.toFromSet and FMGCInternal.crzSet and FMGCInternal.crzTempSet and FMGCInternal.zfwSet) {
2020-07-10 00:09:19 +00:00
crz = FMGCInternal.crzFl;
temp = FMGCInternal.crzTemp;
2020-05-09 14:46:53 +00:00
dist = flightPlanController.arrivalDist;
2020-05-05 14:24:24 +00:00
2020-08-01 13:57:19 +00:00
trpWind = FMGCInternal.tripWind;
wind_value = FMGCInternal.tripWindValue;
2020-06-14 17:30:58 +00:00
if (find("HD", trpWind) != -1 or find("-", trpWind) != -1 or find("H", trpWind) != -1) {
2020-05-03 17:29:46 +00:00
wind_value = wind_value * -1;
}
dist = dist - (dist * wind_value * 0.002);
2020-05-05 02:39:06 +00:00
#trip_fuel = 4.003e+02 + (dist * -5.399e+01) + (dist * dist * -7.322e-02) + (dist * dist * dist * 1.091e-05) + (dist * dist * dist * dist * 2.962e-10) + (dist * dist * dist * dist * dist * -1.178e-13) + (dist * dist * dist * dist * dist * dist * 6.322e-18) + (crz * 5.387e+01) + (dist * crz * 1.583e+00) + (dist * dist * crz * 7.695e-04) + (dist * dist * dist * crz * -1.057e-07) + (dist * dist * dist * dist * crz * 1.138e-12) + (dist * dist * dist * dist * dist * crz * 1.736e-16) + (crz * crz * -1.171e+00) + (dist * crz * crz * -1.219e-02) + (dist * dist * crz * crz * -2.879e-06) + (dist * dist * dist * crz * crz * 3.115e-10) + (dist * dist * dist * dist * crz * crz * -4.093e-15) + (crz * crz * crz * 9.160e-03) + (dist * crz * crz * crz * 4.311e-05) + (dist * dist * crz * crz * crz * 4.532e-09) + (dist * dist * dist * crz * crz * crz * -2.879e-13) + (crz * crz * crz * crz * -3.338e-05) + (dist * crz * crz * crz * crz * -7.340e-08) + (dist * dist * crz * crz * crz * crz * -2.494e-12) + (crz * crz * crz * crz * crz * 5.849e-08) + (dist * crz * crz * crz * crz * crz * 4.898e-11) + (crz * crz * crz * crz * crz * crz * -3.999e-11);
trip_fuel = 4.018e+02 + (dist*3.575e+01) + (dist*dist*-4.260e-02) + (dist*dist*dist*-1.446e-05) + (dist*dist*dist*dist*4.101e-09) + (dist*dist*dist*dist*dist*-6.753e-13) + (dist*dist*dist*dist*dist*dist*5.074e-17) + (crz*-2.573e+01) + (dist*crz*-1.583e-01) + (dist*dist*crz*8.147e-04) + (dist*dist*dist*crz*4.485e-08) + (dist*dist*dist*dist*crz*-7.656e-12) + (dist*dist*dist*dist*dist*crz*4.503e-16) + (crz*crz*4.427e-01) + (dist*crz*crz*-1.137e-03) + (dist*dist*crz*crz*-4.409e-06) + (dist*dist*dist*crz*crz*-3.345e-11) + (dist*dist*dist*dist*crz*crz*4.985e-15) + (crz*crz*crz*-2.471e-03) + (dist*crz*crz*crz*1.223e-05) + (dist*dist*crz*crz*crz*9.660e-09) + (dist*dist*dist*crz*crz*crz*-2.127e-14) + (crz*crz*crz*crz*5.714e-06) + (dist*crz*crz*crz*crz*-3.546e-08) + (dist*dist*crz*crz*crz*crz*-7.536e-12) + (crz*crz*crz*crz*crz*-4.061e-09) + (dist*crz*crz*crz*crz*crz*3.355e-11) + (crz*crz*crz*crz*crz*crz*-1.451e-12);
2020-05-03 16:52:38 +00:00
if (trip_fuel < 400) {
trip_fuel = 400;
2021-06-13 18:29:25 +00:00
} elsif (trip_fuel > 80000) {
2020-05-18 19:51:09 +00:00
trip_fuel = 80000;
2020-05-03 16:52:38 +00:00
}
2020-05-03 20:00:58 +00:00
2020-05-09 14:46:53 +00:00
# cruize temp correction
trip_fuel = trip_fuel + (0.033 * (temp - 15 + (2 * crz / 10)) * flightPlanController.arrivalDist);
2020-05-10 16:39:01 +00:00
trip_time = 9.095e-02 + (dist*-3.968e-02) + (dist*dist*4.302e-04) + (dist*dist*dist*2.005e-07) + (dist*dist*dist*dist*-6.876e-11) + (dist*dist*dist*dist*dist*1.432e-14) + (dist*dist*dist*dist*dist*dist*-1.177e-18) + (crz*7.348e-01) + (dist*crz*3.310e-03) + (dist*dist*crz*-8.700e-06) + (dist*dist*dist*crz*-4.214e-10) + (dist*dist*dist*dist*crz*5.652e-14) + (dist*dist*dist*dist*dist*crz*-6.379e-18) + (crz*crz*-1.449e-02) + (dist*crz*crz*-7.508e-06) + (dist*dist*crz*crz*4.529e-08) + (dist*dist*dist*crz*crz*3.699e-13) + (dist*dist*dist*dist*crz*crz*8.466e-18) + (crz*crz*crz*1.108e-04) + (dist*crz*crz*crz*-4.126e-08) + (dist*dist*crz*crz*crz*-9.645e-11) + (dist*dist*dist*crz*crz*crz*-1.544e-16) + (crz*crz*crz*crz*-4.123e-07) + (dist*crz*crz*crz*crz*1.831e-10) + (dist*dist*crz*crz*crz*crz*7.438e-14) + (crz*crz*crz*crz*crz*7.546e-10) + (dist*crz*crz*crz*crz*crz*-1.921e-13) + (crz*crz*crz*crz*crz*crz*-5.453e-13);
2020-05-05 02:39:06 +00:00
if (trip_time < 10) {
trip_time = 10;
2021-06-13 18:29:25 +00:00
} elsif (trip_time > 480) {
2020-05-18 19:51:09 +00:00
trip_time = 480;
2020-05-05 02:39:06 +00:00
}
2020-05-03 16:52:38 +00:00
# if (low air conditioning) {
# trip_fuel = trip_fuel * 0.995;
#}
# if (total anti-ice) {
# trip_fuel = trip_fuel * 1.045;
2021-06-13 18:29:25 +00:00
#} elsif (engine anti-ice) {
2020-05-03 16:52:38 +00:00
# trip_fuel = trip_fuel * 1.02;
#}
2020-08-01 13:57:19 +00:00
zfw = FMGCInternal.zfw;
2020-05-05 02:39:06 +00:00
landing_weight_correction = 9.951e+00 + (dist*-2.064e+00) + (dist*dist*2.030e-03) + (dist*dist*dist*8.179e-08) + (dist*dist*dist*dist*-3.941e-11) + (dist*dist*dist*dist*dist*2.443e-15) + (crz*2.771e+00) + (dist*crz*3.067e-02) + (dist*dist*crz*-1.861e-05) + (dist*dist*dist*crz*2.516e-10) + (dist*dist*dist*dist*crz*5.452e-14) + (crz*crz*-4.483e-02) + (dist*crz*crz*-1.645e-04) + (dist*dist*crz*crz*5.212e-08) + (dist*dist*dist*crz*crz*-8.721e-13) + (crz*crz*crz*2.609e-04) + (dist*crz*crz*crz*3.898e-07) + (dist*dist*crz*crz*crz*-4.617e-11) + (crz*crz*crz*crz*-6.488e-07) + (dist*crz*crz*crz*crz*-3.390e-10) + (crz*crz*crz*crz*crz*5.835e-10);
2020-08-01 13:57:19 +00:00
trip_fuel = trip_fuel + (landing_weight_correction * (FMGCInternal.lw * 1000 - 121254.24421) / 2204.622622);
2020-05-05 02:39:06 +00:00
if (trip_fuel < 400) {
trip_fuel = 400;
2021-06-13 18:29:25 +00:00
} elsif (trip_fuel > 80000) {
2020-05-18 19:51:09 +00:00
trip_fuel = 80000;
2020-05-05 02:39:06 +00:00
}
2020-08-01 13:57:19 +00:00
FMGCInternal.tripFuel = trip_fuel / 1000;
2020-05-05 13:15:45 +00:00
if (num(trip_time) >= 60) {
2020-05-05 02:39:06 +00:00
trip_min = int(math.mod(trip_time, 60));
trip_hour = int((trip_time - trip_min) / 60);
2020-08-01 13:57:19 +00:00
FMGCInternal.tripTime = sprintf("%02d", trip_hour) ~ sprintf("%02d", trip_min);
2020-05-05 02:39:06 +00:00
} else {
2020-08-01 13:57:19 +00:00
FMGCInternal.tripTime = sprintf("%04d", trip_time);
2020-05-05 02:39:06 +00:00
}
2020-05-03 14:01:28 +00:00
} else {
2020-08-01 13:57:19 +00:00
FMGCInternal.tripFuel = 0.0;
FMGCInternal.tripTime = "0000";
2020-05-02 18:12:44 +00:00
}
# Calculate reserve fuel
2020-08-01 13:57:19 +00:00
if (FMGCInternal.rteRsvSet) {
2020-08-04 10:43:18 +00:00
if (num(FMGCInternal.tripFuel) <= 0.0) {
2020-08-01 13:57:19 +00:00
FMGCInternal.rtePercent = 0.0;
2020-05-02 20:05:52 +00:00
} else {
2020-08-01 13:57:19 +00:00
if (num(FMGCInternal.rteRsv / FMGCInternal.tripFuel * 100.0) <= 15.0) {
FMGCInternal.rtePercent = num(FMGCInternal.rteRsv / FMGCInternal.tripFuel * 100.0);
2020-05-05 13:52:11 +00:00
} else {
2020-08-01 13:57:19 +00:00
FMGCInternal.rtePercent = 15.0; # need reasearch on this value
2020-05-05 13:52:11 +00:00
}
2020-05-02 20:05:52 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.rtePercentSet) {
2020-08-01 13:57:19 +00:00
FMGCInternal.rteRsv = num(FMGCInternal.tripFuel * FMGCInternal.rtePercent / 100.0);
2020-05-02 19:42:39 +00:00
} else {
2020-08-04 10:43:18 +00:00
if (num(FMGCInternal.tripFuel) <= 0.0) {
2020-08-01 13:57:19 +00:00
FMGCInternal.rtePercent = 5.0;
2020-05-02 19:40:19 +00:00
} else {
2020-08-01 13:57:19 +00:00
FMGCInternal.rteRsv = num(FMGCInternal.tripFuel * FMGCInternal.rtePercent / 100.0);
2020-05-02 19:40:19 +00:00
}
}
2020-05-02 18:12:44 +00:00
2020-08-04 10:43:18 +00:00
# Misc fuel claclulations
2020-10-03 09:59:43 +00:00
if (fmgc.FMGCInternal.blockCalculating) {
2020-08-04 10:43:18 +00:00
FMGCInternal.block = num(FMGCInternal.altFuel + FMGCInternal.finalFuel + FMGCInternal.tripFuel + FMGCInternal.rteRsv + FMGCInternal.taxiFuel);
FMGCInternal.blockSet = 1;
}
2020-10-03 09:59:43 +00:00
fmgc.FMGCInternal.fob = num(pts.Consumables.Fuel.totalFuelLbs.getValue() / 1000);
fmgc.FMGCInternal.fuelPredGw = num(pts.Fdm.JSBsim.Inertia.weightLbs.getValue() / 1000);
2020-08-04 10:43:18 +00:00
fmgc.FMGCInternal.cg = fmgc.FMGCInternal.zfwcg;
2020-08-03 22:54:14 +00:00
2020-05-09 16:59:33 +00:00
# Calcualte extra fuel
2020-10-03 09:59:43 +00:00
if (num(pts.Engines.Engine.n1Actual[0].getValue()) > 0 or num(pts.Engines.Engine.n1Actual[1].getValue()) > 0) {
2020-08-04 10:43:18 +00:00
extra_fuel = 1000 * num(FMGCInternal.fob - FMGCInternal.tripFuel - FMGCInternal.minDestFob - FMGCInternal.taxiFuel - FMGCInternal.rteRsv);
} else {
extra_fuel = 1000 * num(FMGCInternal.block - FMGCInternal.tripFuel - FMGCInternal.minDestFob - FMGCInternal.taxiFuel - FMGCInternal.rteRsv);
2020-05-05 02:39:06 +00:00
}
2020-08-04 10:43:18 +00:00
FMGCInternal.extraFuel = extra_fuel / 1000;
lw = 1000 * FMGCInternal.lw;
extra_time = extra_fuel / (2.0 * ((lw*lw*-2e-10) + (lw*0.0003) + 2.8903)); # x2 for 2 engines
if (extra_time < 0) {
extra_time = 0;
2021-06-13 18:29:25 +00:00
} elsif (extra_time > 480) {
2020-08-04 10:43:18 +00:00
extra_time = 480;
}
if (num(extra_time) >= 60) {
extra_min = int(math.mod(extra_time, 60));
extra_hour = int((extra_time - extra_min) / 60);
FMGCInternal.extraTime = sprintf("%02d", extra_hour) ~ sprintf("%02d", extra_min);
} else {
FMGCInternal.extraTime = sprintf("%04d", extra_time);
}
if (FMGCInternal.extraFuel > -0.1 and FMGCInternal.extraFuel < 0.1) {
FMGCInternal.extraFuel = 0.0;
}
FMGCInternal.tow = num(FMGCInternal.zfw + FMGCInternal.block - FMGCInternal.taxiFuel);
2020-05-01 19:59:47 +00:00
}
2019-10-14 16:48:35 +00:00
############################
# Flight Phase and Various #
############################
2021-12-27 13:36:18 +00:00
# TODO - if no ID is found, should trigger a NOT IN DATA BASE message
2021-12-27 11:44:08 +00:00
var freqnav0 = nil;
2020-07-12 18:27:04 +00:00
var nav0 = func {
2021-12-27 11:44:08 +00:00
freqnav0 = sprintf("%.2f", pts.Instrumentation.Nav.Frequencies.selectedMhz[0].getValue());
2020-07-12 18:27:04 +00:00
if (freqnav0 >= 108.10 and freqnav0 <= 111.95) {
2021-12-27 11:44:08 +00:00
var namenav0 = getprop("/instrumentation/nav[0]/nav-id") or " ";
fmgc.FMGCInternal.ILS.mcdu = namenav0 ~ "/" ~ freqnav0;
2020-07-12 18:27:04 +00:00
}
}
2021-12-27 11:44:08 +00:00
var freqnav2 = nil;
2020-07-12 18:27:04 +00:00
var nav2 = func {
2021-12-27 11:44:08 +00:00
freqnav2 = sprintf("%.2f", pts.Instrumentation.Nav.Frequencies.selectedMhz[2].getValue());
2020-07-12 18:27:04 +00:00
if (freqnav2 >= 108.00 and freqnav2 <= 117.95) {
2021-12-27 11:44:08 +00:00
var namenav2 = getprop("/instrumentation/nav[2]/nav-id") or " ";
fmgc.FMGCInternal.VOR1.mcdu = namenav2 ~ "/" ~ freqnav2;
2020-07-12 18:27:04 +00:00
}
}
2021-12-27 11:44:08 +00:00
var freqnav3 = nil;
2020-07-12 18:27:04 +00:00
var nav3 = func {
2021-12-27 11:44:08 +00:00
freqnav3 = sprintf("%.2f", pts.Instrumentation.Nav.Frequencies.selectedMhz[3].getValue());
2020-07-12 18:27:04 +00:00
if (freqnav3 >= 108.00 and freqnav3 <= 117.95) {
2021-12-27 11:44:08 +00:00
var namenav3 = getprop("/instrumentation/nav[3]/nav-id") or " ";
fmgc.FMGCInternal.VOR2.mcdu = freqnav3 ~ "/" ~ namenav3;
2020-07-12 18:27:04 +00:00
}
}
2021-12-27 11:44:08 +00:00
var freqadf0 = nil;
2020-07-12 18:27:04 +00:00
var adf0 = func {
2021-12-27 11:44:08 +00:00
freqadf0 = sprintf("%.1f", pts.Instrumentation.Adf.Frequencies.selectedKhz[0].getValue());
2021-12-24 19:33:31 +00:00
if (freqadf0 >= 190 and freqadf0 <= 1799) {
var nameadf0 = pts.Instrumentation.Adf.ident[0].getValue() or " ";
2021-12-27 11:44:08 +00:00
fmgc.FMGCInternal.ADF1.mcdu = nameadf0 ~ "/" ~ freqadf0;
2020-07-12 18:27:04 +00:00
}
}
2021-12-27 11:44:08 +00:00
var freqadf1 = nil;
2020-07-12 18:27:04 +00:00
var adf1 = func {
2021-12-27 11:44:08 +00:00
freqadf1 = sprintf("%.1f", pts.Instrumentation.Adf.Frequencies.selectedKhz[1].getValue());
2021-12-24 19:33:31 +00:00
if (freqadf1 >= 190 and freqadf1 <= 1799) {
var nameadf1 = pts.Instrumentation.Adf.ident[1].getValue() or " ";
2021-12-27 11:44:08 +00:00
fmgc.FMGCInternal.ADF2.mcdu = freqadf1 ~ "/" ~ nameadf1;
2020-07-12 18:27:04 +00:00
}
}
var radios = maketimer(1, func() {
nav0();
nav2();
nav3();
adf0();
adf1();
});
2021-06-13 18:29:25 +00:00
var newphase = nil;
2021-06-12 13:42:41 +00:00
2019-10-14 16:48:35 +00:00
var masterFMGC = maketimer(0.2, func {
2021-06-12 13:42:41 +00:00
2021-06-13 18:29:25 +00:00
n1_left = pts.Engines.Engine.n1Actual[0].getValue();
n1_right = pts.Engines.Engine.n1Actual[1].getValue();
2020-10-05 18:18:10 +00:00
modelat = Modes.PFD.FMA.rollMode.getValue();
mode = Modes.PFD.FMA.pitchMode.getValue();
2021-06-13 18:29:25 +00:00
gs = pts.Velocities.groundspeed.getValue();
alt = pts.Instrumentation.Altimeter.indicatedFt.getValue();
2020-07-10 00:09:19 +00:00
# cruiseft = FMGCInternal.crzFt;
# cruiseft_b = FMGCInternal.crzFt - 200;
2021-06-13 18:29:25 +00:00
state1 = pts.Systems.Thrust.state[0].getValue();
state2 = pts.Systems.Thrust.state[1].getValue();
2020-10-05 18:18:10 +00:00
accel_agl_ft = Setting.reducAglFt.getValue();
2021-06-13 18:29:25 +00:00
gear0 = pts.Gear.wow[0].getValue();
2020-10-05 18:18:10 +00:00
altSel = Input.alt.getValue();
2020-05-01 16:46:53 +00:00
2021-06-13 18:29:25 +00:00
newphase = FMGCInternal.phase;
2021-06-12 13:42:41 +00:00
2021-06-13 18:29:25 +00:00
if (FMGCInternal.phase == 0) {
2021-06-12 13:42:41 +00:00
if (gear0 and ((n1_left >= 85 and n1_right >= 85 and mode == "SRS") or gs >= 90)) {
newphase = 1;
systems.PNEU.pressMode.setValue("TO");
}
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.phase == 1) {
2021-06-12 13:42:41 +00:00
if (gear0) {
if ((n1_left < 85 or n1_right < 85) and gs < 90 and mode == " ") { # rejected takeoff
newphase = 0;
systems.PNEU.pressMode.setValue("GN");
}
2021-06-13 18:29:25 +00:00
} elsif (((mode != "SRS" and mode != " ") or alt >= accel_agl_ft)) {
2021-06-12 13:42:41 +00:00
newphase = 2;
systems.PNEU.pressMode.setValue("TO");
}
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.phase == 2) {
2021-06-12 13:42:41 +00:00
if ((mode == "ALT CRZ" or mode == "ALT CRZ*")) {
newphase = 3;
systems.PNEU.pressMode.setValue("CR");
2020-04-16 12:25:06 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.phase == 3) {
2021-06-12 13:42:41 +00:00
if (FMGCInternal.crzFl >= 200) {
2021-08-23 17:32:32 +00:00
if ((flightPlanController.arrivalDist <= 200 and altSel < 20000)) {
2021-06-12 13:42:41 +00:00
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");
}
}
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.phase == 4) {
2021-01-20 19:32:21 +00:00
if (getprop("/FMGC/internal/decel")) {
2021-06-12 13:42:41 +00:00
newphase = 5;
2021-01-20 19:32:21 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.phase == 5) {
2021-06-12 13:42:41 +00:00
if (state1 == "TOGA" and state2 == "TOGA") {
newphase = 6;
systems.PNEU.pressMode.setValue("TO");
Input.toga.setValue(1);
}
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.phase == 6) {
2021-06-12 13:42:41 +00:00
if (alt >= accel_agl_ft) { # todo when insert altn or new dest
newphase = 2;
}
2020-04-10 18:38:58 +00:00
}
2021-06-12 13:42:41 +00:00
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);
2021-06-13 18:29:25 +00:00
} elsif (getprop("/FMGC/internal/decel") == 1 and (FMGCInternal.phase == 0 or FMGCInternal.phase == 6)) {
2021-06-12 13:42:41 +00:00
setprop("/FMGC/internal/decel", 0);
}
2020-04-10 18:38:58 +00:00
2021-06-10 15:38:16 +00:00
tempOverspeed = systems.ADIRS.overspeedVFE.getValue();
if (tempOverspeed != 1024) {
FMGCInternal.maxspeed = tempOverspeed - 4;
2020-01-01 22:15:58 +00:00
} elsif (pts.Gear.position[0].getValue() != 0 or pts.Gear.position[1].getValue() != 0 or pts.Gear.position[2].getValue() != 0) {
2020-08-01 16:49:54 +00:00
FMGCInternal.maxspeed = 284;
2019-11-02 14:52:06 +00:00
} else {
2020-11-24 19:21:58 +00:00
FMGCInternal.maxspeed = fmgc.FMGCInternal.vmo_mmo;
2019-11-02 14:52:06 +00:00
}
2021-06-13 18:29:25 +00:00
if (newphase != FMGCInternal.phase) { # phase changed
2021-06-12 13:42:41 +00:00
FMGCInternal.phase = newphase;
FMGCNodes.phase.setValue(newphase);
}
2020-08-03 22:54:14 +00:00
############################
# fuel
############################
2020-08-04 10:43:18 +00:00
updateFuel();
2020-08-03 22:54:14 +00:00
2020-08-05 23:37:26 +00:00
############################
# wind
############################
2020-10-05 18:18:10 +00:00
windHdg = pts.Environment.windFromHdg.getValue();
windSpeed = pts.Environment.windSpeedKt.getValue();
2020-08-05 23:37:26 +00:00
if (FMGCInternal.phase == 3 or FMGCInternal.phase == 4 or FMGCInternal.phase == 6) {
2020-11-28 12:24:24 +00:00
windsDidChange = 0;
2020-08-05 23:37:26 +00:00
if (FMGCInternal.crzFt > 5000 and alt > 4980 and alt < 5020) {
2020-10-05 18:18:10 +00:00
if (sprintf("%03d", windHdg) != fmgc.windController.fl50_wind[0] or sprintf("%03d", windSpeed) != fmgc.windController.fl50_wind[1]) {
fmgc.windController.fl50_wind[0] = sprintf("%03d", windHdg);
fmgc.windController.fl50_wind[1] = sprintf("%03d", windSpeed);
2020-08-08 12:55:49 +00:00
fmgc.windController.fl50_wind[2] = "FL50";
2020-08-05 23:37:26 +00:00
windsDidChange = 1;
}
}
if (FMGCInternal.crzFt > 15000 and alt > 14980 and alt < 15020) {
2020-10-05 18:18:10 +00:00
if (sprintf("%03d", windHdg) != fmgc.windController.fl150_wind[0] or sprintf("%03d", windSpeed) != fmgc.windController.fl150_wind[1]) {
fmgc.windController.fl150_wind[0] = sprintf("%03d", windHdg);
fmgc.windController.fl150_wind[1] = sprintf("%03d", windSpeed);
2020-08-05 23:37:26 +00:00
fmgc.windController.fl150_wind[2] = "FL150";
windsDidChange = 1;
}
}
if (FMGCInternal.crzFt > 25000 and alt > 24980 and alt < 25020) {
2020-10-05 18:18:10 +00:00
if (sprintf("%03d", windHdg) != fmgc.windController.fl250_wind[0] or sprintf("%03d", windSpeed) != fmgc.windController.fl250_wind[1]) {
fmgc.windController.fl250_wind[0] = sprintf("%03d", windHdg);
fmgc.windController.fl250_wind[1] = sprintf("%03d", windSpeed);
2020-08-05 23:37:26 +00:00
fmgc.windController.fl250_wind[2] = "FL250";
windsDidChange = 1;
}
}
if (FMGCInternal.crzSet and alt > FMGCInternal.crzFt - 20 and alt < FMGCInternal.crzFt + 20) {
2020-10-05 18:18:10 +00:00
if (sprintf("%03d", windHdg) != fmgc.windController.flcrz_wind[0] or sprintf("%03d", windSpeed) != fmgc.windController.flcrz_wind[1]) {
fmgc.windController.flcrz_wind[0] = sprintf("%03d", windHdg);
fmgc.windController.flcrz_wind[1] = sprintf("%03d", windSpeed);
2020-08-05 23:37:26 +00:00
fmgc.windController.flcrz_wind[2] = "FL" ~ FMGCInternal.crzFl;
windsDidChange = 1;
}
}
if (windsDidChange) {
fmgc.windController.write();
}
}
2020-05-27 15:59:40 +00:00
############################
2020-04-11 10:46:17 +00:00
# calculate speeds
2020-05-27 15:59:40 +00:00
############################
2020-10-05 18:18:10 +00:00
flap = pts.Controls.Flight.flapsPos.getValue();
2020-10-03 09:59:43 +00:00
weight_lbs = pts.Fdm.JSBsim.Inertia.weightLbs.getValue() / 1000;
2020-10-05 18:18:10 +00:00
altitude = pts.Instrumentation.Altimeter.indicatedFt.getValue();
2020-04-11 10:46:17 +00:00
2020-05-27 15:59:40 +00:00
# current speeds
2020-08-01 16:49:54 +00:00
FMGCInternal.clean = 2 * weight_lbs * 0.45359237 + 85;
2020-04-11 10:46:17 +00:00
if (altitude > 20000) {
2020-08-01 16:49:54 +00:00
FMGCInternal.clean += (altitude - 20000) / 1000;
2020-04-11 10:46:17 +00:00
}
2020-08-01 16:49:54 +00:00
FMGCInternal.vs1g_clean = 0.0024 * weight_lbs * weight_lbs + 0.124 * weight_lbs + 88.942;
FMGCInternal.vs1g_conf_1 = -0.0007 * weight_lbs * weight_lbs + 0.6795 * weight_lbs + 44.673;
FMGCInternal.vs1g_conf_1f = -0.0001 * weight_lbs * weight_lbs + 0.5211 * weight_lbs + 49.027;
FMGCInternal.vs1g_conf_2 = -0.0005 * weight_lbs * weight_lbs + 0.5488 * weight_lbs + 44.279;
FMGCInternal.vs1g_conf_3 = -0.0005 * weight_lbs * weight_lbs + 0.5488 * weight_lbs + 43.279;
FMGCInternal.vs1g_conf_full = -0.0007 * weight_lbs * weight_lbs + 0.6002 * weight_lbs + 38.479;
FMGCInternal.slat = FMGCInternal.vs1g_clean * 1.23;
FMGCInternal.flap2 = FMGCInternal.vs1g_conf_2 * 1.47;
FMGCInternal.flap3 = FMGCInternal.vs1g_conf_3 * 1.36;
2020-09-28 19:15:19 +00:00
if (FMGCInternal.ldgConfig3) {
2020-08-01 16:49:54 +00:00
FMGCInternal.vls = FMGCInternal.vs1g_conf_3 * 1.23;
2020-04-11 10:46:17 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.vls = FMGCInternal.vs1g_conf_full * 1.23
2020-04-11 10:46:17 +00:00
}
2020-08-01 16:49:54 +00:00
if (FMGCInternal.vls < 113) {
FMGCInternal.vls = 113;
2020-04-19 21:39:05 +00:00
}
2020-09-28 19:15:19 +00:00
if (!fmgc.FMGCInternal.vappSpeedSet) {
2020-08-01 16:49:54 +00:00
if (FMGCInternal.destWind < 5) {
FMGCInternal.vapp = FMGCInternal.vls + 5;
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.destWind > 15) {
2020-08-01 16:49:54 +00:00
FMGCInternal.vapp = FMGCInternal.vls + 15;
2020-04-11 10:46:17 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.vapp = FMGCInternal.vls + FMGCInternal.destWind;
2020-04-11 10:46:17 +00:00
}
}
2020-05-27 15:59:40 +00:00
# predicted takeoff speeds
2021-06-13 18:29:25 +00:00
if (FMGCInternal.phase == 1) {
2020-08-01 16:49:54 +00:00
FMGCInternal.clean_to = FMGCInternal.clean;
FMGCInternal.vs1g_clean_to = FMGCInternal.vs1g_clean;
FMGCInternal.vs1g_conf_2_to = FMGCInternal.vs1g_conf_2;
FMGCInternal.vs1g_conf_3_to = FMGCInternal.vs1g_conf_3;
FMGCInternal.vs1g_conf_full_to = FMGCInternal.vs1g_conf_full;
FMGCInternal.slat_to = FMGCInternal.slat;
FMGCInternal.flap2_to = FMGCInternal.flap2;
2020-05-27 15:59:40 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.clean_to = 2 * FMGCInternal.tow * 0.45359237 + 85;
2020-05-27 15:59:40 +00:00
if (altitude > 20000) {
2020-08-01 16:49:54 +00:00
FMGCInternal.clean_to += (altitude - 20000) / 1000;
2020-05-27 15:59:40 +00:00
}
2020-08-01 16:49:54 +00:00
FMGCInternal.vs1g_clean_to = 0.0024 * FMGCInternal.tow * FMGCInternal.tow + 0.124 * FMGCInternal.tow + 88.942;
FMGCInternal.vs1g_conf_2_to = -0.0005 * FMGCInternal.tow * FMGCInternal.tow + 0.5488 * FMGCInternal.tow + 44.279;
FMGCInternal.vs1g_conf_3_to = -0.0005 * FMGCInternal.tow * FMGCInternal.tow + 0.5488 * FMGCInternal.tow + 43.279;
FMGCInternal.vs1g_conf_full_to = -0.0007 * FMGCInternal.tow * FMGCInternal.tow + 0.6002 * FMGCInternal.tow + 38.479;
FMGCInternal.slat_to = FMGCInternal.vs1g_clean_to * 1.23;
FMGCInternal.flap2_to = FMGCInternal.vs1g_conf_2_to * 1.47;
2020-05-27 15:59:40 +00:00
}
# predicted approach (temp go-around) speeds
2021-06-13 18:29:25 +00:00
if (FMGCInternal.phase == 5 or FMGCInternal.phase == 6) {
2020-08-01 16:49:54 +00:00
FMGCInternal.clean_appr = FMGCInternal.clean;
FMGCInternal.vs1g_clean_appr = FMGCInternal.vs1g_clean;
FMGCInternal.vs1g_conf_2_appr = FMGCInternal.vs1g_conf_2;
FMGCInternal.vs1g_conf_3_appr = FMGCInternal.vs1g_conf_3;
FMGCInternal.vs1g_conf_full_appr = FMGCInternal.vs1g_conf_full;
FMGCInternal.slat_appr = FMGCInternal.slat;
FMGCInternal.flap2_appr = FMGCInternal.flap2;
FMGCInternal.vls_appr = FMGCInternal.vls;
2020-09-28 19:15:19 +00:00
if (!fmgc.FMGCInternal.vappSpeedSet) {
2020-08-01 16:49:54 +00:00
FMGCInternal.vapp_appr = FMGCInternal.vapp;
2020-05-27 15:59:40 +00:00
}
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.clean_appr = 2 * FMGCInternal.lw * 0.45359237 + 85;
2020-05-27 15:59:40 +00:00
if (altitude > 20000) {
2020-08-01 16:49:54 +00:00
FMGCInternal.clean_appr += (altitude - 20000) / 1000;
2020-05-27 15:59:40 +00:00
}
2020-08-01 16:49:54 +00:00
FMGCInternal.vs1g_clean_appr = 0.0024 * FMGCInternal.lw * FMGCInternal.lw + 0.124 * FMGCInternal.lw + 88.942;
FMGCInternal.vs1g_conf_2_appr = -0.0005 * FMGCInternal.lw * FMGCInternal.lw + 0.5488 * FMGCInternal.lw + 44.279;
FMGCInternal.vs1g_conf_3_appr = -0.0005 * FMGCInternal.lw * FMGCInternal.lw + 0.5488 * FMGCInternal.lw + 43.279;
FMGCInternal.vs1g_conf_full_appr = -0.0007 * FMGCInternal.lw * FMGCInternal.lw + 0.6002 * FMGCInternal.lw + 38.479;
FMGCInternal.slat_appr = FMGCInternal.vs1g_clean_appr * 1.23;
FMGCInternal.flap2_appr = FMGCInternal.vs1g_conf_2_appr * 1.47;
2020-09-28 19:15:19 +00:00
if (FMGCInternal.ldgConfig3) {
2020-08-01 16:49:54 +00:00
FMGCInternal.vls_appr = FMGCInternal.vs1g_conf_3_appr * 1.23;
2020-05-27 15:59:40 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.vls_appr = FMGCInternal.vs1g_conf_full_appr * 1.23
2020-05-27 15:59:40 +00:00
}
2020-08-01 16:49:54 +00:00
if (FMGCInternal.vls_appr < 113) {
FMGCInternal.vls_appr = 113;
2020-05-27 15:59:40 +00:00
}
2020-09-28 19:15:19 +00:00
if (!fmgc.FMGCInternal.vappSpeedSet) {
2020-08-01 16:49:54 +00:00
if (FMGCInternal.destWind < 5) {
FMGCInternal.vapp_appr = FMGCInternal.vls_appr + 5;
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.destWind > 15) {
2020-08-01 16:49:54 +00:00
FMGCInternal.vapp_appr = FMGCInternal.vls_appr + 15;
2020-05-27 15:59:40 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.vapp_appr = FMGCInternal.vls_appr + FMGCInternal.destWind;
2020-05-27 15:59:40 +00:00
}
}
}
# Need info on these, also correct for height at altitude...
# https://www.pprune.org/archive/index.php/t-587639.html
2020-04-12 17:37:15 +00:00
aoa_prot = 15;
aoa_max = 17.5;
aoa_0 = -5;
2020-05-01 16:46:53 +00:00
aoa = getprop("/systems/navigation/adr/output/aoa-1");
cas = getprop("/systems/navigation/adr/output/cas-1");
2020-05-09 15:11:31 +00:00
if (aoa > -5) {
2020-08-01 16:49:54 +00:00
FMGCInternal.alpha_prot = cas * math.sqrt((aoa - aoa_0)/(aoa_prot - aoa_0));
FMGCInternal.alpha_max = cas * math.sqrt((aoa - aoa_0)/(aoa_max - aoa_0));
2020-05-09 15:11:31 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.alpha_prot = 0;
FMGCInternal.alpha_max = 0;
2020-05-09 15:11:31 +00:00
}
2020-05-02 00:26:05 +00:00
2020-08-01 16:49:54 +00:00
#FMGCInternal.vs1g_conf_2_appr = FMGCInternal.vs1g_conf_2;
#FMGCInternal.vs1g_conf_3_appr = FMGCInternal.vs1g_conf_3;
#FMGCInternal.vs1g_conf_full_appr = FMGCInternal.vs1g_conf_full;
2020-04-11 10:46:17 +00:00
2020-07-11 19:13:21 +00:00
if (flap == 0) { # 0
2020-08-01 16:49:54 +00:00
FMGCInternal.vsw = FMGCInternal.vs1g_clean;
FMGCInternal.minspeed = FMGCInternal.clean;
2020-07-11 19:13:21 +00:00
2020-08-01 16:49:54 +00:00
if (FMGCInternal.takeoffState) {
FMGCInternal.vls_min = FMGCInternal.vs1g_clean * 1.28;
2020-07-11 19:13:21 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.vls_min = FMGCInternal.vs1g_clean * 1.23;
2020-04-12 17:37:15 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif (flap == 1) { # 1
2020-08-01 16:49:54 +00:00
FMGCInternal.vsw = FMGCInternal.vs1g_conf_2;
FMGCInternal.minspeed = FMGCInternal.slat;
2020-07-11 19:13:21 +00:00
2020-08-01 16:49:54 +00:00
if (FMGCInternal.takeoffState) {
FMGCInternal.vls_min = FMGCInternal.vs1g_conf_1 * 1.28;
2020-07-11 19:13:21 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.vls_min = FMGCInternal.vs1g_conf_1 * 1.23;
2020-07-11 19:13:21 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif (flap == 2) { # 1+F
2020-08-01 16:49:54 +00:00
FMGCInternal.vsw = FMGCInternal.vs1g_conf_1f;
FMGCInternal.minspeed = FMGCInternal.slat;
2020-07-11 19:13:21 +00:00
2020-08-01 16:49:54 +00:00
if (FMGCInternal.takeoffState) {
FMGCInternal.vls_min = FMGCInternal.vs1g_clean * 1.13;
2020-07-11 19:13:21 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.vls_min = FMGCInternal.vs1g_conf_1f * 1.23;
2020-07-11 19:13:21 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif (flap == 3) { # 2
2020-08-01 16:49:54 +00:00
FMGCInternal.vsw = FMGCInternal.vs1g_conf_2;
FMGCInternal.minspeed = FMGCInternal.flap2;
2020-07-11 19:13:21 +00:00
2020-08-01 16:49:54 +00:00
if (FMGCInternal.takeoffState) {
FMGCInternal.vls_min = FMGCInternal.vs1g_clean * 1.13;
2020-07-11 19:13:21 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.vls_min = FMGCInternal.vs1g_conf_2 * 1.23;
2020-07-11 19:13:21 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif (flap == 4) { # 3
2020-08-01 16:49:54 +00:00
FMGCInternal.vsw = FMGCInternal.vs1g_conf_3;
FMGCInternal.minspeed = FMGCInternal.flap3;
2020-07-11 19:13:21 +00:00
2020-08-01 16:49:54 +00:00
if (FMGCInternal.takeoffState) {
FMGCInternal.vls_min = FMGCInternal.vs1g_clean * 1.13;
2020-07-11 19:13:21 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.vls_min = FMGCInternal.vs1g_conf_3 * 1.23;
2020-07-11 19:13:21 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif (flap == 5) { # FULL
2020-08-01 16:49:54 +00:00
FMGCInternal.vsw = FMGCInternal.vs1g_conf_full;
2020-10-05 18:40:30 +00:00
if (FMGCInternal.vappSpeedSet) {
FMGCInternal.minspeed = FMGCInternal.vapp_appr;
} else {
FMGCInternal.minspeed = FMGCInternal.vapp;
}
2020-07-11 19:13:21 +00:00
2020-08-01 16:49:54 +00:00
if (FMGCInternal.takeoffState) {
FMGCInternal.vls_min = FMGCInternal.vs1g_clean * 1.13;
2020-07-11 19:13:21 +00:00
} else {
2020-08-01 16:49:54 +00:00
FMGCInternal.vls_min = FMGCInternal.vs1g_conf_full * 1.23;
2020-07-11 19:13:21 +00:00
}
2020-04-12 18:09:56 +00:00
}
2021-06-12 13:42:41 +00:00
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")) {
2020-08-01 16:49:54 +00:00
if (!FMGCInternal.takeoffState) {
2020-07-11 19:13:21 +00:00
fmgc.FMGCNodes.toState.setValue(1);
}
2020-08-01 16:49:54 +00:00
FMGCInternal.takeoffState = 1;
2020-07-11 19:13:21 +00:00
} elsif (pts.Position.gearAglFt.getValue() >= 55) {
2020-08-01 16:49:54 +00:00
if (FMGCInternal.takeoffState) {
2020-07-11 19:13:21 +00:00
fmgc.FMGCNodes.toState.setValue(0);
}
2020-08-01 16:49:54 +00:00
FMGCInternal.takeoffState = 0;
2019-10-14 16:48:35 +00:00
}
2020-04-16 12:50:34 +00:00
2021-06-12 13:42:41 +00:00
});
############################
#handle radios, runways, v1/vr/v2
############################
var updateAirportRadios = func {
2020-04-26 19:14:06 +00:00
departure_rwy = fmgc.flightPlanController.flightplans[2].departure_runway;
destination_rwy = fmgc.flightPlanController.flightplans[2].destination_runway;
2021-12-28 12:43:14 +00:00
if (FMGCInternal.phase >= 2 and destination_rwy != nil) {
2020-08-01 16:49:54 +00:00
var airport = airportinfo(FMGCInternal.arrApt);
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/ldg-elev", airport.elevation * M2FT); # eventually should be runway elevation
2021-12-28 12:43:14 +00:00
magnetic_hdg = geo.normdeg(destination_rwy.heading - pts.Environment.magVar.getValue());
2020-04-26 19:14:06 +00:00
runway_ils = destination_rwy.ils_frequency_mhz;
2021-12-28 12:43:14 +00:00
2021-12-27 11:44:08 +00:00
if (runway_ils != nil and !fmgc.FMGCInternal.ILS.freqSet and !fmgc.FMGCInternal.ILS.crsSet) {
fmgc.FMGCInternal.ILS.freqCalculated = runway_ils;
pts.Instrumentation.Nav.Frequencies.selectedMhz[0].setValue(runway_ils);
pts.Instrumentation.Nav.Radials.selectedDeg[0].setValue(magnetic_hdg);
} elsif (runway_ils != nil and !fmgc.FMGCInternal.ILS.freqSet) {
fmgc.FMGCInternal.ILS.freqCalculated = runway_ils;
pts.Instrumentation.Nav.Frequencies.selectedMhz[0].setValue(runway_ils);
} elsif (!fmgc.FMGCInternal.ILS.crsSet) {
pts.Instrumentation.Nav.Radials.selectedDeg[0].setValue(magnetic_hdg);
2020-04-16 12:50:34 +00:00
}
2021-12-28 12:43:14 +00:00
} elsif (FMGCInternal.phase <= 1 and departure_rwy != nil) {
magnetic_hdg = geo.normdeg(departure_rwy.heading - pts.Environment.magVar.getValue());
2020-04-26 19:14:06 +00:00
runway_ils = departure_rwy.ils_frequency_mhz;
2021-12-28 12:43:14 +00:00
2021-12-27 11:44:08 +00:00
if (runway_ils != nil and !fmgc.FMGCInternal.ILS.freqSet and !fmgc.FMGCInternal.ILS.crsSet) {
fmgc.FMGCInternal.ILS.freqCalculated = runway_ils;
pts.Instrumentation.Nav.Frequencies.selectedMhz[0].setValue(runway_ils);
pts.Instrumentation.Nav.Radials.selectedDeg[0].setValue(magnetic_hdg);
} elsif (runway_ils != nil and !fmgc.FMGCInternal.ILS.freqSet) {
fmgc.FMGCInternal.ILS.freqCalculated = runway_ils;
pts.Instrumentation.Nav.Frequencies.selectedMhz[0].setValue(runway_ils);
} elsif (!fmgc.FMGCInternal.ILS.crsSet) {
pts.Instrumentation.Nav.Radials.selectedDeg[0].setValue(magnetic_hdg);
2020-04-16 12:50:34 +00:00
}
}
2021-06-12 13:42:41 +00:00
};
2021-06-12 19:46:44 +00:00
setlistener(FMGCNodes.phase, updateAirportRadios,0,0);
2021-06-13 17:57:13 +00:00
setlistener(flightPlanController.changed, updateAirportRadios,0,0);
2019-10-14 16:48:35 +00:00
var reset_FMGC = func {
2020-08-01 16:49:54 +00:00
FMGCInternal.phase = 0;
2021-06-12 18:49:37 +00:00
FMGCNodes.phase.setValue(0);
2020-10-05 18:18:10 +00:00
fd1 = Input.fd1.getValue();
2020-10-05 18:22:38 +00:00
fd2 = Input.fd2.getValue();
2020-10-05 18:30:49 +00:00
spd = Input.kts.getValue();
2020-10-05 18:18:10 +00:00
hdg = Input.hdg.getValue();
alt = Input.alt.getValue();
2019-10-14 16:48:35 +00:00
ITAF.init();
FMGCinit();
2020-01-23 14:14:48 +00:00
flightPlanController.reset();
2020-06-10 02:42:30 +00:00
windController.reset();
2020-07-30 02:32:30 +00:00
windController.init();
2019-10-14 16:48:35 +00:00
mcdu.MCDU_reset(0);
mcdu.MCDU_reset(1);
2021-06-13 16:55:01 +00:00
Simbrief.SimbriefParser.inhibit = 0;
2020-10-05 18:18:10 +00:00
mcdu.ReceivedMessagesDatabase.clearDatabase();
2021-01-16 13:27:55 +00:00
mcdu.FlightLogDatabase.reset(); # track reset events without loosing recorded data
2020-10-05 18:18:10 +00:00
Input.fd1.setValue(fd1);
Input.fd2.setValue(fd2);
Input.kts.setValue(spd);
Input.hdg.setValue(hdg);
Input.alt.setValue(alt);
systems.PNEU.pressMode.setValue("GN");
2020-10-04 14:23:37 +00:00
setprop("/systems/pressurization/vs", "0");
setprop("/systems/pressurization/targetvs", "0");
setprop("/systems/pressurization/vs-norm", "0");
setprop("/systems/pressurization/auto", 1);
setprop("/systems/pressurization/deltap", "0");
setprop("/systems/pressurization/outflowpos", "0");
setprop("/systems/pressurization/deltap-norm", "0");
setprop("/systems/pressurization/outflowpos-norm", "0");
2020-10-05 18:18:10 +00:00
altitude = pts.Instrumentation.Altimeter.indicatedFt.getValue();
2020-10-04 14:23:37 +00:00
setprop("/systems/pressurization/cabinalt", altitude);
setprop("/systems/pressurization/targetalt", altitude);
setprop("/systems/pressurization/diff-to-target", "0");
setprop("/systems/pressurization/ditchingpb", 0);
setprop("/systems/pressurization/targetvs", "0");
setprop("/systems/pressurization/ambientpsi", "0");
setprop("/systems/pressurization/cabinpsi", "0");
2020-07-31 13:12:44 +00:00
2019-10-14 16:48:35 +00:00
}
#################
# Managed Speed #
#################
var ManagedSPD = maketimer(0.25, func {
2020-08-02 12:01:06 +00:00
if (FMGCInternal.crzSet and FMGCInternal.costIndexSet) {
2020-10-05 18:18:10 +00:00
if (Custom.Input.spdManaged.getBoolValue()) {
altitude = pts.Instrumentation.Altimeter.indicatedFt.getValue();
mode = Modes.PFD.FMA.pitchMode.getValue();
ias = pts.Instrumentation.AirspeedIndicator.indicatedSpdKt.getValue();
mach = pts.Instrumentation.AirspeedIndicator.indicatedMach.getValue();
ktsmach = Input.ktsMach.getValue();
kts_sel = Input.kts.getValue();
mach_sel = Input.mach.getValue();
2020-05-01 16:46:53 +00:00
srsSPD = getprop("/it-autoflight/settings/togaspd");
2020-08-01 16:49:54 +00:00
phase = FMGCInternal.phase; # 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
2020-10-05 18:18:10 +00:00
flap = pts.Controls.Flight.flapsPos.getValue();
2020-05-01 16:46:53 +00:00
decel = getprop("/FMGC/internal/decel");
2019-10-14 16:48:35 +00:00
2020-10-05 18:18:10 +00:00
mng_alt_spd = math.round(FMGCNodes.mngSpdAlt.getValue(), 1);
mng_alt_mach = math.round(FMGCNodes.mngMachAlt.getValue(), 0.001);
2019-10-14 16:48:35 +00:00
2020-07-11 13:03:30 +00:00
if (mach > mng_alt_mach and (FMGCInternal.phase == 2 or FMGCInternal.phase == 3)) {
2020-10-05 18:18:10 +00:00
FMGCInternal.machSwitchover = 1;
2020-11-28 12:24:24 +00:00
} elsif (ias > mng_alt_spd and (FMGCInternal.phase == 4 or FMGCInternal.phase == 5)) {
2020-10-05 18:18:10 +00:00
FMGCInternal.machSwitchover = 0;
2019-10-14 16:48:35 +00:00
}
2020-07-11 13:03:30 +00:00
if ((mode == " " or mode == "SRS") and (FMGCInternal.phase == 0 or FMGCInternal.phase == 1)) {
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngKtsMach) {
FMGCInternal.mngKtsMach = 0;
2019-10-14 16:48:35 +00:00
}
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngSpdCmd != srsSPD) {
FMGCInternal.mngSpdCmd = srsSPD;
2019-10-14 16:48:35 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif ((FMGCInternal.phase == 2 or FMGCInternal.phase == 3) and altitude <= 10050) {
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngKtsMach) {
FMGCInternal.mngKtsMach = 0;
2019-10-14 16:48:35 +00:00
}
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngSpdCmd != 250 and !decel) {
FMGCInternal.mngSpdCmd = 250;
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.mngSpdCmd != FMGCInternal.minspeed and decel) {
2020-10-05 18:18:10 +00:00
FMGCInternal.mngSpdCmd = FMGCInternal.minspeed;
2019-10-14 16:48:35 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif ((FMGCInternal.phase == 2 or FMGCInternal.phase == 3) and altitude > 10070 and !FMGCInternal.machSwitchover) {
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngKtsMach) {
FMGCInternal.mngKtsMach = 0;
2019-10-14 16:48:35 +00:00
}
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngSpdCmd != mng_alt_spd) {
FMGCInternal.mngSpdCmd = mng_alt_spd;
2019-10-14 16:48:35 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif ((FMGCInternal.phase == 2 or FMGCInternal.phase == 3) and altitude > 10070 and FMGCInternal.machSwitchover) {
2020-10-05 18:18:10 +00:00
if (!FMGCInternal.mngKtsMach) {
FMGCInternal.mngKtsMach = 1;
2019-10-14 16:48:35 +00:00
}
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngSpdCmd != mng_alt_mach) {
FMGCInternal.mngSpdCmd = mng_alt_mach;
2019-10-14 16:48:35 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.phase == 4 and altitude > 11000 and !FMGCInternal.machSwitchover) {
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngKtsMach) {
FMGCInternal.mngKtsMach = 0;
2019-10-14 16:48:35 +00:00
}
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngSpdCmd != mng_alt_spd) {
FMGCInternal.mngSpdCmd = mng_alt_spd;
2019-10-14 16:48:35 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.phase == 4 and altitude > 11000 and FMGCInternal.machSwitchover) {
2020-10-05 18:18:10 +00:00
if (!FMGCInternal.mngKtsMach) {
FMGCInternal.mngKtsMach = 1;
2019-10-14 16:48:35 +00:00
}
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngSpdCmd != mng_alt_mach) {
FMGCInternal.mngSpdCmd = mng_alt_mach;
2019-10-14 16:48:35 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif ((FMGCInternal.phase == 4 or FMGCInternal.phase == 5 or FMGCInternal.phase == 6) and altitude > 11000 and !FMGCInternal.machSwitchover) {
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngKtsMach) {
FMGCInternal.mngKtsMach = 0;
2019-10-14 16:48:35 +00:00
}
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngSpdCmd != mng_alt_spd and !decel) {
FMGCInternal.mngSpdCmd = mng_alt_spd;
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.mngSpdCmd != FMGCInternal.minspeed and decel) {
2020-10-05 18:18:10 +00:00
FMGCInternal.mngSpdCmd = FMGCInternal.minspeed;
2019-10-14 16:48:35 +00:00
}
2021-06-13 18:29:25 +00:00
} elsif ((FMGCInternal.phase == 4 or FMGCInternal.phase == 5 or FMGCInternal.phase == 6) and altitude <= 10980) {
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngKtsMach) {
FMGCInternal.mngKtsMach = 0;
2019-10-14 16:48:35 +00:00
}
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngSpdCmd != 250 and !decel) {
FMGCInternal.mngSpdCmd = 250;
2021-06-13 18:29:25 +00:00
} elsif (FMGCInternal.mngSpdCmd != FMGCInternal.minspeed and decel) {
2020-10-05 18:18:10 +00:00
FMGCInternal.mngSpdCmd = FMGCInternal.minspeed;
2019-10-14 16:48:35 +00:00
}
}
2020-10-05 18:18:10 +00:00
if (FMGCInternal.mngSpdCmd > FMGCInternal.maxspeed - 5) {
FMGCInternal.mngSpd = (FMGCInternal.maxspeed - 5);
2019-10-14 16:48:35 +00:00
} else {
2020-10-05 18:18:10 +00:00
FMGCInternal.mngSpd = FMGCInternal.mngSpdCmd;
2019-10-14 16:48:35 +00:00
}
2020-10-05 18:18:10 +00:00
if (ktsmach and !FMGCInternal.mngKtsMach) {
Input.ktsMach.setValue(0);
2021-06-13 18:29:25 +00:00
} elsif (!ktsmach and FMGCInternal.mngKtsMach) {
2020-10-05 18:18:10 +00:00
Input.ktsMach.setValue(1);
2019-10-14 16:48:35 +00:00
}
2020-10-05 18:18:10 +00:00
if (kts_sel != FMGCInternal.mngSpd and !ktsmach) {
Input.kts.setValue(FMGCInternal.mngSpd);
2021-06-13 18:29:25 +00:00
} elsif (mach_sel != FMGCInternal.mngSpd and ktsmach) {
2020-10-05 18:18:10 +00:00
Input.mach.setValue(FMGCInternal.mngSpd);
2019-10-14 16:48:35 +00:00
}
} else {
ManagedSPD.stop();
}
} else {
ManagedSPD.stop();
2020-05-16 20:04:03 +00:00
fcu.FCUController.SPDPull();
2019-10-14 16:48:35 +00:00
}
});
2021-12-28 12:43:14 +00:00
# Nav Database
var navDataBase = {
currentCode: "AB20170101",
currentDate: "01JAN-28JAN",
standbyCode: "AB20170102",
standbyDate: "29JAN-26FEB",
};
var tempStoreCode = nil;
var tempStoreDate = nil;
2019-10-14 16:48:35 +00:00
var switchDatabase = func {
2021-12-28 12:43:14 +00:00
tempStoreCode = navDataBase.currentCode;
tempStoreDate = navDataBase.currentDate;
navDataBase.currentCode = navDataBase.standbyCode;
navDataBase.currentDate = navDataBase.standbyDate;
navDataBase.standbyCode = tempStoreCode;
navDataBase.standbyDate = tempStoreDate;
2020-04-16 12:25:06 +00:00
}
2020-04-16 19:27:10 +00:00
# Landing to phase 7
2021-12-28 12:59:08 +00:00
setlistener("/gear/gear[1]/wow", func(val) {
2022-01-04 17:24:49 +00:00
print("Called gear");
2021-12-28 12:59:08 +00:00
if (val.getValue() == 0 and timer30secLanding.isRunning) {
2022-01-04 17:24:49 +00:00
print("Stopping timer");
2020-04-16 18:19:47 +00:00
timer30secLanding.stop();
2021-12-28 12:59:08 +00:00
FMGCInternal.landingTime = -99;
2020-04-16 12:25:06 +00:00
}
2021-12-28 12:59:08 +00:00
if (val.getValue() and FMGCInternal.landingTime == -99) {
2022-01-04 17:24:49 +00:00
print("Starting timer");
2020-04-16 16:43:49 +00:00
timer30secLanding.start();
2021-12-28 12:59:08 +00:00
FMGCInternal.landingTime = pts.Sim.Time.elapsedSec.getValue();
2020-04-16 12:25:06 +00:00
}
}, 0, 0);
2020-04-16 19:27:10 +00:00
# Align IRS 1
2020-05-16 14:48:26 +00:00
setlistener("/systems/navigation/adr/operating-1", func() {
2020-04-16 19:27:10 +00:00
if (timer48gpsAlign1.isRunning) {
timer48gpsAlign1.stop();
}
2021-06-13 18:29:25 +00:00
if (FMGCAlignTime[0].getValue() == -99) {
2020-04-16 19:27:10 +00:00
timer48gpsAlign1.start();
2021-06-13 18:29:25 +00:00
FMGCAlignTime[0].setValue(pts.Sim.Time.elapsedSec.getValue());
2020-04-16 19:27:10 +00:00
}
}, 0, 0);
# Align IRS 2
2020-05-16 14:48:26 +00:00
setlistener("/systems/navigation/adr/operating-2", func() {
2020-04-16 19:27:10 +00:00
if (timer48gpsAlign2.isRunning) {
timer48gpsAlign2.stop();
}
2021-06-13 18:29:25 +00:00
if (FMGCAlignTime[1].getValue() == -99) {
2020-04-16 19:27:10 +00:00
timer48gpsAlign2.start();
2021-06-13 18:29:25 +00:00
FMGCAlignTime[1].setValue(pts.Sim.Time.elapsedSec.getValue());
2020-04-16 19:27:10 +00:00
}
}, 0, 0);
# Align IRS 3
2020-05-16 14:48:26 +00:00
setlistener("/systems/navigation/adr/operating-3", func() {
2020-04-16 19:27:10 +00:00
if (timer48gpsAlign3.isRunning) {
timer48gpsAlign3.stop();
}
2021-06-13 18:29:25 +00:00
if (FMGCAlignTime[2].getValue() == -99) {
2020-04-16 19:27:10 +00:00
timer48gpsAlign3.start();
2021-06-13 18:29:25 +00:00
FMGCAlignTime[2].setValue(pts.Sim.Time.elapsedSec.getValue());
2020-04-16 19:27:10 +00:00
}
}, 0, 0);
2020-05-02 00:26:05 +00:00
# Calculate Block Fuel
setlistener("/FMGC/internal/block-calculating", func() {
if (timer3blockFuel.isRunning) {
2021-12-28 12:59:08 +00:00
FMGCInternal.blockFuelTime = -99;
2021-12-31 16:01:02 +00:00
timer3blockFuel.stop();
2020-05-02 00:26:05 +00:00
}
2021-12-28 12:59:08 +00:00
if (FMGCInternal.blockFuelTime == -99) {
2020-05-02 00:26:05 +00:00
timer3blockFuel.start();
2021-12-28 12:59:08 +00:00
FMGCInternal.blockFuelTime = pts.Sim.Time.elapsedSec.getValue();
2020-05-02 00:26:05 +00:00
}
}, 0, 0);
2020-04-19 21:10:13 +00:00
2020-05-02 00:26:05 +00:00
# Calculate Fuel Prediction
setlistener("/FMGC/internal/fuel-calculating", func() {
if (timer5fuelPred.isRunning) {
2021-12-28 12:59:08 +00:00
FMGCInternal.fuelPredTime = -99;
2021-12-31 16:01:02 +00:00
timer5fuelPred.stop();
2020-05-02 00:26:05 +00:00
}
2021-12-28 12:59:08 +00:00
if (FMGCInternal.fuelPredTime == -99) {
2020-05-02 00:26:05 +00:00
timer5fuelPred.start();
2021-12-28 12:59:08 +00:00
FMGCInternal.fuelPredTime = pts.Sim.Time.elapsedSec.getValue();
2020-05-02 00:26:05 +00:00
}
}, 0, 0);
# Maketimers
2020-04-19 21:10:13 +00:00
var timer30secLanding = maketimer(1, func() {
2022-01-04 17:24:49 +00:00
if (pts.Sim.Time.elapsedSec.getValue() > (FMGCInternal.landingTime + 30)) {
2020-08-01 16:49:54 +00:00
FMGCInternal.phase = 7;
2022-01-04 17:24:49 +00:00
FMGCNodes.phase.setValue(7);
2021-12-27 11:44:08 +00:00
2020-07-10 19:54:13 +00:00
if (FMGCInternal.costIndexSet) {
setprop("/FMGC/internal/last-cost-index", FMGCInternal.costIndex);
2020-05-23 11:37:22 +00:00
} else {
setprop("/FMGC/internal/last-cost-index", 0);
}
2021-12-28 12:59:08 +00:00
FMGCInternal.landingTime = -99;
2020-04-19 21:10:13 +00:00
timer30secLanding.stop();
}
});
var timer48gpsAlign1 = maketimer(1, func() {
2021-06-13 18:29:25 +00:00
if (pts.Sim.Time.elapsedSec.getValue() > (FMGCAlignTime[0].getValue() + 48) or adirsSkip.getValue()) {
FMGCAlignDone[0].setValue(1);
FMGCAlignTime[0].setValue(-99);
2020-04-19 21:10:13 +00:00
timer48gpsAlign1.stop();
}
});
var timer48gpsAlign2 = maketimer(1, func() {
2021-06-13 18:29:25 +00:00
if (pts.Sim.Time.elapsedSec.getValue() > (FMGCAlignTime[1].getValue() + 48) or adirsSkip.getValue()) {
FMGCAlignDone[1].setValue(1);
FMGCAlignTime[1].setValue(-99);
2020-04-19 21:10:13 +00:00
timer48gpsAlign2.stop();
}
});
2020-04-16 19:27:10 +00:00
var timer48gpsAlign3 = maketimer(1, func() {
2021-06-13 18:29:25 +00:00
if (pts.Sim.Time.elapsedSec.getValue() > (FMGCAlignTime[2].getValue() + 48) or adirsSkip.getValue()) {
FMGCAlignDone[2].setValue(1);
FMGCAlignTime[2].setValue(-99);
2020-04-16 19:27:10 +00:00
timer48gpsAlign3.stop();
}
2020-05-02 00:26:05 +00:00
});
var timer3blockFuel = maketimer(1, func() {
2021-12-28 12:59:08 +00:00
if (pts.Sim.Time.elapsedSec.getValue() > FMGCInternal.blockFuelTime + 3) {
2020-08-04 10:43:18 +00:00
#updateFuel();
2020-10-03 09:59:43 +00:00
fmgc.FMGCInternal.blockCalculating = 0;
2020-10-03 11:34:29 +00:00
fmgc.blockCalculating.setValue(0);
2021-12-28 12:59:08 +00:00
FMGCInternal.blockFuelTime = -99;
2020-05-02 00:26:05 +00:00
timer3blockFuel.stop();
}
});
var timer5fuelPred = maketimer(1, func() {
2021-12-28 12:59:08 +00:00
if (pts.Sim.Time.elapsedSec.getValue() > FMGCInternal.fuelPredTime + 5) {
2020-08-04 10:43:18 +00:00
#updateFuel();
2020-10-03 09:59:43 +00:00
fmgc.FMGCInternal.fuelCalculating = 0;
2020-10-03 11:34:29 +00:00
fmgc.fuelCalculating.setValue(0);
2021-12-28 12:59:08 +00:00
FMGCInternal.fuelPredTime = -99;
2020-05-02 00:26:05 +00:00
timer5fuelPred.stop();
}
2020-04-16 12:25:06 +00:00
});