From 0d2f485c5746d960ce70ecf6e057b412a701ac4f Mon Sep 17 00:00:00 2001 From: nicoboy Date: Mon, 1 Jun 2026 15:00:30 +0200 Subject: [PATCH] Fix position_gps : GPS info en cache, plus de blocage async MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - gps_fix et gps_sats ajoutés à telemetry_cache - monitor_telemetry surveille aussi gps_info() en continu - position_gps lit depuis le cache (comme battery/mode) et ne risque plus de bloquer sur async for ... break Co-Authored-By: Claude Sonnet 4.6 --- wireclaw_core.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/wireclaw_core.py b/wireclaw_core.py index 8e44a00..143eb5d 100644 --- a/wireclaw_core.py +++ b/wireclaw_core.py @@ -34,7 +34,7 @@ Nord = lat+, Sud = lat-, Est = lon+, Ouest = lon- drone_armed = False current_pos = {"lat": BASE_LAT, "lon": BASE_LON, "alt": 0, "abs_alt": 584} -telemetry_cache = {"battery": -1.0, "mode": "UNKNOWN"} +telemetry_cache = {"battery": -1.0, "mode": "UNKNOWN", "gps_fix": "UNKNOWN", "gps_sats": 0} mav = None drone = None @@ -75,7 +75,12 @@ async def monitor_telemetry(drone): async for fm in drone.telemetry.flight_mode(): telemetry_cache["mode"] = str(fm) - await asyncio.gather(watch_battery(), watch_mode()) + async def watch_gps(): + async for gps in drone.telemetry.gps_info(): + telemetry_cache["gps_fix"] = str(gps.fix_type) + telemetry_cache["gps_sats"] = gps.num_satellites + + await asyncio.gather(watch_battery(), watch_mode(), watch_gps()) async def interpret_command(text): response = client.models.generate_content( @@ -217,17 +222,13 @@ async def execute_command(drone, cmd): import datetime await refresh_position(drone) ts = datetime.datetime.now().strftime("%H:%M:%S") - async for gps in drone.telemetry.gps_info(): - fix = gps.fix_type - sats = gps.num_satellites - break return (f"\nHorodatage : {ts}\n" f"Latitude : {current_pos['lat']:.7f}\n" f"Longitude : {current_pos['lon']:.7f}\n" f"Alt AGL : {current_pos['alt']:.2f} m\n" f"Alt MSL : {current_pos['abs_alt']:.2f} m\n" - f"Fix GPS : {fix}\n" - f"Satellites : {sats}") + f"Fix GPS : {telemetry_cache['gps_fix']}\n" + f"Satellites : {telemetry_cache['gps_sats']}") elif action == "hover": await drone.action.hold()