#%TITLE% INCA.MAC
#%NAME%
# Macros for operating inclined analyser stages.
#
#%CATEGORY% Positioning
#
#%DESCRIPTION%
#%PRE%
# This macro set allows you to define pseudo motors on inclined (45 degrees) analyser chi th stages.
#
# Since version 1.0 (Feb 2006) this macro file allows also to
# define new style calculation macro motors on inclined stages.
#
# To define new style macro motors you must define:
#
# an inca controller in config (one controller will work on one or
# more analyser stages):
#
# MOTORS DEVICE ADDR <>MODE NUM <>TYPE
# YES inca 6 Macro Motors
#
# motors in config referring to that controller. Channel assignment
# will decide on the motor role as follow:
#
# Channel
# 0 - chi
# 1 - theta
#
# Different pairs of inclined analyser stages can be defined by using
# additional module numbers in the motor unit/module/channel assignment.
#
# Config file
# The following motor parameters have to be associated in config
# file to the channel 0 of the controller/module.
#
# Example:
#
# MOT000 = MAXE:0/0 [...] achip2
# MOT001 = MAXE:0/1 [...] athp2
# MOT002 = MAXE:0/2 [...] achip3
# MOT003 = MAXE:0/3 [...] athp3
# MOT004 = MAXE:0/4 [...] achip4
# MOT005 = MAXE:0/5 [...] athp4
#
# MOT006 = MAC_MOT:0/0/0 [....] achi2
# MOTPAR:xmot = achip2
# MOTPAR:ymot = athp2
# MOT007 = MAC_MOT:0/0/1 [....] ath2
#
# MOT008 = MAC_MOT:0/0/0 [....] achi3
# MOTPAR:xmot = achip3
# MOTPAR:ymot = athp3
# MOT009 = MAC_MOT:0/0/1 [....] ath3
#
# MOT010 = MAC_MOT:0/0/0 [....] achi4
# MOTPAR:xmot = achip4
# MOTPAR:ymot = athp4
# MOT011 = MAC_MOT:0/0/1 [....] ath4
#
#%PRE%
def inca_config(mne,type,unit,module,chan) '{
if (type == "ctrl") return
master = motor_par(mne,"chan0")
chan = motor_par(mne,"channel")
xmot = motor_par(master,"xmot")
ymot = motor_par(master,"ymot")
if ( motor_num(xmot) == -1 || motor_num(ymot) == -1) {
return ".error."
}
if (chan == 0) {
motor_par(mne, "role", "achi","add")
motor_par(master, "achi", motor_mne(mne), "add")
motor_par(xmot, "chan0", mne, "add")
motor_par(ymot, "chan0", mne, "add")
motor_par(xmot, "role", "xmot", "add")
motor_par(ymot, "role", "ymot", "add")
print "Using Inca Analyser Stage: master",motor_mne(mne)
} else if (chan == 1) {
motor_par(mne, "role", "ath", "add")
motor_par(master, "ath", motor_mne(mne), "add")
} else {
print "Wrong channel assignment for inca motor. Only 0 or 1 accepted"
return ".error."
}
return sprintf("%s %s", xmot, ymot)
}'
def inca_calc (mne, mode) '{
local role master motnum
local xmot ymot athmot achimot
local xnum ynum athnum achinum
motnum = motor_num(mne)
if (mne == "..") return
role = motor_par(mne,"role")
master = motor_par(mne,"chan0")
if ( mode == 0) {
xmot = motor_par(master, "xmot")
ymot = motor_par(master, "ymot")
xnum = motor_num(xmot)
ynum = motor_num(ymot)
if (role == "ath") {
A[motnum] = A[ynum]/sqrt(2) + A[xnum]/sqrt(2)
} else if ( role == "achi") {
A[motnum] = A[ynum]/sqrt(2) - A[xnum]/sqrt(2)
}
} else {
athmot = motor_par(master, "ath")
achimot = motor_par(master, "achi")
athnum = motor_num(athmot)
achinum = motor_num(achimot)
if (role == "xmot") {
A[motnum] = A[athnum]/sqrt(2) - A[achinum]/sqrt(2)
} else if (role == "ymot") {
A[motnum] = A[athnum]/sqrt(2) + A[achinum]/sqrt(2)
}
}
}'
def inca '{
local mne master
mne = "$1"
master = motor_par(mne,"chan0")
print "ACHI :" motor_par(master,"achi")
print "ATH :" motor_par(master,"ath")
print "Xmot :" motor_par(master,"xmot")
print "Ymot :" motor_par(master,"ymot")
}'
def incasetup '{
global INCA_OLD INCA_ON
global INCA_MOT
global INCA_NAMES INCA_NO
local _motname _achip _athp _motx _moty
if ($# != 5) {
if (INCA_NO) {
printf("Current definitions\n")
for (i=0;i<INCA_NO;i++) {
_motname = INCA_NAMES[i]
printf("NAME = %s - MOTORS -> %s %s %s %s\n ",_motname, \
INCA_MOT[_motname]["achip"], INCA_MOT[_motname]["athp"],\
INCA_MOT[_motname]["x"], INCA_MOT[_motname]["y"])
}
}
_motname = getval("Analyser",INCA_NAMES[INCA_NO-1])
_achip = getval(" ACHI mnemonic", INCA_MOT[_motname]["achip"])
_athp = getval(" ATH mnemonic", INCA_MOT[_motname]["athp"])
_motx = getval(" Real MOT 1 mnemonic",INCA_MOT[_motname]["x"])
_moty = getval(" Real MOT 2 mnemonic",INCA_MOT[_motname]["y"])
} else {
_motname ="$1"
_achip ="$2"
_athp ="$3"
_motx ="$4"
_moty ="$5"
}
inca_add(_motname,_achip,_athp,_motx,_moty)
setup_tail("inca_",_motname)
}'
def inca_add(name,achip,athp,motx,moty,radius) '{
local found
for (i=0;i<INCA_NO;i++) {
if (name == INCA_NAMES[i]) {
found = 1
break
}
}
if (!found) {
p "Adding ",name
INCA_NAMES[i] = name
INCA_NO++
}
INCA_MOT[name]["achip"] = achip
INCA_MOT[name]["athp"] = athp
INCA_MOT[name]["x"] = motx
INCA_MOT[name]["y"] = moty
inca_on
}'
def inca_on '{
INCA_ON = 1
for ( i = 0;i<INCA_NO;i++) {
name = INCA_NAMES[i]
cdef("user_checkall", sprintf("inca_move %s\n",name),name)
cdef("user_getpangles",sprintf("inca_get %s\n",name),name)
}
}'
def inca_off '{
INCA_ON = 0
for ( i = 0;i<INCA_NO;i++) {
name = INCA_NAMES[i]
cdef("", "",name,"delete")
}
}'
def inca_unsetup '{
local name tmpno tmpnames
name = "$1"
tmpno = 0
for ( i = 0;i<INCA_NO;i++) {
if ( name == INCA_NAMES[i] ) {
cdef("", "",name,"delete")
continue
} else {
tmpnames[tmpno] = INCA_NAMES[i]
tmpno++
}
}
for (i=0;i<tmpno;i++) {
INCA_NAMES[i] = tmpnames[i]
}
INCA_NO = tmpno
}'
def inca_move '{
local achipnum athnum xnum ynum
motname = "$1"
achipnum = motor_num(INCA_MOT[motname]["achip"])
athnum = motor_num(INCA_MOT[motname]["athp"])
xnum = motor_num(INCA_MOT[motname]["x"])
ynum = motor_num(INCA_MOT[motname]["y"])
error = 0
if (ynum == -1 || xnum == -1 || athnum == -1 || achipnum == -1 ) {
error = 1
}
if (!error) {
_bad_lim = 0
_chk_lim achipnum A[achipnum]
_chk_lim athnum A[athnum]
_chk_lim xnum A[xnum]
_chk_lim ynum A[ynum]
if (_bad_lim) {
print "$1 ACHI/ATH - Bad limit: resetting"
A[xnum] = INCA_OLD[motname]["x"]
A[ynum] = INCA_OLD[motname]["y"]
A[athnum] = INCA_OLD[motname]["athp"]
A[achipnum] = INCA_OLD[motname]["achip"]
}}
if (!error) {
movex = ( A[xnum] != INCA_OLD[motname]["x"])
movey = ( A[ynum] != INCA_OLD[motname]["y"])
moveathp = ( A[athnum] != INCA_OLD[motname]["athp"])
moveachip = ( A[achipnum] != INCA_OLD[motname]["achip"])
if (!movex && !movey ) {
if ( moveathp || moveachip ) {
A[xnum]= A[athnum]/sqrt(2)-A[achipnum]/sqrt(2)
A[ynum]= A[athnum]/sqrt(2)+A[achipnum]/sqrt(2)
}
}
}
}'
def inca_get '{
local achipnum athnum xnum ynum
motname = "$1"
achipnum = motor_num(INCA_MOT[motname]["achip"])
athnum = motor_num(INCA_MOT[motname]["athp"])
xnum = motor_num(INCA_MOT[motname]["x"])
ynum = motor_num(INCA_MOT[motname]["y"])
error = 0
if (ynum == -1 || xnum == -1 || athnum == -1 || achipnum == -1 ) {
error = 1
}
if (!error) {
A[achipnum] = A[ynum]/sqrt(2)-A[xnum]/sqrt(2)
A[athnum] = A[ynum]/sqrt(2)+A[xnum]/sqrt(2)
INCA_OLD[motname]["achip"] = A[achipnum]
INCA_OLD[motname]["athp"] = A[athnum]
INCA_OLD[motname]["x"] = A[xnum]
INCA_OLD[motname]["y"] = A[ynum]
}
}'
|