Compare commits

..

28 Commits

Author SHA1 Message Date
c9aa0eaab8 ctrl_panel: Reformat SpinBox text always if valid
The parameter SpinBoxes previously would only update if the interpreted
value was changed, missing cases where the text would have changed but
the value stays the same, e.g. removing trailing decimal zeros.
2024-10-07 16:13:56 +08:00
ed6cee4394 ctrl_panel: Move postfilter into its own group 2024-10-07 16:13:56 +08:00
e1bd960900 ctrl_panel: Use new locking mechanism from Kirdy 2024-10-07 16:13:56 +08:00
aed0c484dd ctrl_panel: Fix editing fields with unit "°C"
A faulty regular expression within PyQtGraph causes any Parameter with a
suffix that doesn't begin with an alphanumeric character (as matched
with \w) to act abnormally. For instance, entering "100 °C" into the
input boxes gets interpreted as 10 °C.

Patch the FLOAT_REGEX in PyQtGraph to simply match for any character in
the suffix group.
2024-10-07 16:13:56 +08:00
3fe343435d ctrl_panel: More appropriate steps and fixes 2024-10-07 16:13:56 +08:00
eddfc40e07 ctrl_panel: Put plotted values into readings group
For more intuitiveness to first-time users
2024-10-07 16:13:56 +08:00
3ae89760ab ctrl_panel: Fix max_v to only have unit "V"
As most users do not need to limit TEC voltage with accuracy of less
than 1mV.
2024-10-07 16:13:56 +08:00
2f9b95f04b ctrl_panel: Bold "Control Method" text 2024-10-07 16:13:56 +08:00
9926c00494 ctrl_panel: Indicate active parameter of control
Instead of hiding the inactive control parameter, underline and bold the
active control parameter title, e.g. "Set Current" when control method
is constant current, and "Setpoint" when it is temperature PID.
2024-10-07 16:13:54 +08:00
fde1e6b3e4 ctrl_panel: Limits fixes
* PID Autotune test current should be positive

* max_v should be 4 V not 5 V

* r0 should not be negative
2024-10-07 16:03:00 +08:00
873f16a675 ctrl_panel: Code cleanup
* Remove unnecessary duplication of `THERMOSTAT_PARAMETERS`

* i -> ch

* Separate ParameterTree and Parameter initiation

* Remove extra "channel" option to root parameters, as the "value"
option is already the channel number
2024-10-07 16:03:00 +08:00
85c8c23f2c ctrl_panel: PID Auto Tune -> PID Autotune 2024-10-07 16:02:58 +08:00
ac10859f70 ctrl_panel: Stop crushing spinboxes
It might not be the case on some themes, but on the default Qt theme the
spinbox are a bit too short for the containing numbers. See
https://github.com/pyqtgraph/pyqtgraph/issues/701.
2024-10-07 16:02:04 +08:00
4bda62ab41 ctrl_panel: Pin down units for editable fields
User input always has the same order of magnitude, so allowing multiple
siPrefixes would be unwanted complexity. Don't allow them to be changed.

The Parameter option "noUnitEditing" is added to do so by the following
measures:

1. Don't validate for changed siPrefix (if pinned) and suffix, which
avoids their removal.

2. Avoid getting the cursor embedded within the unit.
2024-10-07 16:01:50 +08:00
6df37e31aa ctrl_panel: Remove need for "mA" hack
Remove all instances of mA scaling scattered all around the code and
specify it in the parameter tree with a single source of truth.

Done by adding the option "pinSiPrefix" for all Parameters of type `int`
or `float`, and using it for current Parameters with unit "mA".
2024-10-07 16:01:41 +08:00
2df4c03c2d ctrl_panel: Appropriate units for measured current
Allow the readonly display of current to vary its SI prefix in the unit,
since as a display entry it won't have the unit adjustment problem.
2024-10-07 16:01:31 +08:00
2b9bc020ce ctrl_panel: Improve postfilter description 2024-10-07 16:01:31 +08:00
dafde57e23 ctrl_panel: Add and improve tooltips and titles
For users' better understanding of what the parameters do
2024-10-07 16:01:29 +08:00
6a38f9b5a6 ctrl_panel: Refer to Parameters by concise names
For displayed string representations, use the `title` key, or for
`ListParameter`s, use the dictionary mapping method instead.
2024-10-07 16:01:21 +08:00
9af4ffd125 ctrl_panel: Config -> Settings 2024-10-07 16:01:13 +08:00
55a7583867 Format JSON 2024-10-07 16:01:11 +08:00
19c3c7a8f2 Merge pull request 'GUI: Refactor send_command' (#4) from gui_dev-refactor-send_command into gui_dev
Reviewed-on: #4
2024-10-07 13:03:38 +08:00
41abad7aa3 send_command: Remove "activater"
Interpret commands anomalies directly in send_command instead
2024-08-14 16:07:15 +08:00
5c8d9c7cce send_command: Simplify "pid_autotune" parameters 2024-08-14 16:07:15 +08:00
278898fad2 send_command: Switch to thermostat:set_param
Use a `dict` to map values to thermostat parameters, which correspond to
the `set_param` parameters in the pytec client. New tag
"thermostat:set_param" used in JSON.
2024-08-14 16:07:14 +08:00
dd83daa5d9 send_command: Remove indirect path to parameter
The child at inner_param's childpath to the root parameter... is just
inner_param itself.
2024-08-14 16:06:31 +08:00
d57cc9ef2a send_command: Alias data as new_value 2024-08-14 16:06:24 +08:00
be77a6f205 send_command: Use in syntax 2024-08-14 16:06:17 +08:00
2 changed files with 87 additions and 122 deletions

View File

@ -42,14 +42,10 @@
"Constant Current": "constant_current", "Constant Current": "constant_current",
"Temperature PID": "temperature_pid" "Temperature PID": "temperature_pid"
}, },
"activaters": [ "thermostat:set_param": {
null, "topic": "pwm",
[ "field": "pid"
"pwm", },
"ch",
"pid"
]
],
"tip": "Select control method of output", "tip": "Select control method of output",
"children": [ "children": [
{ {
@ -68,11 +64,10 @@
"siPrefix": true, "siPrefix": true,
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"pwm", "topic": "pwm",
"ch", "field": "i_set"
"i_set" },
],
"tip": "The set current through TEC", "tip": "The set current through TEC",
"lock": false "lock": false
}, },
@ -90,11 +85,10 @@
"suffix": "°C", "suffix": "°C",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"pid", "topic": "pid",
"ch", "field": "target"
"target" },
],
"tip": "The temperature setpoint of the TEC", "tip": "The temperature setpoint of the TEC",
"lock": false "lock": false
} }
@ -123,11 +117,10 @@
"suffix": "A", "suffix": "A",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"pwm", "topic": "pwm",
"ch", "field": "max_i_pos"
"max_i_pos" },
],
"tip": "The maximum cooling (+ve) current through the output pins", "tip": "The maximum cooling (+ve) current through the output pins",
"lock": false "lock": false
}, },
@ -147,11 +140,10 @@
2 2
], ],
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"pwm", "topic": "pwm",
"ch", "field": "max_i_neg"
"max_i_neg" },
],
"tip": "The maximum heating (-ve) current through the output pins", "tip": "The maximum heating (-ve) current through the output pins",
"lock": false "lock": false
}, },
@ -169,11 +161,10 @@
"suffix": "V", "suffix": "V",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"pwm", "topic": "pwm",
"ch", "field": "max_v"
"max_v" },
],
"tip": "The maximum voltage (in both directions) across the output pins", "tip": "The maximum voltage (in both directions) across the output pins",
"lock": false "lock": false
} }
@ -202,11 +193,10 @@
"suffix": "°C", "suffix": "°C",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"s-h", "topic": "s-h",
"ch", "field": "t0"
"t0" },
],
"tip": "The base temperature", "tip": "The base temperature",
"lock": false "lock": false
}, },
@ -222,11 +212,10 @@
"suffix": "Ω", "suffix": "Ω",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"s-h", "topic": "s-h",
"ch", "field": "r0"
"r0" },
],
"tip": "The resistance of the thermistor at base temperature T₀", "tip": "The resistance of the thermistor at base temperature T₀",
"lock": false "lock": false
}, },
@ -240,11 +229,10 @@
"noUnitEditing": true, "noUnitEditing": true,
"decimals": 4, "decimals": 4,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"s-h", "topic": "s-h",
"ch", "field": "b"
"b" },
],
"tip": "The Beta Parameter", "tip": "The Beta Parameter",
"lock": false "lock": false
} }
@ -261,11 +249,10 @@
"title": "50/60 Hz Rejection Filter", "title": "50/60 Hz Rejection Filter",
"type": "list", "type": "list",
"value": 16.67, "value": 16.67,
"param": [ "thermostat:set_param": {
"postfilter", "topic": "postfilter",
"ch", "field": "rate"
"rate" },
],
"limits": { "limits": {
"16.67 SPS": 16.67, "16.67 SPS": 16.67,
"20 SPS": 20.0, "20 SPS": 20.0,
@ -291,11 +278,10 @@
"type": "float", "type": "float",
"step": 0.1, "step": 0.1,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"pid", "topic": "pid",
"ch", "field": "kp"
"kp" },
],
"tip": "Proportional gain", "tip": "Proportional gain",
"lock": false "lock": false
}, },
@ -307,11 +293,10 @@
"suffix": "Hz", "suffix": "Hz",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"pid", "topic": "pid",
"ch", "field": "ki"
"ki" },
],
"tip": "Integral gain", "tip": "Integral gain",
"lock": false "lock": false
}, },
@ -323,11 +308,10 @@
"suffix": "s", "suffix": "s",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"pid", "topic": "pid",
"ch", "field": "kd"
"kd" },
],
"tip": "Differential gain", "tip": "Differential gain",
"lock": false "lock": false
}, },
@ -353,11 +337,10 @@
"suffix": "A", "suffix": "A",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"pid", "topic": "pid",
"ch", "field": "output_min"
"output_min" },
],
"tip": "Minimum PID output", "tip": "Minimum PID output",
"lock": false "lock": false
}, },
@ -376,11 +359,10 @@
"suffix": "A", "suffix": "A",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"param": [ "thermostat:set_param": {
"pid", "topic": "pid",
"ch", "field": "output_max"
"output_max" },
],
"tip": "Maximum PID output", "tip": "Maximum PID output",
"lock": false "lock": false
} }
@ -403,10 +385,7 @@
"suffix": "°C", "suffix": "°C",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"pid_autotune": [ "pid_autotune": "target_temp",
"target_temp",
"ch"
],
"tip": "The target temperature to autotune for" "tip": "The target temperature to autotune for"
}, },
{ {
@ -425,10 +404,7 @@
"suffix": "A", "suffix": "A",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"pid_autotune": [ "pid_autotune": "test_current",
"test_current",
"ch"
],
"tip": "The testing current when autotuning" "tip": "The testing current when autotuning"
}, },
{ {
@ -441,10 +417,7 @@
"suffix": "K", "suffix": "K",
"noUnitEditing": true, "noUnitEditing": true,
"compactHeight": false, "compactHeight": false,
"pid_autotune": [ "pid_autotune": "temp_swing",
"temp_swing",
"ch"
],
"tip": "The temperature swing around the target" "tip": "The temperature swing around the target"
}, },
{ {
@ -457,10 +430,7 @@
"noUnitEditing": true, "noUnitEditing": true,
"suffix": "s", "suffix": "s",
"compactHeight": false, "compactHeight": false,
"pid_autotune": [ "pid_autotune": "lookback",
"lookback",
"ch"
],
"tip": "Amount of time referenced for tuning" "tip": "Amount of time referenced for tuning"
}, },
{ {

View File

@ -266,37 +266,32 @@ class MainWindow(QtWidgets.QMainWindow):
for inner_param, change, data in changes: for inner_param, change, data in changes:
if change == "value": if change == "value":
if inner_param.opts.get("param", None) is not None: new_value = data
thermostat_param = inner_param.opts["param"] if "thermostat:set_param" in inner_param.opts:
if thermostat_param[1] == "ch": thermostat_param = inner_param.opts["thermostat:set_param"]
thermostat_param[1] = ch
if inner_param.name() == "rate" and data is None: # Handle thermostat command irregularities
set_param_args = (*thermostat_param[:2], "off") match inner_param.name(), new_value:
else: case "rate", None:
set_param_args = (*thermostat_param, data) thermostat_param = thermostat_param.copy()
param.child(*param.childPath(inner_param)).setOpts(lock=True) thermostat_param["field"] = "off"
await self.client.set_param(*set_param_args) new_value = ""
param.child(*param.childPath(inner_param)).setOpts(lock=False) case "control_method", "constant_current":
thermostat_param = thermostat_param.copy()
thermostat_param["field"] = "i_set"
new_value = inner_param.child("i_set").value()
case "control_method", "temperature_pid":
new_value = ""
if inner_param.opts.get("pid_autotune", None) is not None: inner_param.setOpts(lock=True)
autotuner_param = inner_param.opts["pid_autotune"][0] await self.client.set_param(
if inner_param.opts["pid_autotune"][1] != "ch": channel=ch, value=new_value, **thermostat_param
ch = inner_param.opts["pid_autotune"][1] )
self.autotuners.set_params(autotuner_param, ch, data) inner_param.setOpts(lock=False)
if inner_param.opts.get("activaters", None) is not None: if "pid_autotune" in inner_param.opts:
activater = inner_param.opts["activaters"][ auto_tuner_param = inner_param.opts["pid_autotune"]
inner_param.reverse[0].index(data) # ListParameter.reverse = list of codename values self.autotuners.set_params(auto_tuner_param, ch, new_value)
]
if activater is not None:
if activater[1] == "ch":
activater[1] = ch
await self.client.set_param(*activater)
else:
await self.client.set_param(
"pwm", ch, "i_set", inner_param.child("i_set").value()
)
@asyncSlot() @asyncSlot()
async def pid_autotune_request(self, ch=0): async def pid_autotune_request(self, ch=0):