- improved temp controller test
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from components.pid import Pid
|
from components.pid.pid import Pid
|
||||||
from components.pid import Kalman
|
from matplotlib.pyplot import plot, figure, subplot, title, xlabel, ylabel, grid, show
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
class TempController:
|
class TempController:
|
||||||
@@ -33,9 +34,53 @@ class TempController:
|
|||||||
self.pid_rate.process(self.dt, self.params['Heat']['Pid'], heatrate_err)
|
self.pid_rate.process(self.dt, self.params['Heat']['Pid'], heatrate_err)
|
||||||
|
|
||||||
def get_power_hold(self):
|
def get_power_hold(self):
|
||||||
power_hold = 200 + self.params['P_max'] * self.pid_hold.get_y()
|
return self.pid_hold.get_y()
|
||||||
return max(self.params['P_min'], min(self.params['P_max'], power_hold))
|
|
||||||
|
|
||||||
def get_power_heat(self):
|
def get_power_heat(self):
|
||||||
power_heat = 1500 + self.params['P_max'] * self.pid_rate.get_y()
|
return self.pid_rate.get_y()
|
||||||
return max(self.params['P_min'], min(self.params['P_max'], power_heat))
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
params = {
|
||||||
|
"dt": 1.0,
|
||||||
|
"Hold": {
|
||||||
|
"Pid": {
|
||||||
|
"kp": 0.4,
|
||||||
|
"ki": 0.00004,
|
||||||
|
"kd": 0.0,
|
||||||
|
"rho": 1.0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Heat": {
|
||||||
|
"Pid": {
|
||||||
|
"kp": 0.002,
|
||||||
|
"ki": 0.0002,
|
||||||
|
"kd": 0.0,
|
||||||
|
"rho": 1.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
temp_ist = 0
|
||||||
|
temp_soll = 20
|
||||||
|
ctrl = TempController(params)
|
||||||
|
ctrl.set_theta_ist(temp_ist)
|
||||||
|
ctrl.set_theta_soll(temp_soll)
|
||||||
|
t = range(0, 100)
|
||||||
|
_temp_ist = np.empty(0)
|
||||||
|
_temp_soll = np.empty(0)
|
||||||
|
for i in t:
|
||||||
|
_temp_ist = np.append(_temp_ist, temp_ist)
|
||||||
|
_temp_soll = np.append(_temp_soll, temp_soll)
|
||||||
|
ctrl.process()
|
||||||
|
y = ctrl.get_power_hold()
|
||||||
|
temp_ist += round(y, 2)
|
||||||
|
ctrl.set_theta_ist(temp_ist)
|
||||||
|
|
||||||
|
figure(1)
|
||||||
|
plot(t, _temp_ist - _temp_soll, 'bx', linewidth=1)
|
||||||
|
grid(True)
|
||||||
|
show()
|
||||||
|
|
||||||
|
print("End of program")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user