esrf

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

#%TITLE% dtox.mac
#%NAME%
#   Macros for dtox motor handling at MX beamlines
#%CATEGORY%  MX
#
#
#%END%

global DTOX_DETM_LIM DTOX_DETF_LLIM DTOX_DETF_RLIM
global DTOX_MOTMNE  DTOX_OLD_DTOX  DTOX_OLD_DETF
global DTOX_ACTIVE

DTOX_MOTMNE=""
DTOX_ACTIVE=0 

def dtoxsetup '{
   DTOX_MOTMNE="$1"
   DTOX_DETM_LIM=$2
   DTOX_DETF_LLIM=$3
   DTOX_DETF_RLIM=$4

   if (motor_num(DTOX_MOTMNE)==-1) {
       print "Motor does not exist. Add it to Spec config first."
       exit
   }

   if (DTOX_ACTIVE == 0) {
      dtoxon
   }

}'


def dtox_cleanup '{
}'


def dtox_mv() '{
   local pos dtoxnum 

   dtoxnum = motor_num(DTOX_MOTMNE)
   pos     = A[dtoxnum]

   if (pos == DTOX_OLD_DTOX) {
     return
   } 

   if ((get_lim(dtoxnum, -1)>pos)||(get_lim(dtoxnum, 1)<pos)) {
     return
   }   

   cdef("cleanup_once", "get_angles; motor_par(detm, \"disable\", 1); motor_par(detf, \"disable\", 1)\n", "dtox_cleanup_once", 0x20)

   motor_par(detm, "disable", 0)
   motor_par(detf, "disable", 0)

   printf("Moving DTOX to %3.4f\n", pos)

   #
	 # Detector was close but now we want to move it out past the minidiff again
	 # So move transversally the detector to the positive limit (away from the minidiff)
	 # so that when we retreat it will be away from the minidiff
	 #
	 if ((DTOX_OLD_DTOX < DTOX_DETM_LIM) && (pos >= DTOX_DETM_LIM)) {
     printf("   --  moving detf away from minidiff (lim-) ready for retreat ...")
     chg_dial(detf, "lim-")
     wait(1) 
     printf("  ok.\n") 
   }

   #
	 # Detector was behind the minidiff (or at the limit reference position)
	 # but we will move it close in
	 # so advance until the lim+ switch is hit (it should be on the detf lim-, see above)
	 #
	 if ((DTOX_OLD_DTOX >= DTOX_DETM_LIM) && (pos < DTOX_DETM_LIM)) {
     printf("   --  sending detm to lim+ (just before the minidiff)...")
     chg_dial(detm, "lim+")
		 wait(1)
     printf("  ok.\n") 
   }

   #
	 # The position asked for is behind the minidiff, so special operations to perform here
	 # as they have already been prepared previously
	 #
	 if (pos >= DTOX_DETM_LIM) {
     printf("   --  moving detm to %3.4f / detf to %3.4f ...",pos,DTOX_DETF_LLIM)
     A[detm] = pos
     # use this method of moving the motor in case there are other moves programmed (e.g backstop)
		 move_all; wait(1)
		 A[detf] = DTOX_DETF_LLIM
		 move_all; wait(1)
   } else {
		 #
		 # the detector is to be moved in close so move to the negative limit 
     #
		 printf("\n   --  sending detf to lim-...")
     chg_dial(detf, "lim-")
     wait(1)
     printf("  ok.\n") 

     printf("\n   --  now going to final position...(detm=%6.2f, detf=%6.2f)",pos,DTOX_DETF_RLIM)
     A[detm] = pos
		 move_all; wait(1)
     A[detf] = DTOX_DETF_RLIM
		 move_all; wait(1)
   }

   # all movements should be finished here
   read_motors(0)
   printf("  ok.\n") 

   dtox_beam_centre_update

   get_angles

   motor_par(detm, "disable", 1)
   motor_par(detf, "disable", 1)

   printf("\nDone\n") 
}'


def dtox_beam_centre_update '{
  local delta 

  ybeam = MXSPEC_PARS["beam"]["by"]
  delta = A[detf] - DTOX_OLD_DETF

  printf("\n    -- adjusting Y Beam (%d)", delta)
  MXSPEC_PARS["beam"]["by"] = ybeam + delta

  beam_centre_update()
}'


def dtox_get() '{
   local dtoxnum

   dtoxnum    = motor_num(DTOX_MOTMNE)
   A[dtoxnum] = A[detm]

   DTOX_OLD_DTOX=A[detm]
   DTOX_OLD_DETF=A[detf]
}'


def dtoxon '{
    if (motor_num(DTOX_MOTMNE)<0) {
       tty_cntl("md")
       print "Run dtoxsetup first"
       tty_cntl("me")
       exit
    } 

    DTOX_ACTIVE=1

    cdef("user_getpangles","dtox_get()\n ",  DTOX_MOTMNE, 0x01)
    cdef("user_checkall",  "dtox_mv()\n ",   DTOX_MOTMNE, 0x01)

    motor_par(detm, "disable", 1)
    motor_par(detf, "disable", 1)
}'


def dtoxoff '{
    DTOX_ACTIVE=0
    cdef ("","",DTOX_MOTMNE,"delete")
    cdef ("","","_dtox_","delete")
    motor_par(detm, "disable", 0)
    motor_par(detf, "disable", 0)
}'