Skip to content

Add emergency UI widgets: EmergencyAlert, KillSwitch, SurfaceButton#1

Open
niclassvardal-boop wants to merge 1 commit intomainfrom
feature/emergency-ui
Open

Add emergency UI widgets: EmergencyAlert, KillSwitch, SurfaceButton#1
niclassvardal-boop wants to merge 1 commit intomainfrom
feature/emergency-ui

Conversation

@niclassvardal-boop
Copy link
Contributor

Step 2: To do in Qt Designer

1. Add a QGroupBox for emergency buttons

  • Object name: EmergencyPanel
  • Add a layout (e.g. QVBoxLayout)
  • Leave it empty — you’ll populate it dynamically

2. Add a QTextEdit for logs

  • Object name: LogPanel
  • Set readOnly = True

3. (optional) Add a QPushButton to trigger the alert

  • Object name: TestAlertButton
  • Label: “Trigger Emergency Alert”

4. Ensure there’s a QWidget named MainTab

  • This is where the alert overlay will be shown

Step 3: Regenerate the Python UI Class

After saving the .ui file, run:

pyuic6 ui_layout.ui -o gui_layout.py

This updates the Python class with references to the promoted widgets.


Step 4: Import Custom Classes Before setupUi()

In your main GUI node ( gui_ros_node.py), make sure you import:

from vortex_pyqt_gui.kill_switch import KillSwitch
from vortex_pyqt_gui.surface_button import SurfaceButton
from .emergency_alert import EmergencyAlert

Then load the UI:

ui = Ui_MainWindow()
ui.setupUi(window)

Qt will automatically instantiate the promoted widgets.


What you’ll do in Python

You’ve already written the logic — just make sure it’s modular and safe:

Add this to gui_ros_node > MyGuiNode > init:

self.setup_safety_controls()

# (Optinal, if you have included a test button)
self.ui.TestAlertButton.clicked.connect(self.show_emergency_alert)

Add this to gui_ros_node > MyGuiNode(Node):

Emergency buttons

def setup_safety_controls(self):
    layout = self.ui.EmergencyPanel.layout()
    for i in reversed(range(layout.count())):
        widget = layout.itemAt(i).widget()
        if widget:
            widget.setParent(None)
            widget.deleteLater()

    self.kill_switch = KillSwitch(
        parent=self.ui.EmergencyPanel,
        on_kill=lambda: self.log_event("Kill switch activated"),
        on_reactivate=lambda: self.log_event("Thrusters reactivated")
    )
    layout.addWidget(self.kill_switch)

    self.surface_button = SurfaceButton(
        parent=self.ui.EmergencyPanel,
        on_surface=lambda: self.log_event("Surface button pressed")
    )
    layout.addWidget(self.surface_button)

Log panel

def log_event(self, message):
    timestamp = QDateTime.currentDateTime().toString("yyyy-MM-dd HH:mm:ss")
    log_panel = getattr(self.ui, 'LogPanel', None)
    if log_panel is not None and hasattr(log_panel, 'append'):
        try:
            log_panel.append(f"[{timestamp}] {message}")
        except Exception:
            self.get_logger().warning('Failed to append to LogPanel')
    else:
        print(f"[{timestamp}] {message}")

Emergency alert

def show_emergency_alert(self):
    self.alert = EmergencyAlert(self.ui.MainTab, on_confirm=self.dismiss_emergency_alert)
    self.alert.setGeometry(self.ui.MainTab.rect())
    self.alert.show()
    self.log_event("Emergency alert triggered: Leak detected")
    
def dismiss_emergency_alert(self):
    if hasattr(self, 'alert') and self.alert is not None:
        self.alert.hide()              # Hide the widget
        self.alert.setParent(None)     # Detach from layout
        self.alert.deleteLater()       # Clean up memory
        self.alert = None              # Clear reference
        self.log_event("Emergency alert dismissed by operator")

Todo

The KillSwitch and SurfaceButton widgets are fully integrated into the GUI layout, but they are not yet connected to any drone commands. Their callbacks currently log events to the GUI (LogPanel) for testing purposes only.

Implementing the actual kill and surface commands — such as publishing to ROS topics or triggering service calls — is a separate task and need to be handled in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant