Commit 6063820e authored by Martin Drechsler's avatar Martin Drechsler

rigol added for control and measurements

parent 4c058262
......@@ -12,3 +12,4 @@ CAMERA_TYPE: if dummy, then a dummy camera is loaded.
WORKING_DIR = '/home/martindrech/Documents/total_control_app/resources/'
CAMERA_TYPE = {'dummy': True}
RIGOL_GEN = True
\ No newline at end of file
......@@ -16,11 +16,15 @@ from subclasses.pyqtgraph_subclasses import CustomRectangularROI
from zylaCameraWorker import CameraWorker
from subclasses.controllayouts import LaserControlLayout, LaserScanLayout
from subclasses.cameraParameterFrame import CameraParameterFrame
from rigolGui import RigolGenGui
from resources.scanFunctions import create_measurement_array
from resources.storage import get_date_string
from resources.messages import show_warning
from appsettings import WORKING_DIR
from measurement import MeasurementFrame
from rigol_measurement import RigolMeasurementFrame
import sys, os
import numpy as np
......@@ -31,7 +35,8 @@ GUI_LOG = LOG.getChild('GUI logger')
class CameraGuiMainWindow(QMainWindow):
signalWithMeasurementParameters = QtCore.pyqtSignal(object)
roiDataReadySignal = QtCore.pyqtSignal(float)
signalWithRigolMeasurementParameters = QtCore.pyqtSignal(object)
roiDataReadySignal = QtCore.pyqtSignal(float, str)
def __init__(self):
super().__init__()
......@@ -63,18 +68,22 @@ class CameraGuiMainWindow(QMainWindow):
self.dMeasurement = dockarea.Dock("Measurement and saving")
self.dConsole = dockarea.Dock("Console for debugging")
self.dCameraScanAnal = dockarea.Dock("Zyla Camera Scan Analysis")
self.dRigolMeasurement = dockarea.Dock('Rigol Measurement')
self.area.addDock(self.dCameraView)
self.area.addDock(self.dCameraScanAnal, "left", self.dCameraView)
self.area.addDock(self.dCameraTimeAnal, "below", self.dCameraScanAnal)
self.area.addDock(self.dCameraControl, "right", self.dCameraView)
self.area.addDock(self.dConsole, "right", self.dCameraControl)
self.area.addDock(self.dMeasurement, "above", self.dConsole)
self.area.addDock(self.dRigolMeasurement, "below", self.dConsole)
#measurement frame
self.measurementFrame = MeasurementFrame()
self.dMeasurement.addWidget(self.measurementFrame)
self.rigolMeasurementFrame = RigolMeasurementFrame()
self.dRigolMeasurement.addWidget(self.rigolMeasurementFrame)
# button spinbox and label
self.cameraButton = QPushButton("Start Acquisition")
......@@ -163,6 +172,15 @@ class CameraGuiMainWindow(QMainWindow):
self.cameraParamFrame.saveImgButton.clicked.connect(self.save_current_image)
self.rigolMeasurementFrame.startMeasureButton.clicked.connect(self.emit_rigol_measurement_parameters_and_start)
self.rigolMeasurementFrame.startValue.valueChanged.connect(self.rigolMeasurementFrame.update_tree)
self.rigolMeasurementFrame.endValue.valueChanged.connect(self.rigolMeasurementFrame.update_tree)
self.rigolMeasurementFrame.stepsNum.valueChanged.connect(self.rigolMeasurementFrame.update_tree)
self.rigolMeasurementFrame.saveMeasureButton.clicked.connect(
lambda: self.rigolMeasurementFrame.saveMeasureButton.setEnabled(False)
)
self.rigolMeasurementFrame.abortMeasureButton.clicked.connect(backend.abort_measurement)
for roi in self.rois:
self.cameraParamFrame.saveRoiButton.clicked.connect(lambda: roi.save(
current_binning=self.cameraParamFrame.paramTree.p.child('Basic acq parameters')
......@@ -212,9 +230,8 @@ class CameraGuiMainWindow(QMainWindow):
roiSlice = roi.getArrayRegion(self.img.image, img=self.img)
self.newData = np.mean(roiSlice)
if self.isMeasuring:
self.roiDataReadySignal.emit(self.newData)
self.roiDataReadySignal.emit(self.newData, self.meas_type)
self.timeROIdataY = np.roll(self.timeROIdataY, -1)
self.scanROIdataY[self.iROIdata] = self.newData
self.timeROIdataY[-1] = self.newData
......@@ -264,15 +281,24 @@ class CameraGuiMainWindow(QMainWindow):
)
self.previous_frame_index = self.frame_index
#@QtCore.pyqtSlot()
def measurement_starting(self):
@QtCore.pyqtSlot(str)
def measurement_starting(self, meas_type):
self.cameraButton.setEnabled(False)
self.measurementFrame.startMeasureButton.setEnabled(False)
self.rigolMeasurementFrame.startMeasureButton.setEnabled(False)
self.meas_type = meas_type
self.isMeasuring = True
start = self.measurementFrame.startValue.value()
end = self.measurementFrame.endValue.value()
steps = self.measurementFrame.stepsNum.value()
if self.meas_type == 'simple':
start = self.measurementFrame.startValue.value()
end = self.measurementFrame.endValue.value()
steps = self.measurementFrame.stepsNum.value()
elif self.meas_type == 'rigol':
start = self.rigolMeasurementFrame.startValue.value()
end = self.rigolMeasurementFrame.endValue.value()
steps = self.rigolMeasurementFrame.stepsNum.value()
else:
raise 'Oh, wrong meas type'
self.frame_index = 0
self.iROIdata = 0
self.scanROIdataX = create_measurement_array(start, end, steps)
......@@ -284,12 +310,15 @@ class CameraGuiMainWindow(QMainWindow):
print('gui meas start')
#@QtCore.pyqtSlot()
@QtCore.pyqtSlot(str)
def measurement_ending(self):
print('entering gui measure ending')
self.cameraButton.setEnabled(True)
self.measurementFrame.startMeasureButton.setEnabled(True)
self.measurementFrame.saveMeasureButton.setEnabled(True)
self.rigolMeasurementFrame.startMeasureButton.setEnabled(True)
self.rigolMeasurementFrame.saveMeasureButton.setEnabled(True)
self.isMeasuring = False
scanned_sb_name = self.measurementFrame.selectScanSignal.currentText()
......@@ -312,6 +341,7 @@ class CameraGuiMainWindow(QMainWindow):
measure_params['steps'] = self.measurementFrame.stepsNum.value()
measure_params['directory'] = self.measurementFrame.folderBrowser.toPlainText()
measure_params['comment'] = self.measurementFrame.comments.toPlainText()
for l in LaserControlLayout._registry:
for sb_name, sb in l.spinboxes.items():
measure_params[sb_name] = sb.value()
......@@ -319,8 +349,28 @@ class CameraGuiMainWindow(QMainWindow):
for roi in self.rois:
measure_params['Roi Pos'] = roi.pos()
measure_params['Roi Size'] = roi.size()
self.signalWithMeasurementParameters.emit(measure_params)
def emit_rigol_measurement_parameters_and_start(self):
measure_params = dict()
measure_params['gui params'] = 0
measure_params['start'] = self.rigolMeasurementFrame.startValue.value()
measure_params['end'] = self.rigolMeasurementFrame.endValue.value()
measure_params['steps'] = self.rigolMeasurementFrame.stepsNum.value()
measure_params['directory'] = WORKING_DIR
measure_params['comment'] = self.rigolMeasurementFrame.comments.toPlainText()
for l in LaserControlLayout._registry:
for sb_name, sb in l.spinboxes.items():
measure_params[sb_name] = sb.value()
for roi in self.rois:
measure_params['Roi Pos'] = roi.pos()
measure_params['Roi Size'] = roi.size()
self.signalWithRigolMeasurementParameters.emit(measure_params)
def save_current_image(self):
if self.cameraParamFrame.imagePrefix.text()=='':
show_warning('You have to write a filename')
......
......@@ -28,6 +28,7 @@ class ControlGui(QtGui.QFrame):
self.initUI()
def initUI(self):
self.setObjectName('Daq Gui')
self.menuBar = QtGui.QMenuBar(self)
self.area = dockarea.DockArea()
self.grid = QtGui.QGridLayout()
......
from appsettings import CAMERA_TYPE
from appsettings import CAMERA_TYPE, RIGOL_GEN
if CAMERA_TYPE['dummy']==True:
from drivers.dummyAndor import AndorZyla
else:
from drivers.andorzyla import AndorZyla
from drivers.GeneradorFuncionesRigol import GeneradorFuncionesRigol
from rigolGui import RigolGenGui
from cameraGui import CameraGuiMainWindow
from zylaCameraWorker import CameraWorker
from MCDAQcontrolsignals import anal_control_signal
......@@ -39,6 +42,10 @@ if __name__ == "__main__":
app.setWindowIcon(app_icon)
camera = AndorZyla(0)
if RIGOL_GEN:
rigGen = GeneradorFuncionesRigol()
rigGenGui = RigolGenGui(rigGen)
piezoA397 = anal_control_signal('piezoA397', channel=13, ao_type='cavity_piezo', out_minimum = 0, out_maximum = 4)
piezoB397 = anal_control_signal('piezoB397', channel=7, ao_type='cavity_piezo')
......@@ -74,7 +81,11 @@ if __name__ == "__main__":
cameraMainWindow = CameraGuiMainWindow()
cameraWorker = CameraWorker(camera)
if RIGOL_GEN:
cameraWorker = CameraWorker(camera, rigGen)
else:
cameraWorker = CameraWorker(camera)
cameraWorker.moveToThread(backendThread)
......@@ -85,4 +96,10 @@ if __name__ == "__main__":
controlGui.toolbar.load()
sys.exit(app.exec_())
app.exec_()
if RIGOL_GEN:
rigGen.__del__()
try:
camera.shutdown()
except:
print('Proper shutdown of camera failed')
\ No newline at end of file
......@@ -11,7 +11,7 @@ The ui skeleton is built with qtdesigner and its structur lies in the measuremen
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtCore import QSettings
from PyQt5.QtWidgets import QAction, QFileDialog, QInputDialog, QWidget
from measurement_ui import Ui_Frame
from resources.measurement_ui import Ui_Frame
from MCDAQcontrolsignals import anal_control_signal
from appsettings import WORKING_DIR
......
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'measurement.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Frame(object):
def setupUi(self, Frame):
Frame.setObjectName("Frame")
Frame.resize(578, 423)
Frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
Frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.gridLayoutWidget = QtWidgets.QWidget(Frame)
self.gridLayoutWidget.setGeometry(QtCore.QRect(20, 90, 231, 211))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.selectScanSignal = QtWidgets.QComboBox(self.gridLayoutWidget)
self.selectScanSignal.setObjectName("selectScanSignal")
self.gridLayout.addWidget(self.selectScanSignal, 0, 1, 1, 1)
self.comments = QtWidgets.QTextEdit(self.gridLayoutWidget)
self.comments.setObjectName("comments")
self.gridLayout.addWidget(self.comments, 4, 1, 1, 1)
self.label = QtWidgets.QLabel(self.gridLayoutWidget)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.label_2 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
self.label_3 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1)
self.label_4 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1)
self.label_5 = QtWidgets.QLabel(self.gridLayoutWidget)
self.label_5.setObjectName("label_5")
self.gridLayout.addWidget(self.label_5, 4, 0, 1, 1)
self.startValue = SpinBox(self.gridLayoutWidget)
self.startValue.setObjectName("startValue")
self.gridLayout.addWidget(self.startValue, 1, 1, 1, 1)
self.endValue = QtWidgets.QDoubleSpinBox(self.gridLayoutWidget)
self.endValue.setObjectName("endValue")
self.gridLayout.addWidget(self.endValue, 2, 1, 1, 1)
self.stepsNum = QtWidgets.QSpinBox(self.gridLayoutWidget)
self.stepsNum.setObjectName("stepsNum")
self.gridLayout.addWidget(self.stepsNum, 3, 1, 1, 1)
self.startMeasureButton = QtWidgets.QPushButton(Frame)
self.startMeasureButton.setGeometry(QtCore.QRect(20, 320, 171, 23))
self.startMeasureButton.setObjectName("startMeasureButton")
self.measureProgressBar = QtWidgets.QProgressBar(Frame)
self.measureProgressBar.setGeometry(QtCore.QRect(20, 350, 171, 23))
self.measureProgressBar.setProperty("value", 24)
self.measureProgressBar.setObjectName("measureProgressBar")
self.treeView = QtWidgets.QTreeView(Frame)
self.treeView.setGeometry(QtCore.QRect(270, 110, 281, 111))
self.treeView.setObjectName("treeView")
self.label_6 = QtWidgets.QLabel(Frame)
self.label_6.setGeometry(QtCore.QRect(340, 80, 161, 20))
self.label_6.setObjectName("label_6")
self.folderButton = QtWidgets.QPushButton(Frame)
self.folderButton.setGeometry(QtCore.QRect(30, 20, 80, 23))
self.folderButton.setObjectName("folderButton")
self.folderBrowser = QtWidgets.QTextBrowser(Frame)
self.folderBrowser.setGeometry(QtCore.QRect(120, 20, 441, 21))
self.folderBrowser.setObjectName("folderBrowser")
self.saveMeasureButton = QtWidgets.QPushButton(Frame)
self.saveMeasureButton.setGeometry(QtCore.QRect(199, 320, 151, 23))
self.saveMeasureButton.setObjectName("saveMeasureButton")
self.abortMeasureButton = QtWidgets.QPushButton(Frame)
self.abortMeasureButton.setGeometry(QtCore.QRect(30, 380, 151, 23))
self.abortMeasureButton.setObjectName("abortMeasureButton")
self.retranslateUi(Frame)
QtCore.QMetaObject.connectSlotsByName(Frame)
def retranslateUi(self, Frame):
_translate = QtCore.QCoreApplication.translate
Frame.setWindowTitle(_translate("Frame", "Frame"))
self.label.setText(_translate("Frame", "Scan signal"))
self.label_2.setText(_translate("Frame", "Start value"))
self.label_3.setText(_translate("Frame", "End value"))
self.label_4.setText(_translate("Frame", "Steps num"))
self.label_5.setText(_translate("Frame", "Comments"))
self.startMeasureButton.setText(_translate("Frame", "Start measurement"))
self.label_6.setText(_translate("Frame", "Info about measurement"))
self.folderButton.setText(_translate("Frame", "Folder"))
self.saveMeasureButton.setText(_translate("Frame", "Save measurement"))
self.abortMeasureButton.setText(_translate("Frame", "Abort measurement"))
from pyqtgraph import SpinBox
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Frame = QtWidgets.QFrame()
ui = Ui_Frame()
ui.setupUi(Frame)
Frame.show()
sys.exit(app.exec_())
......@@ -20,13 +20,15 @@ from resources.storage import Storage
class CameraWorker(QtCore.QObject):
imageReadySignal = QtCore.pyqtSignal(np.ndarray, int)
measurementStartingSignal = QtCore.pyqtSignal()
measurementEndingSignal = QtCore.pyqtSignal()
measurementStartingSignal = QtCore.pyqtSignal(str)
measurementEndingSignal = QtCore.pyqtSignal(str)
def __init__(self, andor_camera):
def __init__(self, andor_camera, rigGen):
super().__init__()
self.cam = andor_camera
self.rigGen = rigGen
self.cam.Init()
self.cam.SensorCooling.setValue(True)
print("camera worker initialized")
......@@ -49,6 +51,13 @@ class CameraWorker(QtCore.QObject):
)
)
frontend.signalWithRigolMeasurementParameters.connect(self.rigol_measurement_start)
frontend.rigolMeasurementFrame.saveMeasureButton.clicked.connect(
lambda: self.permanent_save_measurement(
comment=frontend.rigolMeasurementFrame.comments.toPlainText()
)
)
# internal connections
self.cam.helper.imageAquiredSignal.connect(self.new_image_acquired)
#self.cam.helper.timeoutSignal.connect()
......@@ -130,7 +139,7 @@ class CameraWorker(QtCore.QObject):
show_warning('Can not start measurement if camera is acquiring')
return 0
self.measurementStartingSignal.emit()
self.measurementStartingSignal.emit('simple')
self.ao_to_scan = self.get_scan_signal(measure_params['signal_to_scan'])
self.ao_initial_value = self.ao_to_scan.AO.get_current_value()
......@@ -160,7 +169,7 @@ class CameraWorker(QtCore.QObject):
def simple_scan_measurement_end(self):
print('entering scan ending in worker')
self.measurementEndingSignal.emit()
self.measurementEndingSignal.emit('simple')
self.cam.trigger()
self._stop_acquisition_loop()
self.ao_to_scan.go_softly_to_value(self.ao_initial_value)
......@@ -185,11 +194,20 @@ class CameraWorker(QtCore.QObject):
def get_scan_signal(self, ao_name):
return [ao for ao in anal_control_signal._registry if ao.name == ao_name][0]
@QtCore.pyqtSlot(float)
def save_data_from_scan_step(self, roiData):
row = [time.time(), self.ao_to_scan.AO.current_value, roiData]
self.storage.append_data_to_current_file(row)
self.simple_scan_measurement_step()
@QtCore.pyqtSlot(float, str)
def save_data_from_scan_step(self, roiData, meas_type):
if meas_type == 'simple':
row = [time.time(), self.ao_to_scan.AO.current_value, roiData]
self.storage.append_data_to_current_file(row)
self.simple_scan_measurement_step()
elif meas_type == 'rigol':
row = [time.time(), float(self.rigGen.Frequency), roiData]
self.storage.append_data_to_current_file(row)
self.rigol_measurement_step()
else:
raise 'Oh, wrong meas type'
def abort_measurement(self):
......@@ -203,4 +221,60 @@ class CameraWorker(QtCore.QObject):
{'Final comment': comment}
)
self.storage.permanent_save_current_data()
\ No newline at end of file
def rigol_measurement_start(self, measure_params):
if self.cam.CameraAcquiring.getValue():
show_warning('Can not start measurement if camera is acquiring')
return 0
self.measurementStartingSignal.emit('rigol')
self.measure_params = measure_params
self.measure_params['Amplitude'] = self.rigGen.Voltage
self.measure_params['Offset'] = self.rigGen.Offset
start = self.measure_params['start']
end = self.measure_params['end']
step_num = self.measure_params['steps']
self.scan_array_gen = yield_array(create_measurement_array(start, end, step_num))
time.sleep(1)
self.storage.set_directory(measure_params['directory'])
self.storage.create_data_file('Time', 'frequency', 'Roi data')
self.storage.append_metadata_to_current_file(self.cam.GetMetaData(), self.measure_params)
self.cam.TriggerMode.setString('Software')
self._start_acquisition_loop()
self.acq_thread = threading.Thread(
target=self.cam.live_acquisition_loop
)
self.acq_thread.start()
#with self._lock:
self.rigol_measurement_step()
def rigol_measurement_step(self):
try:
print('Setting value of step')
value = next(self.scan_array_gen)
print('value set to ' + str(value))
self.rigGen.Frequency = value
print('value sent to rigol')
# aca puede esperar o chequear algo, por ahora nada
self.cam.trigger()
print('trigger')
except StopIteration:
self.rigol_measurement_end()
except:
raise
def rigol_measurement_end(self):
print('entering scan ending in worker')
self.measurementEndingSignal.emit('rigol')
self.cam.trigger()
self._stop_acquisition_loop()
self.cam.TriggerMode.setString('Internal')
print('exiting scan ending in worker')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment