This commit is contained in:
gac-x11ma
2020-12-15 15:20:00 +01:00
parent caccd1e648
commit b707f89f2b
9 changed files with 277 additions and 210 deletions

View File

@@ -1,27 +1,59 @@
POL_IDS={ "Circ_Plus": 1, "Circ_Minus": 2, "Lin_Hor":3, "Lin_Ver": 4, "Lin": 5}
channel_id1_status=Channel("X11MA-ID1-USER:STATUS", 'i', monitored=True)
channel_id2_status=Channel("X11MA-ID2-USER:STATUS", 'i', monitored=True)
channel_id1_error=Channel("X11MA-ID1-USER:ERROR-SOURCE", 'i', monitored=True)
channel_id2_error=Channel("X11MA-ID2-USER:ERROR-SOURCE", 'i', monitored=True)
channel_id1_control=Channel("X11MA-ID1-GAP:SCTRL", 'i', monitored=True)
channel_id2_control=Channel("X11MA-ID2-GAP:SCTRL", 'i', monitored=True)
channel_ring_status=Channel("ACOAU-ACCU:OP-MODE", 'i', monitored=True)
def get_id_status(id):
# 0 = ok
# 1 = Warning
# 2 = Error
# 3 = Not available
if id<1 or id>2: raise Exception("Invalid id")
return caget("X11MA-ID1-USER:STATUS" if (id==1) else "X11MA-ID2-USER:STATUS")
def get_id_error(id):
# B0 (1) = PLC (Taper, Motor controller, Limitswitch....)
# B1 (2) = Encoders (cabel, not referenced)
# B2 (4) = FeedForward (PS off, PS defect, FF ausgeschaltet)
# B3 (8) = Operator COntrol
# B4 (16)= Moving Timeout (moving longer then 120 sec)
# B5 (32)= Interlock (Orbit, Temperature...)\
if id<1 or id>2:
raise Exception("Invalid id")
return caget("X11MA-ID1-USER:ERROR-SOURCE" if (id==1) else "X11MA-ID2-USER:ERROR-SOURCE")
return channel_id1_status.get() if (id==1) else channel_id2_status.get()
def get_id_error(id):
# B0 (1) = PLC (Taper, Motor controller, Limitswitch....)
# B1 (2) = Encoders (cabel, not referenced)
# B2 (4) = FeedForward (PS off, PS defect, FF ausgeschaltet)
# B3 (8) = Operator COntrol
# B4 (16)= Moving Timeout (moving longer then 120 sec)
# B5 (32)= Interlock (Orbit, Temperature...)\
if id<1 or id>2:
raise Exception("Invalid id")
return channel_id1_error.get() if (id==1)else channel_id2_error.get()
def get_id_control(id):
#0 = SLS control, 1 = experiment
if id<1 or id>2: raise Exception("Invalid id")
return channel_id1_control.get() if (id==1) else channel_id2_control.get()
def get_ring_status():
#ACOAU-ACCU:OP-MODE kann Werte zwischen 0 und 5 annehmen:
# rule from 24.8.04
#If (PCT beam current <0.09) -> State 0: "Machine Down"
#Else If (GUN Trigger OFF) -> State 1: "Inj. Stopped"
#Else If (INJ_MODE == Normal) -> State 2: "Accumulating."
#Else If !(reached Top-Up Current) -> State 3: "Accumulating"
#Else If (OP-READY == Wait) -> State 4: "Top-up ready"
#Else If (OFB off) -> State 5: "Light-Available" (former State 4)
#Else -> State 6: "Light Available" (former State 5)
return channel_ring_status.get()
def get_pol_as_string(pol):
for (k,v) in POL_IDS.items():
if v==pol:
return k
return "Unknown"
def get_id_pol(id, as_string=False):
@@ -49,10 +81,7 @@ def get_id_pol(id, as_string=False):
else:
ret = -1
if as_string:
for (k,v) in POL_IDS.items():
if v==ret:
return k
return "Unknown"
return get_pol_as_string(ret)
return ret
def get_alpha_id(id):
@@ -84,6 +113,9 @@ def put_id_pol(id, pol, alpha=None):
if id<1 or id>2:
raise Exception("Invalid id")
if get_dry_run():
return
mode_dev = id1_mode if (id==1) else id2_mode
alpha_dev = id1_alpha if (id==1) else id2_alpha
@@ -114,6 +146,9 @@ def put_id_pol(id, pol, alpha=None):
def tune_detune(active_id):
if get_dry_run():
return
offset_1 = float(get_setting("OFFSET_ID_1"))
offset_2 = float(get_setting("OFFSET_ID_2"))
@@ -196,6 +231,8 @@ def init_pol_switch(switching_type, sid = None, pol_id1=None, pol_id2=None):
else:
if _switching_id == "ID1_ID2":
put_id_pol(2, _switching_current_pol) #Force both IDs to same polarization
if get_dry_run():
return
wait_channel("X11PHS:alldone", 1)
@@ -216,10 +253,8 @@ def nextpol():
def switch_pol():
global _switching_type, _switching_active_id, _switching_current_pol, _switching_pol_id1, _switching_pol_id2, _switching_id
if DRY_RUN:
return
newpol=nextpol()
print "Switch pol: ", newpol
print "Switch pol: ", get_pol_as_string(newpol)
if _switching_id == "ID1":
put_id_pol(1,newpol)
elif _switching_id == "ID2":

View File

@@ -246,62 +246,24 @@ for dev in ["eiger", "id", "chopper", "LEEM2000", "diag"]:
###################################################################################################
#ID and Machine status
#Beamline and Machine status
###################################################################################################
def get_id_status(id):
# 0 = ok
# 1 = Warning
# 2 = Error
# 3 = Not available
if id<1 or id>2:
raise Exception("Invalid id")
return caget("X11MA-ID1-USER:STATUS" if (id==1) else "X11MA-ID2-USER:STATUS")
def get_id_error(id):
# B0 (1) = PLC (Taper, Motor controller, Limitswitch....)
# B1 (2) = Encoders (cabel, not referenced)
# B2 (4) = FeedForward (PS off, PS defect, FF ausgeschaltet)
# B3 (8) = Operator COntrol
# B4 (16)= Moving Timeout (moving longer then 120 sec)
# B5 (32)= Interlock (Orbit, Temperature...)\
if id<1 or id>2:
raise Exception("Invalid id")
return caget("X11MA-ID1-USER:ERROR-SOURCE" if (id==1) else "X11MA-ID2-USER:ERROR-SOURCE")
def get_id_control(id):
#0 = SLS control, 1 = experiment
if id<1 or id>2: raise Exception("Invalid id")
return caget("X11MA-ID1-GAP:SCTRL" if id==1 else "X11MA-ID2-GAP:SCTRL")
def get_ring_status():
#ACOAU-ACCU:OP-MODE kann Werte zwischen 0 und 5 annehmen:
# rule from 24.8.04
#If (PCT beam current <0.09) -> State 0: "Machine Down"
#Else If (GUN Trigger OFF) -> State 1: "Inj. Stopped"
#Else If (INJ_MODE == Normal) -> State 2: "Accumulating."
#Else If !(reached Top-Up Current) -> State 3: "Accumulating"
#Else If (OP-READY == Wait) -> State 4: "Top-up ready"
#Else If (OFB off) -> State 5: "Light-Available" (former State 4)
#Else -> State 6: "Light Available" (former State 5)
return caget("ACOAU-ACCU:OP-MODE", 'i')
def assert_machine_ok(wait = True):
print "Checking machine..."
ID1status=get_id_control(1)
ID2status=get_id_control(2)
Ringstatus=get_ring_status()
oldRingstatus=Ringstatus
if get_dry_run():
return
ring_status=get_ring_status()
old_ring_status=ring_status
checkRing=0
if Ringstatus==5:
if ring_status==5:
log ("FB off")
#checkRing=1
if Ringstatus==0:
if ring_status==0:
log ("Machine down")
checkRing=2
@@ -309,83 +271,76 @@ def assert_machine_ok(wait = True):
status=False
while not status:
ID1status=get_id_control(1)
ID2status=get_id_control(2)
Ringstatus=get_ring_status()
if oldRingstatus != Ringstatus:
if Ringstatus == 0:
id1_status=get_id_control(1)
id2_status=get_id_control(2)
ring_status=get_ring_status()
if old_ring_status != ring_status:
if ring_status == 0:
log("Machine down")
checkRing=2
oldRingstatus=Ringstatus
elif Ringstatus == 1:
elif ring_status == 1:
log("Inj. Stopped")
checkRing=2
oldRingstatus=Ringstatus
elif Ringstatus == 2:
elif ring_status == 2:
log("Accumulating.")
checkRing=2
oldRingstatus=Ringstatus
elif Ringstatus == 3:
elif ring_status == 3:
log("Accumulating")
checkRing=2
oldRingstatus=Ringstatus
elif Ringstatus == 4:
elif ring_status == 4:
log("Top-up ready, Gap still open")
checkRing=2
oldRingstatus=Ringstatus
elif Ringstatus == 5:
elif ring_status == 5:
log("Light-Available, no OFB")
checkRing=2
oldRingstatus=Ringstatus
elif Ringstatus == 6:
elif ring_status == 6:
log("Light Available")
checkRing=2
oldRingstatus=Ringstatus
status= (Ringstatus ==6) and (ID1status==1) and (ID2status==1)
old_ring_status=ring_status
status= (ring_status ==6) and (id1_status==1) and (id2_status==1)
if not wait:
raise Exception ("Ring error: " + str(Ringstatus))
raise Exception ("Ring error: " + str(ring_status))
time.sleep(1)
if checkRing==2:
log("wait 120 s")
time.sleep(120)
log("continue")
elif checkRing==2:
log("wait 10 s")
time.sleep(10)
log("continue")
print "Machine ok"
def assert_bemline_ok():
def assert_beamline_ok():
print "Checking beamline..."
if get_dry_run():
return
checkbeamline=0
message=[ "PLC error","Encoder error", "Feedforward error","Operator control", "Moving timeout", "Interlock"]
ID = get_setting("ID")
if ID == "ID1":
ID1status=get_id_status(1)
ID2status=0
id1_status=get_id_status(1)
id2_status=0
elif ID == "ID2":
ID1status=0
ID2status=get_id_status(2)
id1_status=0
id2_status=get_id_status(2)
if ID == "ID1_ID2":
ID1status=get_id_status(1)
ID2status=get_id_status(2)
if ID1status >= 1:
ID1error=get_id_error(1)
id1_status=get_id_status(1)
id2_status=get_id_status(2)
if id1_status >= 1:
id1_error=get_id_error(1)
for bit in range (5,-1, -1):
if ID1error & (2**bit):
if id1_error & (2**bit):
log ("ID1 "+ str(message[bit]))
ID1error=ID1error-(2**bit)
if ID2status >= 1:
ID2error=get_id_error(2)
id1_error=id1_error-(2**bit)
if id2_status >= 1:
id2_error=get_id_error(2)
for bit in range (5,-1, -1):
if ID2error & (2**bit):
if id2_error & (2**bit):
log ("ID2 "+ str(message[bit]))
ID2error=ID2error-(2**bit)
if ID1status >= 1:
raise Exception("ID1 error")
if ID2status >= 1:
raise Exception("ID2 error")
id2_error=id2_error-(2**bit)
if id1_status >= 1:
raise Exception("ID1 error: " + str(id1_status))
if id2_status >= 1:
raise Exception("ID2 error: "+ str(id2_status))
def assert_status_ok(wait = True):
assert_machine_ok(wait)
assert_beamline_ok()
###################################################################################################
#Manual log file
@@ -438,7 +393,7 @@ def change_energy(v):
if v<91 or v>2500:
raise Exception ("Invalid energy: " + str(v))
print "Setting energy: " + str(v)
if DRY_RUN:
if get_dry_run():
return
put_energy(v)

View File

@@ -1,17 +1,19 @@
#If running from editor
if get_exec_pars().source == CommandSource.ui:
METHOD = "Two_Pol"
SWITCHING = "Tune_Detune"
SEQUENCE = "A"
MEASUREMENTS = 4
AUTO_SAVE = True
EXPOSURE = 1.0
AVERAGE = 2.0
ENERGY_1 = 850.0
ENERGY_2= 900.0
SWITCH_POL=False
#SEQUENCE = "A": C+,C-,C-,C+,C+;C-,C-,C+,
#SEQUENCE = "B": C+,C-,C+,C-,C+,-;C+,C-.
SHOW_IMAGES = True
SAVE_DIAGS = True
@@ -68,32 +70,12 @@ def getLEEM():
LEEMtemp=getLEEMtemp()
"""
def assert_status_ok():
if DRY_RUN: return
assert_machine_ok()
#assert_beamline_ok()
"""
getbeamline
getLEEM
Rem check status of machine
If checkRing = 3 Then
Close
Exit Sub
End If
Rem check status of the beamline
If checkbeamline = 3 Then
Close
Exit Sub
"""
#Initialize vartiables
#Initialize vartiables
if not get_dry_run() and str(get_setting("AUTO_SWITCH_VALVE")).lower() == "true":
open_vg10()
#rbkEnergy=energy_rbk.read()
#rbkEnergy=energy_rbk.read()
if METHOD == "Two_Pol" or (SWITCH_POL and (METHOD == "Take_Image")):
init_pol_switch(SWITCHING)
@@ -112,21 +94,21 @@ def save_image_file(frame, cycle=-1, frame_index=0):
print filename
# log("SV:"+Format(startvoltage,"0.000")+" OB:"+Format(objective,"0.00")+" ST:"+Format(LEEMtemp,"0.0"))
init_eiger(exposure=EXPOSURE)
#print "Startup time: " + str(time.time() - start)
try:
#Do the measurement loop
for cycle in range(1, MEASUREMENTS + 1):
frames = []
if MEASUREMENTS > 1:
if MEASUREMENTS > 1:
log("nround = " + str(cycle) + " / " + str(MEASUREMENTS))
if METHOD == "Two_Energies":
for i in range(2):
for i in range(2):
if (cycle == 1) or (METHOD != "Take_Image"):
assert_status_ok()
if METHOD == "Two_Energies":
change_energy(ENERGY[i])
print "--- Grabing " + str(AVERAGE)+ " frames - cycle: " + str(cycle) + " step: " + str(i)
#s=time.time()
@@ -137,21 +119,19 @@ try:
save_image_file(frames[i], cycle, i)
if METHOD == "Take_Image":
break
if METHOD == "Two_Pol":
print "--- Switching polatization..."
switch_pol()
if METHOD == "Two_Energies":
break
if METHOD == "Two_Pol":
if (i==0) or (SEQUENCE == "B"):
switch_pol()
#time.sleep(1)
if (METHOD == "Two_Pol") or (METHOD == "Two_Energies"):
if (METHOD == "Two_Energies") or (get_cur_pol() in (2,3)):
if (METHOD == "Two_Pol") or (METHOD == "Two_Energies"):
if (METHOD == "Two_Energies") or (SEQUENCE == "B") or ((cycle%2)==1):
#print "Divide first frame by second"
frames.append(frames[0].copy())
frames[2].div(frames[1])
else:
#print "Divide second frame by first"
frames.append(frames[1].copy())
frames[2].div(frames[0])
@@ -187,11 +167,33 @@ try:
integration = ip
else:
integration =integrate_ips ([integration, ip], as_float=True)
av=op_const(integration, "divide", float(MEASUREMENTS), in_place=True)
av=op_const(integration, "divide", float(MEASUREMENTS), in_place=True)
save_image_file(av, -1, i)
if SWITCH_POL and (METHOD == "Take_Image"):
switch_pol()
SWITCH_POL = False
set_exec_pars(then_success="run('templates/Eiger2Img')")
"""
get_context().incrementDaySequentialNumber()
set_exec_pars(open=False)
set_exec_pars(open=True)
for cycle in range(1, MEASUREMENTS + 1):
frames = []
if MEASUREMENTS > 1:
log("nround = " + str(cycle) + " / " + str(MEASUREMENTS))
print "--- Grabing " + str(AVERAGE)+ " frames - cycle: " + str(cycle) + " step: " + str(i)
av = average_eiger_frames(AVERAGE, roi=None, wait_next=True)
imageinfo("I")
save_image_file(av, cycle, i)
"""
finally:
for i in range(max_index):
get_context().incrementDaySequentialNumber()
get_context().incrementDaySequentialNumber()
if not get_dry_run() and str(get_setting("AUTO_SWITCH_VALVE")).lower() == "true":
close_vg10()
restore_eiger()

View File

@@ -10,7 +10,6 @@ if get_exec_pars().source == CommandSource.ui:
NUMBER_SCANS =1
RANGES = [[500.0, 1000.0, 100.0]]
DRY_RUN = get_dry_run()
SAVE_DIAGS = True
if SWITCH_POL:
@@ -44,7 +43,7 @@ frames=[]
class SyncEnergy(Writable):
def write(self,pos):
if not DRY_RUN:
if not get_dry_run():
put_energy(pos)
else:
print "Energy=" + str(pos)
@@ -82,7 +81,7 @@ set_device_alias(averager, "Image") #Set display name
sensors.append(averager) #sensors.append(eiger.getDataMatrix())
#Initialize vartiables
if not DRY_RUN and str(get_setting("AUTO_SWITCH_VALVE")).lower() == "true":
if not get_dry_run() and str(get_setting("AUTO_SWITCH_VALVE")).lower() == "true":
open_vg10()
#put_id_offset(1, OFFSET_ID_1) #offset on ID1
@@ -120,7 +119,7 @@ finally:
if AVERAGE>1:
for i in range(len(rois)):
rois[i].parent.monitored = False # Remove listeners on the image
if not DRY_RUN and str(get_setting("AUTO_SWITCH_VALVE")).lower() == "true":
if not get_dry_run() and str(get_setting("AUTO_SWITCH_VALVE")).lower() == "true":
close_vg10()
restore_eiger()
print "Running time: " + str(time.time() - start)

View File

@@ -32,7 +32,7 @@ init_eiger(EXPOSURE_TIME)
try:
lscan(objective, sensors, SCAN_RANGE[0], SCAN_RANGE[1], float(STEP_SIZE), latency=SETTLING_TIME, before_read=trigger_eiger, keep=False)
finally:
if not DRY_RUN and str(get_setting("AUTO_SWITCH_VALVE")).lower() == "true":
if not get_dry_run() and str(get_setting("AUTO_SWITCH_VALVE")).lower() == "true":
close_vg10()
restore_eiger()
print "Running time: " + str(time.time() - start)