#%TITLE% HEIDEN.MAC
#%NAME%
# Heidenhain AWE 1024 (Encoder) as pseudo motor
#%DESCRIPTION%
# A motor will be set up, which reads its position by asking a
# Heidenhain AWE 1024 about its encoder readings. This pseudomotor can
# either have a controller NONE (in spec config) and serve only for
# information. It can also be defined for a real motor . The position
# of this motor will be replaced by the encoder readings.
#
#%CATEGORY% Positioning
#
#%EXAMPLE%
#%DL%
#%DT% heidensetup 1 7 heid %DD%
# One pseudo motor heid will be set up for a Heidenhain AWE at gpib
# address 7. If the motor heid is defined with spec config editor
# the its position will be read with the AWE.
#%XDL%
def heidencntsetup '
HEIDENCOUNTER=1
_heidensetup $*
'
#%UU% [no_of_exe] [gpib_channel_of_first_exe] [pseudomne1] [....]
#%MDESC%
# Define the heiden AWEs as pseudo motors. The gpib address must
# follow each other.
def heidensetup '
HEIDENCOUNTER=0
_heidensetup $*
'
def _heidensetup '
##
## Setup the Heidenhain Pseudomotors.
##
global HEIDEN_NO HEIDEN_CHANNEL HEIDEN_MNE HEIDENCOUNTER
# How many?
#
if ($# < 1) {
HEIDEN_NO = getval("How many Heidenhaim AWE do you use ",HEIDEN_NO)
}
else {
HEIDEN_NO =$1
}
# On which channel?
#
if ($# < 2) {
HEIDEN_CHANNEL = getval("The Heidenhaim encoder AWE start from which gpib channel ",HEIDEN_CHANNEL)
}
else {
HEIDEN_CHANNEL=$2
}
# Reserve variables for doing a loop on the number of parameters.
#
_p[0] = "$3"; _p[1] = "$4"; _p[2] = "$5"; _p[3] = "$6"; _p[4] = "$7"
_p[5] = "$8"; _p[6] = "$9"; _p[7] = "$10"; _p[8] = "$11"; _p[9] = "$12"
# Get the names.
#
if ( $# < 3 )
{
for (i=0; i<HEIDEN_NO; i++)
{
HEIDEN_MNE[i] = getval(sprintf(" Name for Heidenhaim AWE %d",i),HEIDEN_MNE[i])
}
}
else
{
for (i=0; i<HEIDEN_NO; i++)
{
HEIDEN_MNE[i] = _p[i]
}
}
for (i=0;i<HEIDEN_NO; i++) {
local ppstring
if (!HEIDENCOUNTER) {
ppstring=sprintf ("%s none none _heidengetangles none none none none %s",HEIDEN_MNE[i],HEIDEN_CHANNEL+i)
pseudosdef ppstring
} else {
ppstring=sprintf ("%s none none _heidengetcounts none none %s",HEIDEN_MNE[i],HEIDEN_CHANNEL+i)
cpseudosdef ppstring
}
}
#for (i=0;i<HEIDEN_NO; i++) {
# heiden_init (HEIDEN_CHANNEL+i)
#}
'
def _heidengetangles '
heiden_read $2
if (HEIDENPOS != "")
A[$1]=HEIDENPOS/motor_par($1,"step_size")
'
def _heidengetcounts '
heiden_read $2
if (HEIDENPOS != "")
S[$1]=HEIDENPOS
'
# Heidenhaim Initialization.
#
# T2 Address send mode,R0 Ref without influences, S1 start counter , C2 = Z=0
#
#%UU% <gpib_channel>
#%MDESC%
# sets the encoder to 0 and starts the internal counter
def heiden_init '{
local comp, ref, counter, format, mode, status
heiden_state $1
gpib_put($1,"T2X")
if (comp) {
if (counter == 1)
p "**** You will have to drive the motor over the reference now"
gpib_put($1,"R1X")
gpib_put($1,"C2X")
} else {
p "Initializing .."
gpib_put($1,"R0X")
gpib_put($1,"S1X")
gpib_put($1,"C2X")
}
heiden_state $1
}'
def heiden_read '{
global HEIDENPOS
local x
x = gpib_get($1,"int4_swap")
#print "value read from RON (GPIB): " x
if (x > pow(2,31)) {
HEIDENPOS = x - pow(2,32)
} else {
HEIDENPOS = x
}
}'
def heiden_old_read '
{
# Tested for Sun, not for HP.
global HEIDENPOS
local y z
local y1 y2 y3 y4
# Get value from GPIB
x = gpib_get($1,"int4_swap")
# Reorder the 4 bytes.
#y=sprintf("%08x",x)
#y1=substr(y,1,2)
#y2=substr(y,3,2)
#y3=substr(y,5,2)
#y4=substr(y,7,2)
#z=sprintf("0x%s%s%s%s",y4,y3,y2,y1)
# Returns the value as a number.(Not a string)
#HEIDENPOS=z+0
HEIDENPOS=x+0
}'
# Defined for setting up.
#
#%UU% <gpib_channel>
#%MDESC%
# displays the values read on the screen
def heiden_wackel '
local maxx minx x
heiden_read $1
minx =x
maxx =x
for (;;) {
heiden_read $1
if (x>maxx) maxx=x
if (x<minx) minx=x
printf("%8x %8x %8x \n",x,minx,maxx)
}
'
# Defined for debugging.
#
def heiden_poll '
printf("%x\n",gpib_poll($1))
'
def heiden_state '{
gpib_put($1,"A0X")
status = gpib_get($1)
sscanf (status, "%1d%1d%1d%1d%1d", comp, ref, counter, format, mode)
printf("Heidenhain GPIB %d AWE1024: %s compensated, %s reference, %s\n", \
$1, comp ? "" : "not", ref == 0 ? "ignoring" : "starting with", \
counter ? "stopped" : "started")
}'
# Defined for debugging.
#
def heiden_get '
gpib_cntl(7,"get")
'
# Defined for debugging.
#
def heiden_t2 '
gpib_put(7,"T2X")
'
# Defined for debugging.
#
def heiden_s1 '
gpib_put(7,"S1X")
'
# Defined for debugging.
#
def heiden_a0 '
gpib_put(7,"A0X")
print "Status = ", gpib_get(7,5)
'
# Defined for debugging.
#
def heiden_c2 '
gpib_put(7,"C2X")
'
#%MACROS%
#%IMACROS%
#%ATTENTION%
#%UL%
#%LI% If you disconnect the AWE you have also to undefine the
# associated pseudo motor with spec's configuration editor.
# Otherwise you will get GPIB timeouts at each wa.
#%LI% The heidenhain unit has to be started in a certain wait. This is
# done by the heiden_init <gpib_number> macro. The position will
# be set to 0 at this moment. If you switch the box off, you have
# to repeat this procedure.
#%XUL%
#%DEPENDENCIES%
# The file heiden.mac has to be read in !done by: startup script
# (this file needs: cpseudo.mac stchanges.mac)
#%AUTHOR%
# HEIDEN.MAC JK 6.93
#%TOC%
|