config: wire TempSensor section from config.json to TempSensorSim

PlantFactory.create() now accepts sensor_config dict; extracts type and
kwargs, falls back to sigma=0.05/temp_offset=-0.15 defaults. brewpi.py
passes config.get('TempSensor', {}). Templates updated with full
TempSensor sections.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-30 19:27:04 +02:00
co-authored by Claude Sonnet 4.6
parent ca1953c9ee
commit 0156e689ca
4 changed files with 24 additions and 6 deletions
+10 -3
View File
@@ -17,14 +17,21 @@ class PlantFactory:
imported - only actually needed when plant_name picks the real rig."""
@staticmethod
def create(plant_name, dt, heater_config):
def create(plant_name, dt, heater_config, sensor_config=None):
sensor_config = sensor_config or {}
if "sim" in plant_name:
heater = HeaterFactory.create("sim", heater_config)
pot = Pot(dt)
sensor = TempSensorFactory.create("sim", temp_offset=-0.15, sigma=0.05)
sensor_type = sensor_config.get('type', 'sim')
sensor_params = {k: v for k, v in sensor_config.items() if k != 'type'}
sensor_params.setdefault('temp_offset', -0.15)
sensor_params.setdefault('sigma', 0.05)
sensor = TempSensorFactory.create(sensor_type, **sensor_params)
return heater, pot, sensor
heater = HeaterFactory.create("Hendi", heater_config)
pot = PotReal()
sensor = TempSensorFactory.create("max31865", temp_offset=-0.15)
sensor_params = {k: v for k, v in sensor_config.items() if k != 'type'}
sensor_params.setdefault('temp_offset', -0.15)
sensor = TempSensorFactory.create("max31865", **sensor_params)
return heater, pot, sensor
+6 -1
View File
@@ -1,7 +1,6 @@
{
"ambient_temperature": 20,
"Controller" : {
"stirrer_name": "pololu1376",
"plant_name": "real",
"pid_type": "Smith"
},
@@ -35,11 +34,17 @@
}
},
"Heater": {
"type": "hendi",
"port": "/dev/ttyUSB0",
"speed": "115200"
},
"Stirrer": {
"type": "pololu1376",
"port": "/dev/ttyACM0",
"speed": "115200"
},
"TempSensor": {
"type": "max31865",
"temp_offset": -0.15
}
}
+7 -1
View File
@@ -1,7 +1,6 @@
{
"ambient_temperature": 20,
"Controller" : {
"stirrer_name": "sim",
"plant_name": "sim",
"pid_type": "Smith"
},
@@ -41,5 +40,12 @@
"Stirrer": {
"port": "/dev/ttyACM0",
"speed": "115200"
},
"TempSensor": {
"type": "sim",
"temp_offset": 0.0,
"sigma": 0.05,
"stirrer_sigma": 0.0,
"stirrer_tau": 20.0
}
}
+1 -1
View File
@@ -90,7 +90,7 @@ if __name__ == '__main__':
# (the modeled plant)/TempSensorSim; anything else gets HeaterHendi/
# PotReal (no model - the real kettle does its own physics)/
# TempSensor_max31865.
heater, pot, sensor = PlantFactory.create(config['Controller']['plant_name'], DT, config['Heater'])
heater, pot, sensor = PlantFactory.create(config['Controller']['plant_name'], DT, config['Heater'], config.get('TempSensor', {}))
sensor_task = TempSensorTask(sensor, DT_TASK, dispatcher.msgio_get("Sensor"))
taskmgr.add(sensor_task)