Skip to content

Commit

Permalink
Merge pull request #381 from 747-4EVER/master
Browse files Browse the repository at this point in the history
fix(ILS): Fixes ILS failing to autotune in some instances.
  • Loading branch information
747-4EVER authored Feb 2, 2022
2 parents 4063d5e + 7bf056b commit 646580f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 41 deletions.
39 changes: 26 additions & 13 deletions salty-747/html_ui/Pages/Salty/WT/Autopilot/LNavDirector.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* A class that manages flight plan lateral guidance.
*/
class LNavDirector {
class LNavDirector {
/**
* Creates an instance of the LNavDirector.
* @param {FlightPlanManager} fpm The FlightPlanManager to use with this instance.
Expand Down Expand Up @@ -221,14 +221,13 @@ class LNavDirector {
*/
getAnticipationDistance(planeState, turnAngle) {
const headwind = AutopilotMath.windComponents(planeState.trueHeading, planeState.windDirection, planeState.windSpeed).headwind;
const turnRadius = AutopilotMath.turnRadius(planeState.trueAirspeed - headwind, planeState.maxBankAngle);
const turnRadius = AutopilotMath.turnRadius(planeState.trueAirspeed - headwind, this.options.maxBankAngle);

const bankDiff = (Math.sign(turnAngle) * planeState.maxBankAngle) - planeState.bankAngle;
const enterBankDistance = 0.5 * (Math.abs(bankDiff) / this.options.bankRate) * ((planeState.trueAirspeed - headwind) / 3600);
const bankDiff = (Math.sign(turnAngle) * this.options.maxBankAngle) - planeState.bankAngle;
const enterBankDistance = (Math.abs(bankDiff) / this.options.bankRate) * ((planeState.trueAirspeed - headwind) / 3600);

const turnAnticipationAngle = Math.min(this.options.maxTurnAnticipationAngle, Math.abs(turnAngle)) * Avionics.Utils.DEG2RAD;
const value = turnRadius * Math.abs(Math.tan(turnAnticipationAngle / 2)) + enterBankDistance;
return value;
return Math.min((turnRadius * Math.abs(Math.tan(turnAnticipationAngle / 2))) + enterBankDistance, this.options.maxTurnAnticipationDistance(planeState));
}

/**
Expand Down Expand Up @@ -268,7 +267,6 @@ class LNavDirector {
if (currentWaypoint && currentWaypoint.endsInDiscontinuity) {
this.state = LNavState.IN_DISCONTINUITY;
SimVar.SetSimVarValue("L:WT_CJ4_IN_DISCONTINUITY", "number", 1);

this.sequencingMode = FlightPlanSequencing.INHIBIT;
LNavDirector.setCourse(SimVar.GetSimVarValue('PLANE HEADING DEGREES TRUE', 'Radians') * Avionics.Utils.RAD2DEG, planeState);
SimVar.SetSimVarValue('L:WT_CJ4_WPT_ALERT', 'number', 0);
Expand All @@ -277,11 +275,11 @@ class LNavDirector {
this.sequencingMode = FlightPlanSequencing.INHIBIT;

this.state = LNavState.TURN_COMPLETING;
this.fpm.setActiveWaypointIndex(this.activeFlightPlan.activeWaypointIndex + 1);
this.fpm.setActiveWaypointIndex(this.activeFlightPlan.activeWaypointIndex + 1, EmptyCallback.Void, 0);
}
else {
this.state = LNavState.TURN_COMPLETING;
this.fpm.setActiveWaypointIndex(this.activeFlightPlan.activeWaypointIndex + 1);
this.fpm.setActiveWaypointIndex(this.activeFlightPlan.activeWaypointIndex + 1, EmptyCallback.Void, 0);
}
}
}
Expand All @@ -297,8 +295,8 @@ class LNavDirector {

const nextWaypointIndex = this.activeFlightPlan.activeWaypointIndex + 1;

this.fpm.setActiveWaypointIndex(nextWaypointIndex);
this.fpm.clearDiscontinuity(nextWaypointIndex - 1);
this.fpm.setActiveWaypointIndex(nextWaypointIndex, EmptyCallback.Void, 0);
this.fpm.clearDiscontinuity(nextWaypointIndex - 1, 0);
}

this.sequencingMode = FlightPlanSequencing.AUTO;
Expand All @@ -316,7 +314,24 @@ class LNavDirector {
* @param {number} navSensitivity The current nav sensitivity.
*/
postDisplayedNavSensitivity(navSensitivity) {
if (navSensitivity !== this.currentNavSensitivity) {
this.currentNavSensitivity = navSensitivity;

switch (this.currentNavSensitivity) {
case NavSensitivity.TERMINAL:
//MessageService.getInstance().post(FMS_MESSAGE_ID.TERM, () => this.currentNavSensitivity !== NavSensitivity.TERMINAL);
break;
case NavSensitivity.TERMINALLPV:
//MessageService.getInstance().post(FMS_MESSAGE_ID.TERM_LPV, () => this.currentNavSensitivity !== NavSensitivity.TERMINALLPV);
break;
case NavSensitivity.APPROACH:
//MessageService.getInstance().post(FMS_MESSAGE_ID.APPR, () => this.currentNavSensitivity !== NavSensitivity.APPROACH);
break;
case NavSensitivity.APPROACHLPV:
//MessageService.getInstance().post(FMS_MESSAGE_ID.APPR_LPV, () => this.currentNavSensitivity !== NavSensitivity.APPROACHLPV);
break;
}
}
}

/**
Expand Down Expand Up @@ -346,7 +361,6 @@ class LNavDirector {
}

if (Math.abs(xtk) < activationXtk) {
SimVar.SetSimVarValue("L:AP_LNAV_ACTIVE", "number", 1);
this.navModeSelector.queueEvent(NavModeEvent.LNAV_ACTIVE);
}
}
Expand Down Expand Up @@ -426,7 +440,6 @@ class LNavDirector {
state.trueTrack = SimVar.GetSimVarValue('GPS GROUND TRUE TRACK', 'Radians') * Avionics.Utils.RAD2DEG;

state.bankAngle = SimVar.GetSimVarValue('PLANE BANK DEGREES', 'Radians') * Avionics.Utils.RAD2DEG;
state.maxBankAngle = SimVar.GetSimVarValue('AUTOPILOT MAX BANK', 'Radians') * Avionics.Utils.RAD2DEG;

return state;
}
Expand Down
10 changes: 5 additions & 5 deletions salty-747/html_ui/Pages/Salty/WT/Autopilot/NavToNavTransfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class NavToNavTransfer {

handleTunePending() {
const timeStamp = Date.now();
if (timeStamp - this.termTimestamp > 30000 || this.navRadioSystem.radioStates[1].mode === NavRadioMode.Auto) {
if (timeStamp - this.termTimestamp > 30000 || this.navRadioSystem.radioStates[3].mode === NavRadioMode.Auto) {
const frequency = this.fpm.getApproachNavFrequency();

if (isFinite(frequency) && frequency >= 108 && frequency <= 117.95) {
this.navRadioSystem.radioStates[1].setManualFrequency(frequency);
this.navRadioSystem.radioStates[3].setManualFrequency(frequency);
this.transferState = NavToNavTransfer.ARMED;
}
else {
Expand All @@ -86,7 +86,7 @@ class NavToNavTransfer {
}

handleTuneFailed() {
const hasLoc = SimVar.GetSimVarValue('NAV HAS LOCALIZER:1', 'number');
const hasLoc = SimVar.GetSimVarValue('NAV HAS LOCALIZER:3', 'number');
const frequency = this.fpm.getApproachNavFrequency();

if (isNaN(frequency)) {
Expand All @@ -108,7 +108,7 @@ class NavToNavTransfer {
handleArmed() {
const frequency = this.fpm.getApproachNavFrequency();
if (isNaN(frequency)) {
const hasLoc = SimVar.GetSimVarValue('NAV HAS LOCALIZER:1', 'number') !== 0;
const hasLoc = SimVar.GetSimVarValue('NAV HAS LOCALIZER:3', 'number') !== 0;
if (!hasLoc) {
this.transferState = NavToNavTransfer.TUNE_FAILED;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ class NavToNavTransfer {
* Attempts to auto-tune the localizer.
*/
tryTuneLocalizer() {
if (this.navRadioSystem.radioStates[1].mode !== NavRadioMode.Auto) {
if (this.navRadioSystem.radioStates[3].mode !== NavRadioMode.Auto) {
this.termTimestamp = Date.now();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
switch (this.currentLateralActiveState) {
case LateralNavModeState.ROLL:
SimVar.SetSimVarValue("L:WT_CJ4_NAV_ON", "number", 1);
SimVar.SetSimVarValue("L:AP_LNAV_ACTIVE", "number", 1);
this.changeToCorrectLNavForMode(true, false);
break;
case LateralNavModeState.LNAV:
Expand All @@ -348,6 +349,7 @@
case LateralNavModeState.TO:
case LateralNavModeState.GA:
SimVar.SetSimVarValue("L:WT_CJ4_NAV_ON", "number", 1);
SimVar.SetSimVarValue("L:AP_LNAV_ACTIVE", "number", 1);
SimVar.SetSimVarValue("L:WT_CJ4_HDG_ON", "number", 0);
this.changeToCorrectLNavForMode(false, false);
SimVar.SetSimVarValue("K:AP_PANEL_HEADING_HOLD", "number", 1);
Expand Down
6 changes: 4 additions & 2 deletions salty-747/html_ui/Pages/Salty/WT/Waypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class AirportInfo extends WayPointInfo {
this.frequencies = [];
if (data.frequencies) {
for (let i = 0; i < data.frequencies.length; i++) {
this.frequencies.push(new Frequency(data.frequencies[i].name, data.frequencies[i].freqMHz, data.frequencies[i].freqBCD16));
this.frequencies.push(new Frequency(data.frequencies[i].name, data.frequencies[i].freqMHz, data.frequencies[i].freqBCD16, data.frequencies[i].type));
}
}
this.runways = [];
Expand Down Expand Up @@ -941,10 +941,12 @@ class IntersectionInfo extends WayPointInfo {
IntersectionInfo.readManager = new InstrumentDataReadManager();
IntersectionInfo.longestAirway = 0;
class Frequency {
constructor(_name, _mhValue, _bcd16Value) {
constructor(_name, _mhValue, _bcd16Value, _type) {
this.name = _name;
this.mhValue = _mhValue;
this.bcd16Value = _bcd16Value;
this.bcd16Value = _bcd16Value;
this.type = _type;
}
}

Expand Down
38 changes: 19 additions & 19 deletions src/modules/src/fpm/flightplanning/FlightPlanManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ export class FlightPlanManager {
/**
* Switches the active flight plan index to the supplied index.
* @param index The index to now use for the active flight plan.
* @param thenSetActive Indicates if the flight plan should become the active flightplan. (inop here)
* @param callback A callback to call when the operation has completed.
*/
public setCurrentFlightPlanIndex(index: number, callback = EmptyCallback.Boolean): void {
public setCurrentFlightPlanIndex(index: number, thenSetActive = false, callback = EmptyCallback.Boolean): void {
if (index >= 0 && index < this._flightPlans.length) {
this._currentFlightPlanIndex = index;
callback(true);
Expand Down Expand Up @@ -838,19 +839,6 @@ export class FlightPlanManager {
return undefined;
}

/**
* Gets the heading of the selected departure runway.
*/
public getDepartureRunwayDirection(): Number {
const origin = this.getOrigin();
const currentFlightPlan = this._flightPlans[this._currentFlightPlanIndex];
if (origin && origin.infos instanceof AirportInfo && currentFlightPlan.procedureDetails.originRunwayIndex !== -1) {
const runway = origin.infos.oneWayRunways[currentFlightPlan.procedureDetails.originRunwayIndex];
return runway.direction;
}
return undefined;
}

/**
* Gets the best runway based on the current plane heading.
*/
Expand Down Expand Up @@ -1059,8 +1047,8 @@ export class FlightPlanManager {
* Clears a discontinuity from the end of a waypoint.
* @param index
*/
public clearDiscontinuity(index: number): void {
const currentFlightPlan = this._flightPlans[this._currentFlightPlanIndex];
public clearDiscontinuity(index: number, fplnIndex = this._currentFlightPlanIndex): void {
const currentFlightPlan = this._flightPlans[fplnIndex];
const waypoint = currentFlightPlan.getWaypoint(index);

if (waypoint !== undefined) {
Expand Down Expand Up @@ -1245,10 +1233,10 @@ export class FlightPlanManager {
const approachRunway = this.getApproach().runway.trim();

const aptInfo = destination.infos as AirportInfo;
const frequency = aptInfo.namedFrequencies.find(f => f.name.replace("RW0", "").replace("RW", "").indexOf(approachRunway) !== -1);
const frequency = aptInfo.frequencies.find(f => f.name.replace("RW0", "").replace("RW", "").indexOf(approachRunway) !== -1);

if (frequency) {
return frequency.value;
return Math.round(frequency.freqMHz * 100) / 100;
}
}

Expand Down Expand Up @@ -1549,4 +1537,16 @@ export class FlightPlanManager {
this._updateFlightPlanVersion();
}

}
/**
* Gets the heading of the selected departure runway.
*/
public getDepartureRunwayDirection(): Number {
const origin = this.getOrigin();
const currentFlightPlan = this._flightPlans[this._currentFlightPlanIndex];
if (origin && origin.infos instanceof AirportInfo && currentFlightPlan.procedureDetails.originRunwayIndex !== -1) {
const runway = origin.infos.oneWayRunways[currentFlightPlan.procedureDetails.originRunwayIndex];
return runway.direction;
}
return undefined;
}
}
5 changes: 3 additions & 2 deletions src/modules/src/fpm/flightplanning/RawDataMapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* A class for mapping raw facility data to WayPoints.
*/
export class RawDataMapper {
export class RawDataMapper {

/**
* Maps a raw facility record to a WayPoint.
Expand Down Expand Up @@ -43,6 +43,8 @@ export class RawDataMapper {
info.oneWayRunways = [];
facility.runways.forEach(runway => info.oneWayRunways.push(...Object.assign(new Runway(), runway).splitIfTwoWays()));

info.frequencies = facility.frequencies;

info.oneWayRunways.sort(RawDataMapper.sortRunways);
waypoint.infos = info;
}
Expand Down Expand Up @@ -143,4 +145,3 @@ export class RawDataMapper {
return enrouteTransition.legs[enrouteTransition.legs.length - 1].fixIcao.substring(7, 12).trim();
}
}

0 comments on commit 646580f

Please sign in to comment.