Added tuning and matching voltages to model and updated the values accordingly. Added an option for voltage sweep with predifined voltages.

This commit is contained in:
jupfi 2023-12-15 15:26:49 +01:00
parent 7b9f680b96
commit 5457b40a65
4 changed files with 103 additions and 60 deletions

View file

@ -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,10 +228,15 @@ class AutoTMController(ModuleController):
text = text[1:].split("t")
matching_voltage, tuning_voltage = map(float, text)
LUT = self.module.model.el_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.
It hides the frequency sweep spinner dialog and adds the data to the model.
@ -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 s<frequency in MHz>o<optional tuning voltage>o<optional matching voltage>
# 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:
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 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
return confirmation
### Electrical Lookup Table ###
@ -601,6 +624,12 @@ class AutoTMController(ModuleController):
LUT.started_frequency = start_frequency
# We write the first command to the serial connection
if self.module.view._ui_form.prevVoltagecheckBox.isChecked():
# Command format is s<frequency in MHz>o<optional tuning voltage>o<optional matching voltage>
# 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

View file

@ -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

View file

@ -152,7 +152,7 @@
<item>
<widget class="QTabWidget" name="typeTab">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="mechTab">
<attribute name="title">
@ -313,11 +313,17 @@
<attribute name="title">
<string>Electrical</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3" rowstretch="0,0,0,0,0,0,0,0,0,0">
<item row="8" column="0" colspan="2">
<widget class="QPushButton" name="generateLUTButton">
<layout class="QGridLayout" name="gridLayout_3" rowstretch="0,0,0,0,0,0,0,0,0,0,0">
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Generate LUT</string>
<string>Set Voltages:</string>
</property>
</widget>
</item>
@ -328,6 +334,16 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="matchingBox"/>
</item>
<item row="8" column="0" colspan="2">
<widget class="QPushButton" name="generateLUTButton">
<property name="text">
<string>Generate LUT</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="tuningBox"/>
</item>
@ -344,27 +360,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Voltage Matching</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Set Voltages:</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<item row="10" column="0" colspan="2">
<widget class="QPushButton" name="viewelLUTButton">
<property name="text">
<string>View LUT</string>
@ -378,8 +374,19 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="matchingBox"/>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Voltage Matching</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QCheckBox" name="prevVoltagecheckBox">
<property name="text">
<string>Start from previous Voltage</string>
</property>
</widget>
</item>
</layout>
</widget>

View file

@ -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"))