Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(a32nx/fms): flight phase init #9903

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ A32NX_OVHD_HYD_EPUMPY_OVRD_PB_IS_ON=0
A32NX_OVHD_HYD_LEAK_MEASUREMENT_G_PB_IS_AUTO=1
A32NX_OVHD_HYD_LEAK_MEASUREMENT_B_PB_IS_AUTO=1
A32NX_OVHD_HYD_LEAK_MEASUREMENT_Y_PB_IS_AUTO=1
A32NX_INITIAL_FLIGHT_PHASE = 5
A32NX_FWC_SKIP_STARTUP=1
A32NX_RAIN_REPELLENT_RIGHT_ON = 0
A32NX_RAIN_REPELLENT_LEFT_ON = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ A32NX_OVHD_HYD_EPUMPY_OVRD_PB_IS_ON=0
A32NX_OVHD_HYD_LEAK_MEASUREMENT_G_PB_IS_AUTO=1
A32NX_OVHD_HYD_LEAK_MEASUREMENT_B_PB_IS_AUTO=1
A32NX_OVHD_HYD_LEAK_MEASUREMENT_Y_PB_IS_AUTO=1
A32NX_INITIAL_FLIGHT_PHASE = 3
A32NX_FWC_SKIP_STARTUP=1
A32NX_RAIN_REPELLENT_RIGHT_ON = 0
A32NX_RAIN_REPELLENT_LEFT_ON = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ A32NX_OVHD_HYD_EPUMPY_OVRD_PB_IS_ON=0
A32NX_OVHD_HYD_LEAK_MEASUREMENT_G_PB_IS_AUTO=1
A32NX_OVHD_HYD_LEAK_MEASUREMENT_B_PB_IS_AUTO=1
A32NX_OVHD_HYD_LEAK_MEASUREMENT_Y_PB_IS_AUTO=1
A32NX_INITIAL_FLIGHT_PHASE = 5
A32NX_FWC_SKIP_STARTUP=1
A32NX_RAIN_REPELLENT_RIGHT_ON = 0
A32NX_RAIN_REPELLENT_LEFT_ON = 0
Expand Down
33 changes: 22 additions & 11 deletions fbw-a32nx/src/systems/fmgc/src/flightphase/FlightPhaseManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { Arinc429Word, ConfirmationNode } from '@flybywiresim/fbw-sdk';
import { VerticalMode } from '@shared/autopilot';
import { FmgcFlightPhase, isAllEngineOn, isAnEngineOn, isOnGround, isReady, isSlewActive } from '@shared/flightphase';
import { EventBus, Subject } from '@microsoft/msfs-sdk';
import { EventBus, GameStateProvider, SimVarValueType, Subject, Wait } from '@microsoft/msfs-sdk';

export interface FlightPhaseManagerEvents {
/** The FMGC flight phase. */
Expand All @@ -38,7 +38,7 @@ function canInitiateDes(distanceToDestination: number): boolean {
export class FlightPhaseManager {
private onGroundConfirmationNode = new ConfirmationNode(30 * 1000);

private readonly activePhase = Subject.create(this.initialPhase || FmgcFlightPhase.Preflight);
private readonly activePhase = Subject.create(FmgcFlightPhase.Preflight);

private phases: { [key in FmgcFlightPhase]: Phase } = {
[FmgcFlightPhase.Preflight]: new PreFlightPhase(),
Expand All @@ -57,16 +57,31 @@ export class FlightPhaseManager {
return this.activePhase.get();
}

get initialPhase(): FmgcFlightPhase {
return SimVar.GetSimVarValue('L:A32NX_INITIAL_FLIGHT_PHASE', 'number');
}

constructor(private readonly bus: EventBus) {}
init(): void {
console.log(`FMGC Flight Phase: ${this.phase}`);
this.phases[this.phase].init();
this.changePhase(this.phase);
this.activePhase.sub((v) => this.bus.getPublisher<FlightPhaseManagerEvents>().pub('fmgc_flight_phase', v));
this.activePhase.sub((v) => this.bus.getPublisher<FlightPhaseManagerEvents>().pub('fmgc_flight_phase', v), true);

// For simulation purposes we need to handle loading or spawning in various states.
// In here we should not rely on aircraft systems, but instead simvars from MSFS.
Wait.awaitSubscribable(GameStateProvider.get(), (v) => v === GameState.ingame).then(() => {
switch (true) {
case SimVar.GetSimVarValue('GEAR IS ON GROUND', SimVarValueType.Bool) > 0:
this.changePhase(FmgcFlightPhase.Preflight);
break;
case SimVar.GetSimVarValue('PLANE ALTITUDE', SimVarValueType.Feet) > 18_000:
this.changePhase(FmgcFlightPhase.Cruise);
break;
case SimVar.GetSimVarValue('FLAPS HANDLE INDEX', SimVarValueType.Enum) > 0:
this.changePhase(FmgcFlightPhase.Approach);
break;
default:
this.changePhase(FmgcFlightPhase.Climb);
break;
}
});
}

shouldActivateNextPhase(_deltaTime: number): void {
Expand All @@ -79,10 +94,6 @@ export class FlightPhaseManager {
}
} else if (isReady() && isSlewActive()) {
this.handleSlewSituation(_deltaTime);
} else if (this.phase !== this.initialPhase) {
// ensure correct init of phase

this.changePhase(this.initialPhase);
}
}

Expand Down