From 371d117b233685f37e1cb72660e343e4f703be24 Mon Sep 17 00:00:00 2001 From: Mark Bumiller Date: Sat, 25 Feb 2023 19:38:04 -0500 Subject: [PATCH] fix crash when no position Jxck-S/plane-notify#117 --- calculate_headings.py | 3 +++ planeClass.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/calculate_headings.py b/calculate_headings.py index 2ac8ac0..437ca37 100644 --- a/calculate_headings.py +++ b/calculate_headings.py @@ -17,6 +17,9 @@ def calculate_cardinal(d): card = dirs[ix % len(dirs)] return card def calculate_deg_change(new_heading, original_heading): + if new_heading is None: + print("Track heading missing. No change") + return 0 """Calculates change between two headings, returns negative degree if change is left, positive if right""" normal = abs(original_heading-new_heading) across_inital = 360 - abs(original_heading-new_heading) diff --git a/planeClass.py b/planeClass.py index 03e6040..4837ec5 100644 --- a/planeClass.py +++ b/planeClass.py @@ -618,7 +618,8 @@ class Plane: from calculate_headings import calculate_deg_change track_change = calculate_deg_change(self.track, self.last_track) track_change = round(track_change, 3) - self.circle_history["traces"].append((time.time(), self.latitude, self.longitude, track_change)) + if self.latitude is not None and self.longitude is not None: + self.circle_history["traces"].append((time.time(), self.latitude, self.longitude, track_change)) total_change = 0 coords = []