forked from M-Labs/thermostat
Compare commits
8 Commits
c6fa3cdb80
...
a6c852369f
Author | SHA1 | Date | |
---|---|---|---|
a6c852369f | |||
3ed181403f | |||
205f5c0ae9 | |||
3c4bc4b50c | |||
3a0bb66212 | |||
9ebdcfc54f | |||
980cabefb5 | |||
e1861263b2 |
@ -7,42 +7,6 @@ from pyqtgraph.parametertree import (
|
||||
import pytec.gui.view.unitful
|
||||
|
||||
|
||||
class MutexParameter(pTypes.ListParameter):
|
||||
"""
|
||||
Mutually exclusive parameter where only one of its children is visible at a time, list selectable.
|
||||
|
||||
The ordering of the list items determines which children will be visible.
|
||||
"""
|
||||
|
||||
def __init__(self, **opts):
|
||||
super().__init__(**opts)
|
||||
|
||||
self.sigValueChanged.connect(self.show_chosen_child)
|
||||
self.sigValueChanged.emit(self, self.opts["value"])
|
||||
|
||||
def _get_param_from_value(self, value):
|
||||
if isinstance(self.opts["limits"], dict):
|
||||
values_list = list(self.opts["limits"].values())
|
||||
else:
|
||||
values_list = self.opts["limits"]
|
||||
|
||||
return self.children()[values_list.index(value)]
|
||||
|
||||
@pyqtSlot(object, object)
|
||||
def show_chosen_child(self, value):
|
||||
for param in self.children():
|
||||
param.hide()
|
||||
|
||||
child_to_show = self._get_param_from_value(value.value())
|
||||
child_to_show.show()
|
||||
|
||||
if child_to_show.opts.get("triggerOnShow", None):
|
||||
child_to_show.sigValueChanged.emit(child_to_show, child_to_show.value())
|
||||
|
||||
|
||||
registerParameterType("mutex", MutexParameter)
|
||||
|
||||
|
||||
def set_tree_label_tips(tree):
|
||||
for item in tree.listAllItems():
|
||||
p = item.param
|
||||
@ -66,6 +30,11 @@ class CtrlPanel(QObject):
|
||||
self.trees_ui = trees_ui
|
||||
self.NUM_CHANNELS = len(trees_ui)
|
||||
|
||||
def _set_value_with_lock(self, value):
|
||||
if not self.opts.get("lock"):
|
||||
self.setValue(value)
|
||||
Parameter.set_value_with_lock = _set_value_with_lock
|
||||
|
||||
self.params = [
|
||||
Parameter.create(
|
||||
name=f"Thermostat Channel {ch} Parameters",
|
||||
@ -83,37 +52,28 @@ class CtrlPanel(QObject):
|
||||
set_tree_label_tips(tree)
|
||||
|
||||
for ch, param in enumerate(self.params):
|
||||
self.params[ch].setValue = self._setValue
|
||||
param.sigTreeStateChanged.connect(sigTreeStateChanged_handle)
|
||||
|
||||
for handle in sigActivated_handles[ch]:
|
||||
param.child(*handle[0]).sigActivated.connect(handle[1])
|
||||
|
||||
def _setValue(self, value, blockSignal=None):
|
||||
"""
|
||||
Implement 'lock' mechanism for Parameter Type
|
||||
def _highlight_usage(param, control_method):
|
||||
for item in param.child("i_set").items:
|
||||
font = item.font(0)
|
||||
font.setUnderline(control_method == "constant_current")
|
||||
font.setBold(control_method == "constant_current")
|
||||
item.setFont(0, font)
|
||||
for item in param.child("target").items:
|
||||
font = item.font(0)
|
||||
font.setUnderline(control_method == "temperature_pid")
|
||||
font.setBold(control_method == "temperature_pid")
|
||||
item.setFont(0, font)
|
||||
|
||||
Modified from the source
|
||||
"""
|
||||
try:
|
||||
if blockSignal is not None:
|
||||
self.sigValueChanged.disconnect(blockSignal)
|
||||
value = self._interpretValue(value)
|
||||
if fn.eq(self.opts["value"], value):
|
||||
return value
|
||||
|
||||
if "lock" in self.opts.keys():
|
||||
if self.opts["lock"]:
|
||||
return value
|
||||
self.opts["value"] = value
|
||||
self.sigValueChanged.emit(
|
||||
self, value
|
||||
) # value might change after signal is received by tree item
|
||||
finally:
|
||||
if blockSignal is not None:
|
||||
self.sigValueChanged.connect(blockSignal)
|
||||
|
||||
return self.opts["value"]
|
||||
param.child("output", "control_method").sigValueChanged.connect(_highlight_usage)
|
||||
for item in param.child("output", "control_method").items:
|
||||
font = item.font(0)
|
||||
font.setBold(True)
|
||||
item.setFont(0, font)
|
||||
|
||||
def change_params_title(self, channel, path, title):
|
||||
self.params[channel].child(*path).setOpts(title=title)
|
||||
@ -123,55 +83,59 @@ class CtrlPanel(QObject):
|
||||
for settings in pid_settings:
|
||||
channel = settings["channel"]
|
||||
with QSignalBlocker(self.params[channel]):
|
||||
self.params[channel].child("pid", "kp").setValue(
|
||||
self.params[channel].child("pid", "kp").set_value_with_lock(
|
||||
settings["parameters"]["kp"]
|
||||
)
|
||||
self.params[channel].child("pid", "ki").setValue(
|
||||
self.params[channel].child("pid", "ki").set_value_with_lock(
|
||||
settings["parameters"]["ki"]
|
||||
)
|
||||
self.params[channel].child("pid", "kd").setValue(
|
||||
self.params[channel].child("pid", "kd").set_value_with_lock(
|
||||
settings["parameters"]["kd"]
|
||||
)
|
||||
self.params[channel].child(
|
||||
"pid", "pid_output_clamping", "output_min"
|
||||
).setValue(settings["parameters"]["output_min"])
|
||||
).set_value_with_lock(settings["parameters"]["output_min"])
|
||||
self.params[channel].child(
|
||||
"pid", "pid_output_clamping", "output_max"
|
||||
).setValue(settings["parameters"]["output_max"])
|
||||
).set_value_with_lock(settings["parameters"]["output_max"])
|
||||
self.params[channel].child(
|
||||
"output", "control_method", "target"
|
||||
).setValue(settings["target"])
|
||||
).set_value_with_lock(settings["target"])
|
||||
|
||||
@pyqtSlot("QVariantList")
|
||||
def update_report(self, report_data):
|
||||
for settings in report_data:
|
||||
channel = settings["channel"]
|
||||
with QSignalBlocker(self.params[channel]):
|
||||
self.params[channel].child("output", "control_method").setValue(
|
||||
self.params[channel].child(
|
||||
"output", "control_method"
|
||||
).set_value_with_lock(
|
||||
"temperature_pid" if settings["pid_engaged"] else "constant_current"
|
||||
)
|
||||
self.params[channel].child(
|
||||
"output", "control_method", "i_set"
|
||||
).setValue(settings["i_set"])
|
||||
).set_value_with_lock(settings["i_set"])
|
||||
if settings["temperature"] is not None:
|
||||
self.params[channel].child("temperature").setValue(
|
||||
settings["temperature"]
|
||||
)
|
||||
self.params[channel].child(
|
||||
"readings", "temperature"
|
||||
).set_value_with_lock(settings["temperature"])
|
||||
if settings["tec_i"] is not None:
|
||||
self.params[channel].child("tec_i").setValue(settings["tec_i"])
|
||||
self.params[channel].child(
|
||||
"readings", "tec_i"
|
||||
).set_value_with_lock(settings["tec_i"])
|
||||
|
||||
@pyqtSlot("QVariantList")
|
||||
def update_thermistor(self, sh_data):
|
||||
for sh_param in sh_data:
|
||||
channel = sh_param["channel"]
|
||||
with QSignalBlocker(self.params[channel]):
|
||||
self.params[channel].child("thermistor", "t0").setValue(
|
||||
self.params[channel].child("thermistor", "t0").set_value_with_lock(
|
||||
sh_param["params"]["t0"] - 273.15
|
||||
)
|
||||
self.params[channel].child("thermistor", "r0").setValue(
|
||||
self.params[channel].child("thermistor", "r0").set_value_with_lock(
|
||||
sh_param["params"]["r0"]
|
||||
)
|
||||
self.params[channel].child("thermistor", "b").setValue(
|
||||
self.params[channel].child("thermistor", "b").set_value_with_lock(
|
||||
sh_param["params"]["b"]
|
||||
)
|
||||
|
||||
@ -182,15 +146,15 @@ class CtrlPanel(QObject):
|
||||
for pwm_params in pwm_data:
|
||||
channel = pwm_params["channel"]
|
||||
with QSignalBlocker(self.params[channel]):
|
||||
self.params[channel].child("output", "limits", "max_v").setValue(
|
||||
pwm_params["max_v"]["value"]
|
||||
)
|
||||
self.params[channel].child("output", "limits", "max_i_pos").setValue(
|
||||
pwm_params["max_i_pos"]["value"]
|
||||
)
|
||||
self.params[channel].child("output", "limits", "max_i_neg").setValue(
|
||||
pwm_params["max_i_neg"]["value"]
|
||||
)
|
||||
self.params[channel].child(
|
||||
"output", "limits", "max_v"
|
||||
).set_value_with_lock(pwm_params["max_v"]["value"])
|
||||
self.params[channel].child(
|
||||
"output", "limits", "max_i_pos"
|
||||
).set_value_with_lock(pwm_params["max_i_pos"]["value"])
|
||||
self.params[channel].child(
|
||||
"output", "limits", "max_i_neg"
|
||||
).set_value_with_lock(pwm_params["max_i_neg"]["value"])
|
||||
|
||||
for limit in "max_i_pos", "max_i_neg", "max_v":
|
||||
if pwm_params[limit]["value"] == 0.0:
|
||||
@ -202,6 +166,6 @@ class CtrlPanel(QObject):
|
||||
for postfilter_params in postfilter_data:
|
||||
channel = postfilter_params["channel"]
|
||||
with QSignalBlocker(self.params[channel]):
|
||||
self.params[channel].child("thermistor", "rate").setValue(
|
||||
self.params[channel].child("postfilter", "rate").set_value_with_lock(
|
||||
postfilter_params["rate"]
|
||||
)
|
||||
|
@ -1,5 +1,11 @@
|
||||
{
|
||||
"ctrl_panel": [
|
||||
{
|
||||
"name": "readings",
|
||||
"title": "Readings",
|
||||
"type": "group",
|
||||
"tip": "Thermostat readings",
|
||||
"children": [
|
||||
{
|
||||
"name": "temperature",
|
||||
"title": "Temperature",
|
||||
@ -18,6 +24,8 @@
|
||||
"decimals": 6,
|
||||
"readonly": true,
|
||||
"tip": "The measured current through the TEC"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "output",
|
||||
@ -29,7 +37,7 @@
|
||||
{
|
||||
"name": "control_method",
|
||||
"title": "Control Method",
|
||||
"type": "mutex",
|
||||
"type": "list",
|
||||
"limits": {
|
||||
"Constant Current": "constant_current",
|
||||
"Temperature PID": "temperature_pid"
|
||||
@ -54,7 +62,6 @@
|
||||
-2,
|
||||
2
|
||||
],
|
||||
"triggerOnShow": true,
|
||||
"decimals": 6,
|
||||
"pinSiPrefix": "m",
|
||||
"suffix": "A",
|
||||
@ -154,11 +161,11 @@
|
||||
"type": "float",
|
||||
"value": 0,
|
||||
"step": 0.1,
|
||||
"decimals": 3,
|
||||
"limits": [
|
||||
0,
|
||||
4
|
||||
],
|
||||
"siPrefix": true,
|
||||
"suffix": "V",
|
||||
"noUnitEditing": true,
|
||||
"compactHeight": false,
|
||||
@ -179,7 +186,7 @@
|
||||
"title": "Thermistor Settings",
|
||||
"expanded": true,
|
||||
"type": "group",
|
||||
"tip": "Settings of the connected thermistor\n- Parameters for the resistance to temperature conversion (with the B-Parameter equation)\n- Settings for the 50/60 Hz filter with the thermistor",
|
||||
"tip": "Parameters for the resistance to temperature conversion with the B-Parameter equation",
|
||||
"children": [
|
||||
{
|
||||
"name": "t0",
|
||||
@ -208,7 +215,7 @@
|
||||
"title": "R₀",
|
||||
"type": "float",
|
||||
"value": 10000,
|
||||
"step": 1,
|
||||
"step": 100,
|
||||
"min": 0,
|
||||
"siPrefix": true,
|
||||
"pinSiPrefix": "k",
|
||||
@ -228,7 +235,7 @@
|
||||
"title": "B",
|
||||
"type": "float",
|
||||
"value": 3950,
|
||||
"step": 1,
|
||||
"step": 10,
|
||||
"suffix": "K",
|
||||
"noUnitEditing": true,
|
||||
"decimals": 4,
|
||||
@ -240,10 +247,18 @@
|
||||
],
|
||||
"tip": "The Beta Parameter",
|
||||
"lock": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "postfilter",
|
||||
"title": "50/60 Hz filter settings",
|
||||
"type": "group",
|
||||
"tip": "Settings for the 50/60 Hz filter with the thermistor",
|
||||
"children": [
|
||||
{
|
||||
"name": "rate",
|
||||
"title": "50/60 Hz filter rejection",
|
||||
"title": "Rejection",
|
||||
"type": "list",
|
||||
"value": 16.67,
|
||||
"param": [
|
||||
@ -275,7 +290,6 @@
|
||||
"title": "Kp",
|
||||
"type": "float",
|
||||
"step": 0.1,
|
||||
"suffix": "",
|
||||
"compactHeight": false,
|
||||
"param": [
|
||||
"pid",
|
||||
@ -423,9 +437,8 @@
|
||||
"type": "float",
|
||||
"value": 1.5,
|
||||
"step": 0.1,
|
||||
"prefix": "±",
|
||||
"format": "{value:.4f} {suffix}",
|
||||
"suffix": "°C",
|
||||
"suffix": "K",
|
||||
"noUnitEditing": true,
|
||||
"compactHeight": false,
|
||||
"pid_autotune": [
|
||||
|
@ -1,3 +1,5 @@
|
||||
import re
|
||||
|
||||
from PyQt6.QtCore import QSignalBlocker
|
||||
from PyQt6.QtGui import QValidator
|
||||
|
||||
@ -7,6 +9,13 @@ from pyqtgraph.parametertree import registerParameterItemType
|
||||
from pyqtgraph.parametertree.parameterTypes import SimpleParameter, NumericParameterItem
|
||||
|
||||
|
||||
# See https://github.com/pyqtgraph/pyqtgraph/issues/3115
|
||||
fn.FLOAT_REGEX = re.compile(
|
||||
r"(?P<number>[+-]?((((\d+(\.\d*)?)|(\d*\.\d+))([eE][+-]?\d+)?)|((?i:nan)|(inf))))\s*"
|
||||
+ r"((?P<siPrefix>[u" + fn.SI_PREFIXES + r"]?)(?P<suffix>.*))?$"
|
||||
)
|
||||
|
||||
|
||||
class UnitfulSpinBox(SpinBox):
|
||||
"""
|
||||
Extension of PyQtGraph's SpinBox widget.
|
||||
@ -82,6 +91,24 @@ class UnitfulSpinBox(SpinBox):
|
||||
|
||||
super().setOpts(**opts)
|
||||
|
||||
def editingFinishedEvent(self):
|
||||
# Modified from pyqtgraph.SpinBox.editingFinishedEvent source
|
||||
|
||||
new_text = self.lineEdit().text()
|
||||
if new_text == self.lastText:
|
||||
return
|
||||
try:
|
||||
val = self.interpret()
|
||||
except Exception:
|
||||
return
|
||||
|
||||
if val is False:
|
||||
return
|
||||
if val == self.val:
|
||||
self.updateText() # still update text so that values are reformatted pretty-like
|
||||
return
|
||||
self.setValue(val, delaySignal=False) ## allow text update so that values are reformatted pretty-like
|
||||
|
||||
def formatText(self, prev=None):
|
||||
"""
|
||||
In addition to pyqtgraph.SpinBox's formatting, incorporate the
|
||||
|
@ -293,6 +293,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
if activater[1] == "ch":
|
||||
activater[1] = ch
|
||||
await self.client.set_param(*activater)
|
||||
else:
|
||||
await self.client.set_param(
|
||||
"pwm", ch, "i_set", inner_param.child("i_set").value()
|
||||
)
|
||||
|
||||
@asyncSlot()
|
||||
async def pid_autotune_request(self, ch=0):
|
||||
|
Loading…
Reference in New Issue
Block a user