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)