forked from M-Labs/thermostat
add param tree, param tree inactive
This commit is contained in:
parent
d841cd2559
commit
b097067afc
|
@ -1,4 +1,6 @@
|
|||
from pyqtgraph.Qt import QtGui, QtCore
|
||||
import pyqtgraph.parametertree.parameterTypes as pTypes
|
||||
from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem, registerParameterType
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
from pytec.client import Client
|
||||
|
@ -8,6 +10,64 @@ tec = Client(host="192.168.1.26", port=23, timeout=None)
|
|||
rec_len = 1000
|
||||
refresh_period = 20
|
||||
|
||||
# Channel 0 or 1
|
||||
# <Status Display : Off / Constant Current / Constant Temperature>
|
||||
# |- Output enable
|
||||
# |- Set Constant Current (Disables Constant Temperature)
|
||||
# |- Set Constant Temperature (Disables Constant Current)
|
||||
# |- Output Config
|
||||
# |- Max Current
|
||||
# |- Max Voltage
|
||||
# |- Thermistor Config
|
||||
# |- T0
|
||||
# |- R0
|
||||
# |- Beta
|
||||
# |- PID Config
|
||||
# |- kP
|
||||
# |- kI
|
||||
# |- kD
|
||||
# |- (Auto Tune PID)
|
||||
# (Save Configs)
|
||||
|
||||
params = [[
|
||||
{'name': 'Enable Output', 'type': 'bool', 'value': False},
|
||||
{'name': 'Enable Constant Current', 'type': 'bool', 'value': False, 'children': [
|
||||
{'name': 'Set Current', 'type': 'float', 'value': 0, 'step': 0.1, 'siPrefix': True, 'suffix': 'A'},
|
||||
]},
|
||||
{'name': 'Enable PID', 'type': 'bool', 'value': False, 'children': [
|
||||
{'name': 'Set Temperature', 'type': 'float', 'value': 25, 'step': 0.1, 'siPrefix': True, 'suffix': 'C'},
|
||||
]},
|
||||
{'name': 'Output Config', 'type': 'group', 'children': [
|
||||
{'name': 'Max Current', 'type': 'float', 'value': 0, 'step': 0.1, 'siPrefix': True, 'suffix': 'A'},
|
||||
{'name': 'Max Voltage', 'type': 'float', 'value': 0, 'step': 0.1, 'siPrefix': True, 'suffix': 'V'},
|
||||
]},
|
||||
{'name': 'Thermistor Config', 'type': 'group', 'children': [
|
||||
{'name': 'T0', 'type': 'float', 'value': 25, 'step': 0.1, 'siPrefix': True, 'suffix': 'C'},
|
||||
{'name': 'R0', 'type': 'float', 'value': 10000, 'step': 1, 'siPrefix': True, 'suffix': 'Ohm'},
|
||||
{'name': 'Beta', 'type': 'float', 'value': 3950, 'step': 1},
|
||||
]},
|
||||
{'name': 'PID Config', 'type': 'group', 'children': [
|
||||
{'name': 'kP', 'type': 'float', 'value': 0, 'step': 0.1},
|
||||
{'name': 'kI', 'type': 'float', 'value': 0, 'step': 0.1},
|
||||
{'name': 'kD', 'type': 'float', 'value': 0, 'step': 0.1},
|
||||
]},
|
||||
{'name': 'Save', 'type': 'action', 'tip': 'Save'},
|
||||
] for _ in range(2)]
|
||||
|
||||
## If anything changes in the tree, print a message
|
||||
def change(param, changes):
|
||||
print("tree changes:")
|
||||
for param, change, data in changes:
|
||||
path = paramList0.childPath(param)
|
||||
if path is not None:
|
||||
childName = '.'.join(path)
|
||||
else:
|
||||
childName = param.name()
|
||||
print(' parameter: %s'% childName)
|
||||
print(' change: %s'% change)
|
||||
print(' data: %s'% str(data))
|
||||
print(' ----------')
|
||||
|
||||
class Curves:
|
||||
def __init__(self, legend: str, key: str, channel: int, color: str, buffer_len: int, period: int):
|
||||
self.curveItem = pg.PlotCurveItem(pen=({'color': color, 'width': 1}))
|
||||
|
@ -46,9 +106,10 @@ class Graph:
|
|||
self.plotItem.setRange(xRange=[(cnt - self.curves[0].buffLen) * self.curves[0].period / 1000, cnt * self.curves[0].period / 1000])
|
||||
|
||||
app = pg.mkQApp()
|
||||
pg.setConfigOptions(antialias=True)
|
||||
mw = QtGui.QMainWindow()
|
||||
mw.setWindowTitle('Thermostat Control Panel')
|
||||
mw.resize(1500,800)
|
||||
mw.resize(1920,1200)
|
||||
cw = QtGui.QWidget()
|
||||
mw.setCentralWidget(cw)
|
||||
l = QtGui.QVBoxLayout()
|
||||
|
@ -56,7 +117,19 @@ layout = pg.LayoutWidget()
|
|||
l.addWidget(layout)
|
||||
cw.setLayout(l)
|
||||
|
||||
pg.setConfigOptions(antialias=True)
|
||||
## Create tree of Parameter objects
|
||||
paramList0 = Parameter.create(name='params', type='group', children=params[0])
|
||||
paramList0.sigTreeStateChanged.connect(change)
|
||||
ch0Tree = ParameterTree()
|
||||
ch0Tree.setParameters(paramList0, showTop=False)
|
||||
|
||||
paramList1 = Parameter.create(name='params', type='group', children=params[1])
|
||||
paramList1.sigTreeStateChanged.connect(change)
|
||||
ch1Tree = ParameterTree()
|
||||
ch1Tree.setParameters(paramList1, showTop=False)
|
||||
|
||||
layout.addWidget(ch0Tree, 1, 1, 1, 1)
|
||||
layout.addWidget(ch1Tree, 2, 1, 1, 1)
|
||||
|
||||
ch0tempGraph = Graph(layout, 'Channel 0 Temperature', 1, 2, [Curves('Feedback', 'temperature', 0, 'r', rec_len, refresh_period)])
|
||||
ch1tempGraph = Graph(layout, 'Channel 1 Temperature', 2, 2, [Curves('Feedback', 'temperature', 1, 'r', rec_len, refresh_period)])
|
||||
|
@ -64,8 +137,6 @@ ch0currentGraph = Graph(layout, 'Channel 0 Current', 1, 3, [Curves('Feedback', '
|
|||
Curves('Setpoint', 'i_set', 0, 'g', rec_len, refresh_period)])
|
||||
ch1currentGraph = Graph(layout, 'Channel 1 Current', 2, 3, [Curves('Feedback', 'tec_i', 1, 'r', rec_len, refresh_period),
|
||||
Curves('Setpoint', 'i_set', 1, 'g', rec_len, refresh_period)])
|
||||
ch0voltGraph = Graph(layout, 'Channel 0 Voltage', 1, 4, [Curves('Feedback', 'tec_u_meas', 0, 'r', rec_len, refresh_period)])
|
||||
ch1voltGraph = Graph(layout, 'Channel 1 Voltage', 2, 4, [Curves('Feedback', 'tec_u_meas', 1, 'r', rec_len, refresh_period)])
|
||||
|
||||
cnt = 0
|
||||
def updateData():
|
||||
|
@ -76,8 +147,6 @@ def updateData():
|
|||
ch1tempGraph.update(data, cnt)
|
||||
ch0currentGraph.update(data, cnt)
|
||||
ch1currentGraph.update(data, cnt)
|
||||
ch0voltGraph.update(data, cnt)
|
||||
ch1voltGraph.update(data, cnt)
|
||||
|
||||
if quit:
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue