Add editable PI controller coefficient fields to GUI

This commit is contained in:
awe
2026-07-29 17:37:50 +03:00
parent 43d490e2f8
commit c6a7e84558
3 changed files with 42 additions and 4 deletions
+16 -1
View File
@@ -44,6 +44,15 @@ def get_float(values, strId):
window['-StartCycle-'].update(disabled = True)
return value
def read_pi_coeff(values, key, params, param_key):
# PI coefficient is entered as a human value and stored as Q8 fixed-point
# (value * 256), clamped to the 16-bit range expected by the firmware.
# On a bad/empty field the previous stored value is kept and Start is disabled.
try:
params[param_key] = max(0, min(65535, int(float(values[key]) * 256)))
except (ValueError, TypeError):
window['-StartCycle-'].update(disabled = True)
def shorten(i):
return "{:.2f}".format(round(i, 2))
@@ -119,7 +128,13 @@ if __name__ == "__main__":
while True:
event, values = window.read(timeout=GUI_TIMEOUT_INTERVAL)
if values:
read_pi_coeff(values, '-InputKp1-', params, 'ProportionalCoeff_1')
read_pi_coeff(values, '-InputKi1-', params, 'IntegralCoeff_1')
read_pi_coeff(values, '-InputKp2-', params, 'ProportionalCoeff_2')
read_pi_coeff(values, '-InputKi2-', params, 'IntegralCoeff_2')
enable_manual_settings = window['-EnableManualSettings-'].get()
if current_and_temperature_settings_available:
window['-EnableT1-'].update(disabled = enable_manual_settings)