file_suffix = '' file_prefix2 = "./Voltage_Current/" + date_str file_prefix3 = "./Pressure/" + date_str f = open(file_prefix + file_suffix + '_temps.txt', 'w') #open a new file to write the temperatures to g = open(file_prefix2 + file_suffix + '_VI.txt', 'w') p = open(file_prefix3 + file_suffix + '_press.txt', 'w') # Current time new_time = time.time() - start # Poll the new data new_temps = get_temps() new_press = get_press() _, new_volt, new_curr = read_power_supplies() power_labels = MonitorPlot.get_volt_labels() # Update the plot monitor_plot.update(new_time, new_temps, new_volt, new_curr, new_press) # Get shorthands for the data t = new_time y = monitor_plot.T_data volt_y = monitor_plot.V_data curr_y = monitor_plot.A_data press_y = monitor_plot.P_data press = new_press temps = new_temps volt = new_volt curr = new_curr
linestyle=lines[j / 7], linewidth=2, label=labels[k] + " " + str(y[419, j])[0:5] + "K") if i != 0: legend.get_texts()[k].set_text( labels[k] + " " + str(y[419, j])[0:5] + "K" ) #if it is not the first time ploting rewrite the legend with the new temps k = k + 1 if i == 0: #if it is the first time ploting generate the legend legend = plt.legend(ncol=2, loc=2) plt.xlim(x[0], x[419]) plt.ylim(0.1, 300) #grab voltages and current from power supplies power_labels, volt, curr = read_power_supplies() volt_y[419, :] = volt curr_y[419, :] = curr # plot the power levels plt.subplot(gs[2, :]) k = 0 for j in range(0, len(volt)): plt.plot(x, volt_y[:, j], color=colors[np.mod(j, 7)], linestyle=lines[j / 7], linewidth=2, label=power_labels[j] + " " + str(volt_y[419, j])[0:4] + "V " + str(curr_y[419, j])[0:6] + "A") if i != 0:
def main(): global start_time global count global dIdt while True: #Main is always looping new_time = time.time() - start_time #current time new_temps = get_temps() _, new_volt, new_curr = read_power_supplies() #monitor_plot.update(new_time, new_temps, new_volt, new_curr, [0]) dIdt, volt, targ, curr, Z = get_ami_data(ami) if count == -3: #make sure the 4He and 3He switches are off turn_off_3He_4He_switches(new_temps, ps) start_time = time.time() + sleep_time count = -2 new_time = time.time() - start_time while new_time < 0: #for haveing a delay in the start hang here until ready to heat 4He pump new_time = time.time() - start_time #current time new_temps = get_temps() _, new_volt, new_curr = read_power_supplies() monitor_plot.update(new_time, new_temps, new_volt, new_curr, [0], curr) writeToFile(volt, curr, L, dIdt, Z, new_temps) print_pretty(volt, curr, L, dIdt, Z, new_temps) if count == -2: #heat up the 4He pump turn_on_ADR_switch(ps) #turn on the ADR switch at the beginning print("Heating up 4He Pump") while new_time < 30 * 60: new_time = time.time() - start_time #current time new_temps = get_temps() _, new_volt, new_curr = read_power_supplies() monitor_plot.update(new_time, new_temps, new_volt, new_curr, [0], curr) heat_4He_pump(new_temps, ps) writeToFile(volt, curr, L, dIdt, Z, new_temps) print_pretty(volt, curr, L, dIdt, Z, new_temps) count = -1 if count == -1: #Heat up the 3He pump keep 4He pump hot print("Heating up 3He pump") while new_time < 50 * 60: new_time = time.time() - start_time #current time new_temps = get_temps() _, new_volt, new_curr = read_power_supplies() monitor_plot.update(new_time, new_temps, new_volt, new_curr, [0], curr) heat_4He_pump(new_temps, ps) heat_3He_pump(new_temps, ps) writeToFile(volt, curr, L, dIdt, Z, new_temps) print_pretty(volt, curr, L, dIdt, Z, new_temps) count = 0 if count == 0: #wait until ready to ramp up print("Waiting to ramp up") while check_start_ramp(new_temps): new_time = time.time() - start_time #current time new_temps = get_temps() _, new_volt, new_curr = read_power_supplies() monitor_plot.update(new_time, new_temps, new_volt, new_curr, [0], curr) heat_4He_pump(new_temps, ps) heat_3He_pump(new_temps, ps) writeToFile(volt, curr, L, dIdt, Z, new_temps) print_pretty(volt, curr, L, dIdt, Z, new_temps) count = 1 if count == 1: #start ramp up print("starting ramp up") new_temps = get_temps() if temp_safety_check( new_temps): #run a safety check on temps before ramping up pass else: print( "Did not pass tempearature safety before beginning ramp up exiting program" ) sys.exit() dIdt, volt, targ, curr, Z = get_ami_data(ami) if magnet_safety_check( dIdt, volt, targ, curr, Z ): #run a safety check on the magnet current and resistance pass else: print( "Did not pass magnet safety check before beginning ramp up exiting program" ) sys.exit() start_ramp_time = time.time() rampU(ami) #start the ramp up while (time.time() - start_ramp_time ) < 30 * 60: #20 mins to ramp and 10 mins for good measure new_time = time.time() - start_time #current time new_temps = get_temps() _, new_volt, new_curr = read_power_supplies() dIdt, volt, targ, curr, Z = get_ami_data(ami) monitor_plot.update(new_time, new_temps, new_volt, new_curr, [0], curr) heat_4He_pump(new_temps, ps) #keep pumps hot during ramp up heat_3He_pump(new_temps, ps) writeToFile(volt, curr, L, dIdt, Z, new_temps) print_pretty(volt, curr, L, dIdt, Z, new_temps) if temp_safety_check(new_temps): #temp safety check pass else: emergency_ramp_down(ami) count = 6 break if magnet_safety_check(dIdt, volt, targ, curr, Z): #magnet safety check pass else: emergency_ramp_down(ami) count = 6 break if count != 6: count = 2 if count == 2: # the magnet is energized time to sink the 4He pump: print("sinking 4He pump") new_temps = get_temps() while new_temps[ 7] > 5.0: #4He pump It might be better to trigger this when the 4He/3He gets below 2K because when the # 4He head is cold but the 3He pump is hot the 4He charge has to fight the conductino of the 3He hot pump to 4K # of course we don't want to sink them at teh same time # maybe don't sink it but stop heating it if the 4He and 3He heads are cold new_time = time.time() - start_time #current time new_temps = get_temps() _, new_volt, new_curr = read_power_supplies() dIdt, volt, targ, curr, Z = get_ami_data(ami) monitor_plot.update(new_time, new_temps, new_volt, new_curr, [0], curr) writeToFile(volt, curr, L, dIdt, Z, new_temps) print_pretty(volt, curr, L, dIdt, Z, new_temps) cool_4He_pump(new_temps, ps) heat_3He_pump(new_temps, ps) if temp_safety_check(new_temps): pass else: ps.change_voltage( 'He4 switch', 0 ) #turn off 4He switch so that the 4HE pump stop sinking and increassing the 4K plate temp emergency_ramp_down(ami) count = 6 break if magnet_safety_check(dIdt, volt, targ, curr, Z): pass else: ps.change_voltage( 'He4 switch', 0 ) #turn off 4He switch so that the 4HE pump stop sinking and increassing the 4K plate temp emergency_ramp_down(ami) count = 6 break if count != 6: count = 3 if count == 3: # the magnet is energized and the 4He pump is sunk, time to sink the 3He pump print("sinking 3He pump") new_temps = get_temps() while new_temps[8] > 4.5: #3He pump new_time = time.time() - start_time #current time new_temps = get_temps() _, new_volt, new_curr = read_power_supplies() dIdt, volt, targ, curr, Z = get_ami_data(ami) monitor_plot.update(new_time, new_temps, new_volt, new_curr, [0], curr) writeToFile(volt, curr, L, dIdt, Z, new_temps) print_pretty(volt, curr, L, dIdt, Z, new_temps) cool_3He_pump(new_temps, ps) if temp_safety_check(new_temps): pass else: ps.change_voltage( 'He3 switch', 0 ) #turn off 3He switch so that the 4HE pump stop sinking and increassing the 4K plate temp emergency_ramp_down(ami) count = 6 break if magnet_safety_check(dIdt, volt, targ, curr, Z): pass else: ps.change_voltage( 'He3 switch', 0 ) #turn off 3He switch so that the 4HE pump stop sinking and increassing the 4K plate temp emergency_ramp_down(ami) count = 6 break if count != 6: count = 4 if count == 4: # both 4H3 and 3He pumpu are sunk turn off the ADR switch print("Turning off ADR switch") turn_off_ADR_switch(ps) new_temps = get_temps() while new_temps[12] > 4.5: #adr switch new_time = time.time() - start_time #current time new_temps = get_temps() _, new_volt, new_curr = read_power_supplies() dIdt, volt, targ, curr, Z = get_ami_data(ami) monitor_plot.update(new_time, new_temps, new_volt, new_curr, [0], curr) writeToFile(volt, curr, L, dIdt, Z, new_temps) print_pretty(volt, curr, L, dIdt, Z, new_temps) if temp_safety_check(new_temps): pass else: emergency_ramp_down(ami) count = 6 break if magnet_safety_check(dIdt, volt, targ, curr, Z): pass else: emergency_ramp_down(ami) count = 6 break if count != 6: count = 5 if count == 5: # ADR switch is off start ramp down print("Starting ramp down") # do i need this #ami.write('CONF:CURR:TARG 0\n') #ami.write('CONF:RAMP:RATE:CURR 1,0.25,10\n') #ami.write('RAMP\n') dIdt_old = -0.25 / 60 #dIdt = -0.25/60 #time.sleep(5) print('Ramping down at -0.25 A/min.') dIdt, volt, targ, curr, Z = get_ami_data(ami) #start pid looping while curr > 0.001 and dont_stop: #stay here until the current is all depleted or stop() is called new_time = time.time() - start_time #current time listen_for_temp_interupt() new_temps = get_temps() _, new_volt, new_curr = read_power_supplies() dIdt, volt, targ, curr, Z = get_ami_data(ami) monitor_plot.update(new_time, new_temps, new_volt, new_curr, [0], curr) writeToFile(volt, curr, L, dIdt, Z, new_temps) print_pretty(volt, curr, L, dIdt, Z, new_temps) if running: #to allow for pausing if use_pid: pid.setpoint = np.float(temp) current_temp = new_temps[18] # print("") print(current_temp) print(pid.setpoint) dIdt_old = dIdt dIdt = pid(current_temp) # print(str(dIdt)[0:6]) # print(str(np.abs(dIdt))[0:6]) # print("") if dIdt > 0: # ami.write('CONF:CURR:TARG 1.5\n') # else: # ami.write('CONF:CURR:TARG 0\n') # ami.write('CONF:RAMP:RATE:CURR 1,' + str(np.abs(dIdt))[0:6] + ',10\n') # ami.write('RAMP\n') # if dIdt != dIdt_old: time.sleep( 5 ) #needs time to equilibrate before measure resistance else: temp_control(new_temps, ami, curr) if temp_safety_check(new_temps): pass else: emergency_ramp_down(ami) break if magnet_safety_check(dIdt, volt, targ, curr, Z): pass else: emergency_ramp_down(ami) break count = 6 # just make sure you ramp to zero when you are done ami.write('CONF:CURR:TARG 0\n') ami.write('CONF:RAMP:RATE:CURR 1,0.5,10\n') ami.write('RAMP\n') if count == 6: # just keep monitoring after the fact while True: new_time = time.time() - start_time #current time new_temps = get_temps() _, new_volt, new_curr = read_power_supplies() dIdt, volt, targ, curr, Z = get_ami_data(ami) monitor_plot.update(new_time, new_temps, new_volt, new_curr, [0], curr)