esrf

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

#%TITLE% motstab.mac
#%DESCRIPTION% realizes a sequence to evaluate the repetability of the motions.
#For that it:
#%BR%- set user soft limits to very high values (out of the hardware limits)
#%BR%- set user position to 0
#%BR%- finds the low an high hardware limits
#%BR%- set the high and low user soft limits to these high and low positions
#%BR%- go to medium value and set user position to 0
#%BR%- move randomly to positions between the limits
#%BR%- finally go to user position 0
#%BR%Note: in case of spec error in an 'eval' command, the macro cannot be
#stopped. But the error message is dispalyed in  the screen and the macro
#continues.
global __MOTSTAB_interrupt
global __MOTSTAB_LIMP 
global __MOTSTAB_LIMN 


#%UU% <mne> <nbmot>
#%MDESC%it realizes the following sequence on motor <mne>
#%BR%- set user position to 0
#%BR%- go to limit- and get position
#%BR%- go to limit+ and get position
#%BR%- go to middle and set 0
#%BR%- make <nbmot> random motions
#%BR%- go to 0
def motstab'{
   global MOTSTAB
   local mne mymot mnum mystring myret reteval retval ii

   if ($# != 2) {
      p "usage: motstab <mne> <nb>"
      exit
   }
    
   #__MOTSTAB_LIMP = 1000000
   #__MOTSTAB_LIMN = -1000000
   __MOTSTAB_LIMP = 100
   __MOTSTAB_LIMN = -100
   
   mymot = motor_num($1)
   #p mymot
   mne = motor_mne($1)
   #p mne
   
   p "... setting position to 0"
   mystring = sprintf("set %s 0",mne)
   p mystring
   reteval = eval(mystring)
   _motstab_wm(mne)
   _motstab_interrupt() 

   # to allow the motions
   p "... setting limits user values to " __MOTSTAB_LIMN " and " __MOTSTAB_LIMP
   mystring = sprintf("set_lm %s %d %d",mne,__MOTSTAB_LIMN,__MOTSTAB_LIMP)
   p mystring
   reteval = eval(mystring)
   _motstab_wm(mne)
   _motstab_interrupt() 
      
   # go to lim-
   p "... going to limit -"
   mystring = sprintf("mv %s %d",mne,__MOTSTAB_LIMN+1)
   p mystring
   reteval = eval(mystring)
   p "found lim- at position " A[mymot]   
   MOTSTAB["lim-"] = A[mymot]
   _motstab_wm(mne)
   _motstab_interrupt()  

   # go to lim+
   p "... going to limit +"
   mystring = sprintf("mvr %s 2;mv %s %d",mne,mne,__MOTSTAB_LIMP-1)
   p mystring
   reteval = eval(mystring)
   p "found lim+ at position " A[mymot]   
   MOTSTAB["lim+"] = A[mymot]
   _motstab_wm(mne)
   _motstab_interrupt()  
   
   #go in the middle of lim+ and lim-  
   target =  (MOTSTAB["lim+"] + MOTSTAB["lim-"])/2
   myrange = MOTSTAB["lim+"] - MOTSTAB["lim-"]
   p "...move to the middle position: " target
   mystring = sprintf("mv %s %f",mne,target)
   p mystring
   reteval = eval(mystring)
   _motstab_wm(mne)
   _motstab_interrupt() 
   p "...setting position to 0"
   mystring = sprintf("set %s 0",mne)
   p mystring
   reteval = eval(mystring)
   _motstab_wm(mne)
   _motstab_interrupt() 
   p "...setting the software limits"
   mystring = sprintf("set_lm %s %f %f",mne,-1*myrange/2,myrange/2)
   p mystring
   reteval = eval(mystring)
   _motstab_wm(mne)
   _motstab_interrupt()
   
   retval = getval("please set your position display unit to 0",retval)
   #doing random motions
   p "... doing random motions between " (-1*myrange/2) " and " (myrange/2)
   for (ii=0; ii<$2; ii++) {
      mytarget = rand(-1*myrange/2)
      p " >>moving to " mytarget
      mystring = sprintf("mv %s %f",mne,mytarget)
      p mystring
      reteval = eval(mystring)
   }
   
   #finally go to 0
   p "...going to 0"
   mystring = sprintf("mv %s 0",mne)
   p mystring
   reteval = eval(mystring)
   _motstab_wm(mne)

   
}'

#%UU% <mne> <nbmot>
#%MDESC%it realizes the random motions then go to 0
def motstab_random'{
   global MOTSTAB
   local mne mymot mnum mystring myret reteval retval ii
   
   if ($# != 2) {
      p "usage: motstab_random <mne> <nb>"
      exit
   }
   
   mymot = motor_num($1)
   #p mymot
   mne = motor_mne($1)
   #p mne
   
   myrange = MOTSTAB["lim+"] - MOTSTAB["lim-"]

   p "...going to 0"
   mystring = sprintf("mv %s 0",mne)
   p mystring
   reteval = eval(mystring)
   _motstab_wm(mne)

   retval = getval("please set your position display unit to 0",retval)
   
   #doing random motions
   p "... doing random motions between " (-1*myrange/2) " and " (myrange/2)
   for (ii=0; ii<$2; ii++) {
      mytarget = rand(-1*myrange/2)
      p " >>moving to " mytarget
      mystring = sprintf("mv %s %f",mne,mytarget)
      p mystring
      reteval = eval(mystring)
   }
   
   #finally go to 0
   p "...going to 0"
   mystring = sprintf("mv %s 0",mne)
   p mystring
   reteval = eval(mystring)
   _motstab_wm(mne)

   
}'

#%UU% <1/0>
#%MDESC%test macro: allows to stop between each command, waiting for user to 
#continue
def motstab_setinterrupt'{
   if ($1 == 0) {
      __MOTSTAB_interrupt = 0
   }
   else {
      __MOTSTAB_interrupt = 1   
   }
}'

#%IU% ()
#%MDESC%interrupting macr
def _motstab_interrupt()'{
   local retval
   
   if (__MOTSTAB_interrupt != 0) {
      retval = 0
      retval = getval("waiting for you to continue",retval)
   }
}'

#%IU% (mne)
#%MDESC%asks wm on the corresponding mmnemonic <mne>
def _motstab_wm(mne)'{
   local mystring reteval
   
   mystring = sprintf("wm %s",mne)
   p mystring
   reteval = eval(mystring)
}'



#%MACROS%
#%IMACROS%
#%AUTHOR% MCD august 10
# %BR%$Revision: 1.5 $ / $Date: 2013/11/29 12:59:19 $
#%TOC%