esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% backstop.mac
#%NAME%
#   This macro set handles the beamstop at mx beamlines.
#%CATEGORY%  Other hardware, MX
#%DESCRIPTION%
#   The macro set shares information with GUI through 
#   the hardware repository XML file
#%BR% %BR%
#   The macros are used to set backstop in and out
#%END%

global BEAMSTOP_XML

#%UU%
def backsetup '{
    local xml_ho
   
    if ($#) {
        BEAMSTOP_XML = "$1"
        _backread()
    } else {
        printf("Usage: %s <beamstop xml file>, example %s /beamstop", "$0", "$0")
        exit
    }
}'

def _backread() '{
  global BEAMSTOP[]
  local Z_PATH Y_PATH hmot vmot
  local Z_MOTOR Y_MOTOR
  local BSTOPZ_IN BSTOPY_IN BSTOPZ_OUT BSTOPY_OUT
  local Z_DELTA_PATH Y_DELTA_PATH Y_DELTA Z_DELTA
  local IN_INDEX OUT_INDEX
  local i n
 
  if ( xml_readRoles(BEAMSTOP_XML) == 0) {
    hmot = XML_tmp["horizontal"]["hwrid"]
    vmot = XML_tmp["vertical"]["hwrid"]
    xml_read(vmot, "/device/specname")
    Z_MOTOR = XML_tmp[0]["__value__"]
    xml_read(hmot, "/device/specname")
    Y_MOTOR = XML_tmp[0]["__value__"]

    if (Z_MOTOR == Y_MOTOR) {
      print "Error with horizontal and vertical motors in xml file"
    }    
  } else {
    print "Cannot read roles in beamstop xml file"
    return    
  }

  Y_DELTA_PATH = "/equipment/deltas/horizontal"
  Z_DELTA_PATH = "/equipment/deltas/vertical"

  if ( xml_read(BEAMSTOP_XML, "/equipment/positions/position/name") != -1) {
    if (xml_read(BEAMSTOP_XML, Y_DELTA_PATH) != -1) {
      Y_DELTA = XML_tmp[0]["__value__"]
    } else {
      Y_DELTA = 0
    }
   
    if (xml_read(BEAMSTOP_XML, Z_DELTA_PATH) != -1) {
      Z_DELTA = XML_tmp[0]["__value__"]
    } else {
      Z_DELTA = 0
    }

    Z_PATH = "/equipment/positions/position/vertical"
    Y_PATH = "/equipment/positions/position/horizontal"
    IN_INDEX=-1
    OUT_INDEX=-1

    xml_read(BEAMSTOP_XML, "/equipment/positions/position/name")
    n = asso_len(XML_tmp)
    
    for (i=0; i<n; i++) {
      if (XML_tmp[i]["__value__"] == "in") {
        IN_INDEX = i
      } else if (XML_tmp[i]["__value__"] == "out") {
        OUT_INDEX = i
      }
    } 
  
    if (xml_read(BEAMSTOP_XML, Z_PATH) != -1) {
      BSTOPZ_IN = XML_tmp[IN_INDEX]["__value__"]
    } else {
      print "Cannot read beamstop Z <in> position from configuration"
      return
    }

    if (xml_read(BEAMSTOP_XML, Y_PATH) != -1) {
      BSTOPY_IN = XML_tmp[IN_INDEX]["__value__"]
    } else {
      print "Cannot read beamstop Y <in> position from configuration"
      return
    }

    if (xml_read(BEAMSTOP_XML, Z_PATH) != -1) {
      BSTOPZ_OUT = XML_tmp[OUT_INDEX]["__value__"]
    } else {
      print "Cannot read beamstop Z <out> position from configuration"
      return
    }

    if (xml_read(BEAMSTOP_XML, Y_PATH) != -1) {
      BSTOPY_OUT = XML_tmp[OUT_INDEX]["__value__"]
    } else {
      print "Cannot read beamstop Y <out> position from configuration"
      return
    }

    BEAMSTOP["z"]["in"]=BSTOPZ_IN
    BEAMSTOP["z"]["out"]=BSTOPZ_OUT
    BEAMSTOP["z"]["delta"]=Z_DELTA
    BEAMSTOP["z"]["motor"]=Z_MOTOR
    BEAMSTOP["y"]["in"]=BSTOPY_IN
    BEAMSTOP["y"]["out"]=BSTOPY_OUT
    BEAMSTOP["y"]["delta"]=Y_DELTA
    BEAMSTOP["y"]["motor"]=Y_MOTOR
  } else {
    print "Cannot read positions from beamstop configuration"
  }
}'


#%UU%
def backin '{
  if (whatis("specific_beamstop_check") > 0) {
    eval("specific_beamstop_check()")
  }

  _backin()

  print "Moving backstop in"

  move_em; move_poll
}'

#%UU%
def backout '{
  _backout()

  print "Moving backstop out" 
 
  move_em; move_poll
}'

def _backin() '{
   global BEAMSTOP[]
   local bstopz_mot bstopy_mot

   _backread()
  
   BSTOPY_POS = BEAMSTOP["y"]["in"]
   BSTOPZ_POS = BEAMSTOP["z"]["in"]
   DELTAZ = BEAMSTOP["z"]["delta"]
   DELTAY = BEAMSTOP["y"]["delta"]
   BSTOPZ = BEAMSTOP["z"]["motor"]
   BSTOPY = BEAMSTOP["y"]["motor"]
   bstopz_mot = motor_num(BSTOPZ)  
   bstopy_mot = motor_num(BSTOPY)
 
   A[bstopz_mot] = BSTOPZ_POS
   A[bstopy_mot] = BSTOPY_POS   
}'

def _backout() '{
   global BEAMSTOP[]
   local bstopz_mot bstopy_mot

   _backread()

   BSTOPY_POS = BEAMSTOP["y"]["out"]
   BSTOPZ_POS = BEAMSTOP["z"]["out"]
   DELTAZ = BEAMSTOP["z"]["delta"]
   DELTAY = BEAMSTOP["y"]["delta"]
   BSTOPZ = BEAMSTOP["z"]["motor"]
   BSTOPY = BEAMSTOP["y"]["motor"]
   bstopz_mot = motor_num(BSTOPZ)
   bstopy_mot = motor_num(BSTOPY)

   A[bstopz] = motor_par(bstopz_mot, "low_limit")+((motor_par(bstopz_mot, "backlash")+1)/motor_par(bstopz_mot, "step_size"))
   A[bstopy] = BSTOPY_POS
}'

def is_backstop_out() '{

   _backread()

   if ( fabs( A[bstopz] - BEAMSTOP["z"]["in"] ) > BEAMSTOP["z"]["delta"])  {
      return(1)
   } else {
      return(0)
   }
}'

#%MACROS%
#%IMACROS%
#%TOC%
#%AUTHOR% M.Guijarro, ESRF/BLISS (2007)