This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
252 lines (214 loc) · 10.2 KB
/
main.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
"""
Author: Ro Sharaf
Maintainers: Ro Sharaf, Austin Lake
Program: science gui and Command & Control
Date: 3/15/2022
"""
import rclpy
import sys
import time
from PyQt5.QtCore import QFile, QTimer, pyqtSignal, pyqtSlot, Qt, QThread
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
from PyQt5 import uic, QtGui
from PyQt5.QtGui import QPixmap
import sys
import cv2
from ui_form import Ui_MainView
from funnel_cake import FunnelCake
from lowering_platform import Platform
from cameras import Cameras
from turret import Turret
class MainWindow(QWidget):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.ui = Ui_MainView()
self.ui.setupUi(self)
self.window = uic.loadUi("form.ui")
self.ui.collect_sample_button.clicked.connect(self.on_collect_sample_pressed)
self.ui.platform_slider.valueChanged.connect(self.on_platform_height_changed)
self.ui.turret_speed.valueChanged.connect(self.on_turret_speed_changed)
# self.ui.microscope_button.clicked.connect(self.on_microscope_pressed)
# self.ui.uv_camera_button.clicked.connect(self.on_uv_camera_pressed)
# self.ui.ir_camera_button.clicked.connect(self.on_ir_camera_pressed)
# self.ui.flashlight_button.clicked.connect(self.on_flashlight_pressed)
# self.ui.brush_button.clicked.connect(self.on_brush_pressed)
# self.ui.uv_light_button.clicked.connect(self.on_uv_light_pressed)
self.ui.water_pump_button.clicked.connect(self.on_water_pump_pressed)
self.ui.set_height_button.clicked.connect(self.on_set_height_pressed)
# self.ui.run_pump_button.clicked.connect(self.on_run_pump_pressed)
# self.ui.pumps_dial.valueChanged.connect(self.on_pumps_dial_value_changed)
# self.ui.camera_camboBox.activated[int].connect(self.on_switch_camera)
# self.ui.take_picture_button.clicked.connect(self.on_take_picture_button_pressed)
self.funnel_cake_controller = FunnelCake()
self.camera_controller = Cameras()
self.turret_controller = Turret()
self.platform_controller = Platform()
self.camera_list = [[1, False, False, False], [2, False, False, False],
[3, False, False, False], [4, False, False, False]]
self.is_collect_sample_pressed = False
self.is_microscope_pressed = False
self.is_uv_camera_pressed = False
self.is_ir_camera_pressed = False
self.is_flashlight_pressed = False
self.is_brush_pressed = False
self.is_uv_light_pressed = False
self.is_water_pump_pressed = False
self.ui_progress_bar = {1: self.ui.pump_one_pb,
2: self.ui.pump_two_pb,
3: self.ui.pump_three_pb,
4: self.ui.pump_four_pb,
5: self.ui.pump_five_pb}
self.showMaximized()
self.frame_updater = QTimer()
self.frame_updater.timeout.connect(self.update_frames)
self.frame_updater.start(30)
def closeEvent(self, event):
self.frame_updater.stop()
self.camera_controller.close()
self.platform_controller.close()
event.accept()
def update_frames(self):
"""Updates the image_label with a new opencv image"""
self.ui.label_2.setPixmap(self.convert_cv_qt(self.camera_controller.get_zed_frame()))
if self.is_microscope_pressed:
self.ui.label_3.setPixmap(self.convert_cv_qt(self.camera_controller.get_microscope_frame()))
if self.is_uv_camera_pressed:
self.ui.label_4.setPixmap(self.convert_cv_qt(self.camera_controller.get_uv_camera_frame()))
if self.is_ir_camera_pressed:
self.ui.label_5.setPixmap(self.convert_cv_qt(self.camera_controller.get_ir_camera_frame()))
def convert_cv_qt(self, cv_img):
"""Convert from an opencv image to QPixmap"""
rgb_image = cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB)
h, w, ch = rgb_image.shape
bytes_per_line = ch * w
convert_to_Qt_format = QtGui.QImage(rgb_image.data, w, h, bytes_per_line, QtGui.QImage.Format_RGB888)
p = convert_to_Qt_format.scaled(640, 480, Qt.KeepAspectRatio)
return QPixmap.fromImage(p)
def on_collect_sample_pressed(self):
if not self.is_collect_sample_pressed:
self.funnel_cake_controller.turn_vacuum_on()
self.ui.collect_sample_button.setStyleSheet('background-color: #B3BAFF;')
else:
self.funnel_cake_controller.turn_vacuum_off()
self.ui.collect_sample_button.setStyleSheet('background-color: white;')
self.is_collect_sample_pressed = not self.is_collect_sample_pressed
def on_water_pump_pressed(self):
if not self.is_water_pump_pressed:
self.funnel_cake_controller.turn_water_pump_off()
self.ui.water_pump_button.setStyleSheet('background-color: #B3BAFF;')
else:
self.funnel_cake_controller.turn_water_pump_on()
self.ui.water_pump_button.setStyleSheet('background-color: white;')
self.is_water_pump_pressed = not self.is_water_pump_pressed
def on_pumps_dial_value_changed(self, value):
# self.funnel_cake_controller.rotate_funnel_index(value)
# self.ui.pump_number.setText(f'{value}')
pass
def on_run_pump_pressed(self):
# self.funnel_cake_controller.turn_funnel_pump_on()
# for funnel in self.funnel_cake_controller.get_funnel_list():
# bar = 0
# if self.funnel_cake_controller.get_funnel_list()[funnel] is True:
# while bar <= 100:
# self.ui_progress_bar[funnel].setValue(bar)
# bar = int(bar + 1666 / 1000)
# time.sleep(1.6/100)
pass
def on_platform_height_changed(self, value):
self.platform_controller.set_height(value)
def on_set_height_pressed(self):
self.platform_controller.set_platform_height(self.platform_controller.get_height())
def on_microscope_pressed(self):
# if not self.is_microscope_pressed:
# self.camera_controller.start_microscope_streaming()
# self.ui.microscope_button.setStyleSheet('background-color: #B3BAFF;')
# else:
# self.camera_controller.stop_microscope_streaming()
# self.ui.microscope_button.setStyleSheet('background-color: white;')
# self.is_microscope_pressed = not self.is_microscope_pressed
pass
def on_uv_camera_pressed(self):
# if not self.is_uv_camera_pressed:
# self.camera_controller.start_uv_camera_streaming()
# self.ui.uv_camera_button.setStyleSheet('background-color: #B3BAFF;')
# else:
# self.camera_controller.stop_uv_camera_streaming()
# self.ui.uv_camera_button.setStyleSheet('background-color: white;')
# self.is_uv_camera_pressed = not self.is_uv_camera_pressed
pass
def on_ir_camera_pressed(self):
# if not self.is_ir_camera_pressed:
# self.camera_controller.start_ir_camera_streaming()
# self.ui.ir_camera_button.setStyleSheet('background-color: #B3BAFF;')
# else:
# self.camera_controller.stop_ir_camera_streaming()
# self.ui.ir_camera_button.setStyleSheet('background-color: white;')
# self.is_ir_camera_pressed = not self.is_ir_camera_pressed
pass
def on_flashlight_pressed(self):
# if not self.is_flashlight_pressed:
# self.platform_controller.turn_flashlight_on()
# self.ui.flashlight_button.setStyleSheet('background-color: #B3BAFF;')
# else:
# self.platform_controller.turn_flashlight_off()
# self.ui.flashlight_button.setStyleSheet('background-color: white;')
# self.is_flashlight_pressed = not self.is_flashlight_pressed
pass
def on_brush_pressed(self):
# if not self.is_brush_pressed:
# self.platform_controller.turn_brush_on()
# self.ui.brush_button.setStyleSheet('background-color: #B3BAFF;')
# else:
# self.platform_controller.turn_brush_off()
# self.ui.brush_button.setStyleSheet('background-color: white;')
# self.is_brush_pressed = not self.is_brush_pressed
pass
def on_uv_light_pressed(self):
# if not self.is_uv_light_pressed:
# self.platform_controller.turn_uv_light_on()
# self.ui.uv_light_button.setStyleSheet('background-color: #B3BAFF;')
# else:
# self.platform_controller.turn_uv_light_off()
# self.ui.uv_light_button.setStyleSheet('background-color: white;')
# self.is_uv_light_pressed = not self.is_uv_light_pressed
pass
def on_take_picture_button_pressed(self):
# self.camera_list[self.ui.camera_camboBox.currentIndex()][2] = True
# cam_index = self.ui.camera_camboBox.currentIndex()
# if cam_index == 0:
# self.camera_controller.take_microscope_snapshot()
# elif cam_index == 1:
# self.camera_controller.take_uv_camera_snapshot()
# elif cam_index == 2:
# self.camera_controller.take_ir_camera_snapshot()
# else:
# self.camera_controller.take_zed_snapshot()
pass
def on_switch_camera(self, index):
# if self.camera_list[self.ui.camera_camboBox.currentIndex()][1]:
# self.ui.start_record_button.setStyleSheet('background-color: #B3BAFF;')
# else:
# self.ui.start_record_button.setStyleSheet('background-color: white;')
#
# if self.camera_list[self.ui.camera_camboBox.currentIndex()][3]:
# self.ui.stop_record_button.setStyleSheet('background-color: #B3BAFF;')
# else:
# self.ui.stop_record_button.setStyleSheet('background-color: white;')
pass
def on_turret_speed_changed(self, value):
self.turret_controller.adjust_speed(value)
def main():
app = QApplication(sys.argv)
rclpy.init()
try:
window = MainWindow()
window.resize(1500, 800)
window.show()
except KeyboardInterrupt:
print('\n')
except Exception as e:
print(f'{e}')
finally:
sys.exit(app.exec_())
if __name__ == "__main__":
main()