diff --git a/GUI5.py b/GUI5.py index ac0e0679..9ad83d35 100644 --- a/GUI5.py +++ b/GUI5.py @@ -5,7 +5,7 @@ from pathlib import Path from PySide6.QtWidgets import QApplication from PySide6.QtQml import QQmlApplicationEngine -from PySide6.QtCore import QObject, Signal, Slot, QProcess, QUrl +from PySide6.QtCore import QObject, Signal, Slot, QProcess, QUrl, QTimer from pdf2image import convert_from_path from djitellopy import Tello import threading @@ -224,6 +224,14 @@ def __init__(self): self.plots_dir = os.path.abspath("plotscode/plots") # Base plots directory self.current_dataset = "refresh" # Default dataset to display self.is_connected = False + + # Timer to send periodic hover signals + self.hover_timer = QTimer() + self.hover_timer.timeout.connect(self.hover_loop) + + self.tello = Tello() + self.is_flying = False + try: self.tello = Tello() self.connected = False @@ -247,6 +255,13 @@ def __init__(self): else: self.bcicon = None + @Slot() + def takeoff(self): + self.tello.takeoff() + self.is_flying = True + self.hover_timer.start(200) + self.logMessage.emit("Hovering") + @Slot(str) def selectModel(self, model_name): """ Select the machine learning model """ @@ -418,6 +433,11 @@ def keepDroneAlive(self): self.flight_log.insert(0, "Keep alive signal sent.") self.flightLogUpdated.emit(self.flight_log) + @Slot() + def hover(self): + self.tello.send_rc_control(0, 0, 0, 0) + self.logMessage.emit("Hovering") + @Slot(str) def getDroneAction(self, action): threading.Thread(target=self._doAction, args=(action,), daemon=True).start() @@ -475,6 +495,9 @@ def _doAction(self, action): except Exception as e: self.logMessage.emit(f"Error during {action}: {e}") + def hover_loop(self): + if self.is_flying: + self.tello.send_rc_control(0, 0, 0, 0) # Method for returning to home (an approximation) def go_home(self): diff --git a/ManualDroneControl.qml b/ManualDroneControl.qml index b1ea0465..b123c92e 100644 --- a/ManualDroneControl.qml +++ b/ManualDroneControl.qml @@ -511,7 +511,7 @@ Rectangle { enabled: root.is_connected onEntered: parent.color = "white" onExited: parent.color = "#242c4d" - onClicked: backend.getDroneAction("takeoff") + onClicked: backend.takeoff() } }