Files
brewpi/tasks/pot.py
T
jensandClaude Sonnet 4.6 77e68afef1 Keep plant/temp control inert until a Sud is actually loaded
server/brewpi.py no longer pre-configures the real Pot's or Smith's model's
plant params at startup - there's no longer any generic baseline at all,
since the only source of truth is now a loaded Sud's own doc (applied via
tasks/sud.py's SudTask.apply_plant_params(), on Load and on every step).
Ambient temperature and PID gains stay configured at startup, since
they're independent of any Sud (global setting / hardware tuning, not
doc-derived).

Add Pot.is_configured() (already existed)/TempControllerBase.is_configured()/
TempController(Smith).is_configured(), and have tasks/pot.py's PotTask and
tasks/tempctrl.py's TcTask skip process() while not yet configured instead
of letting it raise - so plant and temp control are genuinely inert (not
crashing) until a Sud is loaded. "Normal" has no plant-model dependency,
so it stays active regardless.

Also refreshes README.md: removes stale tracer.py/.mat references (already
removed in an earlier commit), documents SudLogTask's JSON logs, the doc's
L/Td fields, and this inert-until-loaded behavior.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DkkuG48uHFCGKe6dPSERFk
2026-06-22 20:05:33 +02:00

44 lines
1.3 KiB
Python

import asyncio
from tasks import ATask
from ws.message import MsgIo
from utils.value import ChangedInteger, ChangedFloat
from components.plant import APlant
class PotTask(ATask):
def __init__(self, pot: APlant, interval, msg_handler: MsgIo):
ATask.__init__(self, interval)
self.msg_handler = msg_handler
msg_handler.set_recv_handler(self.recv)
self.plant = pot
def on_changed_power(self, value):
asyncio.create_task(self.send({'Power': value}))
def on_changed_temp(self, value):
asyncio.create_task(self.send({'Temp': value}))
async def recv(self, data):
for pair in data.items():
if 'Reset' in pair[0]:
self.plant.initial(self.plant.theta_amb)
async def send(self, data):
await self.msg_handler.send(data)
async def on_process(self):
print("{}: Started with interval {} s".format(self.msg_handler.get_key(), self.interval))
self.plant.set_on_changed('power_actual', ChangedInteger(self.on_changed_power).set)
self.plant.set_on_changed('temp', ChangedFloat(self.on_changed_temp, prec=1).set)
while True:
# Stays inert until a Sud actually supplies plant params (see
# tasks/sud.py's SudTask.apply_plant_params()) - process()
# would otherwise raise (components/plant/pot.py's Pot).
if self.plant.is_configured():
self.plant.process()
await asyncio.sleep(self.interval)