From 6a78b2e0419aa2fb4018f3395f681b4cf6effb1f Mon Sep 17 00:00:00 2001 From: Corwin Perren Date: Thu, 8 Mar 2018 23:39:08 -0800 Subject: [PATCH] Added silly spinny compass. It's the framwwork for later. --- .../SpeedAndHeadingIndication.py | 78 +++++++++++++++++++ .../Framework/NavigationSystems/__init__.py | 0 .../ground_station/src/ground_station.py | 8 +- 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 software/ros_packages/ground_station/src/Framework/NavigationSystems/SpeedAndHeadingIndication.py create mode 100644 software/ros_packages/ground_station/src/Framework/NavigationSystems/__init__.py diff --git a/software/ros_packages/ground_station/src/Framework/NavigationSystems/SpeedAndHeadingIndication.py b/software/ros_packages/ground_station/src/Framework/NavigationSystems/SpeedAndHeadingIndication.py new file mode 100644 index 0000000..2305d09 --- /dev/null +++ b/software/ros_packages/ground_station/src/Framework/NavigationSystems/SpeedAndHeadingIndication.py @@ -0,0 +1,78 @@ +##################################### +# Imports +##################################### +# Python native imports +from PyQt5 import QtCore, QtWidgets, QtGui +import logging +from time import time +import PIL.Image +from PIL.ImageQt import ImageQt + +##################################### +# Global Variables +##################################### +THREAD_HERTZ = 10 + + +##################################### +# Controller Class Definition +##################################### +class SpeedAndHeadingIndication(QtCore.QThread): + show_compass_image__signal = QtCore.pyqtSignal() + + def __init__(self, shared_objects): + super(SpeedAndHeadingIndication, self).__init__() + + # ########## Reference to class init variables ########## + self.shared_objects = shared_objects + self.right_screen = self.shared_objects["screens"]["right_screen"] + self.heading_compass_label = self.right_screen.heading_compass_label # type: QtWidgets.QLabel + + # ########## Get the settings instance ########## + self.settings = QtCore.QSettings() + + # ########## Get the Pick And Plate instance of the logger ########## + self.logger = logging.getLogger("groundstation") + + # ########## Thread Flags ########## + self.run_thread_flag = True + + # ########## Class Variables ########## + self.wait_time = 1.0 / THREAD_HERTZ + + self.main_compass_image = PIL.Image.open("Resources/Images/compass.png").resize((300, 300)) + self.compass_pixmap = None + + self.current_rotation = 0 + + # compass_image = PIL.Image.open("Resources/Images/compass.png").resize((300, 300)).rotate(45) # PIL.Image + # self.shared_objects["screens"]["right_screen"].heading_compass_label.setPixmap(QtGui.QPixmap.fromImage(ImageQt(compass_image))) + + def run(self): + while self.run_thread_flag: + + start_time = time() + self.current_rotation += 1 + + new_compass_image = self.main_compass_image.rotate(self.current_rotation) + + self.compass_pixmap = QtGui.QPixmap.fromImage(ImageQt(new_compass_image)) + self.show_compass_image__signal.emit() + + time_diff = time() - start_time + + self.msleep(max(int(self.wait_time - time_diff), 0)) + + def on_new_compass_image_ready__slot(self): + self.heading_compass_label.setPixmap(self.compass_pixmap) + + def connect_signals_and_slots(self): + self.show_compass_image__signal.connect(self.on_new_compass_image_ready__slot) + + def setup_signals(self, start_signal, signals_and_slots_signal, kill_signal): + start_signal.connect(self.start) + signals_and_slots_signal.connect(self.connect_signals_and_slots) + kill_signal.connect(self.on_kill_threads_requested__slot) + + def on_kill_threads_requested__slot(self): + self.run_thread_flag = False diff --git a/software/ros_packages/ground_station/src/Framework/NavigationSystems/__init__.py b/software/ros_packages/ground_station/src/Framework/NavigationSystems/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/software/ros_packages/ground_station/src/ground_station.py b/software/ros_packages/ground_station/src/ground_station.py index 1a8cc2a..b7a33ad 100644 --- a/software/ros_packages/ground_station/src/ground_station.py +++ b/software/ros_packages/ground_station/src/ground_station.py @@ -8,8 +8,7 @@ import signal import rospy import logging import qdarkstyle -import PIL.Image -from PIL.ImageQt import ImageQt + # Custom Imports import Framework.StartupSystems.ROSMasterChecker as ROSMasterChecker @@ -17,6 +16,7 @@ import Framework.LoggingSystems.Logger as Logger import Framework.VideoSystems.RoverVideoCoordinator as RoverVideoCoordinator import Framework.MapSystems.RoverMapCoordinator as RoverMapCoordinator import Framework.JoystickControlSystems.JoystickControlSender as JoystickControlSender +import Framework.NavigationSystems.SpeedAndHeadingIndication as SpeedAndHeading ##################################### # Global Variables @@ -100,12 +100,10 @@ class GroundStation(QtCore.QObject): self.__add_thread("Video Coordinator", RoverVideoCoordinator.RoverVideoCoordinator(self.shared_objects)) self.__add_thread("Map Coordinator", RoverMapCoordinator.RoverMapCoordinator(self.shared_objects)) self.__add_thread("Joystick Sender", JoystickControlSender.JoystickControlSender(self.shared_objects)) + self.__add_thread("Speed and Heading", SpeedAndHeading.SpeedAndHeadingIndication(self.shared_objects)) self.connect_signals_and_slots_signal.emit() self.__connect_signals_to_slots() self.start_threads_signal.emit() - - compass_image = PIL.Image.open("Resources/Images/compass.png").resize((300, 300)) # PIL.Image - self.shared_objects["screens"]["right_screen"].heading_compass_label.setPixmap(QtGui.QPixmap.fromImage(ImageQt(compass_image))) def ___ros_master_running(self): checker = ROSMasterChecker.ROSMasterChecker()