Skip to content

Commit

Permalink
fix(a380x/fms): f speed generation (flybywiresim#8965)
Browse files Browse the repository at this point in the history
* fix(fms): set f speed rather than vfto

* fix: optimise speed local var writes

* docs: add spdx
  • Loading branch information
tracernz authored Sep 22, 2024
1 parent d1c7964 commit 5625f5c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2023-2024 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0

import { FlightPlanService } from '@fmgc/flightplanning/FlightPlanService';
import { GuidanceController } from '@fmgc/guidance/GuidanceController';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { EventBus, UnitType } from '@microsoft/msfs-sdk';
// Copyright (c) 2023-2024 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0

import { EventBus, SimVarValueType, Subject, UnitType } from '@microsoft/msfs-sdk';
import { Arinc429SignStatusMatrix, Arinc429Word } from '@flybywiresim/fbw-sdk';
import { FmsOansData } from 'instruments/src/MsfsAvionicsCommon/providers/FmsOansPublisher';
import { FlapConf } from '@fmgc/guidance/vnav/common';
Expand All @@ -17,13 +20,6 @@ import { FmcInterface } from 'instruments/src/MFD/FMC/FmcInterface';
* Essentially part of the FMC (-A/-B/-C)
*/
export class FmcAircraftInterface {
constructor(
private bus: EventBus,
private fmc: FmcInterface,
private fmgc: FmgcDataService,
private flightPlanService: FlightPlanService,
) {}

// ARINC words
// arinc bus output words
public arincDiscreteWord2 = FmArinc429OutputWord.emptyFm('DISCRETE_WORD_2');
Expand Down Expand Up @@ -82,6 +78,44 @@ export class FmcAircraftInterface {
this.arincEisWord2,
];

private readonly speedAlphaProt = Subject.create(0);
private readonly speedAlphaMax = Subject.create(0);
private readonly speedAlphaStall = Subject.create(0);
private readonly speedVs1g = Subject.create(0);
private readonly speedVls = Subject.create(0);
private readonly speedVmax = Subject.create(0);
private readonly speedVfeNext = Subject.create(0);
private readonly speedVapp = Subject.create(0);

constructor(
private bus: EventBus,
private fmc: FmcInterface,
private fmgc: FmgcDataService,
private flightPlanService: FlightPlanService,
) {
this.init();
}

private init(): void {
// write local vars for other systems
this.fmgc.data.greenDotSpeed.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_GD', 'number', v), true);
this.fmgc.data.slatRetractionSpeed.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_S', 'number', v), true);
this.fmgc.data.flapRetractionSpeed.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_F', 'number', v), true);

this.speedAlphaProt.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_ALPHA_PROTECTION_CALC', 'number', v), true);
this.speedAlphaMax.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_ALPHA_MAX_CALC', 'number', v), true);
this.speedAlphaStall.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_STALL_WARN', 'number', v), true);
this.speedVs1g.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_VS', 'number', v), true);
this.speedVls.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_VLS', 'number', v), true);
this.speedVmax.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_VMAX', 'number', v), true);
this.speedVfeNext.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_VFEN', 'number', v), true);
this.speedVapp.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_VAPP', 'number', v), true);

this.fmgc.data.approachFlapConfig
.map((v) => v === FlapConf.CONF_3)
.sub((v) => SimVar.SetSimVarValue('L:A32NX_SPEEDS_LANDING_CONF3', SimVarValueType.Bool, v), true);
}

thrustReductionAccelerationChecks() {
const activePlan = this.flightPlanService.active;

Expand Down Expand Up @@ -1079,35 +1113,30 @@ export class FmcAircraftInterface {
towerHeadwind,
);

SimVar.SetSimVarValue('L:A32NX_SPEEDS_ALPHA_PROTECTION_CALC', 'number', speeds.alphaProt);
SimVar.SetSimVarValue('L:A32NX_SPEEDS_ALPHA_MAX_CALC', 'number', speeds.alphaMax);
SimVar.SetSimVarValue('L:A32NX_SPEEDS_STALL_WARN', 'number', speeds.alphaStallWarn);
SimVar.SetSimVarValue('L:A32NX_SPEEDS_VS', 'number', speeds.vs1g);
SimVar.SetSimVarValue('L:A32NX_SPEEDS_VLS', 'number', speeds.vls);
this.speedAlphaProt.set(Math.round(speeds.alphaProt));
this.speedAlphaMax.set(Math.round(speeds.alphaMax));
this.speedAlphaStall.set(Math.round(speeds.alphaStallWarn));
this.speedVs1g.set(Math.round(speeds.vs1g));
this.speedVls.set(Math.round(speeds.vls));

if (this.fmgc.getFlightPhase() === FmgcFlightPhase.Preflight) {
const f = Math.max(speeds.f2, Vmcl + 5);
SimVar.SetSimVarValue('L:A32NX_SPEEDS_F', 'number', f);
this.fmgc.data.greenDotSpeed.set(Math.ceil(f));
this.fmgc.data.flapRetractionSpeed.set(Math.ceil(f));
} else {
if (flaps === 2) {
const f = Math.max(speeds.f2, Vmcl + 15);
SimVar.SetSimVarValue('L:A32NX_SPEEDS_F', 'number', f);
this.fmgc.data.greenDotSpeed.set(Math.ceil(f));
this.fmgc.data.flapRetractionSpeed.set(Math.ceil(f));
} else if (flaps === 3) {
const f = Math.max(speeds.f3, Vmcl + 10);
SimVar.SetSimVarValue('L:A32NX_SPEEDS_F', 'number', f);
this.fmgc.data.greenDotSpeed.set(Math.ceil(f));
this.fmgc.data.flapRetractionSpeed.set(Math.ceil(f));
}
}

SimVar.SetSimVarValue('L:A32NX_SPEEDS_S', 'number', speeds.s);
this.fmgc.data.slatRetractionSpeed.set(Math.ceil(speeds.s));
SimVar.SetSimVarValue('L:A32NX_SPEEDS_GD', 'number', speeds.gd);
this.fmgc.data.greenDotSpeed.set(Math.ceil(speeds.gd));

SimVar.SetSimVarValue('L:A32NX_SPEEDS_VMAX', 'number', speeds.vmax);
SimVar.SetSimVarValue('L:A32NX_SPEEDS_VFEN', 'number', speeds.vfeN);
this.speedVmax.set(Math.round(speeds.vmax));
this.speedVfeNext.set(Math.round(speeds.vfeN));

const approachSpeeds = new A380OperatingSpeeds(
ldgWeight / 1000,
Expand All @@ -1120,13 +1149,7 @@ export class FmcAircraftInterface {
this.fmgc.data.approachSpeed.set(Math.ceil(approachSpeeds.vapp));
this.fmgc.data.approachVls.set(Math.ceil(approachSpeeds.vls));
this.fmgc.data.approachVref.set(Math.ceil(approachSpeeds.vref));
SimVar.SetSimVarValue('L:A32NX_SPEEDS_VAPP', 'number', approachSpeeds.vapp); // Needed for ROP/BTV

SimVar.SetSimVarValue(
'L:A32NX_SPEEDS_LANDING_CONF3',
'boolean',
this.fmgc.data.approachFlapConfig.get() === FlapConf.CONF_3,
);
this.speedVapp.set(Math.round(approachSpeeds.vapp));
}

/** Write gross weight to SimVar */
Expand Down
3 changes: 3 additions & 0 deletions fbw-a380x/src/systems/instruments/src/MFD/FMC/fmgc.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2023-2024 FlyByWire Simulations
// SPDX-License-Identifier: GPL-3.0

import { FlightPlanService } from '@fmgc/flightplanning/FlightPlanService';
import { Fmgc, GuidanceController } from '@fmgc/guidance/GuidanceController';

Expand Down

0 comments on commit 5625f5c

Please sign in to comment.