'***************************************************************************
'Galil Motion Control Sample DMC Code
'***************************************************************************
'Description:
'Web Tension Example.  Change gear ratio based on x/y position change.
'***************************************************************************
#initial                 ;'label
g = 0                    ;'define G
GA y                     ;'set y as master
GR g                     ;'initial gear ratio
JG 0                     ;'initial jog speed
BG A                     ;'begin motion
xp = _TPA                ;'read inital x position
yp = _TPB                ;'read inital y position
XQ #trim, 1

#gear
y = _TPB                 ;'read new y
x = _TPA                 ;'read new x
JP #gear, y = yp         ;'repeat if no y motion
dx = x - xp              ;'compute x increment
DY = y - yp              ;'compute y increment
xp = x                   ;'update x position
yp = y                   ;'update y position
ratio = dx / dy          ;'ratio of increments
g = (g * 7 + ratio) / 8  ;'estimate gear
GR g                     ;'update gear
JP #gear                 ;'repeat cycle
EN

#trim                    ;'label
e = @AN[1] - 4           ;'tension error
JG e * 20                ;'fine jog speed
JP #trim                 ;'repeat
EN                       ;'end program