#%TITLE% ICE_SHUTTER.MAC
#
#%NAME%
# Macros to use a shutter controled by an IcePAP motor.
#
#%DESCRIPTION%
# The aim is to have a motor moving to two different
# positions depending on an incoming electrical signals.
#
# Typically, for a shutter, the two positions correspond
# to open and close positions of the shutter.
#
# The underlying IcePAP features used are the position
# lists and the tracking mechanism.
#
#%END%
#
# Mandatory standard IcePAP macros
need ice
#%UU% motor pos_closed pos_open [velocity acctime]
#%MDESC%
# Defines the closed and open positions used when tracking the
# incoming signal. The positions are absolute and given in user units.
#
# Optionaly new velocity/acceleration can be used when the motor
# will be moving during tracking. The acceleration is giveng in ms.
#
# No action on motor is done, therefore it's still usable
# as any other motor.
#
# ex ID16b: iceshutsetup shutr 15 0 6000 2
def iceshutsetup '{
local _usage
_usage = "Usage: $0 motor pos_closed pos_open [velocity(Hz) acctime(ms)]"
_usage = _usage "\n\tpositions given in user units"
_usage = _usage "\n\tvelocity given in Hz"
_usage = _usage "\n\tacctime given in ms"
# Minium check on arguments
if($#<3) {
_icepap_err
print "Missing mandatory arguments"
print _usage
exit
}
# Minimum check on motor argument
local mne
mne = "$1"
if(_icepap_ismot(mne)) {
_icepap_err
print "Not an IcePAP motor"
exit
}
# Minium check on arguments
if(($#>3) && ($#<5)) {
_icepap_err
print "Missing velocity and accetime"
print _usage
exit
}
# Optional vel/acct
local _vel _acct
if($#>=5) {
_vel = $4
_acc = $5
} else {
_vel = 0
_acc = 0
}
# TODO: block poslist change while in tracking mode
if(icepap_cmd($1, "get_status") == 0x02) {
_icepap_err
print "Not allowed while tracking incoming signal"
print "Hint: use \"iceshutoff\""
exit
}
_iceshutsetup($1, $2, $3, _vel, _acc)
}'
#%IU%(motor, pos_closed, pos_open, velocity, acctime)
#%MDESC%
# If velocity/acctime are null, the values from the motor config
# will be used.
#
def _iceshutsetup(num, pos_closed, pos_open, vel, acc) '{
local long array poslist[2]
local stp_sz
if(vel == 0) {
vel = motor_par(num, "config_velocity")
}
if(acc == 0) {
acc = motor_par(num, "config_acceleration")
}
motor_par(num, "shutr_vel", vel, "add")
motor_par(num, "shutr_acc", acc, "add")
stp_sz = motor_par(num, "step_size")
poslist[0] = stp_sz * dial(num, pos_closed)
poslist[1] = stp_sz * dial(num, pos_open)
# download the new position list into the IcePAP axis
_poslistsetup(num, "CYCLIC", poslist)
motor_par(num, "shutter_mode", 0, "add")
}'
#%UU% motor
#%MDESC%
# Move the motor to the "closed" position and activate the
# tracking on the incoming signals.
#
# No check is done on the current incoming signal level. The current
# level MUST correspond to the "closed" position of the shutter.
#
# The motor velocity/acceleration will be changed to new values if they
# have been given on setup.
#
def iceshuton '{
# Minium check on arguments
_iceshutcheck $*
# TODO: check that the position list has been already loaded
_iceshuton($1)
}'
#%IU%
#%MDESC%
#
def _iceshutcheck '{
# Minium check on arguments
if($#!=1) {
_icepap_err
print "Missing mandatory arguments"
print "$0: motor"
exit
}
# Minimum check on motor argument
local mne
mne = "$1"
if(_icepap_ismot(mne)) {
_icepap_err
print "Not an IcePAP motor"
exit
}
}'
#%IU%(motor)
#%MDESC%
#
def _iceshuton(num) '{
local silent
icepap_cmd(num, "slew_rate", motor_par(num, "shutr_vel"))
icepap_cmd(num, "acceleration", motor_par(num, "shutr_acc"))
silent = 1
_poslisttrackon(num, "INPOS", 0, silent)
motor_par(num, "shutter_mode", 1, "add")
}'
#%UU% motor
#%MDESC%
# Tracking incoming signal is des-activated. The motor can now
# be moved as any other motor. The velocity/acceleration are
# restored with the config values.
#
def iceshutoff '{
# Minium check on arguments
_iceshutcheck $*
_iceshutoff($1)
}'
#%IU%(motor)
#%MDESC%
#
def _iceshutoff(num) '{
local silent
# stop the tracking
silent = 1
_poslisttrackoff(num, silent)
# restore default motion settings
icepap_cmd(num, "slew_rate", motor_par(num, "config_velocity"))
icepap_cmd(num, "acceleration", motor_par(num, "config_acceleration"))
motor_par(num, "shutter_mode", 0, "add")
# Position discrepancies between spec and the
# motor hardware will be silently resolved in favor of the hardware
read_motors(0x06)
}'
#%IU%(motor)
#%MDESC%
#
def _iceshut_sync '{
read_motors(0x06)
}'
#%MACROS%
#%IMACROS%
#%AUTHOR% MP BLISS (Original 05/2016).
# %BR%$Revision: 1.4 $ / $Date: 2021/12/02 11:42:12 $
#%TOC%
|