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:
@@ -7,11 +7,14 @@ class TempController(TempControllerBase):
|
||||
self.dt = dt
|
||||
self.last_theta_ist = 20
|
||||
self.heatrate_ist = 0
|
||||
|
||||
def process(self):
|
||||
# Process Kalman
|
||||
self.theta_ist = self.theta_ist_set
|
||||
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
|
||||
|
||||
# Compensate for max heat rate to reduce overshoot
|
||||
|
||||
@@ -45,7 +45,9 @@ class TempController(TempControllerBase):
|
||||
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
|
||||
self.heatrate_ist = heatrate
|
||||
|
||||
alpha = 0.1
|
||||
self.heatrate_ist = (1-alpha) * self.heatrate_ist + alpha*heatrate
|
||||
self.last_theta_ist = self.theta_ist
|
||||
|
||||
# Compensate for max heat rate to reduce overshoot
|
||||
|
||||
@@ -6,13 +6,14 @@ class TempSensorSim(ATemperatureSensor):
|
||||
def name(self):
|
||||
return "FakeTemp"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, temp_offset=0.0, variance=0.0, **kwargs):
|
||||
ATemperatureSensor.__init__(self)
|
||||
self.temp_set = 19.99
|
||||
self.k_noise = 0.01
|
||||
self.offset = temp_offset
|
||||
self.variance = variance
|
||||
|
||||
def set_fake_temp(self, temp):
|
||||
self.temp_set = temp
|
||||
|
||||
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)
|
||||
|
||||
@@ -8,7 +8,7 @@ class TempSensor_max31865(ATemperatureSensor):
|
||||
def name(self):
|
||||
return "Max31865"
|
||||
|
||||
def __init__(self, temp_offset=0):
|
||||
def __init__(self, temp_offset=0, **kwargs):
|
||||
ATemperatureSensor.__init__(self)
|
||||
# Open SPI bus
|
||||
self.spi = spidev.SpiDev()
|
||||
|
||||
Reference in New Issue
Block a user