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(mathutils): remove machToKCas temperature dependency #9771

Merged
merged 1 commit into from
Jan 17, 2025
Merged
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
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
Loading