# File: mechtest.src
#
# This procedure sets MTM1, MTM2 and PAW wheels spinning and
# records the +15V and motor current levels.
#

program "@(#) MODULE: mechtest.src RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/sim/src/mechtest.src"
descr "mechtest - Monitor mechanism power usage"

perform open_log_v05

display "Executing procedure mechtest."
write  !GS9 "Executing procedure mechtest :"
write  !GS9 " %s" !DATE
writen !GS9 " %s" !TIME
writen !GS9 " "
wait time 15

display "Setting MTM1 to position 30; clockwise move."
writen !GS9 "Setting MTM1 to position 30; clockwise move."
tcblock mbm1sp 30
tcblock mbm1cw
wait time 30
writen !GS9 "MTM1 Position: %12d" getint(mkm1pos)
write  !GS9 " %s  " !TIME
write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
writen !GS9 " "

display "Spin MTM1 clockwise"
writen !GS9 " %s  Spin MTM1 clockwise" !TIME
tcblock mbm1sp 200
tcblock mbm1cw
for !LI0 = 1 to 5 
  wait time 15
  write  !GS9 " %s  " !TIME
  write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
  writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
end for 

display "Reset MTM1                                                    "
writen !GS9 " %s  Reset MTM1" !TIME
writen !GS9 " "
tcblock mbm1rs
wait time 15

display "Setting MTM1 to position 30; counterclockwise move."
writen !GS9 "Setting MTM1 to position 30; counterclockwise move."
tcblock mbm1sp 30
tcblock mbm1ccw
wait time 30
writen !GS9 "MTM1 Position: %12d" getint(mkm1pos)
write  !GS9 " %s  " !TIME
write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
writen !GS9 " "

display "Spin MTM1 counterclockwise."
writen !GS9 " %s  Spin MTM1 counterclockwise" !TIME
tcblock mbm1sp 200
tcblock mbm1ccw
for !LI0 = 1 to 5
  wait time 15
  write  !GS9 " %s  " !TIME
  write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
  writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
end for 

display "Reset MTM1                                                    "
writen !GS9 " %s  Reset MTM1" !TIME
writen !GS9 " "
tcblock mbm1rs
wait time 15

display "Setting MTM2 to position 30; clockwise move."
writen !GS9 "Setting MTM2 to position 30; clockwise move."
tcblock mbm2sp 30
tcblock mbm2cw
wait time 30
writen !GS9 "MTM2 Position: %12d" getint(mkm2pos)
write  !GS9 " %s  " !TIME
write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
writen !GS9 " "

display "Spin MTM2 clockwise."
writen !GS9 " %s  Spin MTM2 clockwise" !TIME
tcblock mbm2sp 200
tcblock mbm2cw
for !LI0 = 1 to 5
  wait time 15
  write  !GS9 " %s  " !TIME
  write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
  writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
end for 

display "Reset MTM2                                                    "
writen !GS9 " %s  Reset MTM2" !TIME
writen !GS9 " "
tcblock mbm2rs
wait time 15

display "Setting MTM2 to position 30; counterclockwise move."
writen !GS9 "Setting MTM2 to position 30; counterclockwise move."
tcblock mbm2sp 30
tcblock mbm2ccw
wait time 30
writen !GS9 "MTM2 Position: %12d" getint(mkm2pos)
write  !GS9 " %s  " !TIME
write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
writen !GS9 " "

display "Spin MTM2 counterclockwise"
writen !GS9 " %s  Spin MTM2 counterclockwise" !TIME
tcblock mbm2sp 200
tcblock mbm2ccw
for !LI0 = 1 to 5
  wait time 15
  write  !GS9 " %s  " !TIME
  write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
  writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
end for 

display "Reset MTM2                                                    "
writen !GS9 " %s  Reset MTM2" !TIME
writen !GS9 " "
tcblock mbm2rs
wait time 15

display "Setting PAW to position 30; clockwise move."
writen !GS9 "Setting PAW to position 30; clockwise move."
tcblock mbpasp 30
tcblock mbpacw
wait time 30
writen !GS9 "PAW Position: %12d" getint(mkpapos)
write  !GS9 " %s  " !TIME
write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
writen !GS9 " "

display "Spin PAW clockwise"
writen !GS9 " %s  Spin PAW clockwise" !TIME
tcblock mbpasp 200
tcblock mbpacw
for !LI0 = 1 to 5
  wait time 15
  write  !GS9 " %s  " !TIME
  write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
  writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
end for 

display "Reset PAW                                                    "
writen !GS9 " %s  Reset PAW" !TIME
writen !GS9 " "
tcblock mbpars
wait time 15

display "Setting PAW to position 30; counterclockwise move."
writen !GS9 "Setting PAW to position 30; counterclockwise move."
tcblock mbpasp 30
tcblock mbpaccw
wait time 30
writen !GS9 "PAW Position: %12d" getint(mkpapos)
write  !GS9 " %s  " !TIME
write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
writen !GS9 " "

display "Spin PAW counterclockwise"
writen !GS9 " %s  Spin PAW counterclockwise" !TIME
tcblock mbpasp 200
tcblock mbpaccw
for !LI0 = 1 to 5
  wait time 15
  write  !GS9 " %s  " !TIME
  write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
  writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
end for 

display "Reset PAW                                                    "
writen !GS9 " %s  Reset PAW" !TIME
writen !GS9 " "
tcblock mbpars
wait time 15

display "Setting CAL1 to position 30; clockwise move."
writen !GS9 "Setting CAL1 to position 30; clockwise move."
tcblock mbc1sp 30
tcblock mbc1cw
wait time 30
writen !GS9 "CAL1 Position: %12d" getint(mkc1pos)
write  !GS9 " %s  " !TIME
write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
writen !GS9 " "

display "Spin CAL1 clockwise"
writen !GS9 " %s  Spin CAL1 clockwise" !TIME
tcblock mbc1sp 200
tcblock mbc1cw
for !LI0 = 1 to 5
  wait time 15
  write  !GS9 " %s  " !TIME
  write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
  writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
end for 

display "Reset CAL1                                                    "
writen !GS9 " %s  Reset CAL1" !TIME
writen !GS9 " "
tcblock mbc1rs
wait time 15

display "Setting CAL1 to position 30; counterclockwise move."
writen !GS9 "Setting CAL1 to position 30; counterclockwise move."
tcblock mbc1sp 30
tcblock mbc1ccw
wait time 30
writen !GS9 "CAL1 Position: %12d" getint(mkc1pos)
write  !GS9 " %s  " !TIME
write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
writen !GS9 " "

display "Spin CAL1 counterclockwise"
writen !GS9 " %s  Spin CAL1 counterclockwise" !TIME
tcblock mbc1sp 200
tcblock mbc1ccw
for !LI0 = 1 to 5
  wait time 15
  write  !GS9 " %s  " !TIME
  write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
  writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
end for 

display "Reset CAL1                                                    "
writen !GS9 " %s  Reset CAL1" !TIME
writen !GS9 " "
tcblock mbc1rs
wait time 15

display "Setting CAL2 to position 30; clockwise move."
writen !GS9 "Setting CAL2 to position 30; clockwise move."
tcblock mbc2sp 30
tcblock mbc2cw
wait time 30
writen !GS9 "CAL2 Position: %12d" getint(mkc2pos)
write  !GS9 " %s  " !TIME
write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
writen !GS9 " "

display "Spin CAL2 clockwise"
writen !GS9 " %s  Spin CAL2 clockwise" !TIME
tcblock mbc2sp 200
tcblock mbc2cw
for !LI0 = 1 to 5
  wait time 15
  write  !GS9 " %s  " !TIME
  write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
  writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
end for 

display "Reset CAL2                                                    "
writen !GS9 " %s  Reset CAL2" !TIME
writen !GS9 " "
tcblock mbc2rs
wait time 15

display "Setting CAL2 to position 30; counterclockwise move."
writen !GS9 "Setting CAL2 to position 30; counterclockwise move."
tcblock mbc2sp 30
tcblock mbc2ccw
wait time 30
writen !GS9 "CAL2 Position: %12d" getint(mkc2pos)
write  !GS9 " %s  " !TIME
write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
writen !GS9 " "

display "Spin CAL2 counterclockwise"
writen !GS9 " %s  Spin CAL2 counterclockwise" !TIME
tcblock mbc2sp 200
tcblock mbc2ccw
for !LI0 = 1 to 5
  wait time 15
  write  !GS9 " %s  " !TIME
  write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
  writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
end for 

display "Reset CAL2                                                    "
writen !GS9 " %s  Reset CAL2" !TIME
writen !GS9 " "
tcblock mbc2rs
wait time 15

display "Setting MTM1, MTM2 and PAW to position 30."
writen !GS9 "Setting MTM1, MTM2 and PAW to position 30."
tcblock mbm1sp 30
tcblock mbm1cw
wait time 2
tcblock mbm2sp 30
tcblock mbm2cw
wait time 2
tcblock mbpasp 30
tcblock mbpacw
wait time 30
writen !GS9 "MTM1 Position: %12d" getint(mkm1pos)
writen !GS9 "MTM2 Position: %12d" getint(mkm2pos)
writen !GS9 " PAW Position: %12d" getint(mkpapos)
write  !GS9 " %s  " !TIME
write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
writen !GS9 " "

display "Spin MTM1, MTM2 and PAW wheels together"
write  !GS9 " %s  " !TIME
writen !GS9 "Spin MTM1, MTM2 and PAW wheels together"
tcblock mbm1sp 200
tcblock mbm1ccw
wait time 5
tcblock mbm2sp 200
tcblock mbm2ccw
wait time 5
tcblock mbpasp 200
tcblock mbpaccw
for !LI0 = 1 to 5
  wait time 15
  write  !GS9 " %s  " !TIME
  write  !GS9 "mtr_V: %5.3f   " getreal(m+15mtr)
  writen !GS9 "mtr_I: %5.3f   " getreal(miaemtr)
end for 

display "Reset MTM1, MTM2 and PAW                                          "
write  !GS9 " %s  " !TIME
writen !GS9 "Reset MTM1, MTM2 and PAW"
writen !GS9 " "
tcblock mbm1rs
tcblock mbm2rs
tcblock mbpars
wait time 15

# Sends the proper configure command. Using the following positions
#       M1:	 24	# Continuum tuning
#       M2:	131    	# Continuum tuning
#       PA:     125     # Linear polarization
#
#       C1:	127	# this is the THIRD focus position
#       C2:      17	# this is the THIRD focus position
#
#       C1:	 55	# this is the FOURTH focus position-recurse  Freeze referred-to files?               (default '1')

#       C2:	 89	# this is the FOURTH focus position
#----------------

tcblock mbdpconf 0x0100 0x0100 0x0100 0x0100 0x0100

display "Going to focus position 3 and continuum tuning" 
writen !GS9 "Going to focus position 3 and continuum tuning" 
tcblock mbdpconf     22    131    125    127     17

#display "Going to focus position 4 and continuum tuning" 
#writen !GS9 "Going to focus position 4 and continuum tuning" 
#tcblock mbdpconf     22    131    125     55     89

wait time 30 

writen !GS9 "Finished procedure mechtest : %s" !TIME
writen !GS9 " "

perform close_log_v04
