Files
brewpi/components/plant/pot.py
T
jensandClaude Sonnet 4.6 241a796ffa Make grain_mass/water_mass per-step and re-derive plant params on change
grain_mass and water_mass now live on each step (defaulted from
default.step) instead of being fixed for the whole brew, since both
change over a mash (malt going in, water boiling off).
Sud.derive_plant_params() takes them as arguments so it can be
recomputed per step; the demo re-applies the resulting M/C to both the
real plant and the controller's Smith-predictor model on every step
change via the new Pot.set_thermal_params()/
TempController.set_model_params().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CgR9tPaSzFkAwRAUyeaaCD
2026-06-20 07:45:42 +02:00

75 lines
1.5 KiB
Python

from components.aplant import APlant
from components.plant import delay
class Pot(APlant):
def __init__(self, dt, params, theta_amb=20):
APlant.__init__(self)
self.dt = dt
self.e = 0
self.x = 0
self.p_pot = 0
# 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']
# Plant temperature [°C]
self.temp = theta_amb
# Ambient temperature [°C]
self.theta_amb = theta_amb
# Set power [W]
self.p_in = 0
# Plant delay [s]
self.delay = delay.Delay(dt, self.Td, 0)
def initial(self, temp):
self.temp = temp
def activate(self, enable):
pass
def process(self):
self.delay.put(self.p_in)
p_loss = self.L * self.M * (self.temp - self.theta_amb)
self.p_pot = self.delay.get() - p_loss
self.temp = min(100, self.temp + self.p_pot/(self.M * self.C) * self.dt)
def is_activated(self):
return True
def set_ambient_temperature(self, theta_amb):
self.theta_amb = theta_amb
def set_thermal_params(self, M, C):
self.M = M
self.C = C
def set_power(self, power):
self.p_in = power
def get_power(self):
return round(self.p_in, 1)
def get_temperature(self):
return self.temp
def get_p_pot(self):
return self.p_pot