Skip to content

Commit

Permalink
Display and offset temp
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwp18 committed Jun 8, 2024
1 parent 10cfc3f commit 2385e49
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/surface/gui/gui/operator_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from gui.widgets.float_comm import FloatComm
from gui.widgets.timer import InteractiveTimer
from gui.widgets.task_selector import TaskSelector
from gui.widgets.temperature import TemperatureSensor
from PyQt6.QtWidgets import QGridLayout, QTabWidget, QWidget, QVBoxLayout


Expand All @@ -21,8 +22,11 @@ def __init__(self) -> None:
timer = InteractiveTimer()
main_layout.addWidget(timer, 0, 1)

task_selector = TaskSelector()
main_layout.addWidget(task_selector, 1, 1)
# task_selector = TaskSelector()
# main_layout.addWidget(task_selector, 1, 1)

temp_sensor = TemperatureSensor()
main_layout.addWidget(temp_sensor, 1, 1)

self.float_comm: FloatComm = FloatComm()
main_layout.addWidget(self.float_comm, 0, 0)
Expand Down
59 changes: 55 additions & 4 deletions src/surface/gui/gui/widgets/temperature.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,68 @@
from collections import deque

from gui.gui_nodes.event_nodes.subscriber import GUIEventSubscriber
from rov_msgs.msg import Temperature
from PyQt6.QtCore import pyqtSignal, pyqtSlot
from PyQt6.QtWidgets import (QGridLayout, QLabel, QLineEdit, QPushButton,
QVBoxLayout, QWidget)

class ThrusterTester(QWidget):
MIN_TEMP_C = 10
MAX_TEMP_C = 30
QUEUE_LEN = 5


temperature_reading_signal: pyqtSignal = pyqtSignal()
class TemperatureSensor(QWidget):
temperature_reading_signal: pyqtSignal = pyqtSignal(Temperature)

def __init__(self) -> None:
self.cmd_client: GUIEventSubscriber = GUIEventSubscriber(
super().__init__()

self.temperature_reading_signal.connect(self.temperature_received)
self.temp_subscriber: GUIEventSubscriber = GUIEventSubscriber(
Temperature,
"temperature",
"/tether/temperature",
self.temperature_reading_signal
)

self.temps: deque[float] = deque(maxlen=QUEUE_LEN)
self.offset = 0.0

root_layout = QVBoxLayout()
self.setLayout(root_layout)

self.ave_temp_label = QLabel()
self.ave_temp_label.setText('Waiting for temp...')

self.offset_field = QLineEdit()
self.offset_field.setPlaceholderText('Enter offset (C)')

self.offset_button = QPushButton('Set offset')
self.offset_button.clicked.connect(self.set_offset)

root_layout.addWidget(self.ave_temp_label)
root_layout.addWidget(self.offset_field)
root_layout.addWidget(self.offset_button)

def set_offset(self) -> None:
offset_text = self.offset_field.text()

if offset_text == '':
offset_text = '0'

try:
self.offset = float(offset_text)
self.offset_button.setText('Offset applied')
except ValueError:
self.offset_button.setText('Illegal')
return

@pyqtSlot(Temperature)
def temperature_received(self, msg: Temperature) -> None:
if MIN_TEMP_C <= msg.reading <= MAX_TEMP_C:
self.temps.append(msg.reading)

ave = sum(self.temps) / QUEUE_LEN
offset_ave = ave + self.offset
self.ave_temp_label.setText(f'{round(offset_ave, 4)}\tC')

self.offset_button.setText('Set offset')

0 comments on commit 2385e49

Please sign in to comment.