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) tree.setParameters(self.params[1], showTop=False)
self.params[1].sigTreeStateChanged.connect(self.send_command) self.params[1].sigTreeStateChanged.connect(self.send_command)
self.prev_autotuner_state = None
@asyncSlot() @asyncSlot()
async def autotune(param): async def autotune(param):
self.prev_autotuner_state = None
match self.autotuner.state(): match self.autotuner.state():
case PIDAutotuneState.STATE_OFF: case PIDAutotuneState.STATE_OFF:
settings = await self.kirdy.device.get_settings_summary() settings = await self.kirdy.device.get_settings_summary()
@ -825,6 +827,7 @@ class MainWindow(QtWidgets.QMainWindow):
param.parent().child('Temperature Swing').value(), param.parent().child('Temperature Swing').value(),
1.0 / settings['thermostat']['temp_adc_settings']['rate'], 1.0 / settings['thermostat']['temp_adc_settings']['rate'],
param.parent().child('Lookback').value()) param.parent().child('Lookback').value())
print(param.parent().child('Lookback').value())
self.autotuner.setReady() self.autotuner.setReady()
param.setOpts(title="Stop") param.setOpts(title="Stop")
self.kirdy.task_dispatcher(self.kirdy.thermostat.set_constant_current_control_mode()) self.kirdy.task_dispatcher(self.kirdy.thermostat.set_constant_current_control_mode())
@ -878,40 +881,43 @@ class MainWindow(QtWidgets.QMainWindow):
self.info_box.setWindowTitle("Command fails to execute") self.info_box.setWindowTitle("Command fails to execute")
self.info_box.show() self.info_box.show()
@pyqtSlot(dict) @asyncSlot(dict)
def autotune_tick(self, report): async def autotune_tick(self, report):
match self.autotuner.state(): self.autotuner.run(report['thermostat']['temperature'], report['ts']/1000)
case PIDAutotuneState.STATE_READY | PIDAutotuneState.STATE_RELAY_STEP_UP | PIDAutotuneState.STATE_RELAY_STEP_DOWN: if self.prev_autotuner_state != self.autotuner.state():
self.autotuner.run(report['thermostat']['temperature'], report['ts']/1000) match self.autotuner.state():
self.kirdy.task_dispatcher(self.kirdy.thermostat.set_tec_i_out(self.autotuner.output())) case PIDAutotuneState.STATE_READY | PIDAutotuneState.STATE_RELAY_STEP_UP | PIDAutotuneState.STATE_RELAY_STEP_DOWN:
case PIDAutotuneState.STATE_SUCCEEDED: await self.kirdy.thermostat.set_tec_i_out(self.autotuner.output())
kp, ki, kd = self.autotuner.get_tec_pid() self.prev_autotuner_state = self.autotuner.state()
self.autotuner.setOff() case PIDAutotuneState.STATE_SUCCEEDED:
self.params[1].child('PID Config', 'PID Auto Tune', 'Run').setOpts(title="Run") kp, ki, kd = self.autotuner.get_tec_pid()
self.kirdy.task_dispatcher(self.kirdy.thermostat.set_pid_kp(kp)) self.autotuner.setOff()
self.kirdy.task_dispatcher(self.kirdy.thermostat.set_pid_ki(ki)) self.params[1].child('PID Config', 'PID Auto Tune', 'Run').setOpts(title="Run")
self.kirdy.task_dispatcher(self.kirdy.thermostat.set_pid_kd(kd)) self.kirdy.task_dispatcher(self.kirdy.thermostat.set_pid_kp(kp))
self.kirdy.task_dispatcher(self.kirdy.thermostat.set_pid_control_mode()) self.kirdy.task_dispatcher(self.kirdy.thermostat.set_pid_ki(ki))
self.kirdy.task_dispatcher(self.kirdy.thermostat.set_temperature_setpoint(self.params[1].child('PID Config', 'PID Auto Tune', 'Target Temperature').value())) self.kirdy.task_dispatcher(self.kirdy.thermostat.set_pid_kd(kd))
self.kirdy_handler.report_update_sig.disconnect(self.autotune_tick) self.kirdy.task_dispatcher(self.kirdy.thermostat.set_pid_control_mode())
self.background_task_lbl.setText("Ready.") self.kirdy.task_dispatcher(self.kirdy.thermostat.set_temperature_setpoint(self.params[1].child('PID Config', 'PID Auto Tune', 'Target Temperature').value()))
self.loading_spinner.stop() self.kirdy_handler.report_update_sig.disconnect(self.autotune_tick)
self.loading_spinner.hide() self.background_task_lbl.setText("Ready.")
self.info_box.setWindowTitle("PID AutoTune Success") self.loading_spinner.stop()
self.info_box.setText("PID Config has been loaded to Thermostat.\nRegulating temperature.") self.loading_spinner.hide()
self.info_box.show() self.info_box.setWindowTitle("PID AutoTune Success")
self.info_box.setText("PID Config has been loaded to Thermostat.\nRegulating temperature.")
case PIDAutotuneState.STATE_FAILED: self.info_box.show()
self.autotuner.setOff() self.prev_autotuner_state = None
self.params[1].child('PID Config', 'PID Auto Tune', 'Run').setOpts(title="Run") case PIDAutotuneState.STATE_FAILED:
self.kirdy.task_dispatcher(self.kirdy.thermostat.set_tec_i_out(0.0)) self.autotuner.setOff()
self.kirdy_handler.report_update_sig.disconnect(self.autotune_tick) self.params[1].child('PID Config', 'PID Auto Tune', 'Run').setOpts(title="Run")
self.background_task_lbl.setText("Ready.") self.kirdy.task_dispatcher(self.kirdy.thermostat.set_tec_i_out(0.0))
self.loading_spinner.stop() self.kirdy_handler.report_update_sig.disconnect(self.autotune_tick)
self.loading_spinner.hide() self.background_task_lbl.setText("Ready.")
self.info_box.setWindowTitle("PID Autotune Failed") self.loading_spinner.stop()
self.info_box.setText("PID Autotune is failed.") self.loading_spinner.hide()
self.info_box.show() 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) @pyqtSlot(bool)
def _on_connection_changed(self, result): def _on_connection_changed(self, result):