From 7541a20cf3d8aecc98c3d2944e18611e4baf9b19 Mon Sep 17 00:00:00 2001 From: jupfi Date: Thu, 7 Dec 2023 13:28:10 +0100 Subject: [PATCH] Updated voltage sweep functionality. --- src/nqrduck_autotm/controller.py | 30 +++++--- src/nqrduck_autotm/model.py | 2 - src/nqrduck_autotm/resources/autotm_widget.ui | 76 ++++++++++--------- src/nqrduck_autotm/view.py | 18 +++-- src/nqrduck_autotm/widget.py | 58 +++++++------- 5 files changed, 96 insertions(+), 88 deletions(-) diff --git a/src/nqrduck_autotm/controller.py b/src/nqrduck_autotm/controller.py index 279c7b2..8369f51 100644 --- a/src/nqrduck_autotm/controller.py +++ b/src/nqrduck_autotm/controller.py @@ -222,6 +222,17 @@ class AutoTMController(ModuleController): LUT.started_frequency = next_frequency logger.debug("Starting next voltage sweep: %s", command) self.send_command(command) + else: + logger.debug("Voltage sweep finished") + self.module.view.el_LUT_spinner.hide() + self.module.model.voltage_sweep_stop = time.time() + self.module.view.add_info_text( + "Voltage sweep finished in %.2f seconds" + % ( + self.module.model.voltage_sweep_stop + - self.module.model.voltage_sweep_start + ) + ) def on_short_calibration( self, start_frequency: float, stop_frequency: float @@ -419,7 +430,6 @@ class AutoTMController(ModuleController): start_frequency: str, stop_frequency: str, frequency_step: str, - voltage_resolution: str, ) -> None: """This method is called when the generate LUT button is pressed. It generates a lookup table for the specified frequency range and voltage resolution. @@ -428,20 +438,17 @@ class AutoTMController(ModuleController): start_frequency (str): The start frequency in Hz. stop_frequency (str): The stop frequency in Hz. frequency_step (str): The frequency step in Hz. - voltage_resolution (str): The voltage resolution in V. """ logger.debug("Generating LUT") try: start_frequency = start_frequency.replace(",", ".") stop_frequency = stop_frequency.replace(",", ".") frequency_step = frequency_step.replace(",", ".") - voltage_resolution = voltage_resolution.replace(",", ".") start_frequency = float(start_frequency) stop_frequency = float(stop_frequency) frequency_step = float(frequency_step) - voltage_resolution = float(voltage_resolution) except ValueError: - error = "Could not generate LUT. Start frequency, stop frequency, frequency step and voltage resolution must be floats" + error = "Could not generate LUT. Start frequency, stop frequency, frequency step must be floats" logger.error(error) self.module.view.add_info_text(error) return @@ -450,9 +457,8 @@ class AutoTMController(ModuleController): start_frequency < 0 or stop_frequency < 0 or frequency_step < 0 - or voltage_resolution < 0 ): - error = "Could not generate LUT. Start frequency, stop frequency, frequency step and voltage resolution must be positive" + error = "Could not generate LUT. Start frequency, stop frequency, frequency step must be positive" logger.error(error) self.module.view.add_info_text(error) return @@ -470,16 +476,15 @@ class AutoTMController(ModuleController): return logger.debug( - "Generating LUT from %s MHz to %s MHz with a frequency step of %s MHz and a voltage resolution of %s V", + "Generating LUT from %s MHz to %s MHz with a frequency step of %s MHz", start_frequency, stop_frequency, frequency_step, - voltage_resolution, ) # We create the lookup table LUT = LookupTable( - start_frequency, stop_frequency, frequency_step, voltage_resolution + start_frequency, stop_frequency, frequency_step ) LUT.started_frequency = start_frequency @@ -487,6 +492,9 @@ class AutoTMController(ModuleController): # We write the first command to the serial connection command = "s%s" % (start_frequency) + self.module.view.create_el_LUT_spinner_dialog() + # For timing of the voltage sweep + self.module.model.voltage_sweep_start = time.time() confirmation = self.send_command(command) if not confirmation: return @@ -544,7 +552,7 @@ class AutoTMController(ModuleController): logger.debug("Confirmation: %s", confirmation) if confirmation == "c": - logger.debug("Command send successfully") + logger.debug("Command sent successfully") return True else: logger.error("Could not send command. No confirmation received") diff --git a/src/nqrduck_autotm/model.py b/src/nqrduck_autotm/model.py index 0635845..9ce0fb1 100644 --- a/src/nqrduck_autotm/model.py +++ b/src/nqrduck_autotm/model.py @@ -170,12 +170,10 @@ class LookupTable: start_frequency: float, stop_frequency: float, frequency_step: float, - voltage_resolution: float, ) -> None: self.start_frequency = start_frequency self.stop_frequency = stop_frequency self.frequency_step = frequency_step - self.voltage_resolution = voltage_resolution # This is the frequency at which the tuning and matching process was started self.started_frequency = None diff --git a/src/nqrduck_autotm/resources/autotm_widget.ui b/src/nqrduck_autotm/resources/autotm_widget.ui index 7721d6d..4e6734a 100644 --- a/src/nqrduck_autotm/resources/autotm_widget.ui +++ b/src/nqrduck_autotm/resources/autotm_widget.ui @@ -93,7 +93,11 @@ - + + + 80.299999999999997 + + @@ -103,7 +107,11 @@ - + + + 80.000000000000000 + + @@ -120,7 +128,11 @@ - + + + 0.100000000000000 + + @@ -140,7 +152,7 @@ - 0 + 1 @@ -283,9 +295,13 @@ Electrical - - - + + + + + Start Voltage Sweep + + @@ -294,20 +310,19 @@ - - + + - - - - Set Voltages + + + + + 75 + true + - - - - - Voltage Resolution + Generate LUT: @@ -318,9 +333,6 @@ - - - @@ -334,32 +346,22 @@ - + View LUT - - + + - Start Voltage Sweep + Set Voltages - - - - - 75 - true - - - - Generate LUT: - - + + diff --git a/src/nqrduck_autotm/view.py b/src/nqrduck_autotm/view.py index dfaf90c..9c2bb1c 100644 --- a/src/nqrduck_autotm/view.py +++ b/src/nqrduck_autotm/view.py @@ -34,7 +34,7 @@ class AutoTMView(ModuleView): self._ui_form.setupUi(self) self.widget = widget - self.frequency_sweep_spinner = self.FrequencySweepSpinner(self) + self.frequency_sweep_spinner = self.LoadingSpinner(self) self.frequency_sweep_spinner.hide() # Disable the connectButton while no devices are selected @@ -67,7 +67,6 @@ class AutoTMView(ModuleView): self._ui_form.startfrequencyBox.text(), self._ui_form.stopfrequencyBox.text(), self._ui_form.frequencystepBox.text(), - self._ui_form.resolutionBox.text(), ) ) @@ -289,21 +288,26 @@ class AutoTMView(ModuleView): def create_frequency_sweep_spinner_dialog(self) -> None: """Creates a frequency sweep spinner dialog.""" - self.frequency_sweep_spinner = self.FrequencySweepSpinner(self) + self.frequency_sweep_spinner = self.LoadingSpinner("Performing frequency sweep ...", self) self.frequency_sweep_spinner.show() + def create_el_LUT_spinner_dialog(self) -> None: + """Creates a electrical LUT spinner dialog.""" + self.el_LUT_spinner = self.LoadingSpinner("Generating electrical LUT ...", self) + self.el_LUT_spinner.show() + def view_el_lut(self) -> None: """Creates a new Dialog that shows the currently active electrical LUT.""" logger.debug("View LUT") self.lut_window = self.LutWindow(self.module) self.lut_window.show() - class FrequencySweepSpinner(QDialog): + class LoadingSpinner(QDialog): """This class implements a spinner dialog that is shown during a frequency sweep.""" - def __init__(self, parent=None): + def __init__(self, text : str, parent=None): super().__init__(parent) - self.setWindowTitle("Frequency sweep") + self.setWindowTitle("Loading") self.setModal(True) self.setWindowFlag(Qt.WindowType.FramelessWindowHint) self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) @@ -313,7 +317,7 @@ class AutoTMView(ModuleView): self.spinner_label.setMovie(self.spinner_movie) self.layout = QVBoxLayout(self) - self.layout.addWidget(QLabel("Performing frequency sweep...")) + self.layout.addWidget(QLabel(text)) self.layout.addWidget(self.spinner_label) self.spinner_movie.start() diff --git a/src/nqrduck_autotm/widget.py b/src/nqrduck_autotm/widget.py index 28c26d2..51f93bc 100644 --- a/src/nqrduck_autotm/widget.py +++ b/src/nqrduck_autotm/widget.py @@ -61,12 +61,14 @@ class Ui_Form(object): self.gridLayout_8 = QtWidgets.QGridLayout() self.gridLayout_8.setObjectName("gridLayout_8") self.stopfrequencyBox = QtWidgets.QDoubleSpinBox(parent=Form) + self.stopfrequencyBox.setProperty("value", 80.3) self.stopfrequencyBox.setObjectName("stopfrequencyBox") self.gridLayout_8.addWidget(self.stopfrequencyBox, 1, 1, 1, 1) self.label_13 = QtWidgets.QLabel(parent=Form) self.label_13.setObjectName("label_13") self.gridLayout_8.addWidget(self.label_13, 1, 0, 1, 1) self.startfrequencyBox = QtWidgets.QDoubleSpinBox(parent=Form) + self.startfrequencyBox.setProperty("value", 80.0) self.startfrequencyBox.setObjectName("startfrequencyBox") self.gridLayout_8.addWidget(self.startfrequencyBox, 0, 1, 1, 1) self.label_12 = QtWidgets.QLabel(parent=Form) @@ -76,6 +78,7 @@ class Ui_Form(object): self.label_14.setObjectName("label_14") self.gridLayout_8.addWidget(self.label_14, 2, 0, 1, 1) self.frequencystepBox = QtWidgets.QDoubleSpinBox(parent=Form) + self.frequencystepBox.setProperty("value", 0.1) self.frequencystepBox.setObjectName("frequencystepBox") self.gridLayout_8.addWidget(self.frequencystepBox, 2, 1, 1, 1) self.verticalLayout_2.addLayout(self.gridLayout_8) @@ -154,27 +157,25 @@ class Ui_Form(object): self.elecTab.setObjectName("elecTab") self.gridLayout_3 = QtWidgets.QGridLayout(self.elecTab) self.gridLayout_3.setObjectName("gridLayout_3") - self.matchingBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab) - self.matchingBox.setObjectName("matchingBox") - self.gridLayout_3.addWidget(self.matchingBox, 2, 1, 1, 1) + self.generateLUTButton = QtWidgets.QPushButton(parent=self.elecTab) + self.generateLUTButton.setObjectName("generateLUTButton") + self.gridLayout_3.addWidget(self.generateLUTButton, 8, 0, 1, 2) self.label_2 = QtWidgets.QLabel(parent=self.elecTab) self.label_2.setObjectName("label_2") self.gridLayout_3.addWidget(self.label_2, 1, 0, 1, 1) - self.resolutionBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab) - self.resolutionBox.setObjectName("resolutionBox") - self.gridLayout_3.addWidget(self.resolutionBox, 5, 1, 1, 1) - self.setvoltagesButton = QtWidgets.QPushButton(parent=self.elecTab) - self.setvoltagesButton.setObjectName("setvoltagesButton") - self.gridLayout_3.addWidget(self.setvoltagesButton, 3, 0, 1, 2) - self.label_4 = QtWidgets.QLabel(parent=self.elecTab) - self.label_4.setObjectName("label_4") - self.gridLayout_3.addWidget(self.label_4, 5, 0, 1, 1) - self.label_3 = QtWidgets.QLabel(parent=self.elecTab) - self.label_3.setObjectName("label_3") - self.gridLayout_3.addWidget(self.label_3, 2, 0, 1, 1) self.tuningBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab) self.tuningBox.setObjectName("tuningBox") self.gridLayout_3.addWidget(self.tuningBox, 1, 1, 1, 1) + self.label_11 = QtWidgets.QLabel(parent=self.elecTab) + font = QtGui.QFont() + font.setBold(True) + font.setWeight(75) + self.label_11.setFont(font) + self.label_11.setObjectName("label_11") + self.gridLayout_3.addWidget(self.label_11, 4, 0, 1, 1) + self.label_3 = QtWidgets.QLabel(parent=self.elecTab) + self.label_3.setObjectName("label_3") + self.gridLayout_3.addWidget(self.label_3, 2, 0, 1, 1) self.label_9 = QtWidgets.QLabel(parent=self.elecTab) font = QtGui.QFont() font.setBold(True) @@ -184,17 +185,13 @@ class Ui_Form(object): self.gridLayout_3.addWidget(self.label_9, 0, 0, 1, 1) self.viewelLUTButton = QtWidgets.QPushButton(parent=self.elecTab) self.viewelLUTButton.setObjectName("viewelLUTButton") - self.gridLayout_3.addWidget(self.viewelLUTButton, 10, 0, 1, 2) - self.generateLUTButton = QtWidgets.QPushButton(parent=self.elecTab) - self.generateLUTButton.setObjectName("generateLUTButton") - self.gridLayout_3.addWidget(self.generateLUTButton, 9, 0, 1, 2) - self.label_11 = QtWidgets.QLabel(parent=self.elecTab) - font = QtGui.QFont() - font.setBold(True) - font.setWeight(75) - self.label_11.setFont(font) - self.label_11.setObjectName("label_11") - self.gridLayout_3.addWidget(self.label_11, 4, 0, 1, 1) + self.gridLayout_3.addWidget(self.viewelLUTButton, 9, 0, 1, 2) + self.setvoltagesButton = QtWidgets.QPushButton(parent=self.elecTab) + self.setvoltagesButton.setObjectName("setvoltagesButton") + self.gridLayout_3.addWidget(self.setvoltagesButton, 3, 0, 1, 2) + self.matchingBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab) + self.matchingBox.setObjectName("matchingBox") + self.gridLayout_3.addWidget(self.matchingBox, 2, 1, 1, 1) self.typeTab.addTab(self.elecTab, "") self.verticalLayout_2.addWidget(self.typeTab) self.rfswitchLabel = QtWidgets.QLabel(parent=Form) @@ -280,7 +277,7 @@ class Ui_Form(object): self.horizontalLayout_2.setStretch(1, 1) self.retranslateUi(Form) - self.typeTab.setCurrentIndex(0) + self.typeTab.setCurrentIndex(1) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): @@ -310,14 +307,13 @@ class Ui_Form(object): self.mechLUTButton.setText(_translate("Form", "Generate LUT")) self.viewmechLUTButton.setText(_translate("Form", "View LUT")) self.typeTab.setTabText(self.typeTab.indexOf(self.mechTab), _translate("Form", "Mechanical")) + self.generateLUTButton.setText(_translate("Form", "Start Voltage Sweep")) self.label_2.setText(_translate("Form", "Voltage Tuning")) - self.setvoltagesButton.setText(_translate("Form", "Set Voltages")) - self.label_4.setText(_translate("Form", "Voltage Resolution")) + self.label_11.setText(_translate("Form", "Generate LUT:")) self.label_3.setText(_translate("Form", "Voltage Matching")) self.label_9.setText(_translate("Form", "Set Voltages:")) self.viewelLUTButton.setText(_translate("Form", "View LUT")) - self.generateLUTButton.setText(_translate("Form", "Start Voltage Sweep")) - self.label_11.setText(_translate("Form", "Generate LUT:")) + self.setvoltagesButton.setText(_translate("Form", "Set Voltages")) self.typeTab.setTabText(self.typeTab.indexOf(self.elecTab), _translate("Form", "Electrical")) self.rfswitchLabel.setText(_translate("Form", "RF Switch:")) self.switchATMButton.setText(_translate("Form", "ATM"))