Add sensor variance config and smooth heat-rate estimate

[Sensor] - replace TempSensorSim's hardcoded k_noise with configurable
temp_offset/variance, accept **kwargs on Max31865 too so both sensors
share a constructor signature usable from TempSensorFactory.create()
[Temp Controller] - low-pass filter the backward-difference heat-rate
estimate (alpha=0.1) in both temp_controller.py and
temp_controller_smith.py instead of using the raw, noisy derivative
[Pot] - drop kn from demo_pot.py's params, matching the unused-field
removal already made to pot.py itself

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-19 15:47:24 +02:00
co-authored by Claude Sonnet 4.6
parent 40977e373e
commit ac8de9da55
6 changed files with 13 additions and 8 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ if __name__ == '__main__':
DT_TASK_TRACER = DT_TASK / DT DT_TASK_TRACER = DT_TASK / DT
# Sensor # Sensor
sensor = TempSensorFactory.create(config['Controller']['sensor_name'], temp_offset=-0.15) sensor = TempSensorFactory.create(config['Controller']['sensor_name'], temp_offset=-0.15, variance=0.01)
sensor_task = TempSensorTask(sensor, DT_TASK, dispatcher.msgio_get("Sensor")) sensor_task = TempSensorTask(sensor, DT_TASK, dispatcher.msgio_get("Sensor"))
taskmgr.add(sensor_task) taskmgr.add(sensor_task)
+4 -1
View File
@@ -7,11 +7,14 @@ class TempController(TempControllerBase):
self.dt = dt self.dt = dt
self.last_theta_ist = 20 self.last_theta_ist = 20
self.heatrate_ist = 0 self.heatrate_ist = 0
def process(self): def process(self):
# Process Kalman # Process Kalman
self.theta_ist = self.theta_ist_set self.theta_ist = self.theta_ist_set
heatrate = (self.theta_ist - self.last_theta_ist)/self.dt*60 heatrate = (self.theta_ist - self.last_theta_ist)/self.dt*60
self.heatrate_ist = heatrate
alpha = 0.1
self.heatrate_ist = (1-alpha) * self.heatrate_ist + alpha*heatrate
self.last_theta_ist = self.theta_ist self.last_theta_ist = self.theta_ist
# Compensate for max heat rate to reduce overshoot # Compensate for max heat rate to reduce overshoot
+3 -1
View File
@@ -45,7 +45,9 @@ class TempController(TempControllerBase):
self.theta_ist = self.theta_ist_model + (self.theta_ist_plant - self.theta_ist_model_delay) self.theta_ist = self.theta_ist_model + (self.theta_ist_plant - self.theta_ist_model_delay)
heatrate = (self.theta_ist - self.last_theta_ist)/self.dt*60 heatrate = (self.theta_ist - self.last_theta_ist)/self.dt*60
self.heatrate_ist = heatrate
alpha = 0.1
self.heatrate_ist = (1-alpha) * self.heatrate_ist + alpha*heatrate
self.last_theta_ist = self.theta_ist self.last_theta_ist = self.theta_ist
# Compensate for max heat rate to reduce overshoot # Compensate for max heat rate to reduce overshoot
+4 -3
View File
@@ -6,13 +6,14 @@ class TempSensorSim(ATemperatureSensor):
def name(self): def name(self):
return "FakeTemp" return "FakeTemp"
def __init__(self, *args, **kwargs): def __init__(self, temp_offset=0.0, variance=0.0, **kwargs):
ATemperatureSensor.__init__(self) ATemperatureSensor.__init__(self)
self.temp_set = 19.99 self.temp_set = 19.99
self.k_noise = 0.01 self.offset = temp_offset
self.variance = variance
def set_fake_temp(self, temp): def set_fake_temp(self, temp):
self.temp_set = temp self.temp_set = temp
def temperature(self): def temperature(self):
return self.temp_set + self.k_noise * np.random.normal(0, 1) / np.sqrt(12.0) return self.temp_set + self.offset+ self.variance * np.random.normal(0, 1) / np.sqrt(12.0)
+1 -1
View File
@@ -8,7 +8,7 @@ class TempSensor_max31865(ATemperatureSensor):
def name(self): def name(self):
return "Max31865" return "Max31865"
def __init__(self, temp_offset=0): def __init__(self, temp_offset=0, **kwargs):
ATemperatureSensor.__init__(self) ATemperatureSensor.__init__(self)
# Open SPI bus # Open SPI bus
self.spi = spidev.SpiDev() self.spi = spidev.SpiDev()
-1
View File
@@ -15,7 +15,6 @@ if __name__ == '__main__':
"M" : 20, "M" : 20,
"L" : 0.4, "L" : 0.4,
"Td" : 30, "Td" : 30,
"kn" : 0.2,
"gain" : 1.0 "gain" : 1.0
} }