def main(): #global instruments global master global Heater master = setup() motor = motorSetup_mtk.motorConfig() motor.setPIDhalfSpeed(master) #motor.setPIDfullSpeed(instruments) #motor.setPIDincfullSpeed(instruments) Heater = heaterSetup_mtk.HeaterConfig() #initizalize class instance Heater.setTempLimit(master) Heater.setTcOffset(master) Heater.setColdJunction(master) Heater.setTcFilter(master) Heater.setPid(master, Heater.RpidReg, 9, Heater.Rpid) Heater.setPid(master, Heater.MpidReg, 9, Heater.Mpid) Heater.setPid(master, Heater.FpidReg, 9, Heater.Fpid) Heater.setPid(master, Heater.UpGratepidReg, 9, Heater.UpGratepid) Heater.setPid(master, Heater.LoGratepidReg, 9, Heater.LoGratepid) homing_mtk.goHome(master, 1) motor.setPIDfullSpeed(master) setpoint_wp.movePlaten(master, CookProfile.hoodHeight) currentTime = 0 rearTemp, midTemp, frontTemp, UpGrateTemp, LoGrateTemp = readTemp() button = 1 while True: print "\n " print "Press %r to start new cycle cook time: %rs RearSP:%r dC MidSP:%r dC" % ( CookProfile.KeyControl, CookProfile.cookTime, Heater.TemperatureSP[0], Heater.TemperatureSP[2]) done = False while not done: Heater.setTemp(master) RearPV, MiddlePV, FrontPV, UpGratePV, LoGratePV = readTemp() rearTemp, midTemp = dMod(master, rearTemp, midTemp, RearPV, MiddlePV, FrontPV) UpGrateTemp, LoGrateTemp = dModGrate(master, UpGrateTemp, LoGrateTemp, UpGratePV, LoGratePV) button = master.execute(1,cst.READ_COILS,2,1) #(id, cst.WRITE_SINGLE_COIL, 35, output_value=state) #(slave,function,address,output) button = button[0] done = keyScan(1,button,1,1) if msvcrt.kbhit(): Key = msvcrt.getch() done = keyScan(2,1,Key,CookProfile.KeyControl) #moving platen to setpoint setpoint_wp.movePlaten(master, CookProfile.stage1) filename = strftime(CookProfile.file_name, time.localtime()) f = open(filename, "w") f.write("\n") f.write("\n") f.write(strftime("Time:%a, %Y%b%d %H:%M:%S\n", time.localtime())) f.write("\n") f.write("---------------------Cooking Profile------------------\n") f.write("\n") f.write("Cooktime:%r s RearSP: %r dC MidSP:%r dC \n" % ( CookProfile.cookTime, Heater.TemperatureSP[0], Heater.TemperatureSP[2])) f.write("------------------------------------------------------\n") f.write("----Logged Data(Time-RearTemp,MiddleTmp,FrontTemp-----\n") f.write("------------------------------------------------------\n") gflag = 0 flag = 0 for x in range(0, 3): winsound.Beep(1000, 200) time.sleep(0.1) startTime = time.time() done = False while timeCal(startTime) < CookProfile.cookTime: if currentTime != int(timeCal(startTime)): currentTime = int(timeCal(startTime)) RearPV, MiddlePV, FrontPV, UpGratePV, LoGratePV = readTemp() f.write("%r,%r,%r,%r,%r,%r\n" % (currentTime, RearPV, MiddlePV, FrontPV, UpGratePV, LoGratePV)) print "Rear heater: %r, Mid heater: %r, Front heater: %r, time: %r s\n" % ( RearPV, MiddlePV, FrontPV, CookProfile.cookTime - currentTime) if done: break if timeCal(startTime) > CookProfile.gapTime and gflag == 0: gflag = 1 #moving platen to setpoint setpoint_wp.movePlaten(master, CookProfile.stage2) if timeCal(startTime) > CookProfile.cookTime - 6 and flag == 0: flag = 1 for x in range(0, 2): winsound.Beep(1000, 200) time.sleep(0.1) button = master.execute(1,cst.READ_COILS,2,1) #(slave,function,address,output) button = button[0] done = keyScan(1,button,1,1) RearPV, MiddlePV, FrontPV, UpGratePV, LoGratePV = readTemp() rearTemp, midTemp = dMod(master, rearTemp, midTemp, RearPV, MiddlePV, FrontPV) UpGrateTemp, LoGrateTemp = dModGrate(master, UpGrateTemp, LoGrateTemp, UpGratePV, LoGratePV) #f.write("%r,%r,%r,%r,%r,%r\n" % (currentTime, RearPV, MiddlePV, FrontPV, UpGratePV, LoGratePV)) winsound.Beep(1000, 1000) f.close() #moving platen to setpoint setpoint_wp.movePlaten(master, CookProfile.hoodHeight)
def main(): global master global cookInfo global Heater #load settings from file cooker = CookProfile() with open('cookProfile.csv', 'rb') as cook: reader = csv.reader(cook) for cookInfo in reader: x = 1 cook.close() cooker.setProfile(cookInfo) print "Load cookProfile.csv...Completed" master = setup() Heater = heaterSetup_mtk.HeaterConfig() # initizalize class instance Heater.setTempLimit(master) Heater.setTcOffset(master) Heater.setColdJunction(master) Heater.setTcFilter(master) Heater.setPid(master, Heater.RpidReg, 9, Heater.Rpid) Heater.setPid(master, Heater.MpidReg, 9, Heater.Mpid) Heater.setPid(master, Heater.FpidReg, 9, Heater.Fpid) Heater.setPid(master, Heater.UpGratepidReg, 9, Heater.UpGratepid) Heater.setPid(master, Heater.LoGratepidReg, 9, Heater.LoGratepid) currentTime = 0 rearTemp, midTemp, frontTemp, UpGrateTemp, LoGrateTemp = readTemp() button = 1 while True: print "\n " print "Press %r to start | Cook time:%rs Platen Time:%rs RearSP:%r dC MidSP:%r dC" % ( cooker.KeyControl, cooker.cookTime, cooker.platenTime, Heater.TemperatureSP[0], Heater.TemperatureSP[2]) done = False while not done: Heater.setTemp(master) RearPV, MiddlePV, FrontPV, UpGratePV, LoGratePV = readTemp() rearTemp, midTemp = dMod(master, rearTemp, midTemp, RearPV, MiddlePV, FrontPV) UpGrateTemp, LoGrateTemp = dModGrate(master, UpGrateTemp, LoGrateTemp, UpGratePV, LoGratePV) button = master.execute(1, cst.READ_COILS, 2, 1) # (slave,function,address,output) button = button[0] done = keyScan(1, 15, button, 1, 1) if msvcrt.kbhit(): Key = msvcrt.getch() done = keyScan(2, 15, 1, Key, cooker.KeyControl) openName = cooker.file_name + strftime("%Y%b%d_%H.%M.%S", time.localtime()) + ".csv" with open(openName, 'w') as log: fieldInfo = ('StartTime', 'CookTime', 'PlatenTime', 'CookZone', 'RearSP', 'MidSP', 'FrontSP', 'RearPID', 'MidPID', 'FrontPID') targetInfo = csv.DictWriter(log, delimiter=',', lineterminator='\n', fieldnames=fieldInfo) Infoheaders = dict((n, n) for n in fieldInfo) targetInfo.writerow(Infoheaders) targetInfo.writerow({ 'StartTime': strftime("Time: %Y %b %d %H:%M:%S", time.localtime()), 'CookTime': cooker.cookTime, 'PlatenTime': cooker.platenTime, 'CookZone': cooker.cookZone, 'RearSP': Heater.TemperatureSP[0], 'MidSP': Heater.TemperatureSP[2], 'FrontSP': Heater.TemperatureSP[4], 'RearPID': Heater.Rpid, 'MidPID': Heater.Mpid, 'FrontPID': Heater.Fpid }) fieldnames = ('Time', 'RearTemp', 'MiddleTemp', 'FrontTemp', 'UpGrate', 'LoGrate', 'RearPWM', 'UpPWM', 'MiddlePWM', 'LoPWM', 'FrontPWM') targetWriter = csv.DictWriter(log, delimiter=',', lineterminator='\n', fieldnames=fieldnames) headers = dict((n, n) for n in fieldnames) targetWriter.writerow(headers) flag = 0 for x in range(0, 3): winsound.Beep(1000, 200) time.sleep(0.1) startTime = time.time() done = False while timeCal(startTime) < cooker.totalTime: if currentTime != int(timeCal(startTime)): currentTime = int(timeCal(startTime)) RearPV, MiddlePV, FrontPV, UpGratePV, LoGratePV = readTemp( ) pwm = Heater.readPWM(master) targetWriter.writerow({ 'Time': currentTime, 'RearTemp': RearPV, 'MiddleTemp': MiddlePV, 'FrontTemp': FrontPV, 'UpGrate': UpGratePV, 'LoGrate': LoGratePV, 'RearPWM': pwm[0], 'UpPWM': pwm[1], 'MiddlePWM': pwm[2], 'LoPWM': pwm[3], 'FrontPWM': pwm[4] }) print "Rear heater: %r, Mid heater: %r, Front heater: %r, time: %r s\n" % ( RearPV, MiddlePV, FrontPV, cooker.totalTime - currentTime) if done: break if timeCal(startTime) > cooker.totalTime - 6 and flag == 0: flag = 1 for x in range(0, 2): winsound.Beep(1000, 200) time.sleep(0.1) button = master.execute(1, cst.READ_COILS, 2, 1) # (slave,function,address,output) button = button[0] done = keyScan(1, int(timeCal(startTime)), button, 1, 1) RearPV, MiddlePV, FrontPV, UpGratePV, LoGratePV = readTemp() rearTemp, midTemp = dMod(master, rearTemp, midTemp, RearPV, MiddlePV, FrontPV) UpGrateTemp, LoGrateTemp = dModGrate(master, UpGrateTemp, LoGrateTemp, UpGratePV, LoGratePV) log.close() winsound.Beep(1000, 1000)
def main(): global master global cookInfo global Heater #load settings from file cooker = CookProfile() with open('cookProfile.csv', 'rb') as cook: reader = csv.reader(cook) for cookInfo in reader: x = 1 cook.close() cooker.setProfile(cookInfo) print "Load cookProfile.csv...Completed" master = setup() motor = motorSetup_mtk.motorConfig() motor.setPIDhalfSpeed(master) Heater = heaterSetup_mtk.HeaterConfig() # initizalize class instance Heater.setTempLimit(master) Heater.setTcOffset(master) Heater.setColdJunction(master) Heater.setTcFilter(master) Heater.setPid(master, Heater.RpidReg, 9, Heater.Rpid) Heater.setPid(master, Heater.MpidReg, 9, Heater.Mpid) Heater.setPid(master, Heater.FpidReg, 9, Heater.Fpid) Heater.setPid(master, Heater.UpGratepidReg, 9, Heater.UpGratepid) Heater.setPid(master, Heater.LoGratepidReg, 9, Heater.LoGratepid) homing_mtk.goHome(master, 1) motor.setPIDfullSpeed(master) setpoint_wp.movePlaten(master, cooker.hoodHeight) currentTime = 0 rearTemp, midTemp, frontTemp, UpGrateTemp, LoGrateTemp = readTemp() button = 1 while True: print "\n " print "Press %r to start | Cook time:%rs Platen Time:%rs RearSP:%r dC MidSP:%r dC" % ( cooker.KeyControl, cooker.cookTime, cooker.platenTime, Heater.TemperatureSP[0], Heater.TemperatureSP[2]) done = False while not done: Heater.setTemp(master) RearPV, MiddlePV, FrontPV, UpGratePV, LoGratePV = readTemp() rearTemp, midTemp = dMod(master, rearTemp, midTemp, RearPV, MiddlePV, FrontPV) UpGrateTemp, LoGrateTemp = dModGrate(master, UpGrateTemp, LoGrateTemp, UpGratePV, LoGratePV) button = master.execute(1, cst.READ_COILS, 2, 1) # (slave,function,address,output) button = button[0] done = keyScan(1, 15, button, 1, 1) if msvcrt.kbhit(): Key = msvcrt.getch() done = keyScan(2, 15, 1, Key, cooker.KeyControl) # moving platen to setpoint setpoint_wp.movePlaten(master, cooker.cookZone) openName = cooker.file_name + strftime("%Y%b%d_%H.%M.%S", time.localtime()) + ".csv" with open(openName, 'w') as log: fieldInfo = ( 'StartTime', 'CookTime', 'PlatenTime', 'CookZone', 'RearSP', 'MidSP', 'FrontSP', 'RearPID', 'MidPID', 'FrontPID') targetInfo = csv.DictWriter(log, delimiter=',', lineterminator='\n', fieldnames=fieldInfo) Infoheaders = dict((n, n) for n in fieldInfo) targetInfo.writerow(Infoheaders) targetInfo.writerow( {'StartTime': strftime("Time: %Y %b %d %H:%M:%S", time.localtime()), 'CookTime': cooker.cookTime, 'PlatenTime': cooker.platenTime, 'CookZone': cooker.cookZone, 'RearSP': Heater.TemperatureSP[0], 'MidSP': Heater.TemperatureSP[2], 'FrontSP': Heater.TemperatureSP[4], 'RearPID': Heater.Rpid, 'MidPID': Heater.Mpid, 'FrontPID': Heater.Fpid}) fieldnames = ( 'Time', 'RearTemp', 'MiddleTemp', 'FrontTemp', 'UpGrate', 'LoGrate', 'RearPWM', 'UpPWM', 'MiddlePWM', 'LoPWM', 'FrontPWM') targetWriter = csv.DictWriter(log, delimiter=',', lineterminator='\n', fieldnames=fieldnames) headers = dict((n, n) for n in fieldnames) targetWriter.writerow(headers) flag = 0 for x in range(0, 3): winsound.Beep(1000, 200) time.sleep(0.1) startTime = time.time() done = False while timeCal(startTime) < cooker.totalTime: if currentTime != int(timeCal(startTime)): currentTime = int(timeCal(startTime)) RearPV, MiddlePV, FrontPV, UpGratePV, LoGratePV = readTemp() pwm = Heater.readPWM(master) targetWriter.writerow( {'Time': currentTime, 'RearTemp': RearPV, 'MiddleTemp': MiddlePV, 'FrontTemp': FrontPV, 'UpGrate': UpGratePV, 'LoGrate': LoGratePV, 'RearPWM': pwm[0], 'UpPWM': pwm[1], 'MiddlePWM': pwm[2], 'LoPWM': pwm[3], 'FrontPWM': pwm[4]}) print "Rear heater: %r, Mid heater: %r, Front heater: %r, time: %r s\n" % ( RearPV, MiddlePV, FrontPV, cooker.totalTime - currentTime) if done: break if timeCal(startTime) > cooker.totalTime - 6 and flag == 0: flag = 1 for x in range(0, 2): winsound.Beep(1000, 200) time.sleep(0.1) button = master.execute(1, cst.READ_COILS, 2, 1) # (slave,function,address,output) button = button[0] done = keyScan(1, int(timeCal(startTime)), button, 1, 1) RearPV, MiddlePV, FrontPV, UpGratePV, LoGratePV = readTemp() rearTemp, midTemp = dMod(master, rearTemp, midTemp, RearPV, MiddlePV, FrontPV) UpGrateTemp, LoGrateTemp = dModGrate(master, UpGrateTemp, LoGrateTemp, UpGratePV, LoGratePV) log.close() winsound.Beep(1000, 1000) # moving platen to setpoint setpoint_wp.movePlaten(master, cooker.hoodHeight)