- TC export some vars
- cleaned up test - added model vars to test
This commit is contained in:
@@ -41,8 +41,8 @@ class Test:
|
|||||||
"theta" : 20,
|
"theta" : 20,
|
||||||
"C" : 4190,
|
"C" : 4190,
|
||||||
"M" : 20,
|
"M" : 20,
|
||||||
"L" : 0.05,
|
"L" : 0.01,
|
||||||
"Td" : 15,
|
"Td" : 30,
|
||||||
"kn" : 0.2,
|
"kn" : 0.2,
|
||||||
"gain" : 1.0
|
"gain" : 1.0
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ class Test:
|
|||||||
"C" : 4190,
|
"C" : 4190,
|
||||||
"M" : 20,
|
"M" : 20,
|
||||||
"L" : 0.01,
|
"L" : 0.01,
|
||||||
"Td" : 15,
|
"Td" : 30,
|
||||||
"kn" : 0.2,
|
"kn" : 0.2,
|
||||||
"gain" : 1.0
|
"gain" : 1.0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ class TempController(APid):
|
|||||||
return self.heatrate_soll_set
|
return self.heatrate_soll_set
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
|
# Process Kalman of Plant
|
||||||
|
Z_plant = self.kalman_plant.process_measurement((self.theta_ist_set, 0), 0.0)
|
||||||
|
xp_plant = self.kalman_plant.process(Z_plant)
|
||||||
|
theta_ist_plant = xp_plant[0, 0]
|
||||||
|
heatrate_ist_plant = xp_plant[1, 0] * 60
|
||||||
|
|
||||||
# Process Kalman of Model
|
# Process Kalman of Model
|
||||||
k_model = self.kalman_model.process_measurement((self.model.get_temperature_intermediate(), 0), 0.0)
|
k_model = self.kalman_model.process_measurement((self.model.get_temperature_intermediate(), 0), 0.0)
|
||||||
xp_model = self.kalman_model.process(k_model)
|
xp_model = self.kalman_model.process(k_model)
|
||||||
@@ -79,11 +85,14 @@ class TempController(APid):
|
|||||||
theta_ist_model_delay = xp_model_delay[0, 0]
|
theta_ist_model_delay = xp_model_delay[0, 0]
|
||||||
dtheta_ist_model_delay = xp_model_delay[1, 0] * 60
|
dtheta_ist_model_delay = xp_model_delay[1, 0] * 60
|
||||||
|
|
||||||
# Process Kalman of Plant
|
self.theta_ist_plant = theta_ist_plant
|
||||||
Z_plant = self.kalman_plant.process_measurement((self.theta_ist_set, 0), 0.0)
|
self.dtheta_ist_plant = heatrate_ist_plant
|
||||||
xp_plant = self.kalman_plant.process(Z_plant)
|
self.theta_ist_model = theta_ist_model
|
||||||
theta_ist_plant = xp_plant[0, 0]
|
self.dtheta_ist_model = heatrate_ist_model
|
||||||
heatrate_ist_plant = xp_plant[1, 0] * 60
|
self.theta_ist_model_delay = theta_ist_model_delay
|
||||||
|
self.dtheta_ist_model_delay = dtheta_ist_model_delay
|
||||||
|
self.theta_ist = theta_ist_plant
|
||||||
|
self.heatrate_ist = heatrate_ist_plant
|
||||||
|
|
||||||
# Compensate for max heat rate to reduce overshoot
|
# Compensate for max heat rate to reduce overshoot
|
||||||
if self.heatrate_soll_set > 0:
|
if self.heatrate_soll_set > 0:
|
||||||
@@ -91,9 +100,6 @@ class TempController(APid):
|
|||||||
|
|
||||||
self.heatrate_soll = self.heatrate_soll_set * self.pid_hold.get_y()
|
self.heatrate_soll = self.heatrate_soll_set * self.pid_hold.get_y()
|
||||||
|
|
||||||
self.theta_ist = theta_ist_plant
|
|
||||||
self.heatrate_ist = heatrate_ist_plant
|
|
||||||
|
|
||||||
print ("Model : T_ist={:2.2f}, dT_ist={:2.2f}".format(theta_ist_model, heatrate_ist_model))
|
print ("Model : T_ist={:2.2f}, dT_ist={:2.2f}".format(theta_ist_model, heatrate_ist_model))
|
||||||
print ("Model*z-1: T_ist={:2.2f}, dT_ist={:2.2f}".format(theta_ist_model_delay, dtheta_ist_model_delay))
|
print ("Model*z-1: T_ist={:2.2f}, dT_ist={:2.2f}".format(theta_ist_model_delay, dtheta_ist_model_delay))
|
||||||
print ("Plant : T_ist={:2.2f}, dT_ist={:2.2f}".format(theta_ist_plant, heatrate_ist_plant))
|
print ("Plant : T_ist={:2.2f}, dT_ist={:2.2f}".format(theta_ist_plant, heatrate_ist_plant))
|
||||||
@@ -161,17 +167,19 @@ class TempController(APid):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
dt = 1.0
|
dt = 1.0
|
||||||
|
|
||||||
temp_ist = 0
|
|
||||||
temp_soll = 20
|
temp_soll = 20
|
||||||
ctrl = TempController(dt, Test.tc_ctrl_params, Test.tc_model_params)
|
ctrl = TempController(dt, Test.tc_ctrl_params, Test.tc_model_params)
|
||||||
plant = Pot(dt, Test.tc_pot_params)
|
plant = Pot(dt, Test.tc_pot_params)
|
||||||
_temp_ist = np.empty(0)
|
|
||||||
_temp_soll = np.empty(0)
|
|
||||||
_y = np.empty(0)
|
_y = np.empty(0)
|
||||||
_fb = np.empty(0)
|
_fb = np.empty(0)
|
||||||
_t = np.empty(0)
|
_t = np.empty(0)
|
||||||
_heatrate_ist_kalman = np.empty(0)
|
_temp_soll = np.empty(0)
|
||||||
_temp_ist_kalman = np.empty(0)
|
_temp_ist_kalman = np.empty(0)
|
||||||
|
_heatrate_ist_kalman = np.empty(0)
|
||||||
|
_temp_ist_kalman_plant = np.empty(0)
|
||||||
|
_heatrate_ist_kalman_plant = np.empty(0)
|
||||||
|
_temp_ist_kalman_model = np.empty(0)
|
||||||
|
_heatrate_ist_kalman_model = np.empty(0)
|
||||||
a = 0.5
|
a = 0.5
|
||||||
fb = 0
|
fb = 0
|
||||||
rho = 0.02
|
rho = 0.02
|
||||||
@@ -203,19 +211,19 @@ if __name__ == '__main__':
|
|||||||
if abs(temp_ist - temp_soll) < 0.1:
|
if abs(temp_ist - temp_soll) < 0.1:
|
||||||
hold = True
|
hold = True
|
||||||
|
|
||||||
temp_ist -= rho
|
|
||||||
_temp_ist = np.append(_temp_ist, temp_ist)
|
|
||||||
_temp_soll = np.append(_temp_soll, temp_soll)
|
|
||||||
_y = np.append(_y, y)
|
_y = np.append(_y, y)
|
||||||
_fb = np.append(_fb, fb)
|
_fb = np.append(_fb, fb)
|
||||||
_t = np.append(_t, t)
|
_t = np.append(_t, t)
|
||||||
_heatrate_ist_kalman = np.append(_heatrate_ist_kalman, max(-1, min(3, ctrl.heatrate_ist)))
|
_temp_soll = np.append(_temp_soll, temp_soll)
|
||||||
_temp_ist_kalman = np.append(_temp_ist, ctrl.theta_ist_set)
|
_temp_ist_kalman_plant = np.append(_temp_ist_kalman_plant, ctrl.theta_ist_plant)
|
||||||
|
_heatrate_ist_kalman_plant = np.append(_heatrate_ist_kalman_plant, max(-1, min(3, ctrl.dtheta_ist_plant)))
|
||||||
|
_temp_ist_kalman_model = np.append(_temp_ist_kalman_model, ctrl.theta_ist_model_delay)
|
||||||
|
_heatrate_ist_kalman_model = np.append(_heatrate_ist_kalman_model, max(-1, min(3, ctrl.dtheta_ist_model_delay)))
|
||||||
t += 1
|
t += 1
|
||||||
|
|
||||||
figure(1)
|
figure(1)
|
||||||
subplot(3, 1, 1)
|
subplot(3, 1, 1)
|
||||||
plot(_t, _temp_ist, _t, _temp_soll, 'r-', linewidth=1)
|
plot(_t, _temp_ist_kalman_plant, _t, _temp_soll, 'r-', linewidth=1)
|
||||||
legend(["ist", "soll"])
|
legend(["ist", "soll"])
|
||||||
grid(True)
|
grid(True)
|
||||||
subplot(3, 1, 2)
|
subplot(3, 1, 2)
|
||||||
@@ -223,9 +231,19 @@ if __name__ == '__main__':
|
|||||||
legend(["y", "pot"])
|
legend(["y", "pot"])
|
||||||
grid(True)
|
grid(True)
|
||||||
subplot(3, 1, 3)
|
subplot(3, 1, 3)
|
||||||
plot(_t, _heatrate_ist_kalman, '-b', linewidth=1)
|
plot(_t, _heatrate_ist_kalman_plant, '-b', linewidth=1)
|
||||||
legend(["heatrate"])
|
legend(["heatrate"])
|
||||||
grid(True)
|
grid(True)
|
||||||
|
|
||||||
|
figure(2)
|
||||||
|
subplot(2, 1, 1)
|
||||||
|
plot(_t, _temp_ist_kalman_plant, '-b', _t, _temp_ist_kalman_model, 'r-', linewidth=1)
|
||||||
|
legend(["plant", "model"])
|
||||||
|
grid(True)
|
||||||
|
subplot(2, 1, 2)
|
||||||
|
plot(_t, _heatrate_ist_kalman_plant, '-b', _t, _heatrate_ist_kalman_model, '-r', linewidth=1)
|
||||||
|
legend(["plant", "model"])
|
||||||
|
grid(True)
|
||||||
show()
|
show()
|
||||||
|
|
||||||
print("End of program")
|
print("End of program")
|
||||||
|
|||||||
Reference in New Issue
Block a user