forked from M-Labs/thermostat
add sync from TEC
This commit is contained in:
parent
1083af1266
commit
d74e806de8
151
pytec/tecQT.py
151
pytec/tecQT.py
@ -5,31 +5,38 @@ import numpy as np
|
|||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from pytec.client import Client
|
from pytec.client import Client
|
||||||
|
|
||||||
tec = Client(host="192.168.1.26", port=23, timeout=None)
|
|
||||||
|
|
||||||
rec_len = 1000
|
rec_len = 1000
|
||||||
refresh_period = 20
|
refresh_period = 20
|
||||||
|
|
||||||
# Channel 0 or 1
|
TECparams = [ [
|
||||||
# <Status Display : Off / Constant Current / Constant Temperature>
|
{'tag': 'report', 'type': 'parent', 'children': [
|
||||||
# |- Output enable
|
{'tag': 'pid_engaged', 'type': 'bool', 'value': False},
|
||||||
# |- Set Constant Current (Disables Constant Temperature)
|
]},
|
||||||
# |- Set Constant Temperature (Disables Constant Current)
|
{'tag': 'pwm', 'type': 'parent', 'children': [
|
||||||
# |- Output Config
|
{'tag': 'max_i_pos', 'type': 'float', 'value': 0},
|
||||||
# |- Max Current
|
{'tag': 'max_i_neg', 'type': 'float', 'value': 0},
|
||||||
# |- Max Voltage
|
{'tag': 'max_v', 'type': 'float', 'value': 0},
|
||||||
# |- Thermistor Config
|
{'tag': 'i_set', 'type': 'float', 'value': 0},
|
||||||
# |- T0
|
]},
|
||||||
# |- R0
|
{'tag': 'pid', 'type': 'parent', 'children': [
|
||||||
# |- Beta
|
{'tag': 'kp', 'type': 'float', 'value': 0},
|
||||||
# |- PID Config
|
{'tag': 'ki', 'type': 'float', 'value': 0},
|
||||||
# |- kP
|
{'tag': 'kd', 'type': 'float', 'value': 0},
|
||||||
# |- kI
|
{'tag': 'output_min', 'type': 'float', 'value': 0},
|
||||||
# |- kD
|
{'tag': 'output_max', 'type': 'float', 'value': 0},
|
||||||
# |- (Auto Tune PID)
|
]},
|
||||||
# (Save Configs)
|
{'tag': 's-h', 'type': 'parent', 'children': [
|
||||||
|
{'tag': 't0', 'type': 'float', 'value': 0},
|
||||||
|
{'tag': 'r0', 'type': 'float', 'value': 0},
|
||||||
|
{'tag': 'b', 'type': 'float', 'value': 0},
|
||||||
|
]},
|
||||||
|
{'tag': 'PIDtarget', 'type': 'parent', 'children': [
|
||||||
|
{'tag': 'target', 'type': 'float', 'value': 0},
|
||||||
|
]},
|
||||||
|
] for _ in range(2)]
|
||||||
|
|
||||||
params = [[
|
|
||||||
|
GUIparams = [[
|
||||||
{'name': 'Enable Output', 'type': 'bool', 'value': False},
|
{'name': 'Enable Output', 'type': 'bool', 'value': False},
|
||||||
{'name': 'Enable Constant Current', 'type': 'bool', 'value': False, 'children': [
|
{'name': 'Enable Constant Current', 'type': 'bool', 'value': False, 'children': [
|
||||||
{'name': 'Set Current', 'type': 'float', 'value': 0, 'step': 0.1, 'siPrefix': True, 'suffix': 'A'},
|
{'name': 'Set Current', 'type': 'float', 'value': 0, 'step': 0.1, 'siPrefix': True, 'suffix': 'A'},
|
||||||
@ -52,7 +59,7 @@ params = [[
|
|||||||
{'name': 'kD', 'type': 'float', 'value': 0, 'step': 0.1},
|
{'name': 'kD', 'type': 'float', 'value': 0, 'step': 0.1},
|
||||||
]},
|
]},
|
||||||
{'name': 'Save', 'type': 'action', 'tip': 'Save'},
|
{'name': 'Save', 'type': 'action', 'tip': 'Save'},
|
||||||
] for _ in range(2)]
|
] for ch in range(2)]
|
||||||
|
|
||||||
## If anything changes in the tree, print a message
|
## If anything changes in the tree, print a message
|
||||||
def change(param, changes):
|
def change(param, changes):
|
||||||
@ -105,38 +112,29 @@ class Graph:
|
|||||||
curve.update(tec_data, cnt)
|
curve.update(tec_data, cnt)
|
||||||
self.plotItem.setRange(xRange=[(cnt - self.curves[0].buffLen) * self.curves[0].period / 1000, cnt * self.curves[0].period / 1000])
|
self.plotItem.setRange(xRange=[(cnt - self.curves[0].buffLen) * self.curves[0].period / 1000, cnt * self.curves[0].period / 1000])
|
||||||
|
|
||||||
app = pg.mkQApp()
|
def TECsync():
|
||||||
pg.setConfigOptions(antialias=True)
|
global TECparams
|
||||||
mw = QtGui.QMainWindow()
|
for channel in range(2):
|
||||||
mw.setWindowTitle('Thermostat Control Panel')
|
for parents in TECparams[channel]:
|
||||||
mw.resize(1920,1200)
|
if parents['tag'] == 'report':
|
||||||
cw = QtGui.QWidget()
|
for data in tec.report_mode():
|
||||||
mw.setCentralWidget(cw)
|
for children in parents['children']:
|
||||||
l = QtGui.QVBoxLayout()
|
children['value'] = data[channel][children['tag']]
|
||||||
layout = pg.LayoutWidget()
|
if quit:
|
||||||
l.addWidget(layout)
|
break
|
||||||
cw.setLayout(l)
|
if parents['tag'] == 'pwm':
|
||||||
|
for children in parents['children']:
|
||||||
|
children['value'] = tec.get_pwm()[channel][children['tag']]['value']
|
||||||
|
if parents['tag'] == 'pid':
|
||||||
|
for children in parents['children']:
|
||||||
|
children['value'] = tec.get_pid()[channel]['parameters'][children['tag']]
|
||||||
|
if parents['tag'] == 's-h':
|
||||||
|
for children in parents['children']:
|
||||||
|
children['value'] = tec.get_steinhart_hart()[channel]['params'][children['tag']]
|
||||||
|
if parents['tag'] == 'PIDtarget':
|
||||||
|
for children in parents['children']:
|
||||||
|
children['value'] = tec.get_pid()[channel]['target']
|
||||||
|
|
||||||
## 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)])
|
|
||||||
ch0currentGraph = Graph(layout, 'Channel 0 Current', 1, 3, [Curves('Feedback', 'tec_i', 0, 'r', rec_len, refresh_period),
|
|
||||||
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)])
|
|
||||||
|
|
||||||
cnt = 0
|
cnt = 0
|
||||||
def updateData():
|
def updateData():
|
||||||
@ -152,11 +150,48 @@ def updateData():
|
|||||||
break
|
break
|
||||||
cnt += 1
|
cnt += 1
|
||||||
|
|
||||||
t = QtCore.QTimer()
|
|
||||||
t.timeout.connect(updateData)
|
|
||||||
t.start(refresh_period)
|
|
||||||
|
|
||||||
mw.show()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
tec = Client(host="192.168.1.26", port=23, timeout=None)
|
||||||
|
TECsync()
|
||||||
|
|
||||||
|
app = pg.mkQApp()
|
||||||
|
pg.setConfigOptions(antialias=True)
|
||||||
|
mw = QtGui.QMainWindow()
|
||||||
|
mw.setWindowTitle('Thermostat Control Panel')
|
||||||
|
mw.resize(1920,1200)
|
||||||
|
cw = QtGui.QWidget()
|
||||||
|
mw.setCentralWidget(cw)
|
||||||
|
l = QtGui.QVBoxLayout()
|
||||||
|
layout = pg.LayoutWidget()
|
||||||
|
l.addWidget(layout)
|
||||||
|
cw.setLayout(l)
|
||||||
|
|
||||||
|
## Create tree of Parameter objects
|
||||||
|
paramList0 = Parameter.create(name='GUIparams', type='group', children=GUIparams[0])
|
||||||
|
paramList0.sigTreeStateChanged.connect(change)
|
||||||
|
ch0Tree = ParameterTree()
|
||||||
|
ch0Tree.setParameters(paramList0, showTop=False)
|
||||||
|
|
||||||
|
paramList1 = Parameter.create(name='GUIparams', type='group', children=GUIparams[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)])
|
||||||
|
ch0currentGraph = Graph(layout, 'Channel 0 Current', 1, 3, [Curves('Feedback', 'tec_i', 0, 'r', rec_len, refresh_period),
|
||||||
|
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)])
|
||||||
|
|
||||||
|
t = QtCore.QTimer()
|
||||||
|
t.timeout.connect(updateData)
|
||||||
|
t.start(refresh_period)
|
||||||
|
|
||||||
|
mw.show()
|
||||||
|
|
||||||
pg.exec()
|
pg.exec()
|
Loading…
Reference in New Issue
Block a user