Skip to content

Commit

Permalink
Fixed heading calculation with only one tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
n1kPLV committed Sep 24, 2023
1 parent 922a8c8 commit 7087526
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Server/src/services/vehicle.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7087526

Please sign in to comment.