better logging

This commit is contained in:
ALIHAN DIKEL
2023-05-19 03:00:52 +03:00
parent 3b045baf7a
commit 0b3523000c
3 changed files with 34 additions and 34 deletions

View File

@@ -26,7 +26,7 @@ class FlightStatsCollector:
temp = tello.get_temperature()
# wsnr = tello.query_wifi_signal_noise_ratio()
print(f"bat: {bat} - temp: {temp}") #- wsnr: {wsnr}")
time.sleep(5)
time.sleep(3)
router = APIRouter()
tello = Tello()
@@ -37,7 +37,6 @@ def land_on_low_battery():
bat_level = tello.get_battery()
if bat_level < 20:
tello.land()
@router.get("/takeoff")
@@ -48,7 +47,7 @@ def takeoff():
return {"msg": "command failed", "reason": "failed to connect"}
if tello.is_flying:
return {"msg": "already flying"}
return {"msg": "command failed", "reason": "already flying"}
try:
tello.takeoff()
@@ -64,7 +63,7 @@ def takeoff():
@router.get("/land")
def land():
if not tello.is_flying:
return {"msg": "already on land"}
return {"msg": "command failed", "reason": "already on land"}
try:
tello.land()
@@ -78,9 +77,9 @@ def land():
@router.get("/turn/{direction}/{degree}")
def turn(direction: str, degree: int):
if direction not in ["left", "right"]:
return {"direction must be only left or right"}
return {"msg": "command failed", "reason": "direction must be only left or right"}
if degree < 1 or degree > 360:
return {"degree must be between 1 and 360"}
return {"msg": "command failed", "reason": "degree must be between 1 and 360"}
try:
if direction == "right":
@@ -88,31 +87,33 @@ def turn(direction: str, degree: int):
elif direction == "left":
tello.rotate_counter_clockwise(degree)
except Exception as e:
return { "msg": "command failed", "reason": e }
return {"msg": "command failed", "reason": e}
return {"msg": "ok"}
@router.get("/move/{direction}/{distance}")
def turn(direction: str, distance: int):
if direction not in ["back", "forward", "left", "right", "up" , "down"]:
return {"direction must be only back, forward, left, right up or down"}
if distance < 20 or distance > 200:
return {"distance must be between 20 and 500"}
return {"msg": "command failed", "reason": "direction must be only back, forward, left, right up or down"}
if distance < 20 or distance > 250:
# tellonun kendi sınırı 500 ama nolur nolmaz diye kısıtladım
return {"msg": "command failed", "reason": "distance must be between 20 and 250"}
try:
tello.move(direction, distance)
except Exception as e:
return { "msg": "command failed", "reason": e }
return {"msg": "command failed", "reason": e}
return {"msg": "ok"}
@router.get("/emergency")
def emercengy_stop():
def emergency_stop():
try:
tello.emergency()
return {"msg": "ok"}
except Exception as e:
return { "msg": "command failed", "reason": e }
return {"msg": "command failed", "reason": e}
@router.get("/end")
def end_flight_session():
@@ -120,4 +121,4 @@ def end_flight_session():
tello.end()
return {"msg": "ok"}
except Exception as e:
return { "msg": "command failed", "reason": e }
return {"msg": "command failed", "reason": e}