From f2aff73f40e6e1ee76a4542444e732549bbde264 Mon Sep 17 00:00:00 2001 From: jens Date: Tue, 22 Dec 2020 10:51:38 +0100 Subject: [PATCH] - refactored temp controllers --- components/pid/temp_controller.py | 2 +- components/pid/temp_controller_smith.py | 4 ++-- components/plant/pot.py | 10 ++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/components/pid/temp_controller.py b/components/pid/temp_controller.py index 32d51e9..7311a92 100644 --- a/components/pid/temp_controller.py +++ b/components/pid/temp_controller.py @@ -169,7 +169,7 @@ if __name__ == '__main__': hold_counter -= 1 ctrl.process() plant.process() - temp_ist = plant.get_temperature_delayed() + 0.0 * np.random.randn() + temp_ist = plant.get_temperature() + 0.0 * np.random.randn() ctrl.set_theta_ist(temp_ist) y = 3500*ctrl.get_power() diff --git a/components/pid/temp_controller_smith.py b/components/pid/temp_controller_smith.py index 83caa6c..0776932 100644 --- a/components/pid/temp_controller_smith.py +++ b/components/pid/temp_controller_smith.py @@ -52,7 +52,7 @@ class TempController(AttributeChange): def process(self): # Process Kalman of Model - Z_model = self.kalman_model.process_measurement((self.model.get_temperature(), 0), 0.0) + Z_model = self.kalman_model.process_measurement((self.model.get_temperature_intermediate(), 0), 0.0) xp_model = self.kalman_model.process(Z_model) theta_ist_model = xp_model[0, 0] heatrate_ist_model = xp_model[1, 0] * 60 @@ -195,7 +195,7 @@ if __name__ == '__main__': hold_counter -= 1 ctrl.process() plant.process() - temp_ist = plant.get_temperature_delayed() + temp_ist = plant.get_temperature() ctrl.set_theta_ist(temp_ist) y = 3500*ctrl.get_power() diff --git a/components/plant/pot.py b/components/plant/pot.py index 7f6db5e..aa08143 100644 --- a/components/plant/pot.py +++ b/components/plant/pot.py @@ -17,6 +17,7 @@ class Pot(APlant): self.Td = params['Td'] self.kn = params['kn'] self.temp = params['theta'] + self.temp_intermediate = params['theta'] self.theta_amb = theta_amb @@ -28,10 +29,11 @@ class Pot(APlant): def process(self): leak = 1/self.M * self.L * (self.theta_amb - self.temp)/self.theta_amb - self.temp += (self.power_set / (self.M * self.C) + leak) * self.dt + self.temp_intermediate += (self.power_set / (self.M * self.C) + leak) * self.dt # Delay - self.delay.put(self.temp) + self.delay.put(self.temp_intermediate) + self.temp = self.delay.get() def is_activated(self): return True @@ -45,5 +47,5 @@ class Pot(APlant): def get_temperature(self): return self.temp - def get_temperature_delayed(self): - return self.delay.get() + def get_temperature_intermediate(self): + return self.temp_intermediate