#Parameters """ FIELD = "Hx" START_FIELD = -0.1 ACQPOINTS = 100 ACQTIME_SECS = 60 ACQLIM = 'POINTS' ENERGIES = (707.90, 703.90) ENERGY_CHANGE_SLEEP = 2.0 MODE = 'CIRC +' OFFSET = -1.0 """ entry_time = time.time() iPS = False # false for old power supply, True for new (Oxford Instr) supply #close_shutter_at_zero = False # True to close shutter during B field scan when it is close to 0 T #signal_field_analog_x if iPS == True: caput('X07MA-ES1-IPS:RAMP-ENBL', 1) # enable non-overshoot mode FIELD_PRECISION = 0.01 if FIELD == field_z: FIELD = "Hz" field = field_z if FIELD == "Hz" else (field_x_ips if iPS else field_x ) field_done = field_z_done if FIELD == "Hz" else (None if iPS else field_x_done) ramp_rate = ramp_rate_z if FIELD == "Hz" else (ramp_rate_x_ips if iPS else ramp_rate_x) #Pre-actions #cawait('ACOAU-ACCU:OP-MODE', 'Light Available', type = 's') if NO_BEAM_CHECK == False: wait_beam() if MODE is not None: pol_mode.write(MODE) if OFFSET is not None: pol_offset.write(OFFSET) #caput('X07MA-ID:ENERGY-OFFS', OFFSET) #caputq('X07MA-PC:CSCALER.INPB', '1') # open shutter caput('X07MA-FE-PH1:CLOSE4BL',1) cawait('X07MA-FE-PH1:MS2', 1) print "OK" #if RAMP_RATE is not None: # ramp_rate.write(RAMP_RATE) # ramp_rate.waitInPosition(RAMP_RATE,10000) if len(ENERGIES) ==2: # dif_series = plot([],"Dif", get_context()="Dif")[0].getSeries(0) dif_series = plot([],"Dif")[0].getSeries(0) else: dif_series = None set_preference(Preference.ENABLED_PLOTS, ['field', 'tey_norm', 'ADC3','ADC4','ADC7','ADC6']) set_preference(Preference.PLOT_TYPES, {'tey_norm':1, 'ADC3':1, 'ADC4':1, 'ADC7':1, 'ADC6':1}) set_preference(Preference.DOMAIN_AXIS, 'Time') field_var = 'fieldAnalogZ' if (FIELD == "Hz") else 'fieldAnalogX' scan = ManualScan(['field', 'Energy'], ['TEY', 'I0', 'ADC3', 'polarization', 'polAngle', 'temperature', 'RingCurrent', \ field_var,'ADC4','ADC7','ADC6', 'tey_norm','trans_norm','Time'], [0.0, ENERGIES[0]], [0.0, ENERGIES[-1]], [0, len(ENERGIES)-1]) #scan = ManualScan(['field', 'Energy'], ['TEY', 'I0', 'trans', 'polarization', 'polAngle', 'temperature', 'RingCurrent', \ # field_var,'ESR_extrachannel', 'tey_norm','trans_norm', 'fieldX' ,'fieldZ'], [0.0, ENERGIES[0]], [0.0, ENERGIES[-1]], [0, len(ENERGIES)-1]) scan.start() write_logs() print "Waiting for start field" #if abs(field.readback.read() - START_FIELD) > FIELD_PRECISION: # enforce field setting here, i.e. it must be set if abs(caget('X07MA-PC-MAG:X:DMD') - START_FIELD) > 0.00001: time.sleep(1.0) ramp_rate.write(2.0) time.sleep(1.0) field.write(START_FIELD) if iPS == True: caput("X07MA-PC-MAG:X:DMD",float(START_FIELD)) if field_done is None: #ramp_rate.write(2.0) ramp_rate.waitInPosition(2.0,10000) time.sleep(1.0) caput("X07MA-ES1-IPS:ACTION", 1) time.sleep(3.0) wait_device_in_range(field, START_FIELD, FIELD_PRECISION) print "Waiting field done..." while caget("X07MA-ES1-IPS:OUTPUT_RBV", "i") != 0 : time.sleep(0.1) print "Done waiting" else: time.sleep(3.0) # wait_device(field_done, 1) #ramp_done.wait_for_value(1.0) ### this waiting procedure was introduced because sometimes the field does not move and the whole script gets stuck then. difference = field.readback.read() - START_FIELD difference0 = difference # difference0 is the field offset before entering the stabilization loop last_difference = difference # last_difference is updated during the stabilization loop while abs(difference) > FIELD_PRECISION: time.sleep(5.0) difference = field.readback.read() - START_FIELD # resend a start ramp in case nothing is happening, ie when it is stuck in this waitfield if abs(difference-difference0) < FIELD_PRECISION: caput('X07MA-PC-MAG:STARTRAMP.PROC',1) print('Field setting stuck: re-starting ramp') # also resend a start ramp in case nothing is happening wrt to the last 5 seconds elif abs(difference-last_difference) < FIELD_PRECISION: caput('X07MA-PC-MAG:STARTRAMP.PROC',1) print('Field setting stuck: re-starting ramp') last_difference = difference #open_valve(2.0) print "Set energy..." setpoint2 = ENERGIES[0] print setpoint2 energy.write(setpoint2) # 2022: comment out, since write apparantly already waits for it to finish #sleep( ENERGY_CHANGE_SLEEP ) # Settling time #wait_device(energy_done, 1 ) print "done energy" #wait_device(pol_done, "DONE") wait_pol_done(1.0) # 2022: new script to wait for polarization. Wait_device does not work for this channel print "done pol" #if WAIT_STABLE_TEMPERATURE == True: # wait_temp() #if RAMP_RATE is not None: # ramp_rate.write(RAMP_RATE) # ramp_rate.waitInPosition(RAMP_RATE,10000) #print "Set end field" #field.write(END_FIELD) #caputq('X07MA-PC-PS2:M:GO.A', END_FIELD) #if iPS == True: #caput("X07MA-PC-MAG:X:DMD",float(END_FIELD)) # buffer these values to increase speed pol_mode_buffer = float(pol_mode.getPositions().index(pol_mode.readback.read())) pol_angle_buffer = pol_angle.read() #polAngle.get() start_time = time.time() index = 0 while(True): #Dimension 2START_FIELD = -0.2 #ArrayPositioner Energy for setpoint2 in ENERGIES: if len (ENERGIES)>1: #Energy.put(setpoint2, timeout=None) # TODO: Set appropriate timeout energy.write(setpoint2) sleep( ENERGY_CHANGE_SLEEP ) # Settling time else: #pass #sleep( 0.25 ) # TODO: Check sleep( 0.3 ) # TODO: Check #TODO: change to Controlled variable? readback2 = energy_readback.read() #EnergyReadback.get() if abs(readback2 - setpoint2) > 0.1 : # TODO: Check accuracy # raise Exception('Energy could not be set to the value ' + str(setpoint2)) #print 'Energy could not be set to the value, try again. ' + str(setpoint2) energy.write(setpoint2) sleep( ENERGY_CHANGE_SLEEP ) # Settling time #while True: # if ABORT_ON_ID_ERROR == False, waits reading with no ID error #Detector field readback #field_readback = field.readback.read() #fieldReadback.get() field_readback = field.readback.read() detector1 = signal_tey.read() #TEY.get() detector2 = signal_i0.read() #I0.get() detector3 = signal_trans.read() #trans.get() detector4 = pol_mode_buffer #float(pol_mode.getPositions().index(pol_mode.readback.read())) #polarization.get() detector5 = pol_angle_buffer #pol_angle.read() #polAngle.get() detector6 = temperature.readback.read() #temperature.get() # once in a single time, there was an error in a script related to this command, namely # Error creating channel: ARIDI-PCT:CURRENT [current] in