Skip to content
Merged
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
13 changes: 4 additions & 9 deletions robotics_application_manager/manager/launcher/launcher_rqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from robotics_application_manager.manager.vnc import Vnc_server
from robotics_application_manager import LogManager
from typing import List, Any
import os
import subprocess


Expand Down Expand Up @@ -39,7 +40,9 @@ def run(self, config_file, callback):
if config_file is None:
config_file = "/opt/jderobot/Launchers/rqt/default.perspective"

config = f"rqt --perspective-file {config_file}"
# Keep the graph plugins refreshed and fitted to the browser panel
autorefresh = os.path.join(os.path.dirname(__file__), "rqt_autorefresh.py")
config = f"python3 {autorefresh} --perspective-file {config_file}"

if ACCELERATION_ENABLED:
self.vnc.start_vnc_gpu(
Expand Down Expand Up @@ -74,14 +77,6 @@ def terminate(self):
for thread in self.threads[:]:
if thread.is_alive():
thread.terminate()
# rqt ignores SIGTERM so join would block forever
subprocess.call(
"pkill -9 -f 'bin/rqt --perspective-file'",
shell=True,
stdout=subprocess.PIPE,
bufsize=1024,
universal_newlines=True,
)
thread.join()
self.threads.remove(thread)
self.running = False
Expand Down
61 changes: 61 additions & 0 deletions robotics_application_manager/manager/launcher/rqt_autorefresh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
Start rqt keeping its graph plugins readable inside the web VNC viewer.

rqt_graph and rqt_tf_tree query the ROS graph only once at startup, before
their node has discovered the rest of the system, so they open empty. They
also fit the graph to the view only when it is drawn, while noVNC resizes
the screen every time the browser panel changes size.

Run by LauncherRqt as a script inside the Robotics Backend, not imported.
"""

import sys
import signal

from python_qt_binding.QtCore import QEvent, QObject, QTimer
from python_qt_binding.QtWidgets import QApplication, QGraphicsView, QPushButton
from rqt_gui.main import Main

# Both plugins name their buttons the same way
REFRESH_BUTTON = "refresh_graph_push_button"
FIT_BUTTON = "fit_in_view_push_button"
REFRESH_DELAYS_MS = [3000, 8000]
FIT_DEBOUNCE_MS = 300


def click_buttons(name):
for widget in QApplication.allWidgets():
if isinstance(widget, QPushButton) and widget.objectName() == name:
widget.click()


class FitOnResize(QObject):
def __init__(self):
super().__init__()
self.timer = QTimer()
self.timer.setSingleShot(True)
self.timer.timeout.connect(lambda: click_buttons(FIT_BUTTON))

def eventFilter(self, obj, event):
if event.type() == QEvent.Resize and isinstance(obj, QGraphicsView):
self.timer.start(FIT_DEBOUNCE_MS)
return False


class AutoRefreshMain(Main):
def create_application(self, argv):
app = super().create_application(argv)
for delay in REFRESH_DELAYS_MS:
QTimer.singleShot(delay, lambda: click_buttons(REFRESH_BUTTON))
self.fit_on_resize = FitOnResize()
app.installEventFilter(self.fit_on_resize)
return app


def sigterm_handler(_signo, _stack_frame):
sys.exit(0)


if __name__ == "__main__":
signal.signal(signal.SIGTERM, sigterm_handler)
sys.exit(AutoRefreshMain().main())
Loading