Skip to content

Commit

Permalink
Add logic for default performance altitudes on origin and destination
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjozork committed Jul 27, 2023
1 parent 68cfd59 commit f3b66b0
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import { Airport, ApproachType, Fix } from 'msfs-navdata';
import { AlternateFlightPlan } from '@fmgc/flightplanning/new/plans/AlternateFlightPlan';
import { EventBus, MagVar } from '@microsoft/msfs-sdk';
import { EventBus, MagVar, UnitType } from '@microsoft/msfs-sdk';
import { FixInfoEntry } from '@fmgc/flightplanning/new/plans/FixInfo';
import { loadAllDepartures, loadAllRunways } from '@fmgc/flightplanning/new/DataLoading';
import { Coordinates, Degrees } from 'msfs-geo';
import { FlightPlanLeg, FlightPlanLegFlags } from '@fmgc/flightplanning/new/legs/FlightPlanLeg';
import { SegmentClass } from '@fmgc/flightplanning/new/segments/SegmentClass';
import { FlightArea } from '@fmgc/navigation/FlightArea';
import { NXDataStore } from '@flybywiresim/fbw-sdk';
import { FlightPlanPerformanceData } from './performance/FlightPlanPerformanceData';
import { BaseFlightPlan, FlightPlanQueuedOperation, SerializedFlightPlan } from './BaseFlightPlan';

Expand Down Expand Up @@ -276,6 +277,66 @@ export class FlightPlan extends BaseFlightPlan {
return FlightArea.Enroute;
}

async setOriginAirport(icao: string): Promise<void> {
await super.setOriginAirport(icao);

FlightPlan.setOriginDefaultPerformanceData(this, this.originAirport);
}

async setDestinationAirport(icao: string | undefined): Promise<void> {
await super.setDestinationAirport(icao);

FlightPlan.setDestinationDefaultPerformanceData(this, this.destinationAirport);
}

/**
* Sets defaults for performance data parameters related to an origin
*
* @param plan the flight plan
* @param airport the origin airport
*/
private static setOriginDefaultPerformanceData(plan: FlightPlan, airport: Airport | undefined): void {
const referenceAltitude = UnitType.FOOT.convertFrom(airport?.location.alt, UnitType.METER); // TODO fix in msfs-navdata (fms-v2)

if (referenceAltitude !== undefined) {
plan.performanceData.defaultThrustReductionAltitude.set(referenceAltitude + parseInt(NXDataStore.get('CONFIG_THR_RED_ALT', '1500')));
plan.performanceData.defaultAccelerationAltitude.set(referenceAltitude + parseInt(NXDataStore.get('CONFIG_ACCEL_ALT', '1500')));
plan.performanceData.defaultEngineOutAccelerationAltitude.set(referenceAltitude + parseInt(NXDataStore.get('CONFIG_ENG_OUT_ACCEL_ALT', '1500')));
} else {
plan.performanceData.defaultThrustReductionAltitude.set(undefined);
plan.performanceData.defaultAccelerationAltitude.set(undefined);
plan.performanceData.defaultEngineOutAccelerationAltitude.set(undefined);
}

plan.performanceData.pilotThrustReductionAltitude.set(undefined);
plan.performanceData.pilotAccelerationAltitude.set(undefined);
plan.performanceData.pilotEngineOutAccelerationAltitude.set(undefined);
}

/**
* Sets defaults for performance data parameters related to a destination
*
* @param plan the flight plan
* @param airport the destination airport
*/
private static setDestinationDefaultPerformanceData(plan: FlightPlan, airport: Airport): void {
const referenceAltitude = UnitType.FOOT.convertFrom(airport?.location.alt, UnitType.METER); // TODO fix in msfs-navdata (fms-v2)

if (referenceAltitude !== undefined) {
plan.performanceData.defaultMissedThrustReductionAltitude.set(referenceAltitude + parseInt(NXDataStore.get('CONFIG_THR_RED_ALT', '1500')));
plan.performanceData.defaultMissedAccelerationAltitude.set(referenceAltitude + parseInt(NXDataStore.get('CONFIG_ACCEL_ALT', '1500')));
plan.performanceData.defaultMissedEngineOutAccelerationAltitude.set(referenceAltitude + parseInt(NXDataStore.get('CONFIG_ENG_OUT_ACCEL_ALT', '1500')));
} else {
plan.performanceData.defaultMissedThrustReductionAltitude.set(undefined);
plan.performanceData.defaultMissedAccelerationAltitude.set(undefined);
plan.performanceData.defaultMissedEngineOutAccelerationAltitude.set(undefined);
}

plan.performanceData.pilotMissedThrustReductionAltitude.set(undefined);
plan.performanceData.pilotMissedAccelerationAltitude.set(undefined);
plan.performanceData.pilotMissedEngineOutAccelerationAltitude.set(undefined);
}

static fromSerializedFlightPlan(index: number, serialized: SerializedFlightPlan, bus: EventBus): FlightPlan {
const newPlan = FlightPlan.empty(index, bus);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MappedSubject, Subject } from '@microsoft/msfs-sdk';

type VSpeedValue = number | undefined;

type AltitudeValue = number | undefined;
type AltitudeValue = Feet | undefined;

export class FlightPlanPerformanceData {
public clone(): FlightPlanPerformanceData {
Expand Down Expand Up @@ -44,6 +44,11 @@ export class FlightPlanPerformanceData {
return cloned;
}

/**
* Cruise FL
*/
readonly cruiseFlightLevel = Subject.create<AltitudeValue>(undefined);

/**
* V1 speed
*/
Expand Down Expand Up @@ -184,7 +189,11 @@ export class FlightPlanPerformanceData {
/**
* Missed EO ACC from pilot if entered, otherwise from database
*/
readonly missedEngineOutAccelerationAltitude = MappedSubject.create(([db, pilot]) => db ?? pilot, this.defaultMissedEngineOutAccelerationAltitude, this.pilotMissedEngineOutAccelerationAltitude)
readonly missedEngineOutAccelerationAltitude = MappedSubject.create(
([db, pilot]) => db ?? pilot,
this.defaultMissedEngineOutAccelerationAltitude,
this.pilotMissedEngineOutAccelerationAltitude,
);

/**
* Whether missed EO ACC is from the database
Expand Down Expand Up @@ -233,6 +242,10 @@ export class FlightPlanPerformanceData {

serialize(): SerializedFlightPlanPerformanceData {
return {
cruiseFlightLevel: this.cruiseFlightLevel.get(),
v1: this.v1.get(),
vr: this.vr.get(),
v2: this.v2.get(),
pilotThrustReductionAltitude: this.pilotThrustReductionAltitude.get(),
defaultThrustReductionAltitude: this.defaultThrustReductionAltitude.get(),
pilotAccelerationAltitude: this.pilotAccelerationAltitude.get(),
Expand All @@ -254,27 +267,35 @@ export class FlightPlanPerformanceData {
}

export interface SerializedFlightPlanPerformanceData {
pilotThrustReductionAltitude: number,
defaultThrustReductionAltitude: number,
cruiseFlightLevel: number | undefined,

v1: number | undefined,

vr: number | undefined,

v2: number | undefined,

pilotThrustReductionAltitude: number | undefined,
defaultThrustReductionAltitude: number | undefined,

pilotAccelerationAltitude: number,
defaultAccelerationAltitude: number,
pilotAccelerationAltitude: number | undefined,
defaultAccelerationAltitude: number | undefined,

pilotEngineOutAccelerationAltitude: number,
defaultEngineOutAccelerationAltitude: number,
pilotEngineOutAccelerationAltitude: number | undefined,
defaultEngineOutAccelerationAltitude: number | undefined,

pilotMissedThrustReductionAltitude: number,
defaultMissedThrustReductionAltitude: number,
pilotMissedThrustReductionAltitude: number | undefined,
defaultMissedThrustReductionAltitude: number | undefined,

pilotMissedAccelerationAltitude: number,
defaultMissedAccelerationAltitude: number,
pilotMissedAccelerationAltitude: number | undefined,
defaultMissedAccelerationAltitude: number | undefined,

pilotMissedEngineOutAccelerationAltitude: number,
defaultMissedEngineOutAccelerationAltitude: number,
pilotMissedEngineOutAccelerationAltitude: number | undefined,
defaultMissedEngineOutAccelerationAltitude: number | undefined,

databaseTransitionAltitude: number,
pilotTransitionAltitude: number,
databaseTransitionAltitude: number | undefined,
pilotTransitionAltitude: number | undefined,

databaseTransitionLevel: number,
pilotTransitionLevel: number,
databaseTransitionLevel: number | undefined,
pilotTransitionLevel: number | undefined,
}

0 comments on commit f3b66b0

Please sign in to comment.