From bf7ec2beaf9ab633a67c99d0f660913a7b43ab81 Mon Sep 17 00:00:00 2001 From: jens Date: Tue, 12 Oct 2021 16:47:05 +0200 Subject: [PATCH] - PID: introduced INIT State - refactored --- components/pid/tc_constants.py | 9 +++++++++ components/pid/temp_controller.py | 17 ++++++----------- components/pid/temp_controller_smith.py | 19 +++++++------------ 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/components/pid/tc_constants.py b/components/pid/tc_constants.py index c534230..40aaf3a 100644 --- a/components/pid/tc_constants.py +++ b/components/pid/tc_constants.py @@ -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_HEAT = 1.0 diff --git a/components/pid/temp_controller.py b/components/pid/temp_controller.py index 0543871..f99afb8 100644 --- a/components/pid/temp_controller.py +++ b/components/pid/temp_controller.py @@ -1,16 +1,9 @@ from components.plant.pot import Pot from matplotlib.pyplot import plot, figure, subplot, grid, show, legend -from components.pid import Pid, Kalman from components import APid -import numpy as np -from enum import Enum +from components.pid import Pid, Kalman from components.pid.tc_constants import * - - -class States(Enum): - IDLE = 0, - HEAT = 1, - HOLD = 2 +import numpy as np class TempController(APid): @@ -28,7 +21,7 @@ class TempController(APid): self.params = params self.kalman = Kalman(dt, params['Kalman']) self.y = -1 - self.state = States.IDLE + self.state = States.INIT self.use_kalman = True self.pid_hold.set_params(params['Hold']) self.pid_rate.set_params(params['Heat']) @@ -93,7 +86,9 @@ class TempController(APid): def process_fsm(self, diff): # Process 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: state_next = States.HEAT self.pid_rate.reset() diff --git a/components/pid/temp_controller_smith.py b/components/pid/temp_controller_smith.py index 59e0381..954dbee 100755 --- a/components/pid/temp_controller_smith.py +++ b/components/pid/temp_controller_smith.py @@ -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 components.pid import Pid, Kalman from components import APid -import numpy as np -from enum import Enum +from components.pid import Pid, Kalman from components.pid.tc_constants import * - - -class States(Enum): - IDLE = 0, - HEAT = 1, - HOLD = 2 +import numpy as np class TempController(APid): @@ -31,7 +24,7 @@ class TempController(APid): self.kalman_model_delay = Kalman(dt, params['Kalman']) self.kalman_plant = Kalman(dt, params['Kalman']) self.y = -1 - self.state = States.IDLE + self.state = States.INIT self.use_kalman = True self.pid_hold.set_params(params['Hold']) self.pid_rate.set_params(params['Heat']) @@ -118,7 +111,9 @@ class TempController(APid): def process_fsm(self, diff): # Process 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: state_next = States.HEAT self.pid_rate.reset()