-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUIInterface.py
executable file
·361 lines (270 loc) · 14.4 KB
/
GUIInterface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#Import ZED module
import pyzed.sl as sl
import cv2
#Import PyQt6 modules
from PyQt6.QtCore import pyqtSlot, QSize
from PyQt6.QtGui import QImage, QPixmap
from PyQt6.QtWidgets import QPushButton, QGridLayout, QLabel, QWidget, QLineEdit
#Import project modules
import Communication
import ZEDController
import GNSSController
import DataController
#TODO: Currently the interface is responsible for storing it's own
class GUIInterface(QWidget, Communication.Observer):
def __init__(self, window_width, window_height, parent = None):
#Run parent class constructors
super().__init__(parent)
#Scale to reduce native images by
self.image_scale = 3.0
#Member variable to handle decimal display precision
self.dec_precision = 2
self.qpx_image = None
self.qpx_depth_image = None
#Window physical dimensions
self.window_width = window_width
self.window_height = window_height
#Component modules
self.zedcontroller = None
self.gnsscontroller = None
self.datacontroller = None
#Create buttons
self.button_zedcontroller_init = QPushButton(text = "Initialize ZEDController", parent = self)
self.button_gnsscontroller_init = QPushButton(text = "Initialize GNSSController", parent = self)
self.button_datacontroller_init = QPushButton(text = "Initialize DataController", parent = self)
self.textbox_slidingwindow = QLineEdit(text = "Duration", parent = self)
self.button_dump = QPushButton(text = "Dump Data", parent = self)
self.button_save = QPushButton(text = "Save Data", parent = self)
self.button_sampleFrame = QPushButton(text = "Sample Frame", parent = self)
self.button_sampleDepthFrame = QPushButton(text = "Sample Depth Frame", parent = self)
self.button_samplePointCloud = QPushButton(text = "Sample Point Cloud", parent = self)
self.button_sampleSensorData = QPushButton(text = "Sample Sensor Data", parent = self)
#Create labels for displaying images and other visualizations
self.window_display_1 = QLabel()
self.window_display_2 = QLabel()
#Create labels for displaying sensor data
self.positioning_timestamp_label = QLabel()
self.positioning_label = QLabel()
self.gnss_misc_label = QLabel()
self.orientation_label = QLabel()
self.lin_accel_label = QLabel()
self.ang_vel_label = QLabel()
self.mag_field_label = QLabel()
self.env_param_label = QLabel()
#Set window title and geometry
self.setWindowTitle("Jetson System GUI REV 1")
self.setGeometry(0, 0, self.window_width, self.window_height)
#Create grid layout to arrange display elements
self.layout = QGridLayout(self)
self.layout.addWidget(self.button_zedcontroller_init, 0, 0)
self.layout.addWidget(self.button_gnsscontroller_init, 0, 1)
self.layout.addWidget(self.button_datacontroller_init, 1, 0)
self.layout.addWidget(self.textbox_slidingwindow, 1, 1)
self.layout.addWidget(self.button_save, 2, 0)
self.layout.addWidget(self.button_dump, 2, 1)
self.layout.addWidget(self.button_sampleFrame, 3, 0)
self.layout.addWidget(self.button_sampleDepthFrame, 3, 1)
self.layout.addWidget(self.button_samplePointCloud, 4, 0)
self.layout.addWidget(self.button_sampleSensorData, 4, 1)
#Add visualization window to layout
self.layout.addWidget(self.window_display_1, 0, 2, 5, 4)
self.layout.addWidget(self.window_display_2, 0, 5, 5, 7)
#Add GNSS widgets to layout
self.layout.addWidget(self.positioning_timestamp_label, 6, 0)
self.layout.addWidget(self.positioning_label, 7, 0)
self.layout.addWidget(self.gnss_misc_label, 8, 2)
#Add sensor labels to layout
self.layout.addWidget(self.orientation_label, 4, 0, 4, 1)
self.layout.addWidget(self.lin_accel_label, 4, 2, 4, 3)
self.layout.addWidget(self.ang_vel_label, 4, 4, 4, 5)
self.layout.addWidget(self.mag_field_label, 5, 0)
self.layout.addWidget(self.env_param_label, 5, 1)
#Set the layout
self.setLayout(self.layout)
#Connect buttons to slots
self.button_zedcontroller_init.clicked.connect(self.slot_ZEDControllerInit)
self.button_gnsscontroller_init.clicked.connect(self.slot_GNSSControllerInit)
self.button_datacontroller_init.clicked.connect(self.slot_DataControllerInit)
self.button_sampleDepthFrame.clicked.connect(self.slot_sampleDepthFrame)
self.button_sampleFrame.clicked.connect(self.slot_sampleFrame)
self.button_samplePointCloud.clicked.connect(self.slot_samplePointCloud)
self.button_sampleSensorData.clicked.connect(self.slot_sampleSensorData)
#Set text
self.positioning_timestamp_label.setText("Last GNSS Timestamp: 00:00:00.00 N/A")
self.positioning_label.setText("Latitude: 00.00000 Longitude: 00.00000 (deg)")
self.gnss_misc_label.setText("Horizontal Dilution: 0.00 Connected Satellites: 0 Connection quality 0.00")
self.orientation_label.setText("Orientation: R-> 0.00 P-> 0.00 Y-> 0.00 (deg)")
self.lin_accel_label.setText("Linear Acceleration: X-> 0.00 Y-> 0.00 Z-> 0.00 (m/s^2)")
self.ang_vel_label.setText("Angular Velocity: X-> 0.00 Y-> 0.00 Z-> 0.00 (deg/s)")
self.mag_field_label.setText("Magnetic Field: X-> 0.00 Y-> 0.00 Z-> 0.00 (uT)")
self.env_param_label.setText("Pressure: 00000.00 (hPa) Relative Altitude: 0.00 (m)")
#Create variable for storing camera information
self.camera_info = None
#Show window
self.show()
def __del__(self):
pass
def paintEvent(self, event):
if (self.qpx_image is not None):
self.window_display_1.setPixmap(self.qpx_image)
if (self.qpx_depth_image is not None):
self.window_display_2.setPixmap(self.qpx_depth_image)
@pyqtSlot()
def slot_ZEDControllerInit(self):
#If ZEDController exists, remove it, if it doesn't exist, create it
if (self.zedcontroller is None):
self.zedcontroller = ZEDController.ZEDController()
self.zedcontroller.attach(self)
self.zedcontroller.daemon = True
self.zedcontroller.start()
self.button_zedcontroller_init.setStyleSheet("background-color: yellow; color: black;")
else:
self.zedcontroller.join()
self.zedcontroller.remove(self)
self.zedcontroller = None
self.button_zedcontroller_init.setStyleSheet("background-color: red; color: black;")
@pyqtSlot()
def slot_DataControllerInit(self):
#If DataController exists, remove it, if it doesn't exist, create it
if (self.datacontroller is None):
duration = self.textbox_slidingwindow.text()
try:
dur_int = int(duration)
except:
dur_int = 120
self.datacontroller = DataController.DataController("./Products", dur_int)
self.datacontroller.daemon = True
self.datacontroller.start()
#If ZEDController exists, attach DataController to it
if (self.zedcontroller is not None):
self.zedcontroller.attach(self.datacontroller)
self.button_zedcontroller_init.setStyleSheet("background-color: green; color: black;")
if (self.gnsscontroller is not None):
self.gnsscontroller.attach(self.datacontroller)
self.button_gnsscontroller_init.setStyleSheet("background-color: green; color: black;")
self.button_datacontroller_init.setStyleSheet("background-color: green; color: black;")
else:
#If ZEDController exists, remove DataController from it
if (self.zedcontroller is not None):
self.zedcontroller.remove(self.datacontroller)
self.button_zedcontroller_init.setStyleSheet("background-color: yellow; color: black;")
if (self.gnsscontroller is not None):
self.gnsscontroller.remove(self.datacontroller)
self.button_gnsscontroller_init.setStyleSheet("background-color: yellow; color: black;")
self.gnsscontroller.join()
self.datacontroller = None
self.button_datacontroller_init.setStyleSheet("background-color: red; color: black;")
@pyqtSlot()
def slot_GNSSControllerInit(self):
#If GNSSController exists, remove it, if it doesn't exist, create it
if (self.gnsscontroller is None):
self.gnsscontroller = GNSSController.GNSSController("/dev/ttyACM0", 9600)
self.gnsscontroller.attach(self)
self.gnsscontroller.daemon = True
self.gnsscontroller.start()
self.button_gnsscontroller_init.setStyleSheet("background-color: yellow; color: black;")
else:
self.gnsscontroller.join()
self.gnsscontroller.remove(self)
self.gnsscontroller = None
self.button_gnsscontroller_init.setStyleSheet("background-color: red; color: black;")
@pyqtSlot()
def slot_sampleDepthFrame(self):
pass
@pyqtSlot()
def slot_sampleFrame(self):
pass
@pyqtSlot()
def slot_samplePointCloud(self):
pass
@pyqtSlot()
def slot_sampleSensorData(self):
pass
@pyqtSlot()
def slot_dump(self):
#Try to dump data
if (self.datacontroller is not None):
self.button_dump.setStyleSheet("background-color: yellow; color: black;")
ret_code = self.datacontroller.dump()
if ret_code == 0:
self.button_dump.setStyleSheet("background-color: green; color: black;")
else:
self.button_dump.setStyleSheet("background-color: red; color: black;")
@pyqtSlot()
def slot_save(self):
#Save data
if (self.datacontroller is not None):
self.button_save.setStyleSheet("background-color: yellow; color: black;")
ret_code = self.datacontroller.save()
if ret_code == 0:
self.button_save.setStyleSheet("background-color: green; color: black;")
else:
self.button_save.setStyleSheet("background-color: red; color: black;")
def c_update(self, observable, *args, **kwargs):
#If object calling c_update() is ZEDController
if (isinstance(observable, ZEDController.ZEDController)):
if self.camera_info is None:
self.camera_info = observable.camera_info
frame_np = cv2.resize(observable.frame.get_data(), None, fx = 1.0 / self.image_scale, fy = 1.0 / self.image_scale, interpolation = cv2.INTER_AREA)
image = QImage(frame_np.data, frame_np.shape[1], frame_np.shape[0], QImage.Format.Format_RGBA8888).rgbSwapped()
self.qpx_image = QPixmap.fromImage(image)
depth_frame_viewable_np = cv2.resize(observable.depth_frame_viewable.get_data(), None, fx = 1.0 / self.image_scale, fy = 1.0 / self.image_scale, interpolation = cv2.INTER_AREA)
depth_image = QImage(depth_frame_viewable_np.data, depth_frame_viewable_np.shape[1], depth_frame_viewable_np.shape[0], QImage.Format.Format_RGBA8888).rgbSwapped()
self.qpx_depth_image = QPixmap.fromImage(depth_image)
la = observable.linear_accel
av = observable.angular_vel
mf = observable.magnetic_fld
fmt_str = "{:." + str(self.dec_precision) + "f}"
r_d = fmt_str.format(observable.roll)
p_d = fmt_str.format(observable.pitch)
y_d = fmt_str.format(observable.yaw)
lx_d = fmt_str.format(la[0])
ly_d = fmt_str.format(la[1])
lz_d = fmt_str.format(la[2])
ax_d = fmt_str.format(av[0])
ay_d = fmt_str.format(av[1])
az_d = fmt_str.format(av[2])
mx_d = fmt_str.format(mf[0])
my_d = fmt_str.format(mf[1])
mz_d = fmt_str.format(mf[2])
press = fmt_str.format(observable.pressure)
rel_alt = fmt_str.format(observable.relative_alt)
if (observable.roll > 0):
r_d = ' ' + r_d
if (observable.pitch > 0):
p_d = ' ' + p_d
if (observable.yaw > 0):
y_d = ' ' + y_d
if (la[0] > 0):
lx_d = ' ' + lx_d
if (la[1] > 0):
ly_d = ' ' + ly_d
if (la[2] > 0):
lz_d = ' ' + lz_d
if (av[0] > 0):
ax_d = ' ' + ax_d
if (av[1] > 0):
ay_d = ' ' + ay_d
if (av[2] > 0):
az_d = ' ' + az_d
if (mf[0] > 0):
mx_d = ' ' + mx_d
if (mf[1] > 0):
my_d = ' ' + my_d
if (mf[2] > 0):
mz_d = ' ' + mz_d
if (observable.pressure > 0):
press = ' ' + press
if (observable.relative_alt > 0):
rel_alt = ' ' + rel_alt
self.orientation_label.setText("Orientation: R-> " + r_d + " P-> " + p_d + " Y-> " + y_d + " (deg)")
self.lin_accel_label.setText("Linear Acceleration: X-> " + lx_d + " Y-> " + ly_d + " Z-> " + lz_d +" (m/s^2)")
self.ang_vel_label.setText("Angular Velocity: X-> " + ax_d + " Y-> " + ay_d + " Z-> " + az_d + " (deg/s)")
self.mag_field_label.setText("Magnetic Field: X-> " + mx_d + " Y-> " + my_d + " Z-> " + mz_d + " (uT)")
self.env_param_label.setText("Pressure: " + press + " (hpa) Relative Altitude: " + rel_alt + " (m)")
if (isinstance(observable, GNSSController.GNSSController)):
gnss_dict = observable.gnss_dict
self.positioning_timestamp_label.setText("Last GNSS Timestamp: " + str(gnss_dict["timestamp"]))
self.positioning_label.setText("Latitude: " + str(round(gnss_dict["latitude"], self.dec_precision)) + " Longitude: " + str(round(gnss_dict["longitude"], self.dec_precision)) + " (deg)")
self.gnss_misc_label.setText("Horizontal Dilution: " + str(round(gnss_dict["horizontal_dil"], self.dec_precision)) + " Connected Satellites: " + str(gnss_dict["num_sats"]) + " Connection quality " + str(gnss_dict["gps_qual"]))
self.show()