From 5457b40a65951886e5f6e7746a721444cbf36be2 Mon Sep 17 00:00:00 2001 From: jupfi Date: Fri, 15 Dec 2023 15:26:49 +0100 Subject: [PATCH] Added tuning and matching voltages to model and updated the values accordingly. Added an option for voltage sweep with predifined voltages. --- src/nqrduck_autotm/controller.py | 49 ++++++++++++--- src/nqrduck_autotm/model.py | 3 + src/nqrduck_autotm/resources/autotm_widget.ui | 63 ++++++++++--------- src/nqrduck_autotm/widget.py | 48 +++++++------- 4 files changed, 103 insertions(+), 60 deletions(-) diff --git a/src/nqrduck_autotm/controller.py b/src/nqrduck_autotm/controller.py index 4e007aa..ea163a2 100644 --- a/src/nqrduck_autotm/controller.py +++ b/src/nqrduck_autotm/controller.py @@ -7,6 +7,7 @@ from serial.tools.list_ports import comports from PyQt6.QtTest import QTest from PyQt6 import QtSerialPort from PyQt6.QtCore import QThread, pyqtSignal, pyqtSlot, Qt +from PyQt6.QtCore import QTimer from PyQt6.QtWidgets import QApplication from nqrduck.module.module_controller import ModuleController from .model import S11Data, ElectricalLookupTable, MechanicalLookupTable, SavedPosition, Stepper @@ -49,6 +50,7 @@ class AutoTMController(ModuleController): elif self.module.model.LUT.TYPE == "Electrical": tunning_voltage, matching_voltage = self.module.model.LUT.get_voltages(frequency) confirmation = self.set_voltages(str(tunning_voltage), str(matching_voltage)) + # We need to waitfor the voltages to be set it would be nicer to have this confirmed by the ATM if confirmation: reflection = self.read_reflection(frequency) self.module.nqrduck_signal.emit("confirm_tune_and_match", reflection) @@ -226,9 +228,14 @@ class AutoTMController(ModuleController): text = text[1:].split("t") matching_voltage, tuning_voltage = map(float, text) LUT = self.module.model.el_lut - logger.debug("Received voltage sweep result: %s %s", matching_voltage, tuning_voltage) - LUT.add_voltages(matching_voltage, tuning_voltage) - self.continue_or_finish_voltage_sweep(LUT) + if LUT is not None: + if LUT.is_incomplete(): + logger.debug("Received voltage sweep result: %s %s", matching_voltage, tuning_voltage) + LUT.add_voltages(matching_voltage, tuning_voltage) + self.continue_or_finish_voltage_sweep(LUT) + + self.module.model.tuning_voltage = tuning_voltage + self.module.model.matching_voltage = matching_voltage def finish_frequency_sweep(self): """This method is called when a frequency sweep is finished. @@ -261,7 +268,14 @@ class AutoTMController(ModuleController): LUT (LookupTable): The lookup table that is being generated. """ next_frequency = LUT.get_next_frequency() - command = f"s{next_frequency}" + # We write the first command to the serial connection + if self.module.view._ui_form.prevVoltagecheckBox.isChecked(): + # Command format is soo + # We use the currently set voltages + command = "s%so%so%s" % (next_frequency, self.module.model.tuning_voltage, self.module.model.matching_voltage) + else: + command = "s%s" % (next_frequency) + LUT.started_frequency = next_frequency logger.debug("Starting next voltage sweep: %s", command) self.send_command(command) @@ -493,6 +507,8 @@ class AutoTMController(ModuleController): """ logger.debug("Setting voltages") MAX_VOLTAGE = 5 # V + timeout_duration = 15 # timeout in seconds + try: tuning_voltage = tuning_voltage.replace(",", ".") matching_voltage = matching_voltage.replace(",", ".") @@ -525,13 +541,20 @@ class AutoTMController(ModuleController): ) command = "v%sv%s" % (matching_voltage, tuning_voltage) + + start_time = time.time() + confirmation = self.send_command(command) if confirmation: - logger.debug("Voltages set successfully") - return True - # Emit nqrduck signal that T&M was successful - # Maybe we measure the reflection first so we don't damage the PA lol - # The broadband module can then decide what to do with the signal + while matching_voltage == self.module.model.matching_voltage: + QApplication.processEvents() + # Check for timeout + if time.time() - start_time > timeout_duration: + logger.error("Absolute move timed out") + break # or handle timeout differently + + logger.debug("Voltages set successfully") + return confirmation ### Electrical Lookup Table ### @@ -601,7 +624,13 @@ class AutoTMController(ModuleController): LUT.started_frequency = start_frequency # We write the first command to the serial connection - command = "s%s" % (start_frequency) + if self.module.view._ui_form.prevVoltagecheckBox.isChecked(): + # Command format is soo + # We use the currently set voltages + logger.debug("Starting preset Voltage sweep with voltage Tuning: %s V and Matching: %s V", self.module.model.tuning_voltage, self.module.model.matching_voltage) + command = "s%so%so%s" % (start_frequency, self.module.model.tuning_voltage, self.module.model.matching_voltage) + else: + command = "s%s" % (start_frequency) # For timing of the voltage sweep self.module.model.voltage_sweep_start = time.time() diff --git a/src/nqrduck_autotm/model.py b/src/nqrduck_autotm/model.py index f9571c4..391e0ff 100644 --- a/src/nqrduck_autotm/model.py +++ b/src/nqrduck_autotm/model.py @@ -390,6 +390,9 @@ class AutoTMModel(ModuleModel): self.last_reflection = None + self.tuning_voltage = None + self.matching_voltage = None + @property def available_devices(self): return self._available_devices diff --git a/src/nqrduck_autotm/resources/autotm_widget.ui b/src/nqrduck_autotm/resources/autotm_widget.ui index 786475c..dcef9b2 100644 --- a/src/nqrduck_autotm/resources/autotm_widget.ui +++ b/src/nqrduck_autotm/resources/autotm_widget.ui @@ -152,7 +152,7 @@ - 0 + 1 @@ -313,11 +313,17 @@ Electrical - - - + + + + + + 75 + true + + - Generate LUT + Set Voltages: @@ -328,6 +334,16 @@ + + + + + + + Generate LUT + + + @@ -344,27 +360,7 @@ - - - - Voltage Matching - - - - - - - - 75 - true - - - - Set Voltages: - - - - + View LUT @@ -378,8 +374,19 @@ - - + + + + Voltage Matching + + + + + + + Start from previous Voltage + + diff --git a/src/nqrduck_autotm/widget.py b/src/nqrduck_autotm/widget.py index 3b0fb83..18fe98a 100644 --- a/src/nqrduck_autotm/widget.py +++ b/src/nqrduck_autotm/widget.py @@ -164,12 +164,22 @@ class Ui_Form(object): self.elecTab.setObjectName("elecTab") self.gridLayout_3 = QtWidgets.QGridLayout(self.elecTab) self.gridLayout_3.setObjectName("gridLayout_3") - self.generateLUTButton = QtWidgets.QPushButton(parent=self.elecTab) - self.generateLUTButton.setObjectName("generateLUTButton") - self.gridLayout_3.addWidget(self.generateLUTButton, 8, 0, 1, 2) + self.label_9 = QtWidgets.QLabel(parent=self.elecTab) + font = QtGui.QFont() + font.setBold(True) + font.setWeight(75) + self.label_9.setFont(font) + self.label_9.setObjectName("label_9") + self.gridLayout_3.addWidget(self.label_9, 0, 0, 1, 1) 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.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.tuningBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab) self.tuningBox.setObjectName("tuningBox") self.gridLayout_3.addWidget(self.tuningBox, 1, 1, 1, 1) @@ -180,25 +190,18 @@ class Ui_Form(object): 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) - font.setWeight(75) - self.label_9.setFont(font) - self.label_9.setObjectName("label_9") - 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, 9, 0, 1, 2) + self.gridLayout_3.addWidget(self.viewelLUTButton, 10, 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.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.prevVoltagecheckBox = QtWidgets.QCheckBox(parent=self.elecTab) + self.prevVoltagecheckBox.setObjectName("prevVoltagecheckBox") + self.gridLayout_3.addWidget(self.prevVoltagecheckBox, 9, 0, 1, 1) self.typeTab.addTab(self.elecTab, "") self.verticalLayout_2.addWidget(self.typeTab) self.rfswitchLabel = QtWidgets.QLabel(parent=Form) @@ -284,7 +287,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): @@ -316,13 +319,14 @@ 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", "Generate LUT")) - self.label_2.setText(_translate("Form", "Voltage Tuning")) - 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.label_2.setText(_translate("Form", "Voltage Tuning")) + self.generateLUTButton.setText(_translate("Form", "Generate LUT")) + self.label_11.setText(_translate("Form", "Generate LUT:")) self.viewelLUTButton.setText(_translate("Form", "View LUT")) self.setvoltagesButton.setText(_translate("Form", "Set Voltages")) + self.label_3.setText(_translate("Form", "Voltage Matching")) + self.prevVoltagecheckBox.setText(_translate("Form", "Start from previous Voltage")) self.typeTab.setTabText(self.typeTab.indexOf(self.elecTab), _translate("Form", "Electrical")) self.rfswitchLabel.setText(_translate("Form", "RF Switch:")) self.switchATMButton.setText(_translate("Form", "ATM"))