- PID: use pot for testing

This commit is contained in:
jens
2020-12-02 11:24:31 +01:00
parent d6037b33d3
commit 6939650708
3 changed files with 23 additions and 10 deletions
+1 -1
View File
@@ -227,7 +227,7 @@ if __name__ == '__main__':
"Hold": { "Hold": {
"Pid": { "Pid": {
"kp": 0.8, "kp": 0.8,
"ki": 0.002, "ki": 0.008,
"kd": 0.0, "kd": 0.0,
"rho": 1.0 "rho": 1.0
} }
+1 -2
View File
@@ -36,7 +36,7 @@ class Pid:
yp = kp * err yp = kp * err
# Reset yi on error sign changes # Reset yi on error sign changes
if yp > self.y_max or yp < self.y_min: if yp > self.y_max or yp <= self.y_min or np.sign(err) != np.sign(self.err):
self.yi = 0 self.yi = 0
self.err = err self.err = err
@@ -44,7 +44,6 @@ class Pid:
y = yp + self.yi + yd y = yp + self.yi + yd
self.y = max(self.y_min, min(self.y_max, y)) self.y = max(self.y_min, min(self.y_max, y))
print("yi = {}".format(self.yi))
def get_y(self): def get_y(self):
return self.y return self.y
+21 -7
View File
@@ -1,4 +1,5 @@
from components.pid.pid import Pid from components.pid.pid import Pid
from components.plant.pot import Pot
from matplotlib.pyplot import plot, figure, subplot, title, xlabel, ylabel, grid, show from matplotlib.pyplot import plot, figure, subplot, title, xlabel, ylabel, grid, show
import numpy as np import numpy as np
from utils.value import AttributeChange from utils.value import AttributeChange
@@ -53,9 +54,9 @@ if __name__ == '__main__':
"dt": 1.0, "dt": 1.0,
"Hold": { "Hold": {
"Pid": { "Pid": {
"kp": 0.5, "kp": 0.8,
"ki": 0.0, "ki": 0.008,
"kd": 0.5, "kd": 0.0,
"rho": 1.0 "rho": 1.0
} }
}, },
@@ -69,9 +70,20 @@ if __name__ == '__main__':
} }
} }
pot_params = {
"dt" : 1.0,
"theta" : 20,
"C" : 4190,
"M" : 20,
"L" : 0.05,
"Td" : 12,
"kn" : 0.2
}
temp_ist = 0 temp_ist = 0
temp_soll = 20 temp_soll = 20
ctrl = TempController(params) ctrl = TempController(params)
plant = Pot(pot_params)
_temp_ist = np.empty(0) _temp_ist = np.empty(0)
_temp_soll = np.empty(0) _temp_soll = np.empty(0)
_y = np.empty(0) _y = np.empty(0)
@@ -80,7 +92,7 @@ if __name__ == '__main__':
a = 0.5 a = 0.5
fb = 0 fb = 0
rho = 0.02 rho = 0.02
temps = [{'Temp': 20, 'Duration': 100}, {'Temp': 40, 'Duration': 100}, {'Temp': 35, 'Duration': 100}] temps = [{'Temp': 20, 'Duration': 1000}, {'Temp': 40, 'Duration': 1000}, {'Temp': 50, 'Duration': 1000}, {'Temp': 60, 'Duration': 1000}, {'Temp': 70, 'Duration': 1000}, {'Temp': 80, 'Duration': 1000}]
t = 0 t = 0
for temp in temps: for temp in temps:
@@ -95,9 +107,11 @@ if __name__ == '__main__':
break break
hold_counter -= 1 hold_counter -= 1
ctrl.process() ctrl.process()
y = max(0, ctrl.get_power_hold()) plant.process()
fb = (1-a)*fb + a*round(y, 2) y = max(0, 3500*ctrl.get_power_hold())
temp_ist += fb plant.setPower(y)
temp_ist = round(plant.getTemperature(), 1)
fb = plant.getPower()
ctrl.set_theta_ist(temp_ist) ctrl.set_theta_ist(temp_ist)
if abs(temp_ist - temp_soll) < 0.1: if abs(temp_ist - temp_soll) < 0.1:
hold = True hold = True