From 19d8294868fdee5fa291515be9e04cf908fa2541 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sun, 31 Mar 2019 08:45:03 +0000 Subject: [PATCH] - temperature from plant simulation is rounded and now causes problems estimating heat rate - create smoother at contruction time git-svn-id: http://moon:8086/svn/projects/HendiControl@201 fda53097-d464-4ada-af97-ba876c37ca34 --- Control/brewpi/controller.py | 21 +++++++++++++-------- Control/brewpi/mass.py | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Control/brewpi/controller.py b/Control/brewpi/controller.py index d338cba..96368a2 100644 --- a/Control/brewpi/controller.py +++ b/Control/brewpi/controller.py @@ -39,6 +39,10 @@ class Controller(): self.is_pause = False self.is_restart = False self.receipe = None + self.theta_sm = Smoother(1.0) + self.heatrate_sm = Smoother(0.5) + self.theta_err_sm = Smoother(1.0) + self.heatrate_err_sm = Smoother(1.0) def log(self, s): now = time.time() @@ -132,8 +136,6 @@ class Controller(): # The loop # ------------------------------ doLoop = True - theta_err_sm = Smoother(0.5) - heatrate_err_sm = Smoother(0.5) while(doLoop): time_start = time.time() @@ -144,15 +146,18 @@ class Controller(): # ----------------------------------------- self.stirrer.process() self.plant.process() - theta_ist = self.plant.getTemperature() - heatrate_ist = 60/self.dt * (theta_ist - self.theta_ist) + theta = self.plant.getTemperature() + theta_ist = self.theta_sm.process(theta) + + heatrate = 60/self.dt * (theta_ist - self.theta_ist) + heatrate_ist = self.heatrate_sm.process(heatrate) theta_err = theta_soll - theta_ist heatrate_err = heatrate_soll - heatrate_ist - theta_err_sm.process(theta_err) - heatrate_err_sm.process(heatrate_err) + self.theta_err_sm.process(theta_err) + self.heatrate_err_sm.process(heatrate_err) if self.ovenState == ovenStates.NOP: if theta_ist < theta_soll: @@ -160,7 +165,7 @@ class Controller(): pid_err = 0 if self.ovenState == ovenStates.HEAT: - pid_err = heatrate_err_sm.get_y() + pid_err = self.heatrate_err_sm.get_y() pid_params_acqu = self.params['Heat']['Acqu']['Pid'] pid_params_track = self.params['Heat']['Track']['Pid'] pid_thresh_acqu = 0.2 @@ -171,7 +176,7 @@ class Controller(): self.timer_ist = timer_soll if self.ovenState == ovenStates.HOLD: - pid_err = theta_err_sm.get_y() + pid_err = self.theta_err_sm.get_y() pid_params_acqu = self.params['Hold']['Acqu']['Pid'] pid_params_track = self.params['Hold']['Track']['Pid'] pid_thresh_acqu = 0.2 diff --git a/Control/brewpi/mass.py b/Control/brewpi/mass.py index 71b9569..fc8b8cd 100644 --- a/Control/brewpi/mass.py +++ b/Control/brewpi/mass.py @@ -39,4 +39,4 @@ class Mass(APlant): return self.P def getTemperature(self): - return self.theta + self.theta_amb + self.kn*np.random.normal(0,1)/sqrt(12.0) + return round(self.theta + self.theta_amb + self.kn*np.random.normal(0,1)/sqrt(12.0), 1)