215 lines
6.6 KiB
Python
215 lines
6.6 KiB
Python
#Debugging
|
|
if get_exec_pars().innerArgs is None:
|
|
E1 = 500
|
|
E2 = 600
|
|
|
|
TIME = 5 #min
|
|
DELAY = 0.0 #s
|
|
MODE = None #'LINEAR' #'CIRC +'
|
|
OFFSET = None
|
|
NAME = 'Circp'
|
|
ALPHA= None #0
|
|
|
|
|
|
|
|
print "\nStart energy scan..."
|
|
print E1,"eV ->",E2,"eV,",TIME,"min duration,",DELAY,"sec delay,",str(MODE),(str(ALPHA)+"deg") if (MODE=="LINEAR") else ""
|
|
|
|
set_exec_pars(reset=True, name= NAME,open=False)
|
|
|
|
|
|
|
|
#Pre-actions
|
|
|
|
#wait_beam() #
|
|
#wait_id_ok()
|
|
|
|
call_mscan=True
|
|
move_mono=True # if true, X-Tremeo runs, if false channel defiend under Ch runs
|
|
|
|
|
|
if move_mono == True:
|
|
set_pol(MODE, ALPHA, OFFSET)
|
|
set_energy_ma(float(E1))
|
|
caput(ma_energy_rbv.channelName+".N", 10) # set energy readback averaging to 10 pts
|
|
else:
|
|
print(' do not move mono ')
|
|
|
|
#Ch=Channel('X07MB-ES-MA1:TRZ1.VAL', name="Setpoint", monitored=True)
|
|
Ch=ChannelDouble('SETPOINT','X07MB-ES-MA1:TRZ1.VAL')
|
|
#Ch_rbv=Channel('X07MB-ES-MA1:TRZ1.RBV', name="Readback",monitored=True)
|
|
Ch_rbv=ChannelDouble('X07MB-ES-MA1:TRZ1.RBV','X07MB-ES-MA1:TRZ1.RBV')
|
|
Ch_rbv.monitored=True
|
|
Ch_rbv.initialize()
|
|
Ch.monitored=True
|
|
Ch.initialize()
|
|
|
|
E0=Ch_rbv.read()
|
|
E1=E0
|
|
E2=E0+.1
|
|
print(E0,E1,E2)
|
|
#E1=970
|
|
#E2=970
|
|
# endexcept
|
|
|
|
|
|
# next
|
|
if move_mono == True:
|
|
print "Setup OTF"
|
|
caput('E1', E1)
|
|
caput('E2', E2)
|
|
caput('TIME', TIME)
|
|
caput('FOLDER', "OTF/" + Setup.expandPath("OTF/{year}_{month}/{date}"))
|
|
caput('FILE', NAME)
|
|
#endif
|
|
time.sleep(max(DELAY, 0.1))
|
|
|
|
#Scan
|
|
print "Start OTF"
|
|
scan_completed = False
|
|
|
|
try:
|
|
while True:
|
|
if move_mono == True:
|
|
caput('START', '1')
|
|
else:
|
|
print('mono off')
|
|
#Ch.putq(E2) # if defin es as channel
|
|
Ch.write(E2) # if defines as ChannelDouble
|
|
#endif
|
|
waiting = True
|
|
|
|
|
|
class Time(Readable):
|
|
def __init__(self):
|
|
self.start = time.time()
|
|
def read(self):
|
|
return time.time()-self.start
|
|
tm = Time()
|
|
|
|
class norm_tey(Readable):
|
|
def read(self):
|
|
return float(ma_cadc1.take())/float(ma_cadc2.take())
|
|
#enddef
|
|
#enf class norm_tey
|
|
|
|
class norm_diode(Readable):
|
|
def read(self):
|
|
return float(ma_cadc3.take())/float(ma_cadc2.take())
|
|
#enddef
|
|
#enf class
|
|
|
|
#class norm_K2_I0(Readable):
|
|
# def read(self):
|
|
# return float(keith_2.take())/float(keith_3.take())
|
|
# #enddef
|
|
##enf class
|
|
|
|
#class norm_keithley(Readable):
|
|
# def read(self):
|
|
# return float(keith_2.take())/float(keith_1.take())
|
|
# #enddef
|
|
##enf class
|
|
|
|
# define channels for PGM paramters
|
|
|
|
#ID_ENERY_TAKE=ID_ENERGY.take()
|
|
#,ma_mono_m1_rbv,ma_mono_m2_rbv
|
|
if move_mono == True:
|
|
position=ma_energy_rbv
|
|
else:
|
|
position=Ch_rbv
|
|
|
|
snaps = (id_pol_mode, id_pol_angle,id_pol_offset,PH.ma_exitslit_rbv,ID_OFFSET,ES3_MF1_PRESSURE) #,ES1_userCalc1_T2)
|
|
diags = (current.cache) #Must use cache because mscan evensts are called from monitor callback tread (or else async=False). Sensors are automatically handled.
|
|
sensors = [position, ma_cadc1, ma_cadc2, ma_cadc3, ma_cadc4, ma_cadc5,norm_tey(), norm_diode()]#,ES1_userCalc1_T2]#, ID_ENERGY,ma_mono_m1_rbv,ma_mono_m2_rbv]
|
|
|
|
|
|
|
|
|
|
tm.setAlias("time")
|
|
ma_cadc1.setAlias("tey_raw")
|
|
ma_cadc2.setAlias("i0")
|
|
ma_cadc3.setAlias("diode_raw")
|
|
|
|
def monitoring_task():
|
|
global scan_completed
|
|
time.sleep(.1)
|
|
print('monitoring_task',move_mono)
|
|
|
|
if move_mono == True:
|
|
print('call wait channel')
|
|
wait_channel('START', 'STOP', type = 's')
|
|
print('after wait channel')
|
|
else:
|
|
#wait_channel(Ch_rbv.get_channel_name(), E2, range=0.02)
|
|
# something is strang with the waiting and comparing...
|
|
# progam explicitly
|
|
#wait_channel(Ch_rbv.name, E2, comparator=.02)
|
|
while abs(Ch_rbv.read()-E2)>0.02:
|
|
print('still waiting',Ch_rbv.read()-E2)
|
|
time.sleep(.1)
|
|
#print('after while ')
|
|
#print('WAIT for ',E2)
|
|
#Ch_rbv.waitValueInRange(E2, timeout=None, comparator=0.02) #todo: in next version
|
|
#Ch_rbv.waitValueInRange(E2, 0.01, -1)
|
|
#endif
|
|
|
|
scan_completed = True
|
|
print('Scan completed ')
|
|
get_exec_pars().currentScan.abort()
|
|
print('after abort in monitoring_task')
|
|
|
|
|
|
monitoring_future = fork(monitoring_task)[0]
|
|
|
|
print("Scanning...\n")
|
|
try:
|
|
if call_mscan==True:
|
|
print('call mscan ')
|
|
mscan( position, sensors, -1, None, \
|
|
range="auto",domain_axis=position.name, \
|
|
enabled_plots=["norm_tey", "norm_diode",ma_cadc1, ma_cadc3, ma_cadc2], \
|
|
snaps=snaps, diags=diags)
|
|
print('.....mscan done ')
|
|
else:
|
|
print('-------------------------------------')
|
|
print('DO NOT CALL mscan ')
|
|
print('-------------------------------------')
|
|
#endelse
|
|
finally:
|
|
if not scan_completed:
|
|
print('... cancel monitoring_future..')
|
|
monitoring_future.cancel(True)
|
|
print('monitoring is done',monitoring_future.isDone())
|
|
print "Finished Energy scan."
|
|
if after_sample(): #Repeat if id error and not ABORT_ON_ID_ERROR:
|
|
break
|
|
|
|
except: #n
|
|
if not scan_completed:
|
|
print sys.exc_info()
|
|
if move_mono == True:
|
|
print("Aborting...")
|
|
while caget('START') == 'START':
|
|
caput('START', '0')
|
|
time.sleep(0.1)
|
|
raise
|
|
#endif
|
|
#endexcept
|
|
print('-------DONE --------------')
|
|
# Finally, if mon is not use
|
|
# return to initial position
|
|
|
|
if move_mono == False:
|
|
time.sleep(1)
|
|
print('------- MOVING BACK FINISHED --------------')
|
|
Ch.write(E0)
|
|
while abs(Ch_rbv.read()-E0)>0.02:
|
|
print('Driving motor back ',Ch_rbv.read()-E0)
|
|
time.sleep(.1)
|
|
|
|
print('------- MOVING BACK FINISHED --------------')
|
|
time.sleep(2)
|
|
#endif
|