- refactored
- increased Hold.Pid.kp - decrease state change HEAT TO HOLD windows to 1°C
This commit is contained in:
@@ -4,6 +4,7 @@ from components.pid import Pid, Kalman
|
||||
from components import APid
|
||||
import numpy as np
|
||||
from enum import Enum
|
||||
from components.pid.tc_constants import *
|
||||
|
||||
|
||||
class States(Enum):
|
||||
@@ -13,7 +14,7 @@ class States(Enum):
|
||||
|
||||
|
||||
class TempController(APid):
|
||||
def __init__(self, dt, params):
|
||||
def __init__(self, dt, params, model_params):
|
||||
APid.__init__(self)
|
||||
self.pid_hold = Pid(dt)
|
||||
self.pid_rate = Pid(dt)
|
||||
@@ -25,6 +26,7 @@ class TempController(APid):
|
||||
self.theta_ist = 0
|
||||
self.heatrate_ist = 0
|
||||
self.params = params
|
||||
self.model_params = model_params
|
||||
self.kalman_model = Kalman(dt, params['Kalman'])
|
||||
self.kalman_plant = Kalman(dt, params['Kalman'])
|
||||
self.y = -1
|
||||
@@ -32,9 +34,9 @@ class TempController(APid):
|
||||
self.use_kalman = True
|
||||
self.pid_hold.set_params(params['Hold'])
|
||||
self.pid_rate.set_params(params['Heat'])
|
||||
self.model = Pot(dt, params['Model'])
|
||||
self.theta_ist_delay_model = Delay(dt, params['Model']['Td'], 0)
|
||||
self.dtheta_ist_delay_model = Delay(dt, params['Model']['Td'], 0)
|
||||
self.model = Pot(dt, model_params)
|
||||
self.theta_ist_delay_model = Delay(dt, model_params['Td'], 0)
|
||||
self.dtheta_ist_delay_model = Delay(dt, model_params['Td'], 0)
|
||||
self.is_startup = True
|
||||
|
||||
def set_theta_ist(self, value):
|
||||
@@ -112,13 +114,6 @@ class TempController(APid):
|
||||
self.process_pid(theta_err, heatrate_err)
|
||||
|
||||
def process_fsm(self, diff):
|
||||
THRESH_HOLD_IDLE = 0.1
|
||||
THRESH_HOLD_HEAT = 2.0
|
||||
THRESH_IDLE_HEAT = 1.0
|
||||
THRESH_IDLE_HOLD = 0.1
|
||||
THRESH_HEAT_HOLD = 2.0
|
||||
THRESH_HEAT_IDLE = 2.0
|
||||
|
||||
# Process state
|
||||
state_next = self.state
|
||||
if self.state == States.IDLE:
|
||||
@@ -167,50 +162,10 @@ class TempController(APid):
|
||||
if __name__ == '__main__':
|
||||
dt = 1.0
|
||||
|
||||
tc_params = {
|
||||
"Model": {
|
||||
"theta" : 20,
|
||||
"C" : 4190,
|
||||
"M" : 20,
|
||||
"L" : 0.05,
|
||||
"Td" : 80,
|
||||
"kn" : 0.2,
|
||||
"gain" : 0.8
|
||||
},
|
||||
"Kalman": {
|
||||
"var_P" : 1.0,
|
||||
"var_Q" : 0.0001,
|
||||
"var_R" : 1.0
|
||||
},
|
||||
"Hold": {
|
||||
"kp": 0.2,
|
||||
"ki": 0.0,
|
||||
"kd": 0.0,
|
||||
"kt": 0.0
|
||||
},
|
||||
"Heat": {
|
||||
"kp": 0.1,
|
||||
"ki": 0.01,
|
||||
"kd": 0.0,
|
||||
"kt": 1.5
|
||||
}
|
||||
}
|
||||
|
||||
pot_params = {
|
||||
"dt" : 1.0,
|
||||
"theta" : 20,
|
||||
"C" : 4190,
|
||||
"M" : 20 + 4,
|
||||
"L" : 0.07,
|
||||
"Td" : 80 + 5,
|
||||
"kn" : 0.2,
|
||||
"gain" : 0.8
|
||||
}
|
||||
|
||||
temp_ist = 0
|
||||
temp_soll = 20
|
||||
ctrl = TempController(dt, tc_params)
|
||||
plant = Pot(dt, pot_params)
|
||||
ctrl = TempController(dt, Test.tc_ctrl_params, Test.tc_model_params)
|
||||
plant = Pot(dt, Test.tc_pot_params)
|
||||
_temp_ist = np.empty(0)
|
||||
_temp_soll = np.empty(0)
|
||||
_y = np.empty(0)
|
||||
@@ -237,10 +192,10 @@ if __name__ == '__main__':
|
||||
if hold_counter == 0:
|
||||
break
|
||||
hold_counter -= 1
|
||||
ctrl.process()
|
||||
plant.process()
|
||||
temp_ist = plant.get_temperature()
|
||||
ctrl.set_theta_ist(temp_ist)
|
||||
ctrl.process()
|
||||
|
||||
y = 3500*ctrl.get_power()
|
||||
power = max(0, y)
|
||||
|
||||
Reference in New Issue
Block a user