Skip to content

Commit

Permalink
fix(mathutils): remove machToKCas temperature dependency (#9771)
Browse files Browse the repository at this point in the history
  • Loading branch information
tracernz authored Jan 17, 2025
1 parent 0984434 commit 2c9109b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
19 changes: 2 additions & 17 deletions fbw-a380x/src/systems/shared/src/OperatingSpeeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,29 +402,14 @@ function getVfeNIdx(fi: number): number {
}
}

/**
* Convert degrees Celsius into Kelvin
* @param T degrees Celsius
* @returns degrees Kelvin
*/
function convertCtoK(T: number): number {
return T + 273.15;
}

/**
* Get correct Vmax for Vmo and Mmo in knots
* @returns Min(Vmo, Mmo)
* @private
*/
function getVmo() {
return Math.min(
Vmo,
MathUtils.convertMachToKCas(
Mmo,
convertCtoK(Simplane.getAmbientTemperature()),
SimVar.GetSimVarValue('AMBIENT PRESSURE', 'millibar'),
),
);
// FIXME use ADR corrected average static pressure
return Math.min(Vmo, MathUtils.convertMachToKCas(Mmo, SimVar.GetSimVarValue('AMBIENT PRESSURE', 'millibar')));
}

export class A380OperatingSpeeds {
Expand Down
10 changes: 10 additions & 0 deletions fbw-common/src/systems/shared/src/MathUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,14 @@ describe('MathUtils.correctMsfsLocaliserError', () => {
expect(MathUtils.correctMsfsLocaliserError(177.5)).toBeCloseTo(2.5);
expect(MathUtils.correctMsfsLocaliserError(90.1)).toBeCloseTo(89.9);
});

describe('MathUtils.convertMachToKCas', () => {
it('correctly converts mach to CAS', () => {
expect(MathUtils.convertMachToKCas(0, 1013.25)).toBeCloseTo(0);
expect(MathUtils.convertMachToKCas(0.84, 1013.25)).toBeCloseTo(555.634);
// FL350 = 238.423 hPa
expect(MathUtils.convertMachToKCas(0, 238.423)).toBeCloseTo(0);
expect(MathUtils.convertMachToKCas(0.84, 238.423)).toBeCloseTo(287.097);
});
});
});
11 changes: 7 additions & 4 deletions fbw-common/src/systems/shared/src/MathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class MathUtils {
return (
1479.1 *
Math.sqrt(
((pressure / 1013) * ((1 + (1 / (oat / 288.15)) * (tas / 1479.1) ** 2) ** 3.5 - 1) + 1) ** (1 / 3.5) - 1,
((pressure / 1013.25) * ((1 + (1 / (oat / 288.15)) * (tas / 1479.1) ** 2) ** 3.5 - 1) + 1) ** (1 / 3.5) - 1,
)
);
}
Expand All @@ -306,7 +306,7 @@ export class MathUtils {
1479.1 *
Math.sqrt(
(oat / 288.15) *
(((1 / (pressure / 1013)) * ((1 + 0.2 * (kcas / 661.4786) ** 2) ** 3.5 - 1) + 1) ** (1 / 3.5) - 1),
(((1 / (pressure / 1013.25)) * ((1 + 0.2 * (kcas / 661.4786) ** 2) ** 3.5 - 1) + 1) ** (1 / 3.5) - 1),
)
);
}
Expand All @@ -318,8 +318,11 @@ export class MathUtils {
* @param pressure current pressure hpa
* @returns Calibrated Air Speed
*/
public static convertMachToKCas(mach: number, oat: number, pressure: number): number {
return MathUtils.convertTasToKCas(MathUtils.convertMachToKTas(mach, oat), oat, pressure);
public static convertMachToKCas(mach: number, pressure: number): number {
// Formula from Jet Transport Performance Methods 2009.
return (
1479.1 * Math.sqrt(Math.pow((pressure / 1013.25) * (Math.pow(0.2 * mach * mach + 1, 3.5) - 1) + 1, 1 / 3.5) - 1)
);
}

/**
Expand Down

0 comments on commit 2c9109b

Please sign in to comment.