#%TITLE% MVHP.mac
#
#%DESCRIPTION%
# control of serveral motors (named as protected motors) which must not move
# when a pair of brakes is applied
#%BR% The pair of brakes is controlled by the macros of 'MVH_brakes.mac'.
#%BR% - macro names for brakes control begins with MVH_ or _MVH_
#%BR% - macro names for the control of the protected motors begins with MVHP_
# or _MVHP.
#%BR% - the protected motors are disabled by default when the 'MVHP_setup' is
#run (usually done in the setup).
#%BR%The parameter provided to the MVHP macro functions represents the index of
# the brakes in the list of brakes defined by MVH_brakes_setup
#%BR% A complete setting will be for example:
#%BR%MVH_brakes_setup mhbru 0 mhbrd 0 tegb1u 0 tegb2u 0
#%BR%MVHP_setup MH 0 mh1 mh2 mh3
#%BR%MVHP_setup TEG 1 teg1 teg2
#%BR%Where 'mh1' 'mh2' 'mh3' use 'mhbru' and 'mhbrd' brakes (using label MH for
#selection)
#%BR%and 'teg1' and 'teg2' use 'tegb1u' and 'tegb2u' brakes (using label TEG for
#selection).
need MVH_brakes.mac
#%UU% <label> <brake_index> <mne1> <mne2> ... <mne'n'>
#%MDESC% It defines the protected motors for the brakes '<brakes_index>'.
# This set is labelled <label>.
#%BR%It defines motors <mne1> <mne2> ... <mne'n'> which must not be moved
# when brakes (defined by MVH_brakes_setup at index <brake_index>) are applied
def MVHP_setup'{
unglobal MVHP MVHPLAB
global MVHP MVHPLAB
local ii nbmot mysplit myarr mybi mylab
if ($# < 3) {
p "usage: MVHP_setup <label> <brake_index> <mne1> <mne2> ... "
exit
}
nbmot = $#-2
split("$*",myarr)
mylab = myarr[0]
mbi = myarr[1]
for (ii=0; ii<nbmot; ii++) {
MVHP[mbi][sprintf("trans%d",ii)] = myarr[ii+2]
}
MVHP[mbi]["nbmot"] = nbmot
MVHPLAB[mbi] = mylab
_MVHP_trans_disable(mbi)
}'
#%IU%(ni)
#%MDESC% disables the motors associated to brakes 'ni'
def _MVHP_trans_disable(ni)'{
local ii ind
__MVHP_debug ">>> _MVHP_trans_disable(): "
for (ii=0; ii<MVHP[ni]["nbmot"]; ii++) {
ind = sprintf("trans%d",ii)
if (motor_num(MVHP[ni][ind]) != -1) {
motor_par(motor_num(MVHP[ni][ind]),"disable",1)
}
}
}'
#%IU%(ni)
#%MDESC% enables the motors associated to brakes 'ni'
def _MVHP_trans_enable(ni)'{
local ii ind
__MVHP_debug ">>> _MVHP_trans_enable():"
for (ii=0; ii<MVHP[ni]["nbmot"]; ii++) {
ind = sprintf("trans%d",ii)
if (motor_num(MVHP[ni][ind]) != -1) {
motor_par(motor_num(MVHP[ni][ind]),"disable",0)
}
}
}'
#%UU%(ni)
#%MDESC%set expert mode for brakes 'ni'. In this mode, the motors are enabled and can be
#moved normally (mv ..) and seen normally (wa ...)
def MVHP_expert(ni)'{
# for having no timeout
onwiz 1
if (spec_par("specwiz") == 1) {
_MVHP_trans_enable(ni)
p "releasing the brakes"
MVH_brakeoff(ni)
tty_cntl("md")
printf("DONE")
tty_cntl("me")
}
}'
#%UU%(ni)
#%MDESC%set safe mode. The motors must be moved using withMVHP. And
#can be seen with MVHP_status(ni)
def MVHP_safe(ni)'{
offwiz
_MVHP_trans_disable(ni)
}'
#%UU%(ni)
#%MDESC% reads the motors positions associated to brakes 'ni'.
def MVHP_show(ni)'{
local mystr ii ind
mystr = "wm "
for (ii=0; ii<MVHP[ni]["nbmot"]; ii++) {
ind = sprintf("trans%d",ii)
mystr = sprintf("%s %s ",mystr,MVHP[ni][ind])
}
eval(mystr)
}'
#%UU%(ni)
#%MDESC%Does MVH_brakeon followed by MVHP_safe
def MVHP_user(ni)'{
p "putting on the brakes"
MVH_brakeon(ni)
MVHP_safe(ni)
tty_cntl("md")
printf("DONE")
tty_cntl("me")
}'
#%UU%(ni)
#%MDESC%Gives the status of the brakes and the positions of the associated
# motors
def MVHP_status(ni)'{
local ii dis ind mne
_MVHP_checkmot(ni)
MVH_status(ni)
for (ii=0; ii<MVHP[ni]["nbmot"]; ii++) {
ind = sprintf("trans%d",ii)
if (motor_num(MVHP[ni][ind]) != -1) {
if (motor_par(motor_num(MVHP[ni][ind]),"disable") == 1)
p "motor " MVHP[ni][ind] " is protected"
else {
p "motor " MVHP[ni][ind] " is NOT PROTECTED"
}
}
}
p "MH: protected motors: "
MVHP_show(ni)
}'
#%IU%(n)
#%MDESC% check that the motors associated to brakes 'ni'exist. exit if not.
def _MVHP_checkmot(ni)'{
local ii ind
for (ii=0; ii<MVHP[ni]["nbmot"]; ii++) {
ind = sprintf("trans%d",ii)
if (motor_num(MVHP[ni][ind]) == -1) {
p "MH: motor " MVHP[ni][ind] " is not defined for mirror"
exit
}
}
}'
#%IU%(n)
#%MDESC% to be hooked in cleanup_once.
def _MVHP_cleanup(ni)'{
_MVHP_trans_disable(ni)
# brakes are not applied (it is long to set the brakes)
# so, as it is not a security reason, it is not done.
}'
if (!(whatis("__MVHP_debug") & 2)) rdef __MVHP_debug \'#$*\'
#%UU%
#%MDESC% toggle debug mode for the present macros.
def MVHP_debug '{
if ((whatis("__MVHP_debug")>>16) <= 3) { # just a # sign -> off
rdef __MVHP_debug "eprint"
print "MVHP debug is ON"
} else {
rdef __MVHP_debug \'#\$*\'
print "MVHP debug is OFF"
}
}'
#%UU% <label>
#%MDESC%Selects a set (by its label) for the use of withMVHP.
def MVHP_select'{
local mylab ii found
mylab = "$1"
found = 0
for (ii in MVHPLAB) {
if (MVHPLAB[ii] == mylab) {
MVHP["selected"] = ii
p "MVHP_select: " mylab " : " ii
found = 1
}
}
if (found == 0) {
p "MVHP_select: no set of motors associated to " mylab " !!!"
#create an error
MVHP["selected"]=-1
}
}'
#%UU% <a command>
#%MDESC% For the motor set previously choosen with MVHP_slect, it
#can be used before an ascan or mv command on the motors, like:
#%BR% withMVHP mv <motor> 3
#%BR% 1- releases the brakes and enable the translation motors associated to
# previously selected set.
#%BR% 2- do the choosen command
#%BR% 3- disables the motors and sets the brakes
#%BR%
#%BR%If a controlC is done during this action,the brakes are set after stopping.
def withMVHP'{
local mystr ind
ind = MVHP["selected"]
p "MVHP: working on motors set " MVHPLAB[ind]
# in case of control C:
# disable translation motors, and remove cleanup_always
str = sprintf("_MVHP_trans_disable(%d);",ind)
cdef("cleanup_once",mystr,"_clean_MVHP__")
# release the brakes and enable the translation motor
p "MVHP: releasing the brakes"
MVH_brakeoff(ind)
_MVHP_trans_enable(ind)
p "MH: executing the command: " "$*"
# execute the command
$*
# disable the motor, remove cleanup_always, set the brakes
p "MH: setting the brakes"
_MVHP_trans_disable(ind)
# remove the cleanup always (so let spec do its own controlC
cdef("cleanup_once","","_clean_MVHP__","delete")
MVH_brakeon(ind)
}'
#%MACROS%
#%IMACROS%
#%LOG%
#$Revision: 1.3 $
#$Log: MVHP.mac,v $
#Revision 1.3 2012/02/07 16:39:07 domingue
#correct bug (string in the code ...)
#
#%AUTHOR%
# mcd july 2011
#%TOC%
|