kopia lustrzana https://github.com/jbruce12000/kiln-controller
prevent self.runtime from going negative during profile run
rodzic
1c8f5843f0
commit
499f029ce5
18
lib/oven.py
18
lib/oven.py
|
@ -231,12 +231,13 @@ class Oven(threading.Thread):
|
|||
|
||||
def update_runtime(self):
|
||||
runtime_delta = datetime.datetime.now() - self.start_time
|
||||
if runtime_delta.total_seconds() < 0:
|
||||
runtime_delta = datetime.timedelta(0)
|
||||
|
||||
if self.startat > 0:
|
||||
self.runtime = self.startat + runtime_delta.total_seconds()
|
||||
else:
|
||||
self.runtime = runtime_delta.total_seconds()
|
||||
if self.runtime < 0:
|
||||
self.runtime = 0
|
||||
|
||||
def update_target_temp(self):
|
||||
self.target = self.profile.get_target_temperature(self.runtime)
|
||||
|
@ -283,10 +284,10 @@ class Oven(threading.Thread):
|
|||
time.sleep(1)
|
||||
continue
|
||||
if self.state == "RUNNING":
|
||||
catching_up = self.kiln_must_catch_up()
|
||||
self.kiln_must_catch_up()
|
||||
self.update_runtime()
|
||||
self.update_target_temp()
|
||||
self.heat_then_cool(catching_up)
|
||||
self.heat_then_cool()
|
||||
self.reset_if_emergency()
|
||||
self.reset_if_schedule_ended()
|
||||
|
||||
|
@ -338,11 +339,10 @@ class SimulatedOven(Oven):
|
|||
self.temperature = self.t
|
||||
self.board.temp_sensor.temperature = self.t
|
||||
|
||||
def heat_then_cool(self, catching_up):
|
||||
def heat_then_cool(self):
|
||||
pid = self.pid.compute(self.target,
|
||||
self.board.temp_sensor.temperature +
|
||||
config.thermocouple_offset,
|
||||
catching_up)
|
||||
config.thermocouple_offset)
|
||||
heat_on = float(self.time_step * pid)
|
||||
heat_off = float(self.time_step * (1 - pid))
|
||||
|
||||
|
@ -471,7 +471,7 @@ class PID():
|
|||
# settled on -50 to 50 and then divide by 50 at the end. This results
|
||||
# in a larger PID control window and much more accurate control...
|
||||
# instead of what used to be binary on/off control.
|
||||
def compute(self, setpoint, ispoint, catching_up):
|
||||
def compute(self, setpoint, ispoint):
|
||||
now = datetime.datetime.now()
|
||||
timeDelta = (now - self.lastNow).total_seconds()
|
||||
|
||||
|
@ -482,7 +482,7 @@ class PID():
|
|||
if self.ki > 0:
|
||||
if config.stop_integral_windup == True:
|
||||
margin = setpoint * config.stop_integral_windup_margin/100
|
||||
if (abs(error) <= abs(margin)) and not catching_up:
|
||||
if (abs(error) <= abs(margin)):
|
||||
self.iterm += (error * timeDelta * (1/self.ki))
|
||||
else:
|
||||
self.iterm += (error * timeDelta * (1/self.ki))
|
||||
|
|
Ładowanie…
Reference in New Issue