From d74e806de8cc272b09474c460acb92c89cab2af1 Mon Sep 17 00:00:00 2001 From: topquark12 Date: Mon, 6 Jun 2022 12:38:44 +0800 Subject: [PATCH] add sync from TEC --- pytec/tecQT.py | 153 ++++++++++++++++++++++++++++++------------------- 1 file changed, 94 insertions(+), 59 deletions(-) diff --git a/pytec/tecQT.py b/pytec/tecQT.py index 92c0306..8b07ff4 100644 --- a/pytec/tecQT.py +++ b/pytec/tecQT.py @@ -5,31 +5,38 @@ import numpy as np import pyqtgraph as pg from pytec.client import Client -tec = Client(host="192.168.1.26", port=23, timeout=None) - rec_len = 1000 refresh_period = 20 -# Channel 0 or 1 -# -# |- 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) +TECparams = [ [ + {'tag': 'report', 'type': 'parent', 'children': [ + {'tag': 'pid_engaged', 'type': 'bool', 'value': False}, + ]}, + {'tag': 'pwm', 'type': 'parent', 'children': [ + {'tag': 'max_i_pos', 'type': 'float', 'value': 0}, + {'tag': 'max_i_neg', 'type': 'float', 'value': 0}, + {'tag': 'max_v', 'type': 'float', 'value': 0}, + {'tag': 'i_set', 'type': 'float', 'value': 0}, + ]}, + {'tag': 'pid', 'type': 'parent', 'children': [ + {'tag': 'kp', 'type': 'float', 'value': 0}, + {'tag': 'ki', 'type': 'float', 'value': 0}, + {'tag': 'kd', 'type': 'float', 'value': 0}, + {'tag': 'output_min', 'type': 'float', 'value': 0}, + {'tag': 'output_max', 'type': 'float', 'value': 0}, + ]}, + {'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 Constant Current', 'type': 'bool', 'value': False, 'children': [ {'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': 'Save', 'type': 'action', 'tip': 'Save'}, -] for _ in range(2)] +] for ch in range(2)] ## If anything changes in the tree, print a message def change(param, changes): @@ -105,38 +112,29 @@ class Graph: 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]) -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) +def TECsync(): + global TECparams + for channel in range(2): + for parents in TECparams[channel]: + if parents['tag'] == 'report': + for data in tec.report_mode(): + for children in parents['children']: + children['value'] = data[channel][children['tag']] + if quit: + break + 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 def updateData(): @@ -152,11 +150,48 @@ def updateData(): break cnt += 1 -t = QtCore.QTimer() -t.timeout.connect(updateData) -t.start(refresh_period) - -mw.show() - + 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() \ No newline at end of file