Compare commits

..

13 Commits

Author SHA1 Message Date
198b07f2a6 README: Introduce Thermostat GUI
Co-authored-by: topquark12 <aw@m-labs.hk>
2024-11-18 11:59:59 +08:00
8a6253ba8a pytec GUI: Set up packaging
Co-authored-by: Egor Savkin <es@m-labs.hk>
2024-11-18 11:59:59 +08:00
0551775ca3 pytec GUI: Implement Control Panel
Co-authored-by: linuswck <linuswck@m-labs.hk>
Co-authored-by: Egor Savkin <es@m-labs.hk>
2024-11-18 11:59:59 +08:00
c16539e45b pytec GUI: Implement PlotSettingsMenu
Co-authored-by: linuswck <linuswck@m-labs.hk>
2024-11-18 11:59:59 +08:00
51ce4ea603 pytec GUI: Implement plotting
Co-authored-by: linuswck <linuswck@m-labs.hk>
2024-11-18 11:59:59 +08:00
136e4d6333 pytec GUI: Incorporate autotuning
Co-authored-by: topquark12 <aw@m-labs.hk>
Co-authored-by: linuswck <linuswck@m-labs.hk>
Co-authored-by: Egor Savkin <es@m-labs.hk>
2024-11-18 11:59:59 +08:00
99ebb03ead pytec GUI: Implement ThermostatSettingsMenu
Co-authored-by: linuswck <linuswck@m-labs.hk>
Co-authored-by: Egor Savkin <es@m-labs.hk>
2024-11-18 11:59:59 +08:00
000d927ee6 pytec GUI: Implement status line
Co-authored-by: linuswck <linuswck@m-labs.hk>
Co-authored-by: Egor Savkin <es@m-labs.hk>
2024-11-18 11:59:59 +08:00
b0365bd4de pytec: Create GUI to Thermostat
- Add connection menu

- Add basic GUI layout skeleton

Co-authored-by: linuswck <linuswck@m-labs.hk>
Co-authored-by: Egor Savkin <es@m-labs.hk>
2024-11-18 11:59:59 +08:00
3ec0990c89 pytec: Create asyncio clients 2024-11-18 11:59:59 +08:00
adc25c9b2a pytec: Add hardware testing script
Eases the process of testing the hardware.

See #143.
2024-11-18 10:31:56 +08:00
9af86be674 pytec: Remove artificial report mode in client
Encourage polling usage instead, as shown in example.
2024-11-16 13:11:59 +08:00
eabc7f6a12 flake: Register the pytec Python package 2024-11-11 17:11:37 +08:00
5 changed files with 118 additions and 64 deletions

View File

@ -58,6 +58,30 @@
auditable = false; auditable = false;
}; };
pytec = pkgs.python3Packages.buildPythonPackage {
pname = "pytec";
version = "0.0.0";
format = "pyproject";
src = "${self}/pytec";
nativeBuildInputs = [ pkgs.qt6.wrapQtAppsHook ];
propagatedBuildInputs =
[ pkgs.qt6.qtbase ]
++ (with pkgs.python3Packages; [
numpy
matplotlib
pyqtgraph
pyqt6
qasync
pglive
]);
dontWrapQtApps = true;
postFixup = ''
wrapQtApp "$out/bin/tec_qt"
'';
};
pglive = pkgs.python3Packages.buildPythonPackage rec { pglive = pkgs.python3Packages.buildPythonPackage rec {
pname = "pglive"; pname = "pglive";
version = "0.7.2"; version = "0.7.2";
@ -72,38 +96,16 @@
numpy numpy
]; ];
}; };
thermostat_gui = pkgs.python3Packages.buildPythonPackage {
pname = "thermostat_gui";
version = "0.0.0";
format = "pyproject";
src = "${self}/pytec";
nativeBuildInputs = [ pkgs.qt6.wrapQtAppsHook ];
propagatedBuildInputs =
[ pkgs.qt6.qtbase ]
++ (with pkgs.python3Packages; [
pyqtgraph
pyqt6
qasync
pglive
]);
dontWrapQtApps = true;
postFixup = ''
wrapQtApp "$out/bin/tec_qt"
'';
};
in in
{ {
packages.x86_64-linux = { packages.x86_64-linux = {
inherit thermostat thermostat_gui; inherit thermostat pytec;
default = thermostat; default = thermostat;
}; };
apps.x86_64-linux.thermostat_gui = { apps.x86_64-linux.thermostat_gui = {
type = "app"; type = "app";
program = "${self.packages.x86_64-linux.thermostat_gui}/bin/tec_qt"; program = "${self.packages.x86_64-linux.pytec}/bin/tec_qt";
}; };
hydraJobs = { hydraJobs = {
@ -120,7 +122,6 @@
openocd openocd
dfu-util dfu-util
rlwrap rlwrap
qtcreator
] ]
++ (with python3Packages; [ ++ (with python3Packages; [
numpy numpy

View File

@ -1,3 +1,4 @@
import time
from pytec.client import Client from pytec.client import Client
tec = Client() #(host="localhost", port=6667) tec = Client() #(host="localhost", port=6667)
@ -7,5 +8,6 @@ print(tec.get_pid())
print(tec.get_output()) print(tec.get_output())
print(tec.get_postfilter()) print(tec.get_postfilter())
print(tec.get_b_parameter()) print(tec.get_b_parameter())
for data in tec.report_mode(): while True:
print(data) print(tec.get_report())
time.sleep(0.05)

View File

@ -1,7 +1,7 @@
import socket import socket
import json import json
import logging import logging
import time
class CommandError(Exception): class CommandError(Exception):
pass pass
@ -147,36 +147,6 @@ class Client:
"""Get Thermostat hardware revision""" """Get Thermostat hardware revision"""
return self._command("hwrev") return self._command("hwrev")
def report_mode(self):
"""Start reporting measurement values
Example of yielded data::
{'channel': 0,
'time': 2302524,
'adc': 0.6199188965423515,
'sens': 6138.519310282602,
'temperature': 36.87032392655527,
'pid_engaged': True,
'i_set': 2.0635816680889123,
'vref': 1.494,
'dac_value': 2.527790834044456,
'dac_feedback': 2.523,
'i_tec': 2.331,
'tec_i': 2.0925,
'tec_u_meas': 2.5340000000000003,
'pid_output': 2.067581958092247}
"""
while True:
self._socket.sendall("report\n".encode('utf-8'))
line = self._read_line()
if not line:
break
try:
yield json.loads(line)
except json.decoder.JSONDecodeError:
pass
time.sleep(0.05)
def set_param(self, topic, channel, field="", value=""): def set_param(self, topic, channel, field="", value=""):
"""Set configuration parameters """Set configuration parameters

View File

@ -30,8 +30,8 @@ def get_argparser():
action="store_true", action="store_true",
help="Automatically connect to the specified Thermostat in host:port format", help="Automatically connect to the specified Thermostat in host:port format",
) )
parser.add_argument("HOST", metavar="host", default=None, nargs="?") parser.add_argument("host", metavar="HOST", default=None, nargs="?")
parser.add_argument("PORT", metavar="port", default=None, nargs="?") parser.add_argument("port", metavar="PORT", default=None, nargs="?")
parser.add_argument( parser.add_argument(
"-l", "-l",
"--log", "--log",
@ -237,10 +237,10 @@ async def coro_main():
main_window.show() main_window.show()
if args.connect: if args.connect:
if args.HOST: if args.host:
main_window.connection_details_menu.host_set_line.setText(args.HOST) main_window.connection_details_menu.host_set_line.setText(args.host)
if args.PORT: if args.port:
main_window.connection_details_menu.port_set_spin.setValue(int(args.PORT)) main_window.connection_details_menu.port_set_spin.setValue(int(args.port))
main_window.connect_btn.click() main_window.connect_btn.click()
await app_quit_event.wait() await app_quit_event.wait()

81
pytec/test.py Normal file
View File

@ -0,0 +1,81 @@
import argparse
from contextlib import contextmanager
from pytec.client import Client
CHANNELS = 2
def get_argparser():
parser = argparse.ArgumentParser(description="Thermostat hardware testing script")
parser.add_argument("host", metavar="HOST", default="192.168.1.26", nargs="?")
parser.add_argument("port", metavar="PORT", default=23, nargs="?")
parser.add_argument(
"-r",
"--testing_resistance",
default=10_000,
help="Testing resistance value through SENS pin in Ohms",
)
parser.add_argument(
"-d",
"--deviation",
default=1,
help="Allowed deviation of resistance in percentage",
)
return parser
def main():
args = get_argparser().parse_args()
min_allowed_resistance = args.testing_resistance * (1 - args.deviation / 100)
max_allowed_resistance = args.testing_resistance * (1 + args.deviation / 100)
print(min_allowed_resistance, max_allowed_resistance)
thermostat = Client(args.host, args.port)
for channel in range(CHANNELS):
print(f"Channel {channel} is active")
print("Checking resistance through SENS input ....", end=" ")
sens_resistance = thermostat.get_report()[channel]["sens"]
if sens_resistance is not None:
print(sens_resistance, "Ω")
if min_allowed_resistance <= sens_resistance <= max_allowed_resistance:
print("PASSED")
else:
print("FAILED")
else:
print("Floating SENS input! Is the channel connected?")
with preserve_thermostat_output_settings(thermostat, channel):
test_output_settings = {
"max_i_pos": 2,
"max_i_neg": 2,
"max_v": 4,
"i_set": 0.1,
"polarity": "normal",
}
for field, value in test_output_settings.items():
thermostat.set_param("output", channel, field, value)
input(f"Check if channel {channel} current = 0.1 A, and press ENTER...")
input(f"Channel {channel} testing done, press ENTER to continue.")
print()
print("Testing complete.")
@contextmanager
def preserve_thermostat_output_settings(client, channel):
original_output_settings = client.get_output()[channel]
yield original_output_settings
for setting in "max_i_pos", "max_i_neg", "max_v", "i_set", "polarity":
client.set_param("output", channel, setting, original_output_settings[setting])
if __name__ == "__main__":
main()