Implemented setting of tuning matching voltages.

This commit is contained in:
jupfi 2023-08-11 14:45:05 +02:00
parent 2fdcb1d0c5
commit 3cca963118
4 changed files with 52 additions and 10 deletions

View file

@ -273,4 +273,42 @@ class AutoTMController(ModuleController):
data = json.load(f)
self.module.model.short_calibration = S11Data.from_json(data["short"])
self.module.model.open_calibration = S11Data.from_json(data["open"])
self.module.model.load_calibration = S11Data.from_json(data["load"])
self.module.model.load_calibration = S11Data.from_json(data["load"])
def set_voltages(self, tuning_voltage : str, matching_voltage : str) -> None:
"""This method is called when the set voltages button is pressed.
It writes the specified tuning and matching voltage to the serial connection.
Args:
tuning_voltage (str): The tuning voltage in V.
matching_voltage (str): The matching voltage in V.
"""
logger.debug("Setting voltages")
MAX_VOLTAGE = 5 # V
try:
tuning_voltage = float(tuning_voltage)
matching_voltage = float(matching_voltage)
except ValueError:
error = "Could not set voltages. Tuning and matching voltage must be floats"
logger.error(error)
self.module.view.add_info_text(error)
return
if tuning_voltage < 0 or matching_voltage < 0:
error = "Could not set voltages. Tuning and matching voltage must be positive"
logger.error(error)
self.module.view.add_info_text(error)
return
if tuning_voltage > MAX_VOLTAGE or matching_voltage > MAX_VOLTAGE:
error = "Could not set voltages. Tuning and matching voltage must be between 0 and 5 V"
logger.error(error)
self.module.view.add_info_text(error)
return
logger.debug("Setting tuning voltage to %s V and matching voltage to %s V", tuning_voltage, matching_voltage)
try:
command = "v%sv%s" % (matching_voltage, tuning_voltage)
self.module.model.serial.write(command.encode('utf-8'))
except AttributeError:
logger.error("Could not set voltages. No device connected.")

View file

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1280</width>
<height>645</height>
<height>705</height>
</rect>
</property>
<property name="sizePolicy">
@ -118,7 +118,7 @@
<widget class="QDoubleSpinBox" name="matchingBox"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QPushButton" name="pushButton_2">
<widget class="QPushButton" name="setvoltagesButton">
<property name="text">
<string>Set Voltages</string>
</property>

View file

@ -44,6 +44,12 @@ class AutoTMView(ModuleView):
self._ui_form.stopEdit.text()
))
# On clicking of the setvoltagesButton call the set_voltages method
self._ui_form.setvoltagesButton.clicked.connect(lambda: self.module.controller.set_voltages(
self._ui_form.tuningBox.text(),
self._ui_form.matchingBox.text()
))
# On clicking of the calibration button call the on_calibration_button_clicked method
self._ui_form.calibrationButton.clicked.connect(self.on_calibration_button_clicked)
@ -177,8 +183,6 @@ class AutoTMView(ModuleView):
phase_ax.set_ylim(-180, 180)
phase_ax.invert_yaxis()
magnitude_ax.set_xlabel("Frequency (MHz)")
magnitude_ax.set_ylabel("S11 (dB)")
magnitude_ax.set_title("S11")

View file

@ -12,7 +12,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(1280, 645)
Form.resize(1280, 705)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
@ -75,9 +75,9 @@ class Ui_Form(object):
self.matchingBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.matchingBox.setObjectName("matchingBox")
self.gridLayout_3.addWidget(self.matchingBox, 1, 1, 1, 1)
self.pushButton_2 = QtWidgets.QPushButton(parent=self.elecTab)
self.pushButton_2.setObjectName("pushButton_2")
self.gridLayout_3.addWidget(self.pushButton_2, 2, 0, 1, 2)
self.setvoltagesButton = QtWidgets.QPushButton(parent=self.elecTab)
self.setvoltagesButton.setObjectName("setvoltagesButton")
self.gridLayout_3.addWidget(self.setvoltagesButton, 2, 0, 1, 2)
self.tuningBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.tuningBox.setObjectName("tuningBox")
self.gridLayout_3.addWidget(self.tuningBox, 0, 1, 1, 1)
@ -176,7 +176,7 @@ class Ui_Form(object):
self.titletypeLabel.setText(_translate("Form", "T&M Type:"))
self.pushButton.setText(_translate("Form", "Homing"))
self.typeTab.setTabText(self.typeTab.indexOf(self.mechTab), _translate("Form", "Mechanical"))
self.pushButton_2.setText(_translate("Form", "Set Voltages"))
self.setvoltagesButton.setText(_translate("Form", "Set Voltages"))
self.label_3.setText(_translate("Form", "Voltage Matching"))
self.label_2.setText(_translate("Form", "Voltage Tuning"))
self.label_4.setText(_translate("Form", "Voltage Resolution"))