#%TITLE% IK320multi.MAC
#%NAME%
# Heidenhain high resolution encoder IK320 as a counter
#
#%CATEGORY% Positioning
#
#%DESCRIPTION%
#
#%EXAMPLE%
#%DL%
#%DT% ik320setup 1 heid id18/ik320/1 1 %DD%
# One pseudo counter heid will be set up for a Heidenhain Encoder
# device name id18/ik320/1. If the counter heid is defined with spec
# config editor the its position will be read with the Encoder.
#%XDL%
#%END%
#%UU% nb_of_cnts mne integrate device channel mne integrate device channel ...
#%MDESC% Set up the pseudo counters given with mne on the esrf device
# device and channel.
def ik320setup '{
global IK320_NO IK320_DEV IK320_MNE IK320_CH IK320_INT
local i
if ($#) {
IK320_NO = $1
IK320_MNE[0] = "$2"; IK320_MNE[1] = "$5"; IK320_MNE[2] = "$8" ;
IK320_DEV[0] = "$3"; IK320_DEV[1] = "$6"; IK320_DEV[2] = "$9";
IK320_CH[0] = "$4"; IK320_CH[1] = "$7"; IK320_CH[2] = "$10";
} else {
IK320_NO = getval("How many VME Heidenhain IK320",IK320_NO)
for (i = 0; i < IK320_NO; i++) {
IK320_MNE[i] = getval("Mnemonic for IK320",IK320_MNE[i])
IK320_DEV[i] = getval(sprintf("Device name for Heidenhain IK320 %s",\
IK320_MNE[i]),IK320_DEV[i])
IK320_CH[i] = getval(sprintf("Channel for Heidenhain IK320 %s",\
IK320_MNE[i]),IK320_CH[i])
}
}
_ik320setup
}
'
#%IU%
def _ik320setup '{
local i
for (i=0; i<IK320_NO; i++) {
_multimsetup(sprintf("%s type=ik320 device=%s channel=%d integrate=0", \
IK320_MNE[i], IK320_DEV[i], IK320_CH[i]))
}
}'
def multim_init_ik320 '{
local pos
if (!("device" in MULTIM[cntr])) {
printf("Device name missing. ")
return(1)
}
if (!("channel" in MULTIM[cntr]))
MULTIM[cntr]["channel"] = counter_par(cntr, "channel")
global ESRF_ERR_MSG
ESRF_ERR = -1
esrf_io(MULTIM[cntr]["device"], "DevReadPosition", \
MULTIM[cntr]["channel"], pos)
if (ESRF_ERR > 0) {
tty_cntl("md")
printf("\n Error while initializing IK320 encoder\n")
printf(" - counter: %s\n",cnt_mne(cntr))
printf(" - ADC dev: %s\n",MULTIM[cntr]["device"])
printf(" - Errno: %d\n",ESRF_ERR)
printf(" %s\n",ESRF_ERR_MSG)
printf(" Please. Check the VME\n\n")
tty_cntl("me")
printf(" Hint: if you got the message \"RPC client call timed out\":\n")
printf(" - the device server process may have died in the VME\n")
printf(" or\n")
printf(" - you may be having network problems\n\n")
return(1)
}
}'
#%IU%
#%MDESC%
# Reads the ADC value for type=ik320
#
def multim_read_ik320 '{
local pos
# ESRF_ERR=-1
esrf_io(MULTIM[cntr]["device"], "DevReadPosition", \
MULTIM[cntr]["channel"], pos)
value = pos[0] * 0x10000 + pos[1]
if (!ESRF_ERR)
ok = 1
}'
#%UU%
#%MDESC% Prepares the first configured IK320 device to move over
# the reference mark. The motor has to be move after a call to this macro
def ik320ref '{
i = 0
p "Reset IK320 by doing POST"
esrf_io(IK320_DEV[i],"timeout",5)
esrf_io(IK320_DEV[i],"DevIK320PowerOnSelfTest")
p "Moving encoder to reference"
getval("Hit ENTER when ready to move to reference","")
esrf_io(IK320_DEV[i],"timeout",500)
esrf_io(IK320_DEV[i],"DevMoveReference",1)
esrf_io(IK320_DEV[i],"timeout",3)
}'
#%UU% <resolution>
#%MDESC% The first IK320 device resolution is set (a value between 1 and 16)
def ik320res '{
local ik320_in
i = 0
res = $1
if (res <= 0 || res > 16) {
p "ik320res resolution"
}
else {
p "Set encoder resolution to " res
for (ik320_i = 0; ik320_i < IK320_NO; ik320_i++) {
ik320_in[0] = "1"
ik320_in[1] = "resolution"
ik320_in[2] = res
esrf_io(IK320_DEV[ik320_i],"DevSetParam",ik320_in)
ik320_in[0] = "2"
esrf_io(IK320_DEV[ik320_i],"DevSetParam",ik320_in)
}
}
}'
#%MACROS%
#%IMACROS%
#%AUTHOR%
# IK320multi.MAC JK 7.00 Rev 0.002 New version using multim.mac to integrate
#%TOC%
|