mirror of
https://github.com/OSURoboticsClub/Rover_2017_2018.git
synced 2025-11-08 18:21:15 +00:00
Compass now responds to heading (when we get one) and moves nicely and smoothly on the GUI. Made a new compass image as the old one was bad.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# coding=utf-8
|
||||
#####################################
|
||||
# Imports
|
||||
#####################################
|
||||
@@ -11,7 +12,9 @@ from PIL.ImageQt import ImageQt
|
||||
#####################################
|
||||
# Global Variables
|
||||
#####################################
|
||||
THREAD_HERTZ = 10
|
||||
THREAD_HERTZ = 20
|
||||
|
||||
ROTATION_SPEED_MODIFIER = 1
|
||||
|
||||
|
||||
#####################################
|
||||
@@ -19,6 +22,7 @@ THREAD_HERTZ = 10
|
||||
#####################################
|
||||
class SpeedAndHeadingIndication(QtCore.QThread):
|
||||
show_compass_image__signal = QtCore.pyqtSignal()
|
||||
heading_text_update_ready__signal = QtCore.pyqtSignal(str)
|
||||
|
||||
def __init__(self, shared_objects):
|
||||
super(SpeedAndHeadingIndication, self).__init__()
|
||||
@@ -26,7 +30,11 @@ class SpeedAndHeadingIndication(QtCore.QThread):
|
||||
# ########## 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
|
||||
self.heading_text_label = self.right_screen.current_heading_label # type: QtWidgets.QLabel
|
||||
self.next_goal_label = self.right_screen.next_goal_label # type: QtWidgets.QLabel
|
||||
self.current_speed_label = self.right_screen.current_speed_label # type: QtWidgets.QLabel
|
||||
|
||||
# ########## Get the settings instance ##########
|
||||
self.settings = QtCore.QSettings()
|
||||
@@ -40,34 +48,78 @@ class SpeedAndHeadingIndication(QtCore.QThread):
|
||||
# ########## Class Variables ##########
|
||||
self.wait_time = 1.0 / THREAD_HERTZ
|
||||
|
||||
self.main_compass_image = PIL.Image.open("Resources/Images/compass.png").resize((300, 300))
|
||||
self.main_compass_image = PIL.Image.open("Resources/Images/compass.png").resize((300, 300), PIL.Image.ANTIALIAS)
|
||||
self.compass_pixmap = None
|
||||
|
||||
self.current_rotation = 0
|
||||
self.current_heading = 0
|
||||
self.current_heading_changed = True
|
||||
|
||||
self.shown_heading = (self.current_heading + 1) % 360
|
||||
self.current_heading_shown_rotation_angle = 0
|
||||
self.rotation_direction = 1
|
||||
|
||||
# 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):
|
||||
self.on_heading_changed__slot(self.current_heading)
|
||||
|
||||
while self.run_thread_flag:
|
||||
|
||||
start_time = time()
|
||||
self.current_rotation += 1
|
||||
|
||||
new_compass_image = self.main_compass_image.rotate(self.current_rotation)
|
||||
if self.current_heading_changed:
|
||||
self.update_heading_movement()
|
||||
self.current_heading_changed = False
|
||||
|
||||
self.compass_pixmap = QtGui.QPixmap.fromImage(ImageQt(new_compass_image))
|
||||
self.show_compass_image__signal.emit()
|
||||
self.rotate_compass_if_needed()
|
||||
|
||||
time_diff = time() - start_time
|
||||
|
||||
self.msleep(max(int(self.wait_time - time_diff), 0))
|
||||
|
||||
def rotate_compass_if_needed(self):
|
||||
if int(self.shown_heading) != self.current_heading:
|
||||
self.shown_heading += self.rotation_direction * ROTATION_SPEED_MODIFIER
|
||||
self.shown_heading %= 360
|
||||
|
||||
self.current_heading_shown_rotation_angle = int(self.shown_heading)
|
||||
|
||||
new_compass_image = self.main_compass_image.rotate(self.current_heading_shown_rotation_angle, resample=PIL.Image.BICUBIC)
|
||||
|
||||
self.compass_pixmap = QtGui.QPixmap.fromImage(ImageQt(new_compass_image))
|
||||
self.show_compass_image__signal.emit()
|
||||
|
||||
def update_heading_movement(self):
|
||||
current_minus_shown = (self.current_heading - self.shown_heading) % 360
|
||||
|
||||
if current_minus_shown >= 180:
|
||||
self.rotation_direction = -1
|
||||
else:
|
||||
self.rotation_direction = 1
|
||||
|
||||
def on_heading_changed__slot(self, new_heading):
|
||||
self.current_heading = new_heading
|
||||
self.heading_text_update_ready__signal.emit(str(new_heading) + "°")
|
||||
self.current_heading_changed = True
|
||||
|
||||
def __on_heading_clicked__slot(self, event):
|
||||
new_heading = self.current_heading
|
||||
if event.button() == QtCore.Qt.LeftButton:
|
||||
new_heading = (self.current_heading + 10) % 360
|
||||
elif event.button() == QtCore.Qt.RightButton:
|
||||
new_heading = (self.current_heading - 10) % 360
|
||||
|
||||
self.on_heading_changed__slot(new_heading)
|
||||
self.heading_text_update_ready__signal.emit(str(new_heading) + "°")
|
||||
|
||||
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)
|
||||
self.heading_text_update_ready__signal.connect(self.heading_text_label.setText)
|
||||
|
||||
self.heading_compass_label.mousePressEvent = self.__on_heading_clicked__slot
|
||||
|
||||
def setup_signals(self, start_signal, signals_and_slots_signal, kill_signal):
|
||||
start_signal.connect(self.start)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# Python native imports
|
||||
from PyQt5 import QtCore, QtWidgets
|
||||
import logging
|
||||
from time import time
|
||||
|
||||
import rospy
|
||||
|
||||
@@ -21,6 +22,11 @@ PRIMARY_LABEL_MAX = (640, 360)
|
||||
SECONDARY_LABEL_MAX = (640, 360)
|
||||
TERTIARY_LABEL_MAX = (640, 360)
|
||||
|
||||
GUI_SELECTION_CHANGE_TIMEOUT = 3 # Seconds
|
||||
|
||||
STYLESHEET_SELECTED = "border: 2px solid orange; background-color:black;"
|
||||
STYLESHEET_UNSELECTED = "background-color:black;"
|
||||
|
||||
|
||||
#####################################
|
||||
# RoverVideoCoordinator Class Definition
|
||||
@@ -89,7 +95,8 @@ class RoverVideoCoordinator(QtCore.QThread):
|
||||
}
|
||||
|
||||
self.current_label_for_joystick_adjust = 0
|
||||
self.gui_selection_update_needed = True
|
||||
self.gui_selection_changed = True
|
||||
self.last_gui_selection_changed_time = time()
|
||||
|
||||
self.set_max_resolutions_flag = True
|
||||
|
||||
@@ -131,19 +138,27 @@ class RoverVideoCoordinator(QtCore.QThread):
|
||||
self.camera_threads[camera_name].toggle_video_display()
|
||||
|
||||
def __update_gui_element_selection(self):
|
||||
if self.gui_selection_update_needed:
|
||||
self.update_element_stylesheet__signal.emit()
|
||||
if (time() - self.last_gui_selection_changed_time) > GUI_SELECTION_CHANGE_TIMEOUT \
|
||||
and self.gui_selection_changed:
|
||||
|
||||
elements_to_reset = range(len(self.index_to_label_element))
|
||||
|
||||
for index in elements_to_reset:
|
||||
self.index_to_label_element[index].setStyleSheet(STYLESHEET_UNSELECTED)
|
||||
|
||||
self.gui_selection_changed = False
|
||||
|
||||
def __on_gui_element_stylesheet_update__slot(self):
|
||||
elements_to_reset = range(len(self.index_to_label_element))
|
||||
elements_to_reset.remove(self.current_label_for_joystick_adjust)
|
||||
|
||||
for index in elements_to_reset:
|
||||
self.index_to_label_element[index].setStyleSheet("background-color:black;")
|
||||
self.index_to_label_element[index].setStyleSheet(STYLESHEET_UNSELECTED)
|
||||
|
||||
self.index_to_label_element[self.current_label_for_joystick_adjust].setStyleSheet("border: 2px solid orange;")
|
||||
self.index_to_label_element[self.current_label_for_joystick_adjust].setStyleSheet(STYLESHEET_SELECTED)
|
||||
|
||||
self.gui_selection_update_needed = False
|
||||
self.gui_selection_changed = True
|
||||
self.last_gui_selection_changed_time = time()
|
||||
|
||||
def __get_cameras(self):
|
||||
topics = rospy.get_published_topics(CAMERA_TOPIC_PATH)
|
||||
@@ -260,7 +275,7 @@ class RoverVideoCoordinator(QtCore.QThread):
|
||||
else:
|
||||
self.current_label_for_joystick_adjust = new_selection
|
||||
|
||||
self.gui_selection_update_needed = True
|
||||
self.update_element_stylesheet__signal.emit()
|
||||
|
||||
def on_camera_selection_for_current_gui_element_changed(self, direction):
|
||||
if self.current_label_for_joystick_adjust == 0: # primary
|
||||
@@ -271,6 +286,7 @@ class RoverVideoCoordinator(QtCore.QThread):
|
||||
self.tertiary_label_current_setting = (self.tertiary_label_current_setting + direction) % len(self.valid_cameras)
|
||||
|
||||
self.set_max_resolutions_flag = True
|
||||
self.update_element_stylesheet__signal.emit()
|
||||
|
||||
def on_gui_selected_camera_toggled(self):
|
||||
if self.current_label_for_joystick_adjust == 0: # primary
|
||||
@@ -292,5 +308,7 @@ class RoverVideoCoordinator(QtCore.QThread):
|
||||
self.disabled_cameras.append(self.tertiary_label_current_setting)
|
||||
self.camera_threads[self.valid_cameras[self.tertiary_label_current_setting]].toggle_video_display()
|
||||
|
||||
self.update_element_stylesheet__signal.emit()
|
||||
|
||||
def on_kill_threads_requested__slot(self):
|
||||
self.run_thread_flag = False
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 144 KiB After Width: | Height: | Size: 233 KiB |
@@ -682,6 +682,11 @@ Connected</string>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
<string>Science Data</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Settings</string>
|
||||
|
||||
@@ -42,16 +42,7 @@
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@@ -562,16 +553,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
@@ -630,6 +612,12 @@
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>115</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>17</pointsize>
|
||||
@@ -647,6 +635,12 @@
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>115</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>17</pointsize>
|
||||
@@ -677,6 +671,23 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>19</pointsize>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>↓</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
@@ -824,7 +835,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="current_speed_label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>22</pointsize>
|
||||
@@ -1050,7 +1061,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: darkblue;</string>
|
||||
<string notr="true">background-color:black;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
@@ -1077,7 +1088,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color:darkgreen;</string>
|
||||
<string notr="true">background-color:black;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
@@ -1099,7 +1110,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color:maroon;</string>
|
||||
<string notr="true">background-color:black;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
|
||||
Reference in New Issue
Block a user