#%TITLE% HUTCHTRIGGER.MAC
#%NAME%
# Macro for the hutch trigger for the framework.
# Hutch Trigger Operation for MX beamlines
#
#%OVERVIEW%
# The procedures are designed to prepare the experimental hutch for when the
#user is inside and to restore the state ready for data collection afterwards.
#
# The macro can be triggered manually or automatically depending on the safety
# shutter status.
#
# If the user enters the hutch:
#
# 1. The fluorescence detector is taken out (if exists)
# 2. The zoom is brought to its minimum value.
# 3. The light is set to the value for the minimum zoom.
# 4. The detector is moved back if less than non-encomberant distance from
# the sample
# 5. The beamstop is moved to the down position.
#
# If the user leaves the hutch:
# 1. The light is brought down.
# 2. The light intensity is set to 0 to increase bulb life.
# 3. The detector is moved back to the original position if it was closer than
# than the user defined non-encomberant distance from the sample.
# 4. The backstop is moved up into the position for data collection.
#
# Moves are done in parallel where possible to save time. If there is no detector distance
# motor given the default is xtod. The other motor names are standard and therefore
# there is no setup for them.
# Beamstop is bstopz
#
# This procedures depends on standard commands:
# fldetout - moves the fluorescence detector out.
# lightout - moves the illumination column out of the way.
# BACKS_POS - an associative array containing the in/out back stop positions.
#%END%
global HUTCH_TRIGGER_MESSAGE HUTCH_DETPOS
#%IU%
#%MDESC%
# For setting up the hutchtrigger. Allows different detector distance names
# and different distances which depend on the beamline setup.
#
def hutchtriggersetup '{
local llim hlim
global HUTCH_DETMOTNUM HUTCH_DETDIST HUTCH_DETMOT HUTCH_TRIGGER_STATUS
global HUTCH_TRIGGER_MESSAGE HUTCH_UDIFF HUTCH_MINDIST
if (!HUTCH_TRIGGER_MESSAGE)
HUTCH_TRIGGER_MESSAGE = "Not configured"
if ($#) {
HUTCH_DETMOT = "$1"
HUTCH_DETMOTNUM = motor_num(HUTCH_DETMOT)
HUTCH_DETDIST = $2
HUTCH_UDIFF = $3
} else {
HUTCH_DETMOT = getval ("Detector distance motor mnemonic",HUTCH_DETMOT)
HUTCH_DETMOTNUM = motor_num(HUTCH_DETMOT)
HUTCH_DETDIST = getval("Non-encombering detector distance from the sample [mm](e.g 400))",HUTCH_DETDIST)
HUTCH_UDIFF = yesno("Are you using the microdiff?",0)
}
if (HUTCH_DETMOTNUM == -1) {
eprintf ("Detector distance motor %s is not configured in spec, ")
eprintf ("please change the name\n", HUTCH_DETMOT)
exit
}
llim = get_lim(HUTCH_DETMOTNUM,-1)
hlim = get_lim(HUTCH_DETMOTNUM,1)
if (HUTCH_DETDIST < llim || HUTCH_DETDIST > hlim) {
HUTCH_DETDIST = (llim + hlim)/2
printf ("Cannot set the arbitrary distance outside the software limits, ")
printf ("setting it to %f\n", HUTCH_DETDIST)
}
if (HUTCH_TRIGGER_MESSAGE == "Not configured")
HUTCH_TRIGGER_MESSAGE = "Configured"
if (HUTCH_UDIFF==0) {
rdef microdiff_phase() \'\'
} else {
if (ismacro("_backout")==0) {
rdef _backout() \'\'
}
if (ismacro("_backin")==0) {
rdef _backin() \'\'
}
}
if (ismacro("flightoff")==0) {
rdef flightoff() \'\'
}
if (ismacro("flighton")==0) {
rdef flighton() \'\'
}
}'
#%IU%
#%MDESC%
# If the macro is aborted a message is sent to the GUI
# A sleep of 1 second is included to give the user time to see the message.
# No motor positions are restored.
#
def hutchtrigger_cleanup '{
HUTCH_TRIGGER_MESSAGE = "Aborted"
sleep(1)
HUTCH_TRIGGER_MESSAGE = ""
}'
#%UU%
#%MDESC% Called from the hutchtrigger brick with one argument (0 or 1):
# 0 = The hutch has been interlocked and the sample environment should be made
# ready for data collection.
# 1 = The interlock is cleared and the user is entering the hutch to change
# the sample(s).
def hutchtrigger '{
local msg
if (whatis(HUTCH_DETMOTNUM)&0x08000000>>27 == 0) {
msg = "The setup is not complete, no detector distance motor set"
print msg
HUTCH_TRIGGER_MESSAGE = sprintf("%s",msg)
exit
}
if (HUTCH_DETDIST == 0 ) {
printf("Non-encomberant distance is 0, default to 400mm")
HUTCH_DETDIST = 400
}
_hutchtrigger($1)
}'
#%IU% (keyword)
#%MDESC% Return 1 if the macro named %B%keyword%B% exist, 0 otherwise.
def ismacro(keyword) '{
return ((whatis(keyword)&2)==2)
}'
#%IU% (inout)
#%MDESC% The hutch has been interlocked and the sample environment should be
#made ready for data collection - %B%inout = 0%B%%BR%
#The interlock is cleared and the user is entering the hutch to change
#the sample(s) - %B%inout = 1%B%.
def _hutchtrigger(inout) '{
local msg
cdef("cleanup_once","hutchtrigger_cleanup;","_hutchtrigger")
if (HUTCH_DETPOS == 0 ) { HUTCH_DETPOS = HUTCH_DETDIST }
printf ("hutchtrigger %d\n", inout)
get_angles
if (inout == 1) {
HUTCH_TRIGGER_STATUS = 1
HUTCH_DETPOS = A[HUTCH_DETMOTNUM]
printf ("saved detector position is %f\n", HUTCH_DETPOS)
if (HUTCH_UDIFF) {
move_em; backout
} else {
if (ismacro("scintoff")) {
printf("Move out the scintilator\n")
scintoff
}
_backout();move_em
}
if (A[HUTCH_DETMOTNUM] < HUTCH_DETDIST) {
HUTCH_TRIGGER_MESSAGE = sprintf("Moving Detector to %d", HUTCH_DETDIST)
printf ("%s\n", HUTCH_TRIGGER_MESSAGE)
HUTCH_DETPOS = A[HUTCH_DETMOTNUM]
A[HUTCH_DETMOTNUM] = HUTCH_DETDIST
move_em
}
HUTCH_TRIGGER_MESSAGE = "Moving equipment to safe position"
if (ismacro("local_hutchtrigger_actions")) {
printf ("Executing local hutchtrigger actions\n")
local_hutchtrigger_actions
}
printf ("%s\n", HUTCH_TRIGGER_MESSAGE)
if (HUTCH_UDIFF) {
if (ismacro("microdiff_phase")) {
if (microdiff_phase(5) < 0)
exit
}
} else {
if (ismacro("fldetout")) {
printf("Move out the fluorescence detector\n")
fldetout
}
if (ismacro("flightoff")) {
printf("Switch off the front light\n")
flightoff()
}
}
HUTCH_TRIGGER_MESSAGE = ""
} else if (inout == 0) {
HUTCH_TRIGGER_STATUS = 0
if (HUTCH_DETPOS < HUTCH_DETDIST && HUTCH_DETPOS != 0) {
if (HUTCH_DETPOS < HUTCH_MINDIST)
HUTCH_DETPOS = HUTCH_MINDIST
HUTCH_TRIGGER_MESSAGE = "Moving Detector to " HUTCH_DETPOS
printf ("%s\n", HUTCH_TRIGGER_MESSAGE)
A[HUTCH_DETMOTNUM] = HUTCH_DETPOS
move_em
}
if (HUTCH_UDIFF) {
move_em; backout
} else {
if (ismacro("scintoff")) {
printf("Move out the scintilator\n")
scintoff
}
_backin();move_em
}
HUTCH_TRIGGER_MESSAGE = "Moving equipment to sample centring position"
printf ("%s\n", HUTCH_TRIGGER_MESSAGE)
if (HUTCH_UDIFF) {
if (microdiff_phase(1) < 0) {
exit
}
} else {
if (ismacro("fldetout")) {
printf("Move out the fluorescence detector\n")
fldetout
}
if (ismacro("flighton")) {
printf("Switch off the front light\n")
flighton()
}
}
if (ismacro("local_hutchtrigger_actions")) {
printf ("Executing local hutchtrigger actions\n")
local_hutchtrigger_actions
}
HUTCH_TRIGGER_MESSAGE = ""
}
move_em; move_poll
}'
#%MACROS%
#%IMACROS%
#%TOC%
#%AUTHOR% BLISS%BR%
#$Revision: 1.19 $ $Date: 2011/04/04 14:59:10 $%BR%
#%END%
#%LOG%
#$Log: hutchtrigger.mac,v $
#Revision 1.19 2011/04/04 14:59:10 guijarro
#HUTCH_TRIGGER_STATUS was causing bugs - simplified it a bit
#
#Revision 1.18 2011/01/26 15:15:45 guijarro
#move scintillator before bstop
#
#Revision 1.17 2010/08/31 13:08:12 guijarro
#added move_em, necessary to make sure motor moves
#
#Revision 1.16 2010/01/27 13:40:43 guijarro
#fixed bug with HUTCH_TRIGGER_MESSAGE
#
#Revision 1.15 2009/09/29 14:20:43 beteva
#added redefinition of _backin. Added some more printing
#
#Revision 1.14 2009/09/23 14:30:17 guijarro
#fixed macro redefinitions using rdef instead of def
#
#Revision 1.12 2009/09/18 09:12:02 beteva
#Check if some macros are defined and define them in the setup if not.
#Make as much as possible motors to move simultaneously to not loose time.
#The procedure differs between the mini and the micro diff.
#
|