- use kalman params
- some improvements for real hardware cooker and temp sensor git-svn-id: http://moon:8086/svn/projects/HendiControl@221 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
@@ -46,15 +46,8 @@ class Controller():
|
|||||||
self.heatrate_sm = Smoother(0.01)
|
self.heatrate_sm = Smoother(0.01)
|
||||||
self.theta_err_sm = Smoother(1.0)
|
self.theta_err_sm = Smoother(1.0)
|
||||||
self.heatrate_err_sm = Smoother(1.0)
|
self.heatrate_err_sm = Smoother(1.0)
|
||||||
|
self.useKalman = params['useKalman']
|
||||||
kparams = {
|
self.kalman = Kalman(params['kalman'])
|
||||||
'dt': 1,
|
|
||||||
'var_P': 0,
|
|
||||||
'var_Q': 0.00001,
|
|
||||||
'var_R': 2,
|
|
||||||
'var_Z': 0
|
|
||||||
}
|
|
||||||
self.kalman = Kalman(kparams)
|
|
||||||
|
|
||||||
def log(self, s):
|
def log(self, s):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
@@ -132,7 +125,7 @@ class Controller():
|
|||||||
def rast(self, rast):
|
def rast(self, rast):
|
||||||
|
|
||||||
# Temperature
|
# Temperature
|
||||||
self.theta = self.plant.getTemperature()
|
theta = self.plant.getTemperature()
|
||||||
theta_soll = rast['temp']
|
theta_soll = rast['temp']
|
||||||
heatrate_soll = rast['heatRate']
|
heatrate_soll = rast['heatRate']
|
||||||
self.log("Target temperature {} °C".format(theta_soll))
|
self.log("Target temperature {} °C".format(theta_soll))
|
||||||
@@ -142,13 +135,13 @@ class Controller():
|
|||||||
timer_soll = 60*rast['time']
|
timer_soll = 60*rast['time']
|
||||||
|
|
||||||
# Kalman filter initial value
|
# Kalman filter initial value
|
||||||
self.kalman.initial((self.theta, 0))
|
self.kalman.initial((theta, 0))
|
||||||
self.theta_sm.initial(self.theta)
|
self.theta_sm.initial(theta)
|
||||||
|
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
# The loop
|
# The loop
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
doLoop = theta_soll > self.theta
|
doLoop = theta_soll > theta
|
||||||
if doLoop:
|
if doLoop:
|
||||||
# Stirrer
|
# Stirrer
|
||||||
self.stirrer.activate()
|
self.stirrer.activate()
|
||||||
@@ -156,7 +149,6 @@ class Controller():
|
|||||||
|
|
||||||
self.stirrer.setCycleTime(self.stirrCycleTime)
|
self.stirrer.setCycleTime(self.stirrCycleTime)
|
||||||
|
|
||||||
useKalman = False
|
|
||||||
while(doLoop):
|
while(doLoop):
|
||||||
|
|
||||||
time_start = time.time()
|
time_start = time.time()
|
||||||
@@ -184,7 +176,7 @@ class Controller():
|
|||||||
self.theta_v = np.append(self.theta_v, theta_ist)
|
self.theta_v = np.append(self.theta_v, theta_ist)
|
||||||
self.heatrate_v = np.append(self.heatrate_v, dtheta_ist * 60/self.dt)
|
self.heatrate_v = np.append(self.heatrate_v, dtheta_ist * 60/self.dt)
|
||||||
|
|
||||||
if useKalman:
|
if self.useKalman:
|
||||||
ctrl_theta_err = theta_soll - theta_ist_k
|
ctrl_theta_err = theta_soll - theta_ist_k
|
||||||
ctrl_heatrate_err = heatrate_soll - dtheta_ist_k * 60/self.dt
|
ctrl_heatrate_err = heatrate_soll - dtheta_ist_k * 60/self.dt
|
||||||
ctrl_theta = theta_ist_k
|
ctrl_theta = theta_ist_k
|
||||||
|
|||||||
Reference in New Issue
Block a user