- remove HeatDiffusion
- use delay line for heat propagation modeling

[Temp Controller]
- remove Kalman
This commit is contained in:
2026-06-19 14:21:23 +02:00
parent 81e66dbcd1
commit 5c7cffa3a7
4 changed files with 84 additions and 49 deletions
+7 -14
View File
@@ -1,25 +1,18 @@
from components.pid import Kalman
from components.pid.temp_controller_base import TempControllerBase
class TempController(TempControllerBase):
def __init__(self, dt, params):
TempControllerBase.__init__(self, dt, params)
self.kalman = Kalman(dt, params['Kalman'])
def init_kalman(self, value):
self.kalman.initial((value, 0))
self.dt = dt
self.last_theta_ist = 20
self.heatrate_ist = 0
def process(self):
# Process Kalman
if self.use_kalman:
Z = self.kalman.process_measurement((self.theta_ist_set, 0), 0.0)
xp = self.kalman.process(Z)
self.theta_ist = xp[0, 0]
self.heatrate_ist = xp[1, 0] * 60
else:
self.theta_ist = self.theta_ist_set
self.heatrate_ist = self.heatrate_ist_set
self.theta_ist = self.theta_ist_set
heatrate = (self.theta_ist - self.last_theta_ist)/self.dt*60
self.heatrate_ist = heatrate
self.last_theta_ist = self.theta_ist
# Compensate for max heat rate to reduce overshoot
if self.heatrate_soll_set > 0:
-5
View File
@@ -19,14 +19,10 @@ class TempControllerBase(APid):
self.thresholds = {**DEFAULT_THRESHOLDS, **params.get('Thresholds', {})}
self.y = -1
self.state = States.INIT
self.use_kalman = True
self.pid_hold.set_params(params['Hold'])
self.pid_rate.set_params(params['Heat'])
self.is_startup = True
def init_kalman(self, value):
raise NotImplementedError
def on_state_entered(self, state):
pass
@@ -37,7 +33,6 @@ class TempControllerBase(APid):
self.theta_ist_set = value
if self.is_startup:
self.is_startup = False
self.init_kalman(value)
def get_theta_ist(self):
return self.theta_ist
+41 -18
View File
@@ -1,6 +1,6 @@
from components.aplant import APlant
from components.plant.heat_diffusion import HeatDiffusion
from components.plant import delay
class Pot(APlant):
def __init__(self, dt, params, theta_amb=20):
@@ -10,35 +10,57 @@ class Pot(APlant):
self.e = 0
self.x = 0
# Plant power gain (efficiency)
self.gain = params['gain']
self.C = params['C']
self.M = params['M']
self.L = params['L']
self.Td = params['Td']
self.kn = params['kn']
self.temp = params['theta']
self.temp_intermediate = params['theta']
# Plant specific thermal capacity [W*s/(kg*K)]
self.C = params['C']
# Plant mass [kg]
self.M = params['M']
# Plant energy loss coefficient [W/(kg*K)]
# Negative input power as a function of plant mass and temperature difference T_plant and T_ambient
# P_loss = L * Mass * (T_plant - T_ambient)
self.L = params['L']
# Energy transport propagation delay
self.Td = params['Td']
# TBD
self.kn = params['kn']
# Plant temperature [°C]
self.temp = params['theta']
# Ambient temperature [°C]
self.theta_amb = theta_amb
# Set power [W]
self.power_set = 0
self.delay = HeatDiffusion(self.dt, self.Td, params['theta'])
# Plant delay [s]
self.delay = delay.Delay(dt, self.Td, 0)
self.p_in = 0
self.p_pot = 0
def initial(self, temp):
self.temp_intermediate = temp
self.temp = temp
self.delay.initial(temp)
def activate(self, enable):
pass
def process(self):
power = self.gain * self.power_set
leak = 1/self.M * self.L * (self.theta_amb - self.temp)/self.theta_amb
self.temp_intermediate += (power / (self.M * self.C) + leak) * self.dt
self.p_in = self.gain * self.power_set
self.delay.put(self.p_in)
# Delay
self.temp = self.delay.process(self.temp_intermediate)
p_loss = self.L * self.M * (self.temp - self.theta_amb)
self.p_pot = self.delay.get() - p_loss
print(f"p_loss: {p_loss}")
print(f"theta_amb: {self.theta_amb}")
print(f"temp: {self.temp}")
self.temp = min(100, self.temp + self.p_pot/(self.M * self.C) * self.dt)
def is_activated(self):
return True
@@ -52,5 +74,6 @@ class Pot(APlant):
def get_temperature(self):
return self.temp
def get_temperature_intermediate(self):
return self.temp_intermediate
def get_p_pot(self):
return self.p_pot