- removed dbug prints

- PID: added Anti Windup code
This commit is contained in:
jens
2020-12-01 21:17:30 +01:00
parent 5a8409eec5
commit 8b481a98b8
2 changed files with 8 additions and 8 deletions
+3 -6
View File
@@ -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": {
+5 -2
View File
@@ -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