#%TITLE% Motor Power
#%NAME%
# Macros to manage the electrical power of motors.
#
#%DESCRIPTION%
# These macros allow the electrical power of a motor to be turned off while
# the motor is not moving. This avoids the motor heating, specially useful
# with high-power motors in vacuum environments. There are two working modes:
# %UL%
# %LI% Standard - Motor power is always ON
# %LI% Optimum - Motor power is ON just when the motor moves
# %XUL%
#
# Currently this only works for MAXE motors. Please not that this won't work
# with the DPAP7.
#
# Recent versions of the Maxe device server (linux version) implement this
# functionality through the use of device server resources. The macros
# can still be interested if using an os9 version.
#
#%EXAMPLE%
# %DL%
# %DT% motorpowersetup m1 m2 m3
# %DD% Initialises the macros and configure motors %B%m1%B%, %B%m2%B% and
# %B%m3%B% in %B%Optimum%B% mode
#
# %DT% motorpowerstandard m3
# %DD% Switch motor %B%m3%B% to %B%Standard%B% mode
#
# %DT% motorpoweroptimum m3
# %DD% Switch motor %B%m3%B% back to %B%Optimum%B% mode
# %XDL%
#
#%LOG%
# $Log: motorpower.mac,v $
# Revision 1.2 2008/08/12 14:10:35 rey
# documentation changes
#
# Revision 1.1 2004/04/27 09:20:57 ahoms
# Added motorpowerstatus
#
# Revision 1.0 2003/11/06 16:09:37 ahoms
# Initial revision
#
#%END%
#%UU% mne1 mne2 ...
#%MDESC%
# Setup the motorpower macros. Specified motors will be added
# in Optimum mode. Multiple %B%motorpowersetup%B% lines can be
# specified.
def motorpowersetup '{
global MOTPOW
local mnestr mnearr[] key mne mnum
mnestr = "Enter the motors to configure in \"motorpower\""
mnestr = ($# > 0) ? "$*" : getval(mnestr, "")
split(mnestr, mnearr)
for (key in mnearr) {
mne = mnearr[key]
mnum = motor_num(mne)
if (motor_mne(mnum) != mne) {
print "motorpower invalid motor:", mne
exit
} else if (!motorpower_check(mnum))
exit
cdef("user_getangles", sprintf("motorpower_getangles %s; ", mne), mne, 0x01)
cdef("user_checkall", sprintf("motorpower_checkall %s; ", mne), mne, 0x01)
cdef("user_finished", sprintf("motorpower_finished %s; ", mne), mne, 0x01)
MOTPOW[mne]["config"] = 1
motorpoweroptimum mne
if (SETUP)
setup_tail("motorpower", mne)
}
}'
#%IU% (mnum)
#%MDESC%
# Checks that the specified motor is a MAXE
def motorpower_check(mnum) '{
if (index(motor_par(mnum, "controller"), "MAXE") == 0) {
print "motorpower: motor is not a MAXE:", motor_mne(mnum)
return 0
}
return 1
}'
#%IU% mne
#%MDESC%
# Called in user_getangles. It will save the current position of the motor
def motorpower_getangles '{
if (MOTPOW["$1"]["active"]) {
MOTPOW["$1"]["move"] = 0
MOTPOW["$1"]["pos"] = A[$1]
}
}'
#%IU% mne
#%MDESC%
# Called in user_checkall. It will check if the motor is going to move and
# enable its power in case of Optimum mode
def motorpower_checkall '{
if (MOTPOW["$1"]["active"]) {
if (fabs(A[$1] - MOTPOW["$1"]["pos"]) >= \
(0.9 / motor_par($1, "step_size"))) {
MOTPOW["$1"]["move"] = 1
motorpower_enable($1)
}
}
}'
#%IU% mne
#%MDESC%
# Called in user_finished. If the motor was moved, disable the power if
# it's on Optimum mode
def motorpower_finished '{
if (MOTPOW["$1"]["active"] && MOTPOW["$1"]["move"])
motorpower_disable($1)
}'
#%IU% mne
#%MDESC%
# Switch to Standard motor power control: always on
def motorpowerstandard '{
local xmne
xmne = ($# > 0) ? motor_mne(motor_num($1)) : \
getval("Enter the motor mnemonic", "")
if (!MOTPOW[xmne]["config"]) {
print "motorpower: motor not configured:", xmne, "- Use \"motorpowersetup\""
exit
}
MOTPOW[xmne]["active"] = 0
motorpower_enable(motor_num(xmne))
}'
#%IU% mne
#%MDESC%
# Switch to Optimum motor power control: on only while moving
def motorpoweroptimum '{
local xmne
xmne = ($# > 0) ? motor_mne(motor_num($1)) : \
getval("Enter the motor mnemonic", "")
if (!MOTPOW[xmne]["config"]) {
print "motorpower: motor not configured:", xmne, "- Use \"motorpowersetup\""
exit
}
MOTPOW[xmne]["active"] = 1
motorpower_disable(motor_num(xmne))
}'
#%UU% (mnum)
#%MDESC%
# Enables the specified motor power
def motorpower_enable(mnum) '{
if (motorpower_check(mnum))
esrf_io(motor_par(mnum, "device_id"), "DevEnablePower", \
motor_par(mnum, "channel"))
}'
#%UU% (mnum)
#%MDESC%
# Disables the specified motor power
def motorpower_disable(mnum) '{
if (motorpower_check(mnum))
esrf_io(motor_par(mnum, "device_id"), "DevDisablePower", \
motor_par(mnum, "channel"))
}'
#%IU% mne
#%MDESC%
# Called when the particular motor is removed from the setup
def motorpowerunsetup '{
motorpowerdel $*
}'
#%UU% mne1 mne2 ...
#%MDESC%
# Delete hooks in macros for the specified mnemonics
def motorpowerdel '{
local mnestr mnearr[] key mne
mnestr = "Enter the motors to remove from \"motorpower\""
mnestr = ($# > 0) ? "$*" : getval(mnestr, "")
split(mnestr, mnearr)
for (key in mnearr) {
mne = mnearr[key]
cdef("user_getangles", "", mne, "delete")
cdef("user_checkall", "", mne, "delete")
cdef("user_finished", "", mne, "delete")
motorpower_enable(motor_num(mne))
}
}'
#%UU%
#%MDESC%
# Show the status of all configured motors
def motorpowerstatus '{
local i mne
for (i = 0; i < MOTORS; i++) {
mne = motor_mne(i)
if (MOTPOW[mne]["config"])
printf("%s\t%s\n", mne, MOTPOW[mne]["active"] ? "Optimum" : "Standard")
}
}'
#%MACROS%
#%IMACROS%
#%INTERNALS%
# The macros use the standard %B%user_getangles%B%, %B%user_checkall%B% and
# %B%user_finished%B% macros. In principle, a real motor should not have hooks
# on those macros. If another set of macros hooks on them, the later in the
# setup will be the only one to work.
#
#%AUTHOR% A. Homs, (Original 11/2003) %BR%
# $Revision: 1.2 $ / $Date: 2008/08/12 14:10:35 $
#%TOC%
|