Skip to content

Commit

Permalink
fix: undo newRa changes, reverted accidental igniter change, restored…
Browse files Browse the repository at this point in the history
… VS line on PFD
  • Loading branch information
2hwk committed Sep 30, 2021
1 parent 6f11595 commit 7babfea
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/instruments/buildSrc/igniter/tasks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const ecamPages = [

export function getInputs() {
const baseInstruments = fs.readdirSync(join(Directories.instruments, 'src'), { withFileTypes: true })
.filter((d) => d.isDirectory() && d.name === 'ND' && fs.existsSync(join(Directories.instruments, 'src', d.name, 'config.json')));
.filter((d) => d.isDirectory() && fs.existsSync(join(Directories.instruments, 'src', d.name, 'config.json')));

return [
...baseInstruments.map(({ name }) => ({ path: name, name, isInstrument: true })),
Expand Down
2 changes: 1 addition & 1 deletion src/instruments/src/PFD/VerticalSpeedIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const VerticalSpeedIndicator = ({ radioAlt, verticalSpeed }: VerticalSpee
isAmber = true;
}

const yOffset = getYoffset(verticalSpeed);
const yOffset = getYoffset(verticalSpeed.value);

const [tcasState] = useSimVar('L:A32NX_TCAS_STATE', 'Enum', 200);
const [tcasCorrective] = useSimVar('L:A32NX_TCAS_RA_CORRECTIVE', 'Boolean', 200);
Expand Down
127 changes: 59 additions & 68 deletions src/tcas/src/components/TCasComputer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class TCasComputer implements TCasComponent {

private activeRa: ResAdvisory | null; // Currently Active RA

private _newRa: ResAdvisory | null; // avoiding GC
// private _newRa: ResAdvisory | null; // avoiding GC

private inhibitions: Inhibit;

Expand Down Expand Up @@ -205,10 +205,11 @@ export class TCasComputer implements TCasComponent {
this.ppos = { lat: NaN, long: NaN };
this._pposLatLong = new LatLong(NaN, NaN);
this._trafficPpos = new LatLong(NaN, NaN);
this._newRa = new ResAdvisory(null, false, 0, false);
// this._newRa = new ResAdvisory(null, false, 0, false);
this.advisoryState = TcasState.NONE;
this.sendAirTraffic = [];
this.activeRa = new ResAdvisory(null, false, 0, false);
// this.activeRa = new ResAdvisory(null, false, 0, false);
this.activeRa = null;
this.soundManager = new TCasSoundManager();
}

Expand All @@ -234,7 +235,7 @@ export class TCasComputer implements TCasComponent {
}

private updateSensitivity(): void {
if (this.activeRa.info === null) {
if (this.activeRa === null) {
if (this.radioAlt < 1000 || this.tcasMode === 1) {
this.sensitivity = 2;
} else if (this.radioAlt <= 2350 && this.radioAlt > 1000) {
Expand Down Expand Up @@ -427,10 +428,10 @@ export class TCasComputer implements TCasComponent {
raTime = _deltaTime;
}
*/
const raTime = _deltaTime;
this.getRa(raTime);
const raTime: number = _deltaTime;
const newRa: ResAdvisory = this.getRa(raTime);
this.updateInhibitions();
this.updateAdvisoryState(raTime);
this.updateAdvisoryState(raTime, newRa);
}

private calculateTrajectory(targetVS: number, traffic: TcasTraffic, delay: number, accel: number): number {
Expand Down Expand Up @@ -501,30 +502,24 @@ export class TCasComputer implements TCasComponent {
return [minSeparation, isCrossing];
}

private getRa(_deltaTime: number): void {
private getRa(_deltaTime: number): ResAdvisory {
// TODO: Store 10 most recent RA and 60 most recent TA - AMM 34-43-00:6
// TODO: Red TCAS error messages on PFD and ND
if (!this.altitude || !this.altitudeStandby
|| !this.altitude.isNormalOperation() || !this.altitudeStandby.isNormalOperation() || this.altitude.value - this.altitudeStandby.value > 300) {
this._newRa.info = null;
return;
return null;
}

this.raTraffic = this.airTraffic
.filter((traffic) => traffic.intrusionLevel === TaRaIntrusion.RA && traffic.raTau !== Infinity)
.sort((a, b) => a.raTau - b.raTau);
this._newRa.info = null;
this._newRa.isReversal = false;
this._newRa.secondsSinceStart = 0;
this._newRa.hasBeenAnnounced = false;
// const newRa = this.activeRa;
this.raTraffic = this.airTraffic.filter((traffic) => traffic.intrusionLevel === 3 && traffic.raTau !== Infinity);
const newRa: ResAdvisory = new ResAdvisory(null, false, 0, false);
const previousRa = this.activeRa;
const ALIM = TcasConst.ALIM[this.sensitivity];

if (this.activeRa.info === null) {
if (this.activeRa === null) {
// First RA
if (this.raTraffic.length === 0) {
this._newRa.info = null;
return;
return null;
}

const [upVerticalSep, upIsCrossing]: [number, boolean] = this.getVerticalSep(
Expand All @@ -545,7 +540,7 @@ export class TCasComputer implements TCasComponent {

console.log('TCAS: INITIAL RA: SELECTING SENSE');
console.log('---------------------------------');
console.log(`UP VERTICAL SEPARATION at 1500: ${upVerticalSep}; upIsCrssing: ${upIsCrossing}`);
console.log(`UP VERTICAL SEPARATION at 1500: ${upVerticalSep}; upIsCrossing: ${upIsCrossing}`);
console.log(`DOWN VERTICAL SEPARATION at -1500: ${downVerticalSep}; downIsCrossing: ${downIsCrossing}`);
console.log('ALIM IS ', ALIM);

Expand Down Expand Up @@ -583,7 +578,6 @@ export class TCasComputer implements TCasComponent {
TcasConst.INITIAL_DELAY,
TcasConst.INITIAL_ACCEL,
);
console.log(`levelSep is: ${levelSep}`);
if (Math.abs(this.verticalSpeed) < 1500 || (this.verticalSpeed <= -1500 && sense === RaSense.UP) || (this.verticalSpeed >= 1500 && sense === RaSense.DOWN)) {
// Choose preventive or corrective
const predictedSep = this.getPredictedSep();
Expand Down Expand Up @@ -613,62 +607,61 @@ export class TCasComputer implements TCasComponent {
// Find preventive RA's which achieve ALIM
// If none achieve ALIM, then use nominal RA
if (sep2000 >= ALIM) {
this._newRa.info = (sense === RaSense.UP) ? TcasConst.RA_VARIANTS.monitor_vs_climb_2000 : TcasConst.RA_VARIANTS.monitor_vs_descend_2000;
newRa.info = (sense === RaSense.UP) ? TcasConst.RA_VARIANTS.monitor_vs_climb_2000 : TcasConst.RA_VARIANTS.monitor_vs_descend_2000;
} else if (sep1000 >= ALIM) {
this._newRa.info = (sense === RaSense.UP) ? TcasConst.RA_VARIANTS.monitor_vs_climb_1000 : TcasConst.RA_VARIANTS.monitor_vs_descend_1000;
newRa.info = (sense === RaSense.UP) ? TcasConst.RA_VARIANTS.monitor_vs_climb_1000 : TcasConst.RA_VARIANTS.monitor_vs_descend_1000;
} else if (sep500 >= ALIM) {
this._newRa.info = (sense === RaSense.UP) ? TcasConst.RA_VARIANTS.monitor_vs_climb_500 : TcasConst.RA_VARIANTS.monitor_vs_descend_500;
newRa.info = (sense === RaSense.UP) ? TcasConst.RA_VARIANTS.monitor_vs_climb_500 : TcasConst.RA_VARIANTS.monitor_vs_descend_500;
} else if (levelSep >= ALIM) {
this._newRa.info = (sense === RaSense.UP) ? TcasConst.RA_VARIANTS.monitor_vs_climb_0 : TcasConst.RA_VARIANTS.monitor_vs_descend_0;
newRa.info = (sense === RaSense.UP) ? TcasConst.RA_VARIANTS.monitor_vs_climb_0 : TcasConst.RA_VARIANTS.monitor_vs_descend_0;
} else if (sense === RaSense.UP) {
this._newRa.info = upIsCrossing ? TcasConst.RA_VARIANTS.climb_cross : TcasConst.RA_VARIANTS.climb;
newRa.info = upIsCrossing ? TcasConst.RA_VARIANTS.climb_cross : TcasConst.RA_VARIANTS.climb;
} else {
this._newRa.info = downIsCrossing ? TcasConst.RA_VARIANTS.descend_cross : TcasConst.RA_VARIANTS.descend;
newRa.info = downIsCrossing ? TcasConst.RA_VARIANTS.descend_cross : TcasConst.RA_VARIANTS.descend;
}
} else {
// Corrective RA (either climb/descend or level off)
const nominalSep = sense === RaSense.UP ? upVerticalSep : downVerticalSep;
if (nominalSep > levelSep) {
if (sense === RaSense.UP) {
this._newRa.info = upIsCrossing ? TcasConst.RA_VARIANTS.climb_cross : TcasConst.RA_VARIANTS.climb;
newRa.info = upIsCrossing ? TcasConst.RA_VARIANTS.climb_cross : TcasConst.RA_VARIANTS.climb;
} else {
this._newRa.info = downIsCrossing ? TcasConst.RA_VARIANTS.descend_cross : TcasConst.RA_VARIANTS.descend;
newRa.info = downIsCrossing ? TcasConst.RA_VARIANTS.descend_cross : TcasConst.RA_VARIANTS.descend;
}
} else {
this._newRa.info = sense === RaSense.UP ? TcasConst.RA_VARIANTS.level_off_300_above : TcasConst.RA_VARIANTS.level_off_300_below;
newRa.info = sense === RaSense.UP ? TcasConst.RA_VARIANTS.level_off_300_above : TcasConst.RA_VARIANTS.level_off_300_below;
}
}
} else {
// We're above 1500 FPM already, so either maintain VS or level off
const nominalSep = sense === RaSense.UP ? upVerticalSep : downVerticalSep;
if (nominalSep > levelSep) {
if (sense === RaSense.UP) {
this._newRa.info = upIsCrossing ? TcasConst.RA_VARIANTS.climb_maintain_vs_crossing : TcasConst.RA_VARIANTS.climb_maintain_vs;
newRa.info = upIsCrossing ? TcasConst.RA_VARIANTS.climb_maintain_vs_crossing : TcasConst.RA_VARIANTS.climb_maintain_vs;
} else {
this._newRa.info = downIsCrossing ? TcasConst.RA_VARIANTS.descend_maintain_vs_crossing : TcasConst.RA_VARIANTS.descend_maintain_vs;
newRa.info = downIsCrossing ? TcasConst.RA_VARIANTS.descend_maintain_vs_crossing : TcasConst.RA_VARIANTS.descend_maintain_vs;
}
} else {
this._newRa.info = sense === RaSense.UP ? TcasConst.RA_VARIANTS.level_off_300_above : TcasConst.RA_VARIANTS.level_off_300_below;
newRa.info = sense === RaSense.UP ? TcasConst.RA_VARIANTS.level_off_300_above : TcasConst.RA_VARIANTS.level_off_300_below;
}
}
} else {
// There is a previous RA, so revise it if necessary
// If no RA threats, then just return null
if (this.raTraffic.length === 0) {
this._newRa.info = null;
return;
return null;
}

// let alreadyAchievedALIM = true;
let alreadyAchievedTaZTHR = true;
let minTimeToCPA = TcasConst.REALLY_BIG_NUMBER;
this.raTraffic.forEach((traffic) => {
/*
if (Math.abs(this.pressureAlt - traffic.alt) < ALIM) {
if (Math.abs(this.altitude.value - traffic.alt) < ALIM) {
alreadyAchievedALIM = false;
}
*/
if (Math.abs(this.pressureAlt - traffic.alt) < TcasConst.ZTHR[this.sensitivity][TaRaIndex.TA]) {
if (Math.abs(this.altitude.value - traffic.alt) < TcasConst.taRaInfo[this.sensitivity][TaRaInfo.ZTHR][TaRa.TA]) {
alreadyAchievedTaZTHR = false;
}
if (traffic.raTau < minTimeToCPA) {
Expand All @@ -677,8 +670,8 @@ export class TCasComputer implements TCasComponent {
});

const sense = previousRa.info.sense;
this._newRa.isReversal = previousRa.isReversal;
this._newRa.secondsSinceStart = previousRa.secondsSinceStart;
newRa.isReversal = previousRa.isReversal;
newRa.secondsSinceStart = previousRa.secondsSinceStart;

if (alreadyAchievedTaZTHR) {
// We've already achieved TA ZTHR (formerly ALIM)
Expand All @@ -693,11 +686,11 @@ export class TCasComputer implements TCasComponent {
if (previousRa.secondsSinceStart >= 10
&& previousRa.info.callout.id !== TcasConst.CALLOUTS.level_off.id
&& previousRa.info.callout.id !== TcasConst.CALLOUTS.monitor_vs.id) {
this._newRa.info = (previousRa.info.sense === RaSense.UP) ? TcasConst.RA_VARIANTS.level_off_300_above : TcasConst.RA_VARIANTS.level_off_300_below;
newRa.info = (previousRa.info.sense === RaSense.UP) ? TcasConst.RA_VARIANTS.level_off_300_above : TcasConst.RA_VARIANTS.level_off_300_below;
} else {
// Continue with same RA
this._newRa.info = previousRa.info;
this._newRa.hasBeenAnnounced = true;
newRa.info = previousRa.info;
newRa.hasBeenAnnounced = true;
}
} else {
const predictedSep = this.getPredictedSep(); // need this to factor in level off/maintain VS RA's
Expand Down Expand Up @@ -751,10 +744,10 @@ export class TCasComputer implements TCasComponent {
// Can only increase strength if able
if (strengthenRaInfo === null) {
// We're at the strongest RA type possible. So cannot reverse.
this._newRa.info = previousRa.info;
this._newRa.hasBeenAnnounced = true;
newRa.info = previousRa.info;
newRa.hasBeenAnnounced = true;
} else {
this._newRa.info = strengthenRaInfo;
newRa.info = strengthenRaInfo;
}
} else {
// Haven't reversed before, so it's still a possibility
Expand All @@ -770,44 +763,45 @@ export class TCasComputer implements TCasComponent {
// If cannot increase RA, then pick between current separation and reverse
if (strengthenRaInfo === null) {
if (predictedSep >= reverseSep) {
this._newRa.info = previousRa.info;
this._newRa.hasBeenAnnounced = true;
return;
newRa.info = previousRa.info;
newRa.hasBeenAnnounced = true;
return newRa;
}
this._newRa.info = (reversedSense === RaSense.UP) ? TcasConst.RA_VARIANTS.climb_now : TcasConst.RA_VARIANTS.descend_now;
this._newRa.isReversal = true;
newRa.info = (reversedSense === RaSense.UP) ? TcasConst.RA_VARIANTS.climb_now : TcasConst.RA_VARIANTS.descend_now;
newRa.isReversal = true;
}

// If both achieve ALIM, prefer non-reversal
if (increaseSep >= ALIM && reverseSep >= ALIM) {
this._newRa.info = strengthenRaInfo;
newRa.info = strengthenRaInfo;
}

// If neither achieve ALIM, choose sense with greatest separation
if (increaseSep < ALIM && reverseSep < ALIM) {
if (increaseSep >= reverseSep) {
this._newRa.info = strengthenRaInfo;
newRa.info = strengthenRaInfo;
} else {
this._newRa.info = (reversedSense === RaSense.UP) ? TcasConst.RA_VARIANTS.climb_now : TcasConst.RA_VARIANTS.descend_now;
this._newRa.isReversal = true;
newRa.info = (reversedSense === RaSense.UP) ? TcasConst.RA_VARIANTS.climb_now : TcasConst.RA_VARIANTS.descend_now;
newRa.isReversal = true;
}
}

// If only one achieves ALIM, pick it
if (increaseSep >= ALIM && reverseSep < ALIM) {
this._newRa.info = strengthenRaInfo;
newRa.info = strengthenRaInfo;
} else {
this._newRa.info = (reversedSense === RaSense.UP) ? TcasConst.RA_VARIANTS.climb_now : TcasConst.RA_VARIANTS.descend_now;
this._newRa.isReversal = true;
newRa.info = (reversedSense === RaSense.UP) ? TcasConst.RA_VARIANTS.climb_now : TcasConst.RA_VARIANTS.descend_now;
newRa.isReversal = true;
}
}
} else {
// Continue with same RA
this._newRa.info = previousRa.info;
this._newRa.hasBeenAnnounced = true;
newRa.info = previousRa.info;
newRa.hasBeenAnnounced = true;
}
}
}
return newRa;
}

/**
Expand Down Expand Up @@ -838,7 +832,7 @@ export class TCasComputer implements TCasComponent {
*/
}

private updateAdvisoryState(_deltaTime) {
private updateAdvisoryState(_deltaTime:number, _ra: ResAdvisory): void {
const taThreatCount = this.airTraffic.reduce((acc, aircraft) => acc + (aircraft.intrusionLevel === TaRaIntrusion.TA ? 1 : 0), 0);
const raThreatCount = this.airTraffic.reduce((acc, aircraft) => acc + (aircraft.intrusionLevel === TaRaIntrusion.RA ? 1 : 0), 0);

Expand All @@ -848,6 +842,7 @@ export class TCasComputer implements TCasComponent {
this.advisoryState = TcasState.RA;
SimVar.SetSimVarValue('L:A32NX_TCAS_STATE', 'Enum', 2);
console.log('TCAS: TA UPGRADED TO RA');
console.log('_ra:', _ra);
} else if (taThreatCount === 0) {
this.advisoryState = TcasState.NONE;
SimVar.SetSimVarValue('L:A32NX_TCAS_STATE', 'Enum', 0);
Expand All @@ -865,7 +860,7 @@ export class TCasComputer implements TCasComponent {
}
console.log('TCAS: CLEAR OF CONFLICT');
this.soundManager.tryPlaySound(TcasConst.SOUNDS.clear_of_conflict, true);
this.activeRa.info = null;
this.activeRa = null;
}
break;
default:
Expand All @@ -884,12 +879,8 @@ export class TCasComputer implements TCasComponent {
break;
}

if (this._newRa.info !== null && this.advisoryState === TcasState.RA) {
this.activeRa.info = this._newRa.info;
this.activeRa.isReversal = this._newRa.isReversal;
this.activeRa.secondsSinceStart = this._newRa.secondsSinceStart;
this.activeRa.hasBeenAnnounced = this._newRa.hasBeenAnnounced;
this.activeRa.secondsSinceStart += _deltaTime / 1000;
if (_ra !== null && this.advisoryState === TcasState.RA) {
this.activeRa = _ra;
if (!this.activeRa.hasBeenAnnounced) {
console.log('TCAS: RA GENERATED: ', this.activeRa.info.callout);

Expand Down

0 comments on commit 7babfea

Please sign in to comment.