# File: lmchscom.src
#
# This procedure performs the commissioning of MTM1, MTM2, PAW, 
# CAL1, CAL2
#

program "@(#) MODULE: lmchscom.src RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/dev/src/lmchscom.src"
descr "lmchscom - Commission MTM1/2, CAL1/2, PAW simultaneously"

display "Executing Mechanism Commissioning"

write  !GS9 "Executing procedure lmchscom : %s" !DATE
writen !GS9 " %s" !TIME
writen !GS9 " "

tcblock mbsqmtmo 0 0                                ## zero MTM offsets

# -------------------------- RESET --------------------------

inhibit mkm1pos                                     ## inhibit limits
inhibit mkm2pos
inhibit mkpapos
inhibit mkc1pos
inhibit mkc2pos

tcblock mbm1rs                                      ## reset motors
tcblock mbm2rs
tcblock mbpars
tcblock mbc1rs
tcblock mbc2rs

limit mkm1pos 255 255 255 255 2                     ## set limits
limit mkm2pos 255 255 255 255 2
limit mkpapos 255 255 255 255 2
limit mkc1pos 255 255 255 255 2
limit mkc2pos 255 255 255 255 2

wait time 15

enable mkm1pos                                      ## enable limits
enable mkm2pos
enable mkpapos
enable mkc1pos
enable mkc2pos

writen !GS9 "Reset Positions"
setstr !GS0   = "   255    255    255    255    255"
perform lmchsprn_v01

halt

# -------------------------- POSITION 1 --------------------------

inhibit mkm1pos                                     ## inhibit limits
inhibit mkm2pos
inhibit mkpapos
inhibit mkc1pos
inhibit mkc2pos

writen !GS9 " "
writen !GS9 "Command motors in clockwise direction"

tcblock mbdpconf 0x0100 0x0100 0x0100 0x0100 0x0100 ## MV to 0 (set CW def)

tcblock mbdpconf      1      1    125     19    125   ## move motors

limit   mkm1pos   0   0   1   1 2                     ## set limits
limit   mkm2pos   0   0   1   1 2
limit   mkpapos 124 124 125 125 2
limit   mkc1pos  18  18  19  19 2
limit   mkc2pos 124 124 125 125 2

wait time 15

enable mkm1pos                                      ## enable limits
enable mkm2pos
enable mkpapos
enable mkc1pos
enable mkc2pos

halt

setstr !GS0   = "     1      1    125     19    125"
perform lmchsprn_v01

# -------------------------- POSITION 2 --------------------------

inhibit mkm1pos                                     ## inhibit limits
inhibit mkm2pos
inhibit mkpapos
inhibit mkc1pos
inhibit mkc2pos

tcblock mbdpconf     21     41     17     55     17   ## move motors

limit   mkm1pos  20  20  21  21 2                     ## set limits
limit   mkm2pos  40  40  41  41 2
limit   mkpapos  16  16  17  17 2
limit   mkc1pos  54  54  55  55 2
limit   mkc2pos  16  16  17  17 2

wait time 15

enable mkm1pos                                      ## enable limits
enable mkm2pos
enable mkpapos
enable mkc1pos
enable mkc2pos

halt

setstr !GS0   = "    21     41     17     55     17"
perform lmchsprn_v01

# -------------------------- POSITION 3 --------------------------

inhibit mkm1pos                                     ## inhibit limits
inhibit mkm2pos
inhibit mkpapos
inhibit mkc1pos
inhibit mkc2pos

tcblock mbdpconf     41     81     53     91     53   ## move motors

limit   mkm1pos  40  40  41  41 2                     ## set limits
limit   mkm2pos  80  80  81  81 2
limit   mkpapos  52  52  53  53 2
limit   mkc1pos  90  90  91  91 2
limit   mkc2pos  52  52  53  53 2

wait time 15

enable mkm1pos                                      ## enable limits
enable mkm2pos
enable mkpapos
enable mkc1pos
enable mkc2pos

halt

setstr !GS0   = "    41     81     53     91     53"
perform lmchsprn_v01

# -------------------------- POSITION 4 --------------------------

inhibit mkm1pos                                     ## inhibit limits
inhibit mkm2pos
inhibit mkpapos
inhibit mkc1pos
inhibit mkc2pos

writen !GS9 "Command motors in clockwise direction"
tcblock mbdpconf 0x0200 0x0200 0x0200 0x0200 0x0200 ## MV to 0 (set CCW def)

tcblock mbdpconf     81    121     89    127     89   ## move motors

limit   mkm1pos  80  80  81  81 2                     ## set limits
limit   mkm2pos 120 120 121 121 2
limit   mkpapos  88  88  89  89 2
limit   mkc1pos 126 126 127 127 2
limit   mkc2pos  88  88  89  89 2

wait time 15

enable mkm1pos                                      ## enable limits
enable mkm2pos
enable mkpapos
enable mkc1pos
enable mkc2pos

halt

setstr !GS0   = "    81    121     89    127     89"
perform lmchsprn_v01

inhibit mkm1pos                                     ## inhibit limits
inhibit mkm2pos
inhibit mkpapos
inhibit mkc1pos
inhibit mkc2pos

display "Completed Mechanism Commissioning"

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