forked from M-Labs/thermostat
Use thermotat_data_model for everything
This commit is contained in:
parent
e129998629
commit
2c019b8208
@ -4,10 +4,11 @@ from autotune import PIDAutotuneState, PIDAutotune
|
||||
|
||||
|
||||
class PIDAutoTuner(QObject):
|
||||
def __init__(self, parent, client, num_of_channel):
|
||||
def __init__(self, parent, client, thermostat, num_of_channel):
|
||||
super().__init__()
|
||||
|
||||
self._client = client
|
||||
self._thermostat = thermostat
|
||||
self.autotuners = [PIDAutotune(25) for _ in range(num_of_channel)]
|
||||
self.target_temp = [20.0 for _ in range(num_of_channel)]
|
||||
self.test_current = [1.0 for _ in range(num_of_channel)]
|
||||
@ -37,7 +38,7 @@ class PIDAutoTuner(QObject):
|
||||
|
||||
async def stop_pid_from_running(self, ch):
|
||||
self.autotuners[ch].setOff()
|
||||
await self._client.set_param("pwm", ch, "i_set", 0)
|
||||
await self.thermostat.set_param("pwm", ch, "i_set", 0)
|
||||
|
||||
@asyncSlot(list)
|
||||
async def tick(self, report):
|
||||
@ -56,21 +57,21 @@ class PIDAutoTuner(QObject):
|
||||
self.autotuners[ch].run(
|
||||
channel_report["temperature"], channel_report["time"]
|
||||
)
|
||||
await self._client.set_param(
|
||||
await self.thermostat.set_param(
|
||||
"pwm", ch, "i_set", self.autotuners[ch].output()
|
||||
)
|
||||
case PIDAutotuneState.STATE_SUCCEEDED:
|
||||
kp, ki, kd = self.autotuners[ch].get_tec_pid()
|
||||
self.autotuners[ch].setOff()
|
||||
|
||||
await self._client.set_param("pid", ch, "kp", kp)
|
||||
await self._client.set_param("pid", ch, "ki", ki)
|
||||
await self._client.set_param("pid", ch, "kd", kd)
|
||||
await self._client.set_param("pwm", ch, "pid")
|
||||
await self.thermostat.set_param("pid", ch, "kp", kp)
|
||||
await self.thermostat.set_param("pid", ch, "ki", ki)
|
||||
await self.thermostat.set_param("pid", ch, "kd", kd)
|
||||
await self.thermostat.set_param("pwm", ch, "pid")
|
||||
|
||||
await self._client.set_param(
|
||||
await self.thermostat.set_param(
|
||||
"pid", ch, "target", self.target_temp[ch]
|
||||
)
|
||||
case PIDAutotuneState.STATE_FAILED:
|
||||
self.autotuners[ch].setOff()
|
||||
await self._client.set_param("pwm", ch, "i_set", 0)
|
||||
await self.thermostat.set_param("pwm", ch, "i_set", 0)
|
||||
|
@ -132,3 +132,6 @@ class Thermostat(QObject, metaclass=PropertyMeta):
|
||||
|
||||
async def get_fan(self):
|
||||
return await self._client.get_fan()
|
||||
|
||||
async def set_param(self, topic, channel, field="", value=""):
|
||||
await self._client.set_param(topic, channel, field, value)
|
||||
|
@ -85,7 +85,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
|
||||
self.thermostat.connection_error.connect(handle_connection_error)
|
||||
|
||||
self.autotuners = PIDAutoTuner(self, self.client, 2)
|
||||
self.autotuners = PIDAutoTuner(self, self.client, self.thermostat, 2)
|
||||
|
||||
def get_ctrl_panel_config(args):
|
||||
with open(args.param_tree, "r") as f:
|
||||
@ -295,7 +295,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
else:
|
||||
set_param_args = (*thermostat_param, data)
|
||||
param.child(*param.childPath(inner_param)).setOpts(lock=True)
|
||||
await self.client.set_param(*set_param_args)
|
||||
await self.thermostat.set_param(*set_param_args)
|
||||
param.child(*param.childPath(inner_param)).setOpts(lock=False)
|
||||
|
||||
if inner_param.opts.get("pid_autotune", None) is not None:
|
||||
@ -313,7 +313,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
if activater is not None:
|
||||
if activater[1] == "ch":
|
||||
activater[1] = ch
|
||||
await self.client.set_param(*activater)
|
||||
await self.thermostat.set_param(*activater)
|
||||
|
||||
@asyncSlot()
|
||||
async def pid_auto_tune_request(self, ch=0):
|
||||
|
Loading…
Reference in New Issue
Block a user