From 2ee70861cd74b24dd825085e04dd98316148bb70 Mon Sep 17 00:00:00 2001 From: Matthias Guillitte Date: Mon, 17 Aug 2026 23:14:18 +0200 Subject: [PATCH] Better GPS read --- orchestrateur/sensors/gps.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/orchestrateur/sensors/gps.py b/orchestrateur/sensors/gps.py index 577afb2..1390afd 100644 --- a/orchestrateur/sensors/gps.py +++ b/orchestrateur/sensors/gps.py @@ -36,23 +36,17 @@ class GROVEGPS: def read(self): """Reads the latest GGA sentence from serial, thread-safely.""" with serial_lock: - # 1. Flush accumulated stale data in the UART buffer - if self.ser.in_waiting > 0: - self.ser.reset_input_buffer() - - # 2. Try reading up to 15 lines to catch the freshest GGA sentence - for _ in range(5): + for _ in range(10): # Read pending lines from buffer + if self.ser.in_waiting == 0: + break raw_bytes = self.ser.readline() try: line = raw_bytes.decode('utf-8', errors='ignore').strip() - # log(f"GPS: Read line: {line}") except Exception: continue - # Supports both $GPGGA and modern $GNGGA sentences if (line.startswith('$GPGGA') or line.startswith('$GNGGA')) and calculate_nmea_checksum(line): - if self.parse_gga(line): - return True + return self.parse_gga(line) return False def parse_gga(self, line):