diff --git a/LCL.ui b/LCL.ui
index 2c5e00e7c15378dac810ed3ec7a42f83292da4ec..237a0ca0a9ebdecc1fb5ad634f946005445e65e3 100644
--- a/LCL.ui
+++ b/LCL.ui
@@ -83,7 +83,7 @@
- 160
+ 240
440
161
41
@@ -93,10 +93,10 @@
- 340
+ 420
420
171
- 101
+ 121
@@ -154,11 +154,37 @@
Left
+
+
+
+ 7
+ 90
+ 75
+ 23
+
+
+
+ Home Stage
+
+
+
+
+
+ 87
+ 90
+ 75
+ 23
+
+
+
+ Get Position
+
+
- 160
+ 240
420
71
16
@@ -171,7 +197,7 @@
- 160
+ 240
490
161
23
diff --git a/LCL_run.py b/LCL_run.py
index 07fa366bac2f1d5d81e45a4b56c68175a54f4d72..7f03762f04dbad8b47cbff106442a56a2a8c313e 100644
--- a/LCL_run.py
+++ b/LCL_run.py
@@ -10,8 +10,8 @@ from utils import screen_shooter,now,comment
from stage_controller import stage_controller
class ShowVideo(QtCore.QObject):
- #initiating the built in camera
camera_port = 1 + cv2.CAP_DSHOW
+ # camera_port = 0 + cv2.CAP_DSHOW
camera = cv2.VideoCapture(camera_port)
VideoSignal = QtCore.pyqtSignal(QtGui.QImage)
screenshot_signal = QtCore.pyqtSignal('PyQt_PyObject')
@@ -19,10 +19,15 @@ class ShowVideo(QtCore.QObject):
def __init__(self, parent = None):
super(ShowVideo, self).__init__(parent)
self.run_video = True
-
+
@QtCore.pyqtSlot()
def startVideo(self):
- comment('starting video')
+ comment('video properties:')
+ self.camera.set(12,128)
+ self.camera.set(17,3000)
+ for i in range(19):
+ comment('property {}, value: {}'.format(i,
+ self.camera.get(i)))
while self.run_video:
ret, image = self.camera.read()
self.screenshot_signal.emit(image)
@@ -35,6 +40,8 @@ class ShowVideo(QtCore.QObject):
QtGui.QImage.Format_RGB888)
self.VideoSignal.emit(qt_image)
QApplication.processEvents()
+ self.camera.release()
+ comment('ending video')
class ImageViewer(QtWidgets.QWidget):
@@ -58,6 +65,9 @@ class ImageViewer(QtWidgets.QWidget):
def resize_dynamically(self,image):
return image.scaled(window.ui.verticalLayoutWidget.size())
+ def mousePressEvent(self, QMouseEvent):
+ print(QMouseEvent.pos())
+
class main_window(QMainWindow):
def __init__(self):
super(main_window, self).__init__()
@@ -86,6 +96,8 @@ class main_window(QMainWindow):
self.ui.right_button.clicked.connect(stage.move_right)
self.ui.down_button.clicked.connect(stage.move_down)
self.ui.up_button.clicked.connect(stage.move_up)
+ self.ui.get_position_button.clicked.connect(stage.get_position)
+ self.ui.home_stage_button.clicked.connect(stage.home_stage)
self.show()
comment('finished init')
@@ -93,6 +105,12 @@ class main_window(QMainWindow):
comment('user comment:{}'.format(self.ui.comment_box.toPlainText()))
self.ui.comment_box.clear()
+ def keyPressEvent(self,event):
+ stage.handle_keypress(event.key())
+
+ def closeEvent(self, event):
+ self.vid.run_video = False
+
if __name__ == '__main__':
app = QApplication(sys.argv)
stage = stage_controller()
diff --git a/LCL_ui.py b/LCL_ui.py
index 7db76e6308d24941cc64f266de698dcbb90ace31..730a3def2600123a9531449fa5fe1737e9835554 100644
--- a/LCL_ui.py
+++ b/LCL_ui.py
@@ -33,10 +33,10 @@ class Ui_MainWindow(object):
self.misc_screenshot_button.setGeometry(QtCore.QRect(10, 130, 81, 61))
self.misc_screenshot_button.setObjectName("misc_screenshot_button")
self.comment_box = QtWidgets.QTextEdit(self.centralwidget)
- self.comment_box.setGeometry(QtCore.QRect(160, 440, 161, 41))
+ self.comment_box.setGeometry(QtCore.QRect(240, 440, 161, 41))
self.comment_box.setObjectName("comment_box")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
- self.groupBox.setGeometry(QtCore.QRect(340, 420, 171, 101))
+ self.groupBox.setGeometry(QtCore.QRect(420, 420, 171, 121))
self.groupBox.setObjectName("groupBox")
self.down_button = QtWidgets.QPushButton(self.groupBox)
self.down_button.setGeometry(QtCore.QRect(40, 60, 90, 23))
@@ -50,11 +50,17 @@ class Ui_MainWindow(object):
self.left_button = QtWidgets.QPushButton(self.groupBox)
self.left_button.setGeometry(QtCore.QRect(10, 40, 75, 23))
self.left_button.setObjectName("left_button")
+ self.home_stage_button = QtWidgets.QPushButton(self.groupBox)
+ self.home_stage_button.setGeometry(QtCore.QRect(7, 90, 75, 23))
+ self.home_stage_button.setObjectName("home_stage_button")
+ self.get_position_button = QtWidgets.QPushButton(self.groupBox)
+ self.get_position_button.setGeometry(QtCore.QRect(87, 90, 75, 23))
+ self.get_position_button.setObjectName("get_position_button")
self.comment_box_label = QtWidgets.QLabel(self.centralwidget)
- self.comment_box_label.setGeometry(QtCore.QRect(160, 420, 71, 16))
+ self.comment_box_label.setGeometry(QtCore.QRect(240, 420, 71, 16))
self.comment_box_label.setObjectName("comment_box_label")
self.user_comment_button = QtWidgets.QPushButton(self.centralwidget)
- self.user_comment_button.setGeometry(QtCore.QRect(160, 490, 161, 23))
+ self.user_comment_button.setGeometry(QtCore.QRect(240, 490, 161, 23))
self.user_comment_button.setObjectName("user_comment_button")
MainWindow.setCentralWidget(self.centralwidget)
@@ -76,6 +82,8 @@ class Ui_MainWindow(object):
self.right_button.setText(_translate("MainWindow", "Right"))
self.up_button.setText(_translate("MainWindow", "Up"))
self.left_button.setText(_translate("MainWindow", "Left"))
+ self.home_stage_button.setText(_translate("MainWindow", "Home Stage"))
+ self.get_position_button.setText(_translate("MainWindow", "Get Position"))
self.comment_box_label.setText(_translate("MainWindow", "Comment box"))
self.user_comment_button.setText(_translate("MainWindow", "Add comment to log"))
diff --git a/__pycache__/LCL_ui.cpython-36.pyc b/__pycache__/LCL_ui.cpython-36.pyc
index f8a7b39f36fedace669b43df8a8a75454cef830b..2cdc259be8d052be6527a6b2ed4eb5ff15fcfc46 100644
Binary files a/__pycache__/LCL_ui.cpython-36.pyc and b/__pycache__/LCL_ui.cpython-36.pyc differ
diff --git a/__pycache__/stage_controller.cpython-36.pyc b/__pycache__/stage_controller.cpython-36.pyc
index deacebf5a855bbf74ed7019538217dd5c4e242e0..18988ab420abb45ad640cc046bdb3e6f40c5398a 100644
Binary files a/__pycache__/stage_controller.cpython-36.pyc and b/__pycache__/stage_controller.cpython-36.pyc differ
diff --git a/stage_controller.py b/stage_controller.py
index d1b9bf92a5a9b6eb75cbf575ec52d578def0ffb7..db024fb9a8697405288f50330e1529df317e8dce 100644
--- a/stage_controller.py
+++ b/stage_controller.py
@@ -10,8 +10,14 @@ class stage_controller():
com = 'COM3'
baud = 9600
parity = serial.PARITY_NONE
- self.ser = serial.Serial(com, baud, timeout=0,
+ self.ser = serial.Serial(com, baud, timeout=.25,
parity=parity)
+ self.standard_move_size = 1000
+ self.key_control_dict = {
+ 87:self.move_up,
+ 65:self.move_left,
+ 83:self.move_down,
+ 68:self.move_right}
def issue_command(self,command):
'''
@@ -21,7 +27,7 @@ class stage_controller():
comment('sending command to stage:{}'.format(command_string))
self.ser.write(command_string.encode('utf-8'))
- def get_response(self):
+ def get_long_response(self):
response = ''
while 'END' not in response:
piece = self.ser.read()
@@ -30,27 +36,51 @@ class stage_controller():
comment('response received from stage:{}'.format(response))
return response
- def get_status(self):
- self.issue_command('?')
- return self.get_response()
+ def send_receive(self,command):
+ self.issue_command(command)
+ response = self.ser.readline()
+ comment('response received from stage:{}'.format(response))
+ return response
+
+ def get_status(self):
+ self.issue_command('?')
+ return self.get_long_response()
@QtCore.pyqtSlot()
- def move_left(self):
- print('test')
+ def home_stage(self):
+ # hits the limit switches and then returns to last known location
+ return self.send_receive('RIS')
@QtCore.pyqtSlot()
- def move_right(self):
- pass
+ def get_position(self):
+ return self.send_receive('P')
+
+ def go_to_position(self,x,y):
+ return self.send_receive('G,{},{}'.format(x,y))
+
+ @QtCore.pyqtSlot()
+ def move_up(self):
+ return self.send_receive('GR,0,-{}'.format(self.standard_move_size))
@QtCore.pyqtSlot()
def move_down(self):
- pass
+ return self.send_receive('GR,0,{}'.format(self.standard_move_size))
@QtCore.pyqtSlot()
- def move_up(self):
- pass
+ def move_right(self):
+ return self.send_receive('GR,{},0'.format(self.standard_move_size))
+
+ @QtCore.pyqtSlot()
+ def move_left(self):
+ return self.send_receive('GR,-{},0'.format(self.standard_move_size))
+
+ def handle_keypress(self,key):
+ if key in self.key_control_dict.keys():
+ self.key_control_dict[key]()
+
if __name__ == '__main__':
stage = stage_controller()
- stage_controller.get_status(stage)
+ stage_controller.home_stage(stage)
+