autocommit

This commit is contained in:
ALIHAN DIKEL
2024-10-30 00:43:53 +03:00
parent 873ba1156e
commit 425975434e

View File

@@ -25,7 +25,7 @@ import asyncio
import os
async def maintain_connection_to_tello(state):
logger.debug("starting maintain connection to tello")
logger.debug("starting conn")
state["connection"] = "NOK"
await asyncio.to_thread(nmcli.connection.reload)
while True:
@@ -66,9 +66,10 @@ async def collect_flight_stats(state):
bat = await asyncio.to_thread(tello.get_battery)
temp = await asyncio.to_thread(tello.get_temperature)
baro = await asyncio.to_thread(tello.get_barometer)
calib_baro = await get_calibrated_altitude(offset=20, measure=baro)
# wsnr = await tello.query_wifi_signal_noise_ratio()
state["stats"] = {"bat": bat, "temp": temp, "baro": baro}
logger.debug(f"Battery: {bat} - Temperature: {temp} - Barometer: {baro}")
state["stats"] = {"bat": bat, "temp": temp, "baro": calib_baro}
logger.debug(f"Battery: {bat} - Temperature: {temp} - Barometer: {calib_baro}")
except TelloException as te:
logger.error(te)
# search for any response if disconnected
@@ -115,6 +116,20 @@ async def forward_video_stream(state):
except Exception as e:
print(f"Unexpected error: {e}")
async def get_calibrated_altitude(offset, measure):
"""
Calculate the calibrated altitude using the barometer reading and an offset.
Args: offset (float): The calibration offset in meters.
Returns: float: The calibrated altitude in meters.
"""
MAX_REASONABLE_ALTITUDE = 10000 # Maximum reasonable altitude in meters
baro_altitude_cm = measure
baro_altitude_m = baro_altitude_cm / 100 # Convert centimeters to meters
if abs(baro_altitude_m) > MAX_REASONABLE_ALTITUDE:
raise ValueError("Barometer reading is out of reasonable altitude range.")
calibrated_altitude = baro_altitude_m + offset
return calibrated_altitude
"""
def land_on_low_battery():
bat_level = tello.get_battery()