#%TITLE% ETEL.mac
#%DESCRIPTION% set of macros for the management of ETEL motors.
#%BR%
#%BR% ETEL motors are seen by spec as MAXE controllers via a dedicated
#device server.
#%BR% The setting of the various parameters is supposed to have been done
# already by CoMet (the ETEL GUI). spec will give access to the
# commands defined for MAXE controllers (such as velocity, acceleration settings,
# home search ...)
#%BR%
#%BR% - note about dial positions: the spec set_dial macro allows to
#set the motor dial position (hardware internal counter). For ETEL motors, it is not
# possible to set a value to the hardware. So, the device server introduces
# an artificial 'offset' in order to satisfy the spec user and the motor
# controller. For some reason, it may be
#necessary to change this offset (for example to set it to 0 if the user
# wants the dial position to reflect the same position as the controller one).
#This can be done with de "DevStore" command of the device server
#%BR% 06/10/10: DevStore now reads array of double
#%BR% 06/10/10: etel_home: moves to 0 at the end.
#%UU% <mne>
#%MDESC% home search. The procedure for the home is the one which has
#been programmed using CoMet
#%BR%At the end of the procedure, a home is found
# and the reference is at the position 0 of the hardware internal counter.
#%BR% spec dial position is set to etel hardware internal counter.
#%BR% When home procedure is finished, the motor is not necessarily stopped
# at position 0 (but position 0 is exactly the reference position).
#%BR%At the end, the original motor velocity is restored (because internally,
#the hardware would have kept the homeslewrate velocity as the normal velocity
# until the next reconfig).
global ETEL_resp ETEL_DEBUG
def etel_dev(mne) '{
local mydev
if((mydev = motor_par(mne,"device_id")) == "etelmac") {
mydev = motor_par(mne,"address")
}
return(mydev)
}'
def etel_home'{
local ret mne myvel mydev mychan myacc myfsr accel
if ($# != 1) {
p "usage: etel_home <mne> "
exit
}
mne = motor_mne($1)
mydev = etel_dev(mne)
mychan = motor_par(mne,"channel")
myvel = motor_par(mne,"velocity")
myacc = motor_par(mne,"acceleration")
myfsr = motor_par(mne,"firststeprate")
p "mnemonic: " mne
p "device: " mydev
p "channel: " mychan
p "velocity: " myvel
p "acceleration: " myacc
p "firststeprate: " myfsr
p "going to home"
chg_dial(motor_num(mne),"home");sleep(1);move_poll
p "home found"
p "restoring the motor velocity"
# no need to tell spec as it thinks that the
# velocity did not change
esrf_io(mydev,"DevSetVelocity",mychan,myvel)
accel = (myvel-myfsr)/myacc*1000
p "restoring the motor acceleration: " accel
esrf_io(mydev,"DevSetAcceleration",mychan,accel)
p "setting offset to 0"
local darr
darr[0] = mychan
darr[1] = 0
esrf_io(mydev,"DevStore",darr)
#now, etel counter and server position are the same.
p "syncing positions"
read_motors(6)
p "moving to 0"
_mv_etel_function(mne, 0)
p "waiting for end of motion"
_poll_etel(mne)
p "syncing positions"
read_motors(6)
}'
#%UU%
#%MDESC% makes an absolute motion instead of relative
def mv_etel'
if ($# != 2) {
eprint "Usage: mv_etel motor position"
exit
}
_mv_etel $*
p "starting to wait end of motion"
_poll_etel($1)
p "syncing positions"
read_motors(6)
'
#%IU% <motor> <position>
#%MDESC% absolute motion
def _mv_etel'
if ($# != 2) {
eprint "Usage: mv_etel motor position"
exit
}
_check0 "$1"
_mv_etel_function(motor_mne($1), $2)
'
#%IU% (<mne>, <position>)
#%MDESC% absolute motion
def _mv_etel_function(mne, pos) '{
local mydev
waitmove; get_angles;
mydev = etel_dev(mne)
mychan = motor_par(mne,"channel")
ESRF_ERR =0
esrf_io(mydev,\
"DevMoveAbsolute",\
motor_par(mne,"channel"),\
pos * motor_par(mne,"step_size"))
if (ESRF_ERR != 0) {
p ESRF_ERR_MSG
return -1
}
return 0
}'
#%IU% (motor_num)
#%MDESC% polling on motion
def _poll_etel(num)'{
local mydev
local _ete ret
_ete[0]=9
mydev = etel_dev(num)
while ( _ete[0] != 2){
ESRF_ERR = 0
ret = esrf_io(mydev,\
"DevReadState",\
motor_par(num,"channel"),\
_ete)
if (ESRF_ERR != 0) {p ESRF_ERR_MSG}
}
}'
#%UU% <mne>
#%MDESC% stops explicitely motor <mne>
def etel_stop'{
if ($# != 1) {
p "usage: etel_stop <mne> "
exit
}
etel_stop_function(motor_mne($1))
}'
#%IU% (mne)
#%MDESC% stops explicitely motor <mne>
def etel_stop_function(mne) '{
local mydev mychan
mydev = etel_dev(mne)
mychan = motor_par(mne,"channel")
esrf_io(mydev,"DevAbortCommand",mychan)
}'
#%UU% <mne>
#%MDESC% prints the status of the motor which can be:
#%BR% - DEVMOVING : motor is moving
#%BR% - DEVON: motor not moving. ready to move
#%BR% - unknown state: else
def etel_status'{
local mne mydev mychan myarr
if ($# != 1) {
p "usage: etel_status <mne> "
exit
}
mne = motor_mne($1)
mydev = etel_dev(mne)
myarr[0]=0
esrf_io(mydev,"DevReadState",mychan,myarr)
if (myarr[0] == 2) {
p "DEVON"
}
else if (myarr[0] == 9) {
p "DEVMOVING"
}
else {
p "unknown state"
}
}'
#%UU% <mne> <Knum>
#%MDESC% read K parameter <Knum> for motor <mne>
#%BR%returns value in global ETEL_resp
def etel_readK'{
if ($# != 2) {
p "usage: etel_readK <mne> <Knum> "
exit
}
_check0 "$1"
etel_readK_function(motor_mne($1),$2)
}'
#%IU% (<mne>, <Knum>)
#%MDESC% read K parameter <Knum> for motor <mne>
#%BR%returns value in global ETEL_resp
def etel_readK_function(mne, myK) '{
local mydev mychan myarr myout
__ETEL_debug ">>>etel_readK on motor: ", mne
mydev = etel_dev(mne)
mychan = motor_par(mne,"channel")
myarr[0] = mychan
myarr[1] = 2
myarr[2] = myK
myout = esrf_io(mydev,"DevReadParam",myarr)
__ETEL_debug ">>>etel_readK Kpar,Kval : ", myK, myout
ETEL_resp = myout
}'
#%UU% <mne> <Knum> <Kval>
#%MDESC% write <Kval> on parameter <Knum> for motor <mne>
#%MDESC% is in increment unit.
def etel_writeK'{
local mne mydev mychan myarr myK myval
if ($# != 3) {
p "usage: etel_writeK <mne> <Knum> <Kval>"
exit
}
_check0 "$1"
etel_writeK_function(motor_mne($1),$2,$3)
}'
#%IU% (<mne>, <Knum>, <Kval>)
#%MDESC% write <Kval> on parameter <Knum> for motor <mne>
#%MDESC% is in increment unit.
def etel_writeK_function(mne,myK,myval) '{
local mydev mychan myarr
__ETEL_debug ">>>etel_writeK on motor: ", mne
mydev = etel_dev(mne)
mychan = motor_par(mne,"channel")
myarr[0] = mychan
myarr[1] = 2
myarr[2] = myK
myarr[3] = myval
__ETEL_debug ">>>etel_writeK Kpar,Kval : ", myK, myval
esrf_io(mydev,"DevSetParam",myarr)
}'
#%UU% <mne> <dir>
#%MDESC% free run on motor <mne> with direction given by the sign of <dir>
def etel_setfreerun' {
local ret mne mydev mychan myarr mydir myK myold mymode
if (($# != 1) && ($# != 2) ){
p "usage: etel_setfreerun <mne> <dir[+/-1>"
exit
}
_check0 "$1"
etel_setfreerun_function(motor_mne($1), $2)
}'
#%IU% (<mne>, <dir>)
#%MDESC% free run on motor <mne> with direction given by the sign of <dir>
def etel_setfreerun_function(mne, mydir)' {
local ret mydev mychan myarr myK myold mymode
__ETEL_debug ">>>etel_setfreerun on motor: ", mne, mydir
mydev = etel_dev(mne)
mychan = motor_par(mne,"channel")
# read present mode value
myK = 202
etel_readK_function(mne, myK)
__ETEL_debug ">>>etel_readK Kpar,Kval : ", myK, ETEL_resp
myold = ETEL_resp
__ETEL_debug ">>>etel_readK old Kval : ", myold
#select freerun mode
etel_writeK_function(mne, myK, 24)
#positive/negative motion
myK = 209
etel_writeK_function(mne, myK, (mydir > 0) ? 0 : 1)
}'
#%UU% <mne>
#%MDESC% standard motion mode on motor <mne>
def etel_setstd' {
if ($# != 1) {
p "usage: etel_setstd <mne> "
exit
}
_check0 "$1"
etel_setstd_function(motor_mne($1))
}'
#%IU% (mne)
#%MDESC% standard motion mode on motor <mne>
def etel_setstd_function(mne) '{
local ret mydev mychan myarr myK myold mymode
mydev = etel_dev(mne)
mychan = motor_par(mne,"channel")
# read present mode value
myK = 202
etel_readK_function(mne, myK)
__ETEL_debug ">>>etel_readK Kpar,Kval : ", myK, ETEL_resp
myold = ETEL_resp
__ETEL_debug ">>>etel_readK old Kval : ", myold
#select std mode (S_curve)
etel_writeK_function(mne, myK, 1)
}'
#%UU% <mne> <dir>
#%MDESC% free run on motor <mne> with direction given by the sign of <dir>
def etel_free_run' {
local ret mne mydev mychan mydir
if ($# != 2) {
p "usage: etel_free_run <mne> <dir[+/-1]> "
exit
}
etel_free_run_function(motor_mne($1),$2)
}'
#%IU% (<mne>, <mydir>)
#%MDESC% free run on motor <mne> with direction given by the sign of <dir>
def etel_free_run_function(mne, mydir) '{
etel_setfreerun_function(mne,mydir)
waitmove; get_angles
A[motor_num(mne)] = 1
move_em
p "now doing a free run: you can stop it using etel_stop"
}'
#%UU%
#%MDESC% toggle the debug mode
if (!(whatis("__ETEL_debug") & 2)) rdef __ETEL_debug \'#$*\'
def ETEL_debug '{
if ((whatis("__ETEL_debug")>>16) <= 3) { # macro length is 3 bytes: comment
rdef __ETEL_debug "eprint"
print "ETEL macro debug mode is ON"
ETEL_DEBUG = 1
}
else {
rdef __ETEL_debug \'#\$*\'
print "ETEL macro debug mode is OFF"
ETEL_DEBUG = 0
}
}'
#%UU% <mne>
#%MDESC% power on motor <mne>
def etel_poweron'{
local mne mydev mychan
if ($# != 1) {
p "usage: etel_poweron <mne> "
exit
}
mne = motor_mne($1)
mydev = etel_dev(mne)
mychan = motor_par(mne,"channel")
esrf_io(mydev,"DevEnablePower",mychan)
}'
#%UU% <mne>
#%MDESC% power off motor <mne>
def etel_poweroff'{
local mne mydev mychan
if ($# != 1) {
p "usage: etel_poweroff <mne> "
exit
}
mne = motor_mne($1)
mydev = etel_dev(mne)
mychan = motor_par(mne,"channel")
esrf_io(mydev,"DevDisablePower",mychan)
}'
#%MACROS%
#%IMACROS%
#%AUTHOR% MCD august 2010
# %BR%$Revision: 1.8 $ / $Date: 2017/01/10 13:56:13 $
#%TOC%
|