From 09041d8ed8cd313069423cad8a2dc185370e403d Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Thu, 25 Apr 2019 17:01:46 +0000 Subject: [PATCH] - new template, changed dt to 3 for rast and sensor - added plant timer git-svn-id: http://moon:8086/svn/projects/HendiControl@267 fda53097-d464-4ada-af97-ba876c37ca34 --- Control/brewpi/brewpi.json.templ | 18 +++++++++--------- Control/brewpi/controller.py | 14 +++++++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Control/brewpi/brewpi.json.templ b/Control/brewpi/brewpi.json.templ index 38b2dfb..e466fc4 100644 --- a/Control/brewpi/brewpi.json.templ +++ b/Control/brewpi/brewpi.json.templ @@ -2,7 +2,7 @@ "Controller" : { - "dt" : 1.0, + "dt" : 3.0, "P_min" : 0, "P_max" : 3500, "sim_warp_factor" : 1000.0, @@ -10,7 +10,7 @@ "plant_name" : "Mass", "useKalman" : true, "kalman" : { - "dt" : 1.0, + "dt" : 3.0, "var_P" : 0, "var_Q" : 0.000001, "var_R" : 1, @@ -18,18 +18,18 @@ }, "Hold" : { "Pid" : { - "kp" : 0.2, - "ki" : 0.0005, - "kd" : 0.05, - "rho" : 0.99999 + "kp" : 0.1, + "ki" : 0.00004, + "kd" : 0.0, + "rho" : 0.9999 } }, "Heat" : { "Pid" : { "kp" : 0.1, - "ki" : 0.004, - "kd" : 0.05, - "rho" : 0.99999 + "ki" : 0.002, + "kd" : 0.0, + "rho" : 0.9999 } } }, diff --git a/Control/brewpi/controller.py b/Control/brewpi/controller.py index 341b559..a773649 100644 --- a/Control/brewpi/controller.py +++ b/Control/brewpi/controller.py @@ -58,8 +58,10 @@ class Controller(TimerListener): self.rastTimer = Timer("Rast", self) self.sensorTimer = Timer("Sensor", self) + self.plantTimer = Timer("Plant", self) self.reportTimer = Timer("Report", self) self.timerMgr.registerTimer(self.sensorTimer) + self.timerMgr.registerTimer(self.plantTimer) self.timerMgr.registerTimer(self.reportTimer) self.rast_running = False @@ -67,9 +69,6 @@ class Controller(TimerListener): if timer == self.sensorTimer: self.sensorTime_v = np.append(self.sensorTime_v, timer.count*self.sensor_dt / 60) - # Process plant - self.plant.process() - # Temperature self.theta_raw = self.plant.getTemperature() @@ -84,10 +83,14 @@ class Controller(TimerListener): Z = self.kalman.process_measurement((self.theta_raw, 0)) xp = self.kalman.process(Z) self.theta_ist_k = xp[0, 0] - self.heatrate_ist_k = xp[1, 0] * 60 / self.sensor_dt + self.heatrate_ist_k = xp[1, 0] * 60 self.theta_k_v = np.append(self.theta_k_v, self.theta_ist_k) self.heatrate_k_v = np.append(self.heatrate_k_v, self.heatrate_ist_k) + if timer == self.plantTimer: + # Process plant + self.plant.process() + if timer == self.reportTimer: self.report() @@ -112,6 +115,7 @@ class Controller(TimerListener): print(json.dumps({recipe['Name'] : recipe}, indent=4, sort_keys=True)) self.sensorTimer.start(self.sensor_dt/self.sim_warp_factor) + self.plantTimer.start(1/self.sim_warp_factor) self.reportTimer.start(self.report_interval) self.rastTimer.start(self.dt/self.sim_warp_factor) @@ -257,7 +261,7 @@ class Controller(TimerListener): self.stirrer.setDutyCycle(1.0) if ovenStateNext == ovenStates.HOLD: - self.pid_hold.reset() +# self.pid_hold.reset() self.stirrer.setSpeed(self.stirrSpeedRast) self.stirrer.setDutyCycle(self.stirrDutyRast)