#%TITLE% MVH_brakes.mac
#
#%DESCRIPTION%
# control of the brakes of the mirrors.
#%UU% <brakeu_mne> <brakeu_pol> <braked_mne> <braked_pol> ...
#%MDESC% Definition of the sets of brakes.
#One set defines 2 brakes (one 'up' and one 'down') and is associated to a mirror.
#%BR%A brake action is realized by a motor applying a vertical force on an horizontal
# plate to avoid motion on the element pressed by this plate.
#The commands to apply or release a brake is done by moving the motor to a specific
#position (). There are 2 brakes, each one pressing on one region of the plate.
#%BR%Typical setup: MVH_setup brakeu braked [brakebu brakebd ...]
#%BR%- brakeu_mne: mnemonic for 'brake up' motor
#%BR%- brakeu_pol: brake polarity for 'brake up' motor: 0 if [applied on lim-, released on lim+] or 1 if
#[applied on lim+, released on lim-]
#%BR%- braked_mne: mnemonic for 'brake down' motor
#%BR%- braked_pol: brake polarity for 'brake up' motor: 0 if [applied on lim-, released on lim+] or 1 if
#[applied on lim+, released on lim-]
#%BR%The macros will give the possibility to move the brakes of a set at the same time.
def MVH_brakes_setup'{
global MVH
local nbmirr nbarg _nn ii jj pars
nbarg = $#
if ( (int(nbarg/4) * 4) != nbarg) {
p "usage: MVH_brakes_setup <brakeu_mne> <brakeu_pol> <braked_mne> <braked_pol> ..."
exit
}
MVH["nbb"] = nbarg/4
pars[0]=0
_nn = split("$*", pars)
jj =0
for (ii=0; ii<MVH["nbb"]; ii++) {
MVH["brakeu"][ii]= pars[jj];jj++
MVH["brakeupol"][ii] = pars[jj];jj++
if (MVH["brakeupol"][ii] == 0) {
MVH["brakeuon"][ii] = "lim-"
MVH["brakeuoff"][ii] = "lim+"
}
else {
MVH["brakeuon"][ii] = "lim+"
MVH["brakeuoff"][ii] = "lim-"
}
MVH["braked"][ii]= pars[jj];jj++
MVH["brakedpol"][ii] = pars[jj];jj++
if (MVH["brakedpol"][ii] == 0) {
MVH["brakedon"][ii] = "lim-"
MVH["brakedoff"][ii] = "lim+"
}
else {
MVH["brakedon"][ii] = "lim+"
MVH["brakedoff"][ii] = "lim-"
}
}
}'
#%UU%(brake_set_number)
#%MDESC% set brakes ON (wait until end of motion)
def MVH_brakeon(mn)'{
_MVH_checkmot(mn)
#check they are not already moving.
if ( (_MVH_statu(mn) & 0x02) || (_MVH_statd(mn) & 0x02 ) ){
p "MVH: brakes already moving !!! Abort"
MVH_stopu(mn)
MVH_stopd(mn)
}
#move the motors at the same time
chg_dial(motor_num(MVH["brakeu"][mn]),MVH["brakeuon"][mn])
chg_dial(motor_num(MVH["braked"][mn]),MVH["brakedon"][mn])
# polling is not done on both at the same time (usefull ?)
# first poll brake down. when stopped, poll brake up
_MVH_polld(mn)
_MVH_pollu(mn)
# motors are not moving, but following is needed
# by spec to return to prompt at the end of this macro.
wait(1)
# write the status
MVH_status(mn)
}'
#%UU%(brake_set_number)
#%MDESC% set brakes OFF (wait until end of motion)
def MVH_brakeoff(mn)'{
_MVH_checkmot(mn)
#check they are not already moving.
if ( (_MVH_statu(mn) & 0x02) || (_MVH_statd(mn) & 0x02 ) ){
p "MVH: brake up already moving !!! Abort"
MVH_stopu(mn)
MVH_stopd(mn)
}
#move the motors at the same time
chg_dial(motor_num(MVH["brakeu"][mn]),MVH["brakeuoff"][mn])
chg_dial(motor_num(MVH["braked"][mn]),MVH["brakedoff"][mn])
# polling is not done on both at the same time (usefull ?)
# first poll brake down. when stopped, poll brake up
_MVH_polld(mn)
_MVH_pollu(mn)
# motors are not moving, but following is needed
# by spec to return to prompt at the end of this macro.
wait(1)
# write the status
MVH_status(mn)
}'
#%UU%(brake_set_number)
#%MDESC%Gives the status of the brakes
def MVH_status(mn)'{
local vald valu mystr
_MVH_checkmot(mn)
valu = _MVH_statu(mn)
mystr = sprintf("MVH: brake up: %s",MVH["brakeu"][mn])
if ( valu&0x02) {mystr = mystr " moving"} else {mystr = mystr " not moving"}
if ( valu&0x04) {
if (MVH["brakeupol"][mn] == 0){
mystr = mystr " brakeon"
}
else {
mystr = mystr " brakeoff"
}
}
if ( valu&0x08) {
if (MVH["brakeupol"][mn] == 0){
mystr = mystr " brakeoff"
}
else {
mystr = mystr " brakeon"
}
}
p mystr
vald = _MVH_statd(mn)
mystr = sprintf("MVH: brake down: %s",MVH["braked"][mn])
if ( vald&0x02) {mystr = mystr " moving"} else {mystr = mystr " not moving"}
if ( vald&0x04) {
if (MVH["brakedpol"][mn] == 0){
mystr = mystr " brakeon"
}
else {
mystr = mystr " brakeoff"
}
}
if ( vald&0x08) {
if (MVH["brakedpol"][mn] == 0){
mystr = mystr " brakeoff"
}
else {
mystr = mystr " brakeon"
}
}
#if ( vald&0x04) {mystr = mystr " brakeon"}
#if ( vald&0x08) { mystr = mystr " brakeoff"}
p mystr
}'
#%IU%(brake_set_number)
#%MDESC%reads icepap status of the brake up motor.
def _MVH_statu(mn)'{
local val
val = icepap_cmd(motor_num(MVH["brakeu"][mn]),"get_status")
return(val)
}'
#%IU%(brake_set_number)
#%MDESC%reads icepap status of the brake down motor.
def _MVH_statd(mn)'{
local val
val = icepap_cmd(motor_num(MVH["braked"][mn]),"get_status")
return(val)
}'
#%IU%(brake_set_number)
#%MDESC% wait for the end of motion of brake up motor. It returns:
#%BR% - -1 if problem
#%BR% - 1 no limit
#%BR% - 2 if lim+
#%BR% - 3 if lim-
#%BR% - 4 if lim+ and lim-
def _MVH_pollu(mn)'{
local polld valu
_MVH_checkmot(mn)
polld = 0
while (polld == 0) {
valu = _MVH_statu(mn)
#p "read1: " valu
if ( !(valu & 0x02) ) {
# not moving
__MVH_debug ">>> _MVH_pollu(): not moving"
polld = 1
if (valu & 0x08){
# lim+
__MVH_debug ">>> _MVH_pollu(): lim+"
polld++
}
if ( valu & 0x04) {
# lim-
__MVH_debug ">>> _MVH_pollu(): lim-"
polld++
}
}
else {
# moving
__MVH_debug ">>> _MVH_pollu(): moving"
if (valu & 0x08) {
# a limit is hit and motor still moving. try again.
#p "read2: " valu
p " MVH: warning : brake up moving with limit+ active"
}
if (valu & 0x04) {
# a limit is hit and motor still moving. try again.
#p "read2: " valu
p " MVH: warning : brake up moving with limit- active"
}
}
if (polld== 0) {sleep(2);}
}
return(polld)
}'
#%IU%(brake_set_number)
#%MDESC% wait for the end of motion of brake down motor. It returns:
#%BR% - -1 if problem
#%BR% - 1 no limit
#%BR% - 2 if lim+
#%BR% - 3 if lim-
#%BR% - 4 if lim+ and lim-
def _MVH_polld(mn)'{
local polld valu
_MVH_checkmot(mn)
polld = 0
while (polld == 0) {
valu = _MVH_statd()
#p "read1: " valu
if ( !(valu & 0x02) ) {
# not moving
__MVH_debug ">>> _MVH_polld(): not moving"
polld = 1
if (valu & 0x08){
# lim+
__MVH_debug ">>> _MVH_polld(): lim+"
polld++
}
if ( valu & 0x04) {
# lim-
__MVH_debug ">>> _MVH_polld(): lim-"
polld++
}
}
else {
# moving
__MVH_debug ">>> _MVH_polld(): moving"
if (valu & 0x08) {
# a limit is hit and motor still moving.
#p "read2: " valu
p " MVH: warning : brake down moving with limit+ active"
}
if (valu & 0x04) {
# a limit is hit and motor still moving.
#p "read2: " valu
p " MVH: warning : brake down moving with limit- active"
}
}
if (polld == 0) {sleep(2);}
}
return(polld)
}'
#%UU%(brake_set_number)
#%MDESC% set brake up ON
def MVH_brakeuon(mn)'{
__MVH_debug ">>> MVH_brakeuon:"
_MVH_checkmot(mn)
#check not already moving.
if ( (_MVH_statu(mn) & 0x02) ){
p "MVH: brake up already moving !!! Abort"
MVH_stopu(mn)
}
chg_dial(motor_num(MVH["brakeu"][mn]),MVH["brakeuon"][mn])
}'
#%UU%(brake_set_number)
#%MDESC% set brake down ON
def MVH_brakedon(mn)'{
__MVH_debug ">>> MVH_brakedon:"
_MVH_checkmot(mn)
if ( (_MVH_statd(mn) & 0x02) ){
p "MVH: brake down already moving !!! Abort"
MVH_stopd(mn)
}
chg_dial(motor_num(MVH["braked"][mn]),MVH["brakedon"][mn])
}'
#%UU%(brake_set_number)
#%MDESC% set brake up OFF
def MVH_brakeuoff(mn)'{
__MVH_debug ">>> MVH_brakeuoff:"
_MVH_checkmot(mn)
if ( (_MVH_statu() & 0x02) ){
p "MVH: brake up already moving !!! Abort"
MVH_stopu(mn)
}
chg_dial(motor_num(MVH["brakeu"][mn]),MVH["brakeuoff"][mn])
}'
#%UU%(brake_set_number)
#%MDESC% set brake down OFF
def MVH_brakedoff(mn)'{
__MVH_debug ">>> MVH_brakedoff:"
_MVH_checkmot(mn)
if ( (_MVH_statd() & 0x02) ){
p "MVH: brake down already moving !!! Abort"
MVH_stopd(mn)
}
chg_dial(motor_num(MVH["braked"][mn]),MVH["brakedoff"][mn])
}'
#%IU%(brake_set_number)
#%MDESC% check that the motors for MVH are defined. exit if not.
def _MVH_checkmot(mn)'{
if (motor_num(MVH["brakeu"][mn]) == -1) {
p "motor " MVH["brakeu"][mn] " is not defined for mirror MVH"
exit
}
if (motor_num(MVH["braked"][mn]) == -1) {
p "motor " MVH["braked"][mn] " is not defined for mirror MV1"
exit
}
}'
if (!(whatis("__MVH_debug") & 2)) rdef __MVH_debug \'#$*\'
#%UU%
#%MDESC% toggle debug mode for the present macros.
def MVH_debug '{
if ((whatis("__MVH_debug")>>16) <= 3) { # just a # sign -> off
rdef __MVH_debug "eprint"
print "MVH debug is ON"
} else {
rdef __MVH_debug \'#\$*\'
print "MVH debug is OFF"
}
}
'
#%UU%(brake_set_number)
#%MDESC% stops brake up
def MVH_stopu(mn)'{
local val
val = icepap_cmd(motor_num(MVH["brakeu"][mn]),"abort_one")
}'
#%UU%(brake_set_number)
#%MDESC% stops brake down
def MVH_stopd(mn)'{
local val
val = icepap_cmd(motor_num(MVH["braked"][mn]),"abort_one")
}'
#%MACROS%
#%IMACROS%
#%AUTHOR%
# mcd march 2011
#%TOC%
|