mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Tracked aircraft keep moving when reports give no speed or a stale one
A fix that moves while the reported speed is 0 or stale used to leave the aircraft frozen, then jump it kilometres at once. The step between fixes now measures a jump, and the drawn speed bounds the recovery.
This commit is contained in:
1 parent
22952f8f16
commit
e3cfdcf44e
7 files changed
+131
-12
No files matched your search
@@ -270,3 +270,50 @@ export function staleCoastSeconds(newest, info, cachedGroundFloor) {
|
|||||||
: 0;
|
: 0;
|
||||||
return Math.max(0, Math.min(limitSec, STALE_COAST_MAX_SEC - alreadySec));
|
return Math.max(0, Math.min(limitSec, STALE_COAST_MAX_SEC - alreadySec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A raw position this far (m) off its own path, plus half its step, is a jump. */
|
||||||
|
const RAW_JUMP_SLACK_M = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a tracked aircraft's raw position jumped this frame: a new report
|
||||||
|
* moved its path. Judged against the path itself, where its last frame's
|
||||||
|
* step carries it, not against a reported speed (which can be stale or 0
|
||||||
|
* while the drawn motion, minutes behind the newest report, is fast). A
|
||||||
|
* frame with no step to go by (the first on a track, or the one after a
|
||||||
|
* jump) is never a jump.
|
||||||
|
* @param {{x: number, y: number, z: number}} raw This frame's raw position.
|
||||||
|
* @param {{x: number, y: number, z: number}} prevRaw Last frame's.
|
||||||
|
* @param {{x: number, y: number, z: number}} prevRawStep Last frame's step.
|
||||||
|
* @param {number} prevRawStepSec Last frame's length, s (0: no step).
|
||||||
|
* @param {number} dtSec This frame's length, s.
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
export function rawPositionJumped(
|
||||||
|
raw,
|
||||||
|
prevRaw,
|
||||||
|
prevRawStep,
|
||||||
|
prevRawStepSec,
|
||||||
|
dtSec,
|
||||||
|
) {
|
||||||
|
if (!(prevRawStepSec > 0)) return false;
|
||||||
|
const k = dtSec / prevRawStepSec;
|
||||||
|
const dx = raw.x - (prevRaw.x + prevRawStep.x * k);
|
||||||
|
const dy = raw.y - (prevRaw.y + prevRawStep.y * k);
|
||||||
|
const dz = raw.z - (prevRaw.z + prevRawStep.z * k);
|
||||||
|
const stepM =
|
||||||
|
Math.hypot(prevRawStep.x, prevRawStep.y, prevRawStep.z) * Math.abs(k);
|
||||||
|
return Math.hypot(dx, dy, dz) > RAW_JUMP_SLACK_M + 0.5 * stepM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How fast the drawn path moves (m/s), from its last raw step; `fallback`
|
||||||
|
* (a reported speed) with no step to go by.
|
||||||
|
* @param {{x: number, y: number, z: number}} step
|
||||||
|
* @param {number} stepSec
|
||||||
|
* @param {number} fallback
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
export function rawStepSpeedMps(step, stepSec, fallback) {
|
||||||
|
if (!(stepSec > 0)) return fallback;
|
||||||
|
return Math.hypot(step.x, step.y, step.z) / stepSec;
|
||||||
|
}
|
||||||
@@ -78,6 +78,8 @@ import {
|
|||||||
fixSpeedMps,
|
fixSpeedMps,
|
||||||
fixTrackDeg,
|
fixTrackDeg,
|
||||||
staleCoastSeconds,
|
staleCoastSeconds,
|
||||||
|
rawPositionJumped,
|
||||||
|
rawStepSpeedMps,
|
||||||
} from '../../data/aircraftMotionRegime.js';
|
} from '../../data/aircraftMotionRegime.js';
|
||||||
|
|
||||||
/** Whether two ECEF points are the same point, component for component. */
|
/** Whether two ECEF points are the same point, component for component. */
|
||||||
@@ -453,12 +455,18 @@ export function createMotion({
|
|||||||
(worldMs - flightState._drPrevWorldMs) / 1000,
|
(worldMs - flightState._drPrevWorldMs) / 1000,
|
||||||
);
|
);
|
||||||
let snapped = false;
|
let snapped = false;
|
||||||
|
let jumpedThisFrame = false;
|
||||||
if (sameTrack) {
|
if (sameTrack) {
|
||||||
const speed = (info && info.velocity) || 0;
|
const speed = (info && info.velocity) || 0;
|
||||||
// Plausible single-frame motion (m): its speed × frame Δt, half again
|
// A jump: a new report moved the path the raw position is on.
|
||||||
// for slack, plus 5 m. More is a jump (a new report put it elsewhere).
|
const jumped = rawPositionJumped(
|
||||||
const plausible = speed * dtSec * 1.5 + 5;
|
raw,
|
||||||
if (distance(raw, flightState._drPrevRaw) > plausible) {
|
flightState._drPrevRaw,
|
||||||
|
flightState._drPrevRawStep,
|
||||||
|
flightState._drPrevRawStepSec,
|
||||||
|
dtSec,
|
||||||
|
);
|
||||||
|
if (jumped) {
|
||||||
// Discontinuity — re-anchor so the DISPLAYED position stays continuous,
|
// Discontinuity — re-anchor so the DISPLAYED position stays continuous,
|
||||||
// then ease onto the new path no faster than a little over its speed;
|
// then ease onto the new path no faster than a little over its speed;
|
||||||
// farther off than RECOVER_SNAP_M it is a break, and it jumps.
|
// farther off than RECOVER_SNAP_M it is a break, and it jumps.
|
||||||
@@ -476,12 +484,22 @@ export function createMotion({
|
|||||||
)
|
)
|
||||||
: flightState._drPrevDisplay;
|
: flightState._drPrevDisplay;
|
||||||
const errorM = distance(anchor, raw);
|
const errorM = distance(anchor, raw);
|
||||||
|
jumpedThisFrame = true;
|
||||||
snapped = errorM >= RECOVER_SNAP_M;
|
snapped = errorM >= RECOVER_SNAP_M;
|
||||||
copyInto(snapped ? vec() : sub(anchor, raw), flightState._drCorrection);
|
copyInto(snapped ? vec() : sub(anchor, raw), flightState._drCorrection);
|
||||||
flightState._drCorrectionStartMs = nowMs;
|
flightState._drCorrectionStartMs = nowMs;
|
||||||
flightState._drCorrectionMs = Math.max(
|
flightState._drCorrectionMs = Math.max(
|
||||||
DR_CORRECTION_MS,
|
DR_CORRECTION_MS,
|
||||||
recoveryMs(errorM, speed),
|
// As fast as the path it was drawn on moves: the newest report's
|
||||||
|
// speed can be stale or 0 minutes ahead of it.
|
||||||
|
recoveryMs(
|
||||||
|
errorM,
|
||||||
|
rawStepSpeedMps(
|
||||||
|
flightState._drPrevRawStep,
|
||||||
|
flightState._drPrevRawStepSec,
|
||||||
|
speed,
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -523,6 +541,12 @@ export function createMotion({
|
|||||||
);
|
);
|
||||||
flightState._drPrevStepSec = dtSec;
|
flightState._drPrevStepSec = dtSec;
|
||||||
} else flightState._drPrevStepSec = 0;
|
} else flightState._drPrevStepSec = 0;
|
||||||
|
// The raw step, to judge the next frame by; none after a jump (its
|
||||||
|
// step is the jump) or a track switch.
|
||||||
|
if (sameTrack && !jumpedThisFrame) {
|
||||||
|
copyInto(sub(raw, flightState._drPrevRaw), flightState._drPrevRawStep);
|
||||||
|
flightState._drPrevRawStepSec = dtSec;
|
||||||
|
} else flightState._drPrevRawStepSec = 0;
|
||||||
copyInto(raw, flightState._drPrevRaw);
|
copyInto(raw, flightState._drPrevRaw);
|
||||||
copyInto(display, flightState._drPrevDisplay);
|
copyInto(display, flightState._drPrevDisplay);
|
||||||
flightState._drPrevMs = nowMs;
|
flightState._drPrevMs = nowMs;
|
||||||
|
|||||||
@@ -340,6 +340,9 @@ export function createFlightState({ source, services }) {
|
|||||||
/** How the tracked icon moved over the last frame, and that frame's length (s; 0 for none). */
|
/** How the tracked icon moved over the last frame, and that frame's length (s; 0 for none). */
|
||||||
flightState._drPrevStep = { x: 0, y: 0, z: 0 };
|
flightState._drPrevStep = { x: 0, y: 0, z: 0 };
|
||||||
flightState._drPrevStepSec = 0;
|
flightState._drPrevStepSec = 0;
|
||||||
|
/** The raw position's last step, and that frame's length (s; 0 for none). */
|
||||||
|
flightState._drPrevRawStep = { x: 0, y: 0, z: 0 };
|
||||||
|
flightState._drPrevRawStepSec = 0;
|
||||||
|
|
||||||
flightState._drPrevMs = 0;
|
flightState._drPrevMs = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ import {
|
|||||||
fixSpeedMps,
|
fixSpeedMps,
|
||||||
fixTrackDeg,
|
fixTrackDeg,
|
||||||
staleCoastSeconds,
|
staleCoastSeconds,
|
||||||
|
rawPositionJumped,
|
||||||
|
rawStepSpeedMps,
|
||||||
} from '../../data/aircraftMotionRegime.js';
|
} from '../../data/aircraftMotionRegime.js';
|
||||||
|
|
||||||
/** Where a military record carries its reported speed and track. */
|
/** Where a military record carries its reported speed and track. */
|
||||||
@@ -355,12 +357,18 @@ export function createMotion({
|
|||||||
(worldMs - flightState._drPrevWorldMs) / 1000,
|
(worldMs - flightState._drPrevWorldMs) / 1000,
|
||||||
);
|
);
|
||||||
let snapped = false;
|
let snapped = false;
|
||||||
|
let jumpedThisFrame = false;
|
||||||
if (sameTrack) {
|
if (sameTrack) {
|
||||||
const speed = (info && info.speedMps) || 0;
|
const speed = (info && info.speedMps) || 0;
|
||||||
// Plausible single-frame motion (m): its speed × frame Δt, half again
|
// A jump: a new report moved the path the raw position is on.
|
||||||
// for slack, plus 5 m. More is a jump (a new report put it elsewhere).
|
const jumped = rawPositionJumped(
|
||||||
const plausible = speed * dtSec * 1.5 + 5;
|
raw,
|
||||||
if (distance(raw, flightState._drPrevRaw) > plausible) {
|
flightState._drPrevRaw,
|
||||||
|
flightState._drPrevRawStep,
|
||||||
|
flightState._drPrevRawStepSec,
|
||||||
|
dtSec,
|
||||||
|
);
|
||||||
|
if (jumped) {
|
||||||
// Discontinuity — re-anchor so the DISPLAYED position stays continuous,
|
// Discontinuity — re-anchor so the DISPLAYED position stays continuous,
|
||||||
// then ease onto the new path no faster than a little over its speed;
|
// then ease onto the new path no faster than a little over its speed;
|
||||||
// farther off than RECOVER_SNAP_M it is a break, and it jumps.
|
// farther off than RECOVER_SNAP_M it is a break, and it jumps.
|
||||||
@@ -378,12 +386,22 @@ export function createMotion({
|
|||||||
)
|
)
|
||||||
: flightState._drPrevDisplay;
|
: flightState._drPrevDisplay;
|
||||||
const errorM = distance(anchor, raw);
|
const errorM = distance(anchor, raw);
|
||||||
|
jumpedThisFrame = true;
|
||||||
snapped = errorM >= RECOVER_SNAP_M;
|
snapped = errorM >= RECOVER_SNAP_M;
|
||||||
copyInto(snapped ? vec() : sub(anchor, raw), flightState._drCorrection);
|
copyInto(snapped ? vec() : sub(anchor, raw), flightState._drCorrection);
|
||||||
flightState._drCorrectionStartMs = nowMs;
|
flightState._drCorrectionStartMs = nowMs;
|
||||||
flightState._drCorrectionMs = Math.max(
|
flightState._drCorrectionMs = Math.max(
|
||||||
DR_CORRECTION_MS,
|
DR_CORRECTION_MS,
|
||||||
recoveryMs(errorM, speed),
|
// As fast as the path it was drawn on moves: the newest report's
|
||||||
|
// speed can be stale or 0 minutes ahead of it.
|
||||||
|
recoveryMs(
|
||||||
|
errorM,
|
||||||
|
rawStepSpeedMps(
|
||||||
|
flightState._drPrevRawStep,
|
||||||
|
flightState._drPrevRawStepSec,
|
||||||
|
speed,
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -408,6 +426,12 @@ export function createMotion({
|
|||||||
);
|
);
|
||||||
flightState._drPrevStepSec = dtSec;
|
flightState._drPrevStepSec = dtSec;
|
||||||
} else flightState._drPrevStepSec = 0;
|
} else flightState._drPrevStepSec = 0;
|
||||||
|
// The raw step, to judge the next frame by; none after a jump (its
|
||||||
|
// step is the jump) or a track switch.
|
||||||
|
if (sameTrack && !jumpedThisFrame) {
|
||||||
|
copyInto(sub(raw, flightState._drPrevRaw), flightState._drPrevRawStep);
|
||||||
|
flightState._drPrevRawStepSec = dtSec;
|
||||||
|
} else flightState._drPrevRawStepSec = 0;
|
||||||
copyInto(raw, flightState._drPrevRaw);
|
copyInto(raw, flightState._drPrevRaw);
|
||||||
copyInto(display, flightState._drPrevDisplay);
|
copyInto(display, flightState._drPrevDisplay);
|
||||||
flightState._drPrevMs = nowMs;
|
flightState._drPrevMs = nowMs;
|
||||||
|
|||||||
@@ -272,6 +272,9 @@ export function createFlightState({ source, services }) {
|
|||||||
/** How the tracked icon moved over the last frame, and that frame's length (s; 0 for none). */
|
/** How the tracked icon moved over the last frame, and that frame's length (s; 0 for none). */
|
||||||
flightState._drPrevStep = { x: 0, y: 0, z: 0 };
|
flightState._drPrevStep = { x: 0, y: 0, z: 0 };
|
||||||
flightState._drPrevStepSec = 0;
|
flightState._drPrevStepSec = 0;
|
||||||
|
/** The raw position's last step, and that frame's length (s; 0 for none). */
|
||||||
|
flightState._drPrevRawStep = { x: 0, y: 0, z: 0 };
|
||||||
|
flightState._drPrevRawStepSec = 0;
|
||||||
|
|
||||||
flightState._drPrevMs = 0;
|
flightState._drPrevMs = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,11 @@ function sharpestTurnDeg(line) {
|
|||||||
return worst;
|
return worst;
|
||||||
}
|
}
|
||||||
|
|
||||||
function run(layer, pollOptions = {}, { drop = [] } = {}) {
|
function run(
|
||||||
|
layer,
|
||||||
|
pollOptions = {},
|
||||||
|
{ drop = [], reportedSpeedMps, frameMs } = {},
|
||||||
|
) {
|
||||||
const polls = slowFeedPolls({
|
const polls = slowFeedPolls({
|
||||||
startMs: T0,
|
startMs: T0,
|
||||||
count: 30,
|
count: 30,
|
||||||
@@ -53,6 +57,8 @@ function run(layer, pollOptions = {}, { drop = [] } = {}) {
|
|||||||
// From the seventh poll: the delay has settled and the trail has begun.
|
// From the seventh poll: the delay has settled and the trail has begun.
|
||||||
measureFromMs: polls[6].receiptMs,
|
measureFromMs: polls[6].receiptMs,
|
||||||
contacts: CONTACTS,
|
contacts: CONTACTS,
|
||||||
|
reportedSpeedMps,
|
||||||
|
...(frameMs ? { frameMs } : {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +105,15 @@ export function feedLatencyTests(layer, floorSec) {
|
|||||||
assertTrail(sim, 60);
|
assertTrail(sim, 60);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(`${layer}: reports that give a speed of 0 still draw the tracked aircraft along its path, with no jump or stall`, () => {
|
||||||
|
// The drawn motion is minutes behind the newest report, whose speed may
|
||||||
|
// be stale or 0: a jump is judged by the path, not by that speed.
|
||||||
|
// At 10 fps a frame moves 13 m, more than a speed of 0 allows.
|
||||||
|
const sim = run(layer, {}, { reportedSpeedMps: 0, frameMs: 100 });
|
||||||
|
assertSmoothMotion(sim);
|
||||||
|
assert.ok(placementError(sim, sim.frames, 'tracked', 0) < 100);
|
||||||
|
});
|
||||||
|
|
||||||
test(`${layer}: a fresh fallback feed for four polls and reports that do not move on: no jump, no stall, no kink`, () => {
|
test(`${layer}: a fresh fallback feed for four polls and reports that do not move on: no jump, no stall, no kink`, () => {
|
||||||
const sim = run(layer, {
|
const sim = run(layer, {
|
||||||
fallback: [12, 13, 14, 15],
|
fallback: [12, 13, 14, 15],
|
||||||
|
|||||||
@@ -227,6 +227,7 @@ export function runAircraftFeedSim({
|
|||||||
contacts,
|
contacts,
|
||||||
followsClock = false,
|
followsClock = false,
|
||||||
onFrame = null,
|
onFrame = null,
|
||||||
|
reportedSpeedMps = null,
|
||||||
}) {
|
}) {
|
||||||
const mod = layer === 'flights' ? flights : military;
|
const mod = layer === 'flights' ? flights : military;
|
||||||
const truth = arrivalPath();
|
const truth = arrivalPath();
|
||||||
@@ -336,7 +337,9 @@ export function runAircraftFeedSim({
|
|||||||
baroAltitudeM: p.heightM,
|
baroAltitudeM: p.heightM,
|
||||||
ellipsoidAltitudeM: p.heightM,
|
ellipsoidAltitudeM: p.heightM,
|
||||||
onGround: false,
|
onGround: false,
|
||||||
speedMps: p.speedMps,
|
// A feed may report a speed that is not how fast the contact flies
|
||||||
|
// (stale, or 0 when it gave none).
|
||||||
|
speedMps: reportedSpeedMps ?? p.speedMps,
|
||||||
courseDeg: p.trackDeg,
|
courseDeg: p.trackDeg,
|
||||||
verticalRateMps: -1.5,
|
verticalRateMps: -1.5,
|
||||||
positionTimeMs: timeMs,
|
positionTimeMs: timeMs,
|
||||||
|
|||||||
Reference in new issue
Block a user