Consolidate States/DEFAULT_THRESHOLDS into temp_controller_base.py
tc_constants.py only held States and DEFAULT_THRESHOLDS, both used exclusively by temp_controller_base.py and its subclasses; fold them into temp_controller_base.py directly and drop the now-empty module. Also drop heat_diffusion.py, unused since pot.py switched to the delay-line model, and the matching dead import in pot.py. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
from components.pid.pid import *
|
from components.pid.pid import *
|
||||||
from components.pid.kalman import *
|
from components.pid.kalman import *
|
||||||
from components.pid.tc_constants import *
|
|
||||||
|
|
||||||
from components.pid.pid_factory import PidFactory
|
from components.pid.pid_factory import PidFactory
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
from enum import Enum
|
|
||||||
|
|
||||||
|
|
||||||
class States(Enum):
|
|
||||||
INIT = -1,
|
|
||||||
IDLE = 0,
|
|
||||||
HEAT = 1,
|
|
||||||
HOLD = 2
|
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_THRESHOLDS = {
|
|
||||||
"HoldIdle": 0.1,
|
|
||||||
"HoldHeat": 1.0,
|
|
||||||
"IdleHeat": 1.0,
|
|
||||||
"IdleHold": 0.1,
|
|
||||||
"HeatHold": 1.0,
|
|
||||||
"HeatIdle": 1.0
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class Test:
|
|
||||||
tc_ctrl_params = {
|
|
||||||
"Kalman": {
|
|
||||||
"var_P": 1.0,
|
|
||||||
"var_Q": 0.0001,
|
|
||||||
"var_R": 1.0
|
|
||||||
},
|
|
||||||
"Hold": {
|
|
||||||
"kp": 0.4,
|
|
||||||
"ki": 0.0,
|
|
||||||
"kd": 0.0,
|
|
||||||
"kt": 0.0
|
|
||||||
},
|
|
||||||
"Heat": {
|
|
||||||
"kp": 0.02,
|
|
||||||
"ki": 0.01,
|
|
||||||
"kd": 0.0,
|
|
||||||
"kt": 1.5
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tc_model_params = {
|
|
||||||
"theta" : 20,
|
|
||||||
"C" : 4190,
|
|
||||||
"M" : 20,
|
|
||||||
"L" : 0.01,
|
|
||||||
"Td" : 30,
|
|
||||||
"kn" : 0.2,
|
|
||||||
"gain" : 1.0
|
|
||||||
}
|
|
||||||
|
|
||||||
tc_pot_params = {
|
|
||||||
"theta" : 20,
|
|
||||||
"C" : 4190,
|
|
||||||
"M" : 20,
|
|
||||||
"L" : 0.01,
|
|
||||||
"Td" : 30,
|
|
||||||
"kn" : 0.2,
|
|
||||||
"gain" : 1.0
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,24 @@
|
|||||||
from components import APid
|
from components import APid
|
||||||
from components.pid.pid import Pid
|
from components.pid.pid import Pid
|
||||||
from components.pid.tc_constants import States, DEFAULT_THRESHOLDS
|
import enum
|
||||||
|
|
||||||
|
DEFAULT_THRESHOLDS = {
|
||||||
|
"HoldIdle": 0.1,
|
||||||
|
"HoldHeat": 1.0,
|
||||||
|
"IdleHeat": 1.0,
|
||||||
|
"IdleHold": 0.1,
|
||||||
|
"HeatHold": 1.0,
|
||||||
|
"HeatIdle": 1.0
|
||||||
|
}
|
||||||
|
|
||||||
|
class States(enum.Enum):
|
||||||
|
INIT = -1,
|
||||||
|
IDLE = 0,
|
||||||
|
HEAT = 1,
|
||||||
|
HOLD = 2
|
||||||
|
|
||||||
class TempControllerBase(APid):
|
class TempControllerBase(APid):
|
||||||
|
|
||||||
def __init__(self, dt, params):
|
def __init__(self, dt, params):
|
||||||
APid.__init__(self)
|
APid.__init__(self)
|
||||||
self.pid_hold = Pid(dt)
|
self.pid_hold = Pid(dt)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from components.plant.pot import Pot
|
from components.plant.pot import Pot
|
||||||
from components.pid.temp_controller_base import TempControllerBase
|
from components.pid.temp_controller_base import TempControllerBase, States
|
||||||
from components.pid.tc_constants import States
|
|
||||||
|
|
||||||
|
|
||||||
class TempController(TempControllerBase):
|
class TempController(TempControllerBase):
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
import numpy as np
|
|
||||||
|
|
||||||
|
|
||||||
class HeatDiffusion:
|
|
||||||
def __init__(self, dt, delay, ic=0):
|
|
||||||
self.alpha = dt/delay
|
|
||||||
self.beta = 1 - self.alpha
|
|
||||||
self.state = ic
|
|
||||||
|
|
||||||
def initial(self, ic):
|
|
||||||
self.state = ic
|
|
||||||
|
|
||||||
def process(self, x):
|
|
||||||
self.state = self.beta * self.state + self.alpha*x
|
|
||||||
return self.state
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
d = HeatDiffusion(0.1, 1)
|
|
||||||
|
|
||||||
for i in range(1, 200):
|
|
||||||
y = d.process(1)
|
|
||||||
print("In = {}, out = {}".format(i, y))
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
from components.aplant import APlant
|
from components.aplant import APlant
|
||||||
from components.plant.heat_diffusion import HeatDiffusion
|
|
||||||
from components.plant import delay
|
from components.plant import delay
|
||||||
|
|
||||||
class Pot(APlant):
|
class Pot(APlant):
|
||||||
|
|||||||
Reference in New Issue
Block a user