From 708752605cd9cf5e443c39179eaf561562735433 Mon Sep 17 00:00:00 2001 From: Daniel Maeckelmann Date: Sun, 24 Sep 2023 12:56:00 +0200 Subject: [PATCH] Fixed heading calculation with only one tracker --- Server/src/services/vehicle.service.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Server/src/services/vehicle.service.ts b/Server/src/services/vehicle.service.ts index 1aa98e8..a2c84a2 100644 --- a/Server/src/services/vehicle.service.ts +++ b/Server/src/services/vehicle.service.ts @@ -500,7 +500,13 @@ export default class VehicleService { if (logs.length === 1) { // compute track heading and map the heading of the vehicle to either 1 or -1 accordingly const trackBearing = TrackService.getTrackHeading(track, logs[0][1]) - return logs[0][0].heading - trackBearing < 90 || logs[0][0].heading - trackBearing > -90 ? 1 : -1 + // compute the angle between the vehicles reported heading and the track + const raw_angle_to_track = logs[0][0].heading - trackBearing + // convert the angle to a positive number in the mod 360 ring + // This will result in a positive number, as long as logs[0][0].heading + // and trackBearing are from the interval [0, 360). + const angle_to_track = (raw_angle_to_track + 360) % 360 + return angle_to_track < 90 || angle_to_track > 270 ? 1 : -1 } else { // we have at least two logs, add all differences of track kilometers together and check if the sum is positive let trackKmDiffSum = 0