diff --git a/brewpi.py b/brewpi.py index f1b2a9d..f43a18a 100644 --- a/brewpi.py +++ b/brewpi.py @@ -31,11 +31,10 @@ class TempSensorTask(ATask): self.kalman = kalman def on_temp_changed(self, value): - print("Sensor temp {}".format(value)) asyncio.create_task(self.send({'Temp': value})) def on_temp_changed_kalman(self, value): - print("Kalman temp {}".format(value)) + pass async def recv(self, data): print(data) @@ -120,11 +119,9 @@ class PotTask(ATask): plant_temp.set(round(self.plant.getTemperature(), 1)) if plant_power.is_changed(): - print("Plant Power {}".format(plant_power.get())) await self.send({'Power': plant_power.get()}) if plant_temp.is_changed(): - print("Plant Temp {}".format(plant_temp.get())) await self.send({'Temp': plant_temp.get()}) await asyncio.sleep(self.interval) @@ -230,9 +227,9 @@ if __name__ == '__main__': "Hold": { "Pid": { "kp": 0.8, - "ki": 0.000004, + "ki": 0.00001, "kd": 0.0, - "rho": 1.0 + "rho": 0.0 } }, "Heat": { diff --git a/components/pid/pid.py b/components/pid/pid.py index fb1fc6f..2c96470 100644 --- a/components/pid/pid.py +++ b/components/pid/pid.py @@ -11,6 +11,7 @@ class Pid: # Auto windup self.y_min = -1.0 self.y_max = 1.0 + self.d = 0 # Output self.y = 0 @@ -30,7 +31,7 @@ class Pid: kd = params['kd'] rho = params['rho'] - yi = rho*self.yi + ki*dt * err + yi = self.yi + ki*dt * err - ki*dt - self.d * rho yd = err - self.xd _yp = kp * err @@ -40,7 +41,9 @@ class Pid: y = _yp + _yi + _yd self.y = max(self.y_min, min(self.y_max, y)) - + self.d = max(0, self.y - y) + if self.d < 0: + print("d = {}".format(self.d)) self.yi = yi self.xd = err