Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion GUI5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 """
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion ManualDroneControl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ Rectangle {
enabled: root.is_connected
onEntered: parent.color = "white"
onExited: parent.color = "#242c4d"
onClicked: backend.getDroneAction("takeoff")
onClicked: backend.takeoff()
}
}

Expand Down