Skip to content

Commit 646580f

Browse files
authored
Merge pull request #381 from 747-4EVER/master
fix(ILS): Fixes ILS failing to autotune in some instances.
2 parents 4063d5e + 7bf056b commit 646580f

File tree

6 files changed

+59
-41
lines changed

6 files changed

+59
-41
lines changed

salty-747/html_ui/Pages/Salty/WT/Autopilot/LNavDirector.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* A class that manages flight plan lateral guidance.
33
*/
4-
class LNavDirector {
4+
class LNavDirector {
55
/**
66
* Creates an instance of the LNavDirector.
77
* @param {FlightPlanManager} fpm The FlightPlanManager to use with this instance.
@@ -221,14 +221,13 @@ class LNavDirector {
221221
*/
222222
getAnticipationDistance(planeState, turnAngle) {
223223
const headwind = AutopilotMath.windComponents(planeState.trueHeading, planeState.windDirection, planeState.windSpeed).headwind;
224-
const turnRadius = AutopilotMath.turnRadius(planeState.trueAirspeed - headwind, planeState.maxBankAngle);
224+
const turnRadius = AutopilotMath.turnRadius(planeState.trueAirspeed - headwind, this.options.maxBankAngle);
225225

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

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

234233
/**
@@ -268,7 +267,6 @@ class LNavDirector {
268267
if (currentWaypoint && currentWaypoint.endsInDiscontinuity) {
269268
this.state = LNavState.IN_DISCONTINUITY;
270269
SimVar.SetSimVarValue("L:WT_CJ4_IN_DISCONTINUITY", "number", 1);
271-
272270
this.sequencingMode = FlightPlanSequencing.INHIBIT;
273271
LNavDirector.setCourse(SimVar.GetSimVarValue('PLANE HEADING DEGREES TRUE', 'Radians') * Avionics.Utils.RAD2DEG, planeState);
274272
SimVar.SetSimVarValue('L:WT_CJ4_WPT_ALERT', 'number', 0);
@@ -277,11 +275,11 @@ class LNavDirector {
277275
this.sequencingMode = FlightPlanSequencing.INHIBIT;
278276

279277
this.state = LNavState.TURN_COMPLETING;
280-
this.fpm.setActiveWaypointIndex(this.activeFlightPlan.activeWaypointIndex + 1);
278+
this.fpm.setActiveWaypointIndex(this.activeFlightPlan.activeWaypointIndex + 1, EmptyCallback.Void, 0);
281279
}
282280
else {
283281
this.state = LNavState.TURN_COMPLETING;
284-
this.fpm.setActiveWaypointIndex(this.activeFlightPlan.activeWaypointIndex + 1);
282+
this.fpm.setActiveWaypointIndex(this.activeFlightPlan.activeWaypointIndex + 1, EmptyCallback.Void, 0);
285283
}
286284
}
287285
}
@@ -297,8 +295,8 @@ class LNavDirector {
297295

298296
const nextWaypointIndex = this.activeFlightPlan.activeWaypointIndex + 1;
299297

300-
this.fpm.setActiveWaypointIndex(nextWaypointIndex);
301-
this.fpm.clearDiscontinuity(nextWaypointIndex - 1);
298+
this.fpm.setActiveWaypointIndex(nextWaypointIndex, EmptyCallback.Void, 0);
299+
this.fpm.clearDiscontinuity(nextWaypointIndex - 1, 0);
302300
}
303301

304302
this.sequencingMode = FlightPlanSequencing.AUTO;
@@ -316,7 +314,24 @@ class LNavDirector {
316314
* @param {number} navSensitivity The current nav sensitivity.
317315
*/
318316
postDisplayedNavSensitivity(navSensitivity) {
317+
if (navSensitivity !== this.currentNavSensitivity) {
318+
this.currentNavSensitivity = navSensitivity;
319319

320+
switch (this.currentNavSensitivity) {
321+
case NavSensitivity.TERMINAL:
322+
//MessageService.getInstance().post(FMS_MESSAGE_ID.TERM, () => this.currentNavSensitivity !== NavSensitivity.TERMINAL);
323+
break;
324+
case NavSensitivity.TERMINALLPV:
325+
//MessageService.getInstance().post(FMS_MESSAGE_ID.TERM_LPV, () => this.currentNavSensitivity !== NavSensitivity.TERMINALLPV);
326+
break;
327+
case NavSensitivity.APPROACH:
328+
//MessageService.getInstance().post(FMS_MESSAGE_ID.APPR, () => this.currentNavSensitivity !== NavSensitivity.APPROACH);
329+
break;
330+
case NavSensitivity.APPROACHLPV:
331+
//MessageService.getInstance().post(FMS_MESSAGE_ID.APPR_LPV, () => this.currentNavSensitivity !== NavSensitivity.APPROACHLPV);
332+
break;
333+
}
334+
}
320335
}
321336

322337
/**
@@ -346,7 +361,6 @@ class LNavDirector {
346361
}
347362

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

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

431444
return state;
432445
}

salty-747/html_ui/Pages/Salty/WT/Autopilot/NavToNavTransfer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ class NavToNavTransfer {
7272

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

7878
if (isFinite(frequency) && frequency >= 108 && frequency <= 117.95) {
79-
this.navRadioSystem.radioStates[1].setManualFrequency(frequency);
79+
this.navRadioSystem.radioStates[3].setManualFrequency(frequency);
8080
this.transferState = NavToNavTransfer.ARMED;
8181
}
8282
else {
@@ -86,7 +86,7 @@ class NavToNavTransfer {
8686
}
8787

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

9292
if (isNaN(frequency)) {
@@ -108,7 +108,7 @@ class NavToNavTransfer {
108108
handleArmed() {
109109
const frequency = this.fpm.getApproachNavFrequency();
110110
if (isNaN(frequency)) {
111-
const hasLoc = SimVar.GetSimVarValue('NAV HAS LOCALIZER:1', 'number') !== 0;
111+
const hasLoc = SimVar.GetSimVarValue('NAV HAS LOCALIZER:3', 'number') !== 0;
112112
if (!hasLoc) {
113113
this.transferState = NavToNavTransfer.TUNE_FAILED;
114114
}
@@ -138,7 +138,7 @@ class NavToNavTransfer {
138138
* Attempts to auto-tune the localizer.
139139
*/
140140
tryTuneLocalizer() {
141-
if (this.navRadioSystem.radioStates[1].mode !== NavRadioMode.Auto) {
141+
if (this.navRadioSystem.radioStates[3].mode !== NavRadioMode.Auto) {
142142
this.termTimestamp = Date.now();
143143
}
144144

salty-747/html_ui/Pages/Salty/WT/Autopilot/SaltyNavModeSelector.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@
340340
switch (this.currentLateralActiveState) {
341341
case LateralNavModeState.ROLL:
342342
SimVar.SetSimVarValue("L:WT_CJ4_NAV_ON", "number", 1);
343+
SimVar.SetSimVarValue("L:AP_LNAV_ACTIVE", "number", 1);
343344
this.changeToCorrectLNavForMode(true, false);
344345
break;
345346
case LateralNavModeState.LNAV:
@@ -348,6 +349,7 @@
348349
case LateralNavModeState.TO:
349350
case LateralNavModeState.GA:
350351
SimVar.SetSimVarValue("L:WT_CJ4_NAV_ON", "number", 1);
352+
SimVar.SetSimVarValue("L:AP_LNAV_ACTIVE", "number", 1);
351353
SimVar.SetSimVarValue("L:WT_CJ4_HDG_ON", "number", 0);
352354
this.changeToCorrectLNavForMode(false, false);
353355
SimVar.SetSimVarValue("K:AP_PANEL_HEADING_HOLD", "number", 1);

salty-747/html_ui/Pages/Salty/WT/Waypoint.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ class AirportInfo extends WayPointInfo {
427427
this.frequencies = [];
428428
if (data.frequencies) {
429429
for (let i = 0; i < data.frequencies.length; i++) {
430-
this.frequencies.push(new Frequency(data.frequencies[i].name, data.frequencies[i].freqMHz, data.frequencies[i].freqBCD16));
430+
this.frequencies.push(new Frequency(data.frequencies[i].name, data.frequencies[i].freqMHz, data.frequencies[i].freqBCD16, data.frequencies[i].type));
431431
}
432432
}
433433
this.runways = [];
@@ -941,10 +941,12 @@ class IntersectionInfo extends WayPointInfo {
941941
IntersectionInfo.readManager = new InstrumentDataReadManager();
942942
IntersectionInfo.longestAirway = 0;
943943
class Frequency {
944-
constructor(_name, _mhValue, _bcd16Value) {
944+
constructor(_name, _mhValue, _bcd16Value, _type) {
945945
this.name = _name;
946946
this.mhValue = _mhValue;
947947
this.bcd16Value = _bcd16Value;
948+
this.bcd16Value = _bcd16Value;
949+
this.type = _type;
948950
}
949951
}
950952

src/modules/src/fpm/flightplanning/FlightPlanManager.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ export class FlightPlanManager {
154154
/**
155155
* Switches the active flight plan index to the supplied index.
156156
* @param index The index to now use for the active flight plan.
157+
* @param thenSetActive Indicates if the flight plan should become the active flightplan. (inop here)
157158
* @param callback A callback to call when the operation has completed.
158159
*/
159-
public setCurrentFlightPlanIndex(index: number, callback = EmptyCallback.Boolean): void {
160+
public setCurrentFlightPlanIndex(index: number, thenSetActive = false, callback = EmptyCallback.Boolean): void {
160161
if (index >= 0 && index < this._flightPlans.length) {
161162
this._currentFlightPlanIndex = index;
162163
callback(true);
@@ -838,19 +839,6 @@ export class FlightPlanManager {
838839
return undefined;
839840
}
840841

841-
/**
842-
* Gets the heading of the selected departure runway.
843-
*/
844-
public getDepartureRunwayDirection(): Number {
845-
const origin = this.getOrigin();
846-
const currentFlightPlan = this._flightPlans[this._currentFlightPlanIndex];
847-
if (origin && origin.infos instanceof AirportInfo && currentFlightPlan.procedureDetails.originRunwayIndex !== -1) {
848-
const runway = origin.infos.oneWayRunways[currentFlightPlan.procedureDetails.originRunwayIndex];
849-
return runway.direction;
850-
}
851-
return undefined;
852-
}
853-
854842
/**
855843
* Gets the best runway based on the current plane heading.
856844
*/
@@ -1059,8 +1047,8 @@ export class FlightPlanManager {
10591047
* Clears a discontinuity from the end of a waypoint.
10601048
* @param index
10611049
*/
1062-
public clearDiscontinuity(index: number): void {
1063-
const currentFlightPlan = this._flightPlans[this._currentFlightPlanIndex];
1050+
public clearDiscontinuity(index: number, fplnIndex = this._currentFlightPlanIndex): void {
1051+
const currentFlightPlan = this._flightPlans[fplnIndex];
10641052
const waypoint = currentFlightPlan.getWaypoint(index);
10651053

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

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

12501238
if (frequency) {
1251-
return frequency.value;
1239+
return Math.round(frequency.freqMHz * 100) / 100;
12521240
}
12531241
}
12541242

@@ -1549,4 +1537,16 @@ export class FlightPlanManager {
15491537
this._updateFlightPlanVersion();
15501538
}
15511539

1552-
}
1540+
/**
1541+
* Gets the heading of the selected departure runway.
1542+
*/
1543+
public getDepartureRunwayDirection(): Number {
1544+
const origin = this.getOrigin();
1545+
const currentFlightPlan = this._flightPlans[this._currentFlightPlanIndex];
1546+
if (origin && origin.infos instanceof AirportInfo && currentFlightPlan.procedureDetails.originRunwayIndex !== -1) {
1547+
const runway = origin.infos.oneWayRunways[currentFlightPlan.procedureDetails.originRunwayIndex];
1548+
return runway.direction;
1549+
}
1550+
return undefined;
1551+
}
1552+
}

src/modules/src/fpm/flightplanning/RawDataMapper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* A class for mapping raw facility data to WayPoints.
33
*/
4-
export class RawDataMapper {
4+
export class RawDataMapper {
55

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

46+
info.frequencies = facility.frequencies;
47+
4648
info.oneWayRunways.sort(RawDataMapper.sortRunways);
4749
waypoint.infos = info;
4850
}
@@ -143,4 +145,3 @@ export class RawDataMapper {
143145
return enrouteTransition.legs[enrouteTransition.legs.length - 1].fixIcao.substring(7, 12).trim();
144146
}
145147
}
146-

0 commit comments

Comments
 (0)