forked from M-Labs/thermostat
Compare commits
7 Commits
e1fdc86e40
...
21eb13ed6f
Author | SHA1 | Date | |
---|---|---|---|
21eb13ed6f | |||
646452f559 | |||
46a22a9c32 | |||
8ec7bb833a | |||
02d04dbae5 | |||
85ff340b6f | |||
d844c02a3a |
@ -6,42 +6,6 @@ from pyqtgraph.parametertree import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
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):
|
def set_tree_label_tips(tree):
|
||||||
for item in tree.listAllItems():
|
for item in tree.listAllItems():
|
||||||
p = item.param
|
p = item.param
|
||||||
@ -65,31 +29,40 @@ class CtrlPanel(QObject):
|
|||||||
self.trees_ui = trees_ui
|
self.trees_ui = trees_ui
|
||||||
self.NUM_CHANNELS = len(trees_ui)
|
self.NUM_CHANNELS = len(trees_ui)
|
||||||
|
|
||||||
self.THERMOSTAT_PARAMETERS = [param_tree for i in range(self.NUM_CHANNELS)]
|
|
||||||
|
|
||||||
self.params = [
|
self.params = [
|
||||||
Parameter.create(
|
Parameter.create(
|
||||||
name=f"Thermostat Channel {ch} Parameters",
|
name=f"Thermostat Channel {ch} Parameters",
|
||||||
type="group",
|
type="group",
|
||||||
value=ch,
|
value=ch,
|
||||||
children=self.THERMOSTAT_PARAMETERS[ch],
|
children=param_tree,
|
||||||
)
|
)
|
||||||
for ch in range(self.NUM_CHANNELS)
|
for ch in range(self.NUM_CHANNELS)
|
||||||
]
|
]
|
||||||
|
|
||||||
for i, param in enumerate(self.params):
|
for ch, tree in enumerate(self.trees_ui):
|
||||||
param.channel = i
|
|
||||||
|
|
||||||
for i, tree in enumerate(self.trees_ui):
|
|
||||||
tree.setHeaderHidden(True)
|
tree.setHeaderHidden(True)
|
||||||
tree.setParameters(self.params[i], showTop=False)
|
tree.setParameters(self.params[ch], showTop=False)
|
||||||
self.params[i].setValue = self._setValue
|
|
||||||
self.params[i].sigTreeStateChanged.connect(sigTreeStateChanged_handle)
|
|
||||||
|
|
||||||
set_tree_label_tips(tree)
|
set_tree_label_tips(tree)
|
||||||
|
|
||||||
for handle in sigActivated_handles[i]:
|
for ch, param in enumerate(self.params):
|
||||||
self.params[i].child(*handle[0]).sigActivated.connect(handle[1])
|
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])
|
||||||
|
|
||||||
|
param.child("output", "control_method").sigValueChanged.connect(
|
||||||
|
lambda param, value: param.child("i_set").setWritable(
|
||||||
|
value == "constant_current"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
param.child("output", "control_method").sigValueChanged.connect(
|
||||||
|
lambda param, value: param.child("target").show(
|
||||||
|
value == "temperature_pid"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def _setValue(self, value, blockSignal=None):
|
def _setValue(self, value, blockSignal=None):
|
||||||
"""
|
"""
|
||||||
@ -161,7 +134,7 @@ class CtrlPanel(QObject):
|
|||||||
)
|
)
|
||||||
if settings["tec_i"] is not None:
|
if settings["tec_i"] is not None:
|
||||||
self.params[channel].child("tec_i").setValue(
|
self.params[channel].child("tec_i").setValue(
|
||||||
settings["tec_i"] * 1000
|
settings["tec_i"]
|
||||||
)
|
)
|
||||||
|
|
||||||
@pyqtSlot("QVariantList")
|
@pyqtSlot("QVariantList")
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
"name": "tec_i",
|
"name": "tec_i",
|
||||||
"title": "Current through TEC",
|
"title": "Current through TEC",
|
||||||
"type": "float",
|
"type": "float",
|
||||||
"suffix": "mA",
|
"siPrefix": true,
|
||||||
|
"suffix": "A",
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
"readonly": true,
|
"readonly": true,
|
||||||
"tip": "The measured current through the TEC"
|
"tip": "The measured current through the TEC"
|
||||||
@ -27,7 +28,7 @@
|
|||||||
{
|
{
|
||||||
"name": "control_method",
|
"name": "control_method",
|
||||||
"title": "Control Method",
|
"title": "Control Method",
|
||||||
"type": "mutex",
|
"type": "list",
|
||||||
"limits": {
|
"limits": {
|
||||||
"Constant Current": "constant_current",
|
"Constant Current": "constant_current",
|
||||||
"Temperature PID": "temperature_pid"
|
"Temperature PID": "temperature_pid"
|
||||||
@ -54,6 +55,7 @@
|
|||||||
],
|
],
|
||||||
"triggerOnShow": true,
|
"triggerOnShow": true,
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
|
"compactHeight": false,
|
||||||
"param": [
|
"param": [
|
||||||
"pwm",
|
"pwm",
|
||||||
"ch",
|
"ch",
|
||||||
@ -66,6 +68,7 @@
|
|||||||
"name": "target",
|
"name": "target",
|
||||||
"title": "Setpoint (°C)",
|
"title": "Setpoint (°C)",
|
||||||
"type": "float",
|
"type": "float",
|
||||||
|
"visible": false,
|
||||||
"value": 25,
|
"value": 25,
|
||||||
"step": 0.1,
|
"step": 0.1,
|
||||||
"limits": [
|
"limits": [
|
||||||
@ -73,6 +76,7 @@
|
|||||||
300
|
300
|
||||||
],
|
],
|
||||||
"format": "{value:.4f}",
|
"format": "{value:.4f}",
|
||||||
|
"compactHeight": false,
|
||||||
"param": [
|
"param": [
|
||||||
"pid",
|
"pid",
|
||||||
"ch",
|
"ch",
|
||||||
@ -97,6 +101,7 @@
|
|||||||
"value": 0,
|
"value": 0,
|
||||||
"step": 100,
|
"step": 100,
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
|
"compactHeight": false,
|
||||||
"limits": [
|
"limits": [
|
||||||
0,
|
0,
|
||||||
2000
|
2000
|
||||||
@ -116,6 +121,7 @@
|
|||||||
"value": 0,
|
"value": 0,
|
||||||
"step": 100,
|
"step": 100,
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
|
"compactHeight": false,
|
||||||
"limits": [
|
"limits": [
|
||||||
0,
|
0,
|
||||||
2000
|
2000
|
||||||
@ -136,9 +142,10 @@
|
|||||||
"step": 0.1,
|
"step": 0.1,
|
||||||
"limits": [
|
"limits": [
|
||||||
0,
|
0,
|
||||||
5
|
4
|
||||||
],
|
],
|
||||||
"siPrefix": true,
|
"siPrefix": true,
|
||||||
|
"compactHeight": false,
|
||||||
"param": [
|
"param": [
|
||||||
"pwm",
|
"pwm",
|
||||||
"ch",
|
"ch",
|
||||||
@ -169,6 +176,7 @@
|
|||||||
100
|
100
|
||||||
],
|
],
|
||||||
"format": "{value:.4f}",
|
"format": "{value:.4f}",
|
||||||
|
"compactHeight": false,
|
||||||
"param": [
|
"param": [
|
||||||
"s-h",
|
"s-h",
|
||||||
"ch",
|
"ch",
|
||||||
@ -184,6 +192,7 @@
|
|||||||
"value": 10000,
|
"value": 10000,
|
||||||
"step": 1,
|
"step": 1,
|
||||||
"siPrefix": true,
|
"siPrefix": true,
|
||||||
|
"compactHeight": false,
|
||||||
"param": [
|
"param": [
|
||||||
"s-h",
|
"s-h",
|
||||||
"ch",
|
"ch",
|
||||||
@ -199,6 +208,7 @@
|
|||||||
"value": 3950,
|
"value": 3950,
|
||||||
"step": 1,
|
"step": 1,
|
||||||
"decimals": 4,
|
"decimals": 4,
|
||||||
|
"compactHeight": false,
|
||||||
"param": [
|
"param": [
|
||||||
"s-h",
|
"s-h",
|
||||||
"ch",
|
"ch",
|
||||||
@ -242,6 +252,7 @@
|
|||||||
"type": "float",
|
"type": "float",
|
||||||
"step": 0.1,
|
"step": 0.1,
|
||||||
"suffix": "",
|
"suffix": "",
|
||||||
|
"compactHeight": false,
|
||||||
"param": [
|
"param": [
|
||||||
"pid",
|
"pid",
|
||||||
"ch",
|
"ch",
|
||||||
@ -255,6 +266,7 @@
|
|||||||
"title": "Ki (Hz)",
|
"title": "Ki (Hz)",
|
||||||
"type": "float",
|
"type": "float",
|
||||||
"step": 0.1,
|
"step": 0.1,
|
||||||
|
"compactHeight": false,
|
||||||
"param": [
|
"param": [
|
||||||
"pid",
|
"pid",
|
||||||
"ch",
|
"ch",
|
||||||
@ -268,6 +280,7 @@
|
|||||||
"title": "Kd (s)",
|
"title": "Kd (s)",
|
||||||
"type": "float",
|
"type": "float",
|
||||||
"step": 0.1,
|
"step": 0.1,
|
||||||
|
"compactHeight": false,
|
||||||
"param": [
|
"param": [
|
||||||
"pid",
|
"pid",
|
||||||
"ch",
|
"ch",
|
||||||
@ -293,6 +306,7 @@
|
|||||||
2000
|
2000
|
||||||
],
|
],
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
|
"compactHeight": false,
|
||||||
"param": [
|
"param": [
|
||||||
"pid",
|
"pid",
|
||||||
"ch",
|
"ch",
|
||||||
@ -311,6 +325,7 @@
|
|||||||
2000
|
2000
|
||||||
],
|
],
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
|
"compactHeight": false,
|
||||||
"param": [
|
"param": [
|
||||||
"pid",
|
"pid",
|
||||||
"ch",
|
"ch",
|
||||||
@ -323,7 +338,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pid_autotune",
|
"name": "pid_autotune",
|
||||||
"title": "PID Auto Tune",
|
"title": "PID Autotune",
|
||||||
"expanded": false,
|
"expanded": false,
|
||||||
"type": "group",
|
"type": "group",
|
||||||
"tip": "Automatically tune PID parameters",
|
"tip": "Automatically tune PID parameters",
|
||||||
@ -335,6 +350,7 @@
|
|||||||
"value": 20,
|
"value": 20,
|
||||||
"step": 0.1,
|
"step": 0.1,
|
||||||
"format": "{value:.4f}",
|
"format": "{value:.4f}",
|
||||||
|
"compactHeight": false,
|
||||||
"pid_autotune": [
|
"pid_autotune": [
|
||||||
"target_temp",
|
"target_temp",
|
||||||
"ch"
|
"ch"
|
||||||
@ -347,9 +363,10 @@
|
|||||||
"type": "float",
|
"type": "float",
|
||||||
"value": 0,
|
"value": 0,
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
|
"compactHeight": false,
|
||||||
"step": 100,
|
"step": 100,
|
||||||
"limits": [
|
"limits": [
|
||||||
-2000,
|
0,
|
||||||
2000
|
2000
|
||||||
],
|
],
|
||||||
"pid_autotune": [
|
"pid_autotune": [
|
||||||
@ -366,6 +383,7 @@
|
|||||||
"step": 0.1,
|
"step": 0.1,
|
||||||
"prefix": "±",
|
"prefix": "±",
|
||||||
"format": "{value:.4f}",
|
"format": "{value:.4f}",
|
||||||
|
"compactHeight": false,
|
||||||
"pid_autotune": [
|
"pid_autotune": [
|
||||||
"temp_swing",
|
"temp_swing",
|
||||||
"ch"
|
"ch"
|
||||||
@ -379,6 +397,7 @@
|
|||||||
"value": 3.0,
|
"value": 3.0,
|
||||||
"step": 0.1,
|
"step": 0.1,
|
||||||
"format": "{value:.4f}",
|
"format": "{value:.4f}",
|
||||||
|
"compactHeight": false,
|
||||||
"pid_autotune": [
|
"pid_autotune": [
|
||||||
"lookback",
|
"lookback",
|
||||||
"ch"
|
"ch"
|
||||||
|
@ -82,7 +82,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
[["load"], partial(self.thermostat.load_cfg, ch)],
|
[["load"], partial(self.thermostat.load_cfg, ch)],
|
||||||
[
|
[
|
||||||
["pid", "pid_autotune", "run_pid"],
|
["pid", "pid_autotune", "run_pid"],
|
||||||
partial(self.pid_auto_tune_request, ch),
|
partial(self.pid_autotune_request, ch),
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
for ch in range(self.NUM_CHANNELS)
|
for ch in range(self.NUM_CHANNELS)
|
||||||
@ -262,7 +262,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
@asyncSlot(object, object)
|
@asyncSlot(object, object)
|
||||||
async def send_command(self, param, changes):
|
async def send_command(self, param, changes):
|
||||||
"""Translates parameter tree changes into thermostat set_param calls"""
|
"""Translates parameter tree changes into thermostat set_param calls"""
|
||||||
ch = param.channel
|
ch = param.value()
|
||||||
|
|
||||||
for inner_param, change, data in changes:
|
for inner_param, change, data in changes:
|
||||||
if change == "value":
|
if change == "value":
|
||||||
@ -283,10 +283,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
param.child(*param.childPath(inner_param)).setOpts(lock=False)
|
param.child(*param.childPath(inner_param)).setOpts(lock=False)
|
||||||
|
|
||||||
if inner_param.opts.get("pid_autotune", None) is not None:
|
if inner_param.opts.get("pid_autotune", None) is not None:
|
||||||
auto_tuner_param = inner_param.opts["pid_autotune"][0]
|
autotuner_param = inner_param.opts["pid_autotune"][0]
|
||||||
if inner_param.opts["pid_autotune"][1] != "ch":
|
if inner_param.opts["pid_autotune"][1] != "ch":
|
||||||
ch = inner_param.opts["pid_autotune"][1]
|
ch = inner_param.opts["pid_autotune"][1]
|
||||||
self.autotuners.set_params(auto_tuner_param, ch, data)
|
self.autotuners.set_params(autotuner_param, ch, data)
|
||||||
|
|
||||||
if inner_param.opts.get("activaters", None) is not None:
|
if inner_param.opts.get("activaters", None) is not None:
|
||||||
activater = inner_param.opts["activaters"][
|
activater = inner_param.opts["activaters"][
|
||||||
@ -298,7 +298,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
await self.client.set_param(*activater)
|
await self.client.set_param(*activater)
|
||||||
|
|
||||||
@asyncSlot()
|
@asyncSlot()
|
||||||
async def pid_auto_tune_request(self, ch=0):
|
async def pid_autotune_request(self, ch=0):
|
||||||
match self.autotuners.get_state(ch):
|
match self.autotuners.get_state(ch):
|
||||||
case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED:
|
case PIDAutotuneState.STATE_OFF | PIDAutotuneState.STATE_FAILED:
|
||||||
self.autotuners.load_params_and_set_ready(ch)
|
self.autotuners.load_params_and_set_ready(ch)
|
||||||
|
Loading…
Reference in New Issue
Block a user