Compare commits

..

21 Commits

Author SHA1 Message Date
5574559ac6 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-08-16 14:05:44 +08:00
e160a6f514 ctrl_panel: Move postfilter into its own group 2024-08-16 14:05:44 +08:00
ae9bd1a859 ctrl_panel: Use new locking mechanism from Kirdy 2024-08-16 14:05:44 +08:00
0f768f30e8 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-08-16 14:05:44 +08:00
07095d77c8 ctrl_panel: More appropriate steps and fixes 2024-08-16 14:05:44 +08:00
4a7d7abf3a ctrl_panel: Put plotted values into readings group
For more intuitiveness to first-time users
2024-08-16 14:05:44 +08:00
b9cf60f2df 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-08-16 14:05:44 +08:00
3ffa939970 ctrl_panel: Bold "Control Method" text 2024-08-16 14:05:44 +08:00
87ba107ce5 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-08-16 14:05:44 +08:00
319fb9cf9e 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-08-16 14:05:44 +08:00
f7c266539b 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-08-16 14:05:44 +08:00
df9715b3ef ctrl_panel: PID Auto Tune -> PID Autotune 2024-08-16 14:05:44 +08:00
82279f15da 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-08-16 14:05:44 +08:00
fff42bfa4c 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-08-16 14:05:44 +08:00
d3b93b1263 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-08-16 14:05:44 +08:00
4309f9044c 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-08-13 12:38:32 +08:00
81418d0a55 ctrl_panel: Improve postfilter description 2024-08-13 12:38:32 +08:00
7fb933faa2 ctrl_panel: Add and improve tooltips and titles
For users' better understanding of what the parameters do
2024-08-13 12:38:29 +08:00
437c9cec34 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-07-19 15:49:19 +08:00
7829ce6adf ctrl_panel: Config -> Settings 2024-07-19 15:49:16 +08:00
0f14212622 Format JSON 2024-07-19 15:48:57 +08:00
2 changed files with 122 additions and 87 deletions

View File

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

View File

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