def run(self): try: on = float(self.config["ON"]) except Exception as e: on = 0 app.logger.error("Wrong ON parameter for hysteresis! Set ON parameter to 0") socketio.emit('message', {"headline": "WRONG_HYSTERESIS_PARAMETER", "message": "WRONG_ON_PARAMETER"}, namespace='/brew') try: off = float(self.config["OFF"]) except Exception as e: off = 0 app.logger.error("Wrong max parameter!") socketio.emit('message', {"headline": "WRONG_HYSTERESIS_PARAMETER", "message": "WRONG_OFF_PARAMETER"}, namespace='/brew') while self.isRunning(): currentTemp = self.getCurrentTemp() ## Current temperature targetTemp = self.getTargetTemp() ## Target Temperature if currentTemp + on < targetTemp: self.switchHeaterON() if currentTemp + off > targetTemp: self.switchHeaterOFF() socketio.sleep(1) self.switchHeaterOFF()
def run(self): try: overshoot = float(self.config["Overshoot"]) except Exception as e: app.logger.error( "Wrong overshoot parameter! Set overshoot parameter to 0") overshoot = 0 while self.isRunning(): currentTemp = self.getCurrentTemp() ## Current temperature targetTemp = self.getTargetTemp() ## Target Temperature if (currentTemp == None): socketio.sleep(1) return ## Current Temp is below Target Temp ... switch heater on if (currentTemp + overshoot < targetTemp and self.state == False): self.state = True self.switchHeaterON() ## Current Temp is equal or higher than Target Temp ... switch Heater off if (currentTemp + overshoot >= targetTemp and self.state == True): self.state = False self.switchHeaterOFF() socketio.sleep(1) self.switchHeaterOFF() app.logger.info("Stop PID - Kettle Id: " + str(self.kid))
def run(self): try: overshoot = float(self.config["Overshoot"]) except Exception as e: app.logger.error("Wrong overshoot parameter! Set overshoot parameter to 0") overshoot = 0 while self.isRunning(): currentTemp = self.getCurrentTemp() ## Current temperature targetTemp = self.getTargetTemp() ## Target Temperature ## Current Temp is below Target Temp ... overshoot is on ... switch heater on if(currentTemp + overshoot < targetTemp and self.state == False and targetTemp != self.setpoint): self.state = True self.switchHeaterON() ## Switch overshoot off if target temp is reached if(currentTemp >= targetTemp): self.setpoint = targetTemp ## Current Temp is below Target Temp ... overshoot is off ... switch heater on if(currentTemp < targetTemp and self.state == False and targetTemp == self.setpoint): self.state = True self.switchHeaterON() ## Current Temp is equal or higher than Target Temp ... overshoot is on ... switch Heater off if(currentTemp + overshoot >= targetTemp and self.state == True and targetTemp != self.setpoint): self.state = False self.switchHeaterOFF() ## Current Temp is equal or higher than Target Temp ... overshoot is off ... switch Heater off if(currentTemp >= targetTemp and self.state == True and targetTemp == self.setpoint): self.state = False self.switchHeaterOFF() socketio.sleep(1) self.switchHeaterOFF() app.logger.info("Stop PID - Kettle Id: "+ str(self.kid))
def run(self): sampleTime = 5 wait_time = 5 outstep = float(self.config[self.KEY_OUTSTEP]) outmax = float(self.config[self.KEY_MAXOUT]) lookbackSec = float(self.config[self.KEY_LOOKBACK]) setpoint = self.getTargetTemp() atune = PIDAutotune(setpoint, outstep, sampleTime, lookbackSec, 0, outmax) while self.isRunning() and not atune.run(self.getCurrentTemp()): heat_percent = atune.output heating_time = sampleTime * heat_percent / 100 wait_time = sampleTime - heating_time self.switchHeaterON() socketio.sleep(heating_time) self.switchHeaterOFF() socketio.sleep(wait_time) app.brewapp_kettle_state[self.kid]["automatic"] = False stopPID(self.kid) socketio.emit('kettle_state_update', app.brewapp_kettle_state, namespace ='/brew') if atune.state == atune.STATE_SUCCEEDED: with io.FileIO('pidparams.txt', 'w') as file: for rule in atune.tuningRules: params = atune.getPIDParameters(rule) file.write('rule: {0}\n'.format(rule)) file.write('P: {0}\n'.format(params.Kp)) file.write('I: {0}\n'.format(params.Ki)) file.write('D: {0}\n\n'.format(params.Kd))
def run(self): # loop for automatic while self.isRunning(): # access config paramter at runtime # make sure to add a sleep to the while loop socketio.sleep(1)
def run(self): sampleTime = 5 wait_time = float(self.config["wait_time"]) p = float(self.config["P"]) i = float(self.config["I"]) d = float(self.config["D"]) pid = PID(wait_time, p, i, d) pumpTime = int(self.config["PumpTime"]) pumpPause = int(self.config["PumpPause"]) pumpSafety = float(self.config["PumpAbschalt"]) while self.isRunning(): heat_percent = pid.calc(self.getCurrentTemp(), self.getTargetTemp()) heating_time = sampleTime * heat_percent / 100 wait_time = sampleTime - heating_time currentTemp = self.getCurrentTemp() ## Current temperature targetTemp = self.getTargetTemp() ## Target Temperatur pumpTime = pumpTime pumpPause = pumpPause ## Current Temp is below Target Temp ... switch heater and pump on if (currentTemp < targetTemp and currentTemp < pumpSafety): print self.config["PumpGPIO"] switchOff(self.config["PumpGPIO"]) self.switchHeaterON() socketio.sleep(heating_time) self.switchHeaterOFF() time.sleep(wait_time) ## Current Temp is eqal or higher than Target Temp ... switch heater off and cycle pump elif (currentTemp >= targetTemp and currentTemp < pumpSafety): self.switchHeaterOFF() for i in range(pumpTime): targetTemp = self.getTargetTemp() if (currentTemp < targetTemp): break socketio.sleep(1) print self.config["PumpGPIO"] switchOff(self.config["PumpGPIO"]) for i in range(pumpPause): targetTemp = self.getTargetTemp() if (currentTemp < targetTemp): break socketio.sleep(1) print self.config["PumpGPIO"] switchOn(self.config["PumpGPIO"]) ## self.switchHeaterOFF() ## Current Temp is above Pump safety temp ... switch pump off elif (currentTemp < targetTemp and currentTemp > pumpSafety): print self.config["PumpGPIO"] switchOn(self.config["PumpGPIO"]) self.switchHeaterON() socketio.sleep(heating_time) self.switchHeaterOFF() socketio.sleep(wait_time)
def run(self): sampleTime = 5 wait_time = float(self.config["wait_time"]) p = float(self.config["P"]) i = float(self.config["I"]) d = float(self.config["D"]) pid = PID(wait_time,p,i,d) pumpTime = int(self.config["PumpTime"]) pumpPause = int(self.config["PumpPause"]) pumpSafety = float(self.config["PumpAbschalt"]) while self.isRunning(): heat_percent = pid.calc(self.getCurrentTemp(), self.getTargetTemp()) heating_time = sampleTime * heat_percent / 100 wait_time = sampleTime - heating_time currentTemp = self.getCurrentTemp() ## Current temperature targetTemp = self.getTargetTemp() ## Target Temperatur pumpTime = pumpTime pumpPause = pumpPause ## Current Temp is below Target Temp ... switch heater and pump on if(currentTemp < targetTemp and currentTemp < pumpSafety): print self.config["PumpGPIO"] switchOff(self.config["PumpGPIO"]) self.switchHeaterON() socketio.sleep(heating_time) self.switchHeaterOFF() time.sleep(wait_time) ## Current Temp is eqal or higher than Target Temp ... switch heater off and cycle pump elif(currentTemp >= targetTemp and currentTemp < pumpSafety): self.switchHeaterOFF() for i in range(pumpTime): targetTemp = self.getTargetTemp() if(currentTemp < targetTemp): break socketio.sleep(1) print self.config["PumpGPIO"] switchOff(self.config["PumpGPIO"]) for i in range(pumpPause): targetTemp = self.getTargetTemp() if(currentTemp < targetTemp): break socketio.sleep(1) print self.config["PumpGPIO"] switchOn(self.config["PumpGPIO"]) ## self.switchHeaterOFF() ## Current Temp is above Pump safety temp ... switch pump off elif(currentTemp < targetTemp and currentTemp > pumpSafety): print self.config["PumpGPIO"] switchOn(self.config["PumpGPIO"]) self.switchHeaterON() socketio.sleep(heating_time) self.switchHeaterOFF() socketio.sleep(wait_time)
def hystresis(id): while app.brewapp_automatic_state["F" + id]: fermenter = app.cbp['FERMENTERS'][int(id)] if type(fermenter["sensorid"]) is not int: socketio.emit('message', { "headline": "NO_TERMOMETER", "message": "NO_THERMOMETER_DEFINED" }, namespace='/brew') break temp = app.brewapp_thermometer_last[fermenter["sensorid"]] target_temp = fermenter["target_temp"] heater_min = fermenter["heateroffset_min"] heater_max = fermenter["heateroffset_max"] cooler_min = fermenter["cooleroffset_min"] cooler_max = fermenter["cooleroffset_max"] heater_id = fermenter["heaterid"] if type( fermenter["heaterid"]) is int else None cooler_id = fermenter["coolerid"] if type( fermenter["coolerid"]) is int else None if heater_id is not None: if temp + heater_min < target_temp: switchOn(fermenter["heaterid"]) if temp + heater_max > target_temp: switchOff(fermenter["heaterid"]) if cooler_id is not None: if temp > target_temp + cooler_min: switchOn(fermenter["coolerid"]) if temp < target_temp + cooler_max: switchOff(fermenter["coolerid"]) socketio.sleep(1) app.brewapp_automatic_state["F" + id] = False if type(fermenter["heaterid"]) is int: switchOff(fermenter["heaterid"]) if type(fermenter["coolerid"]) is int: switchOff(fermenter["coolerid"])
def run(self): while self.isRunning(): currentTemp = self.getCurrentTemp() # Current temperature targetTemp = self.getTargetTemp() # Target Temperature # Current Temp is below Target Temp ... switch heater on if currentTemp > targetTemp and self.state is False: self.state = True self.switchHeaterON() # Current Temp is equal or higher than Target Temp ... switch Heater off if currentTemp <= targetTemp and self.state is True: self.state = False self.switchHeaterOFF() socketio.sleep(1) self.switchHeaterOFF() app.logger.info("Stop Automatic - Kettle Id: " + str(self.kid))
def run(self): sampleTime = 5 wait_time = float(self.config["wait_time"]) p = float(self.config["P"]) i = float(self.config["I"]) d = float(self.config["D"]) pid = PID(wait_time,p,i,d) while self.isRunning(): heat_percent = pid.calc(self.getCurrentTemp(), self.getTargetTemp()) heating_time = sampleTime * heat_percent / 100 wait_time = sampleTime - heating_time self.switchHeaterON() socketio.sleep(heating_time) self.switchHeaterOFF() socketio.sleep(wait_time)
def run(self): sampleTime = 5 wait_time = 5 p = float(self.config[self.KEY_P]) i = float(self.config[self.KEY_I]) d = float(self.config[self.KEY_D]) maxout = float(self.config[self.KEY_MAXOUT]) pid = PIDArduino(sampleTime, p, i, d, 0, maxout) while self.isRunning(): heat_percent = pid.calc(self.getCurrentTemp(), self.getTargetTemp()) heating_time = sampleTime * heat_percent / 100 wait_time = sampleTime - heating_time self.switchHeaterON() socketio.sleep(heating_time) self.switchHeaterOFF() socketio.sleep(wait_time)
def hystresis(id): while app.brewapp_automatic_state["F" + id]: fermenter = app.cbp['FERMENTERS'][int(id)] if type(fermenter["sensorid"]) is not int: socketio.emit('message', {"headline": "NO_TERMOMETER", "message": "NO_THERMOMETER_DEFINED"}, namespace='/brew') break temp = app.brewapp_thermometer_last[fermenter["sensorid"]] target_temp = fermenter["target_temp"] heater_min = fermenter["heateroffset_min"] heater_max = fermenter["heateroffset_max"] cooler_min = fermenter["cooleroffset_min"] cooler_max = fermenter["cooleroffset_max"] heater_id = fermenter["heaterid"] if type(fermenter["heaterid"]) is int else None cooler_id = fermenter["coolerid"] if type(fermenter["coolerid"]) is int else None if heater_id is not None: if temp + heater_min < target_temp: switchOn(fermenter["heaterid"]) if temp + heater_max > target_temp: switchOff(fermenter["heaterid"]) if cooler_id is not None: if temp > target_temp + cooler_min: switchOn(fermenter["coolerid"]) if temp < target_temp + cooler_max: switchOff(fermenter["coolerid"]) socketio.sleep(1) app.brewapp_automatic_state["F" + id] = False if type(fermenter["heaterid"]) is int: switchOff(fermenter["heaterid"]) if type(fermenter["coolerid"]) is int: switchOff(fermenter["coolerid"])
def run(self): try: on = float(self.config["ON"]) except Exception as e: on = 0 app.logger.error( "Wrong ON parameter for hysteresis! Set ON parameter to 0") socketio.emit('message', { "headline": "WRONG_HYSTERESIS_PARAMETER", "message": "WRONG_ON_PARAMETER" }, namespace='/brew') try: off = float(self.config["OFF"]) except Exception as e: off = 0 app.logger.error("Wrong max parameter!") socketio.emit('message', { "headline": "WRONG_HYSTERESIS_PARAMETER", "message": "WRONG_OFF_PARAMETER" }, namespace='/brew') while self.isRunning(): currentTemp = self.getCurrentTemp() ## Current temperature targetTemp = self.getTargetTemp() ## Target Temperature if currentTemp + on < targetTemp: self.switchHeaterON() if currentTemp + off > targetTemp: self.switchHeaterOFF() socketio.sleep(1) self.switchHeaterOFF()
def run(self): sampleTime = 5 pumpRunning = False heaterOn = False heaterLastOff = 0 agitatorName = app.brewapp_kettle_state[self.kid]["agitator"] wait_time = float(self.config["wait_time"]) p = float(self.config["P"]) i = float(self.config["I"]) d = float(self.config["D"]) pumpWait = float(self.config["PumpWait"]) pid = PID(wait_time, p, i, d) while self.isRunning(): heat_percent = pid.calc(self.getCurrentTemp(), self.getTargetTemp()) heating_time = sampleTime * heat_percent / 100 wait_time = sampleTime - heating_time if(heating_time > 0.1): # If not already running, start pump and wait 1 round (5 Seconds) if(app.brewapp_switch_state[agitatorName] == False and pumpRunning == False): pumpRunning = True switchOn(agitatorName) socketio.sleep(sampleTime) else: if(heaterOn == False): heaterOn = True self.switchHeaterON() heaterLastOff = 0 socketio.sleep(heating_time) if(wait_time > 0.1): heaterOn = False self.switchHeaterOFF() heaterLastOff = time.time() socketio.sleep(wait_time) else: if(heaterOn == True): heaterOn = False self.switchHeaterOFF() heaterLastOff = time.time() if(pumpRunning and heaterLastOff != 0 and (time.time() - heaterLastOff) > pumpWait): if(app.brewapp_switch_state[agitatorName] == False): pumpRunning = False switchOff(agitatorName)
def run_for_seconds(id, seconds): switchOn(id) socketio.sleep(seconds) switchOff(id)