esrf

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

#%TITLE% syncmot.mac
#%CATEGORY% Positioning
#%NAME%
#  Synchronized macro motor 
#%DESCRIPTION%
#  Macro for defining macro motors as a combination of 
#  an arbitrary number of real motors that need to be
#  moved together like, for example, the height of a 
#  table.
#%BR%
#  To define a motor that would perform synchronize movement
#  on other motors you need to define a macro motor controller
#  in config with macro prefix = syncmot
#%BR%
#  Then define a motor on that controller and set as motor 
#  parameter in config the nbmotors value and as many mot-x-
#  entries as necessary referring to real motors
#%BR%
#
#%EXAMPLE%
#  In CONFIG file header:
#%PRE%
#   PSE_MAC_MOT      = syncmot 8
#%PRE%
#
#  Then define in the motor definition area: 
#%PRE%
#  MOT011 = MAC_MOT:0/0  2000  1  2000  200   50  125    0 0x003     mhgt  Hht 
#  MOTPAR:nbmotors = 3
#  MOTPAR:mot1 = j1
#  MOTPAR:mot2 = j2 
#  MOTPAR:mot3 = j3
#%PRE%
#
#%END%

#%IU%
#%MDESC% Used on spec config or reconfig
#
def syncmot_config(mne,type,unit,module,chan) '{

   local motn nmotors depstr

   if (type == "ctrl") return
   
   nmotors = motor_par(mne,"nbmotors")

   depstr = ""

   for (motn=1;motn<=nmotors;motn++) {

     motnmne = motor_par(mne,sprintf("mot%d",motn))

     if ( motor_num(motnmne) == -1 ) {  
       return ".error."
     }
     motor_par(motnmne, "hgt",  mne, "add")
     depstr = depstr " " motnmne
   }
   printf("Returning %s\n", depstr)
   motnum = motor_num(mne)
   motor_par( mne, "oldpos", A[motnum], "add" )
   return sprintf("%s", depstr )
}'

#%IU%
#%MDESC% Used for reading macro motor position or calculating 
#  real motor displacements
#
def syncmot_calc(mne, mode) '{

   local motnum
   local totalpos dist motnnum mothgt
   local nmotors motnmne motn

   motnum = motor_num(mne)

   if (mne == "..") return

   if (mode == 0) {
      nmotors = motor_par(mne,"nbmotors")
      for (motn=1;motn<=nmotors;motn++) {
        motnmne = motor_par(mne, sprintf("mot%d", motn))
        motnnum = motor_num(motnmne)
        totalpos += A[motnnum]
      }
      A[motnum] = totalpos / nmotors
      motor_par( mne, "oldpos", A[motnum] )
   } else {
      mothgt    = motor_par(mne,"hgt")
      dist      = A[mothgt] - motor_par(mothgt,"oldpos")
      A[motnum] = A[motnum] + dist
   }
}'

#%MACROS%
#%IMACROS%
#%TOC%
#%AUTHOR% BLISS / ESRF 2007