- PID: introduced INIT State

- refactored
This commit is contained in:
jens
2021-10-12 16:47:05 +02:00
parent 55315e268e
commit bf7ec2beaf
3 changed files with 22 additions and 23 deletions
+9
View File
@@ -1,3 +1,12 @@
from enum import Enum
class States(Enum):
INIT = -1,
IDLE = 0,
HEAT = 1,
HOLD = 2
THRESH_HOLD_IDLE = 0.1 THRESH_HOLD_IDLE = 0.1
THRESH_HOLD_HEAT = 1.0 THRESH_HOLD_HEAT = 1.0
+6 -11
View File
@@ -1,16 +1,9 @@
from components.plant.pot import Pot from components.plant.pot import Pot
from matplotlib.pyplot import plot, figure, subplot, grid, show, legend from matplotlib.pyplot import plot, figure, subplot, grid, show, legend
from components.pid import Pid, Kalman
from components import APid from components import APid
import numpy as np from components.pid import Pid, Kalman
from enum import Enum
from components.pid.tc_constants import * from components.pid.tc_constants import *
import numpy as np
class States(Enum):
IDLE = 0,
HEAT = 1,
HOLD = 2
class TempController(APid): class TempController(APid):
@@ -28,7 +21,7 @@ class TempController(APid):
self.params = params self.params = params
self.kalman = Kalman(dt, params['Kalman']) self.kalman = Kalman(dt, params['Kalman'])
self.y = -1 self.y = -1
self.state = States.IDLE self.state = States.INIT
self.use_kalman = True self.use_kalman = True
self.pid_hold.set_params(params['Hold']) self.pid_hold.set_params(params['Hold'])
self.pid_rate.set_params(params['Heat']) self.pid_rate.set_params(params['Heat'])
@@ -93,7 +86,9 @@ class TempController(APid):
def process_fsm(self, diff): def process_fsm(self, diff):
# Process state # Process state
state_next = self.state state_next = self.state
if self.state == States.IDLE: if self.state == States.INIT:
state_next = States.IDLE
elif self.state == States.IDLE:
if diff >= THRESH_IDLE_HEAT: if diff >= THRESH_IDLE_HEAT:
state_next = States.HEAT state_next = States.HEAT
self.pid_rate.reset() self.pid_rate.reset()
+7 -12
View File
@@ -1,16 +1,9 @@
from components.plant.pot import Pot, HeatDiffusion from components.plant.pot import Pot
from matplotlib.pyplot import plot, figure, subplot, grid, show, legend from matplotlib.pyplot import plot, figure, subplot, grid, show, legend
from components.pid import Pid, Kalman
from components import APid from components import APid
import numpy as np from components.pid import Pid, Kalman
from enum import Enum
from components.pid.tc_constants import * from components.pid.tc_constants import *
import numpy as np
class States(Enum):
IDLE = 0,
HEAT = 1,
HOLD = 2
class TempController(APid): class TempController(APid):
@@ -31,7 +24,7 @@ class TempController(APid):
self.kalman_model_delay = Kalman(dt, params['Kalman']) self.kalman_model_delay = Kalman(dt, params['Kalman'])
self.kalman_plant = Kalman(dt, params['Kalman']) self.kalman_plant = Kalman(dt, params['Kalman'])
self.y = -1 self.y = -1
self.state = States.IDLE self.state = States.INIT
self.use_kalman = True self.use_kalman = True
self.pid_hold.set_params(params['Hold']) self.pid_hold.set_params(params['Hold'])
self.pid_rate.set_params(params['Heat']) self.pid_rate.set_params(params['Heat'])
@@ -118,7 +111,9 @@ class TempController(APid):
def process_fsm(self, diff): def process_fsm(self, diff):
# Process state # Process state
state_next = self.state state_next = self.state
if self.state == States.IDLE: if self.state == States.INIT:
state_next = States.IDLE
elif self.state == States.IDLE:
if diff >= THRESH_IDLE_HEAT: if diff >= THRESH_IDLE_HEAT:
state_next = States.HEAT state_next = States.HEAT
self.pid_rate.reset() self.pid_rate.reset()