gui: autotuner only set_i when relay state changes

- Previously, autotuner issues set_i cmd for each report obj received
- These change increase the maximum autotune-able PID update rate with GUI
This commit is contained in:
linuswck 2024-10-22 14:38:15 +08:00
parent a1b7538295
commit 49dc8a9b96
1 changed files with 40 additions and 34 deletions

View File

@ -814,8 +814,10 @@ class MainWindow(QtWidgets.QMainWindow):
tree.setParameters(self.params[1], showTop=False)
self.params[1].sigTreeStateChanged.connect(self.send_command)
self.prev_autotuner_state = None
@asyncSlot()
async def autotune(param):
self.prev_autotuner_state = None
match self.autotuner.state():
case PIDAutotuneState.STATE_OFF:
settings = await self.kirdy.device.get_settings_summary()
@ -825,6 +827,7 @@ class MainWindow(QtWidgets.QMainWindow):
param.parent().child('Temperature Swing').value(),
1.0 / settings['thermostat']['temp_adc_settings']['rate'],
param.parent().child('Lookback').value())
print(param.parent().child('Lookback').value())
self.autotuner.setReady()
param.setOpts(title="Stop")
self.kirdy.task_dispatcher(self.kirdy.thermostat.set_constant_current_control_mode())
@ -878,12 +881,14 @@ class MainWindow(QtWidgets.QMainWindow):
self.info_box.setWindowTitle("Command fails to execute")
self.info_box.show()
@pyqtSlot(dict)
def autotune_tick(self, report):
@asyncSlot(dict)
async def autotune_tick(self, report):
self.autotuner.run(report['thermostat']['temperature'], report['ts']/1000)
if self.prev_autotuner_state != self.autotuner.state():
match self.autotuner.state():
case PIDAutotuneState.STATE_READY | PIDAutotuneState.STATE_RELAY_STEP_UP | PIDAutotuneState.STATE_RELAY_STEP_DOWN:
self.autotuner.run(report['thermostat']['temperature'], report['ts']/1000)
self.kirdy.task_dispatcher(self.kirdy.thermostat.set_tec_i_out(self.autotuner.output()))
await self.kirdy.thermostat.set_tec_i_out(self.autotuner.output())
self.prev_autotuner_state = self.autotuner.state()
case PIDAutotuneState.STATE_SUCCEEDED:
kp, ki, kd = self.autotuner.get_tec_pid()
self.autotuner.setOff()
@ -900,7 +905,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.info_box.setWindowTitle("PID AutoTune Success")
self.info_box.setText("PID Config has been loaded to Thermostat.\nRegulating temperature.")
self.info_box.show()
self.prev_autotuner_state = None
case PIDAutotuneState.STATE_FAILED:
self.autotuner.setOff()
self.params[1].child('PID Config', 'PID Auto Tune', 'Run').setOpts(title="Run")
@ -912,6 +917,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.info_box.setWindowTitle("PID Autotune Failed")
self.info_box.setText("PID Autotune is failed.")
self.info_box.show()
self.prev_autotuner_state = None
@pyqtSlot(bool)
def _on_connection_changed(self, result):