'***************************************************************************
'Galil Motion Control Sample DMC Code
'***************************************************************************
'Description:
'Calculate the settling time using an error window
'***************************************************************************
#settle
dist= 10000
speed= 256000
acc= 1000000
dec= 1000000
error= 2;  'error limit squared
loops= 50;  'verify error stays inside deadband
dtime= 1000
wtime= dtime+100
fwdset= -1;  'Forward settle time
~a= 0;  'axis 0 or A
#move
DP~a= 0; 'define position to zero
PR~a= dist
SP~a= speed
AC~a= acc
DC~a= dec
BG ~a
AM ~a
n1= TIME;  'set N1 equal to current time
#l
tf= TIME
JP #endf,tf>n1+dtime;   'JP to ENDF if over time limit
s= 0
#lc
p_err= _TEA
JP #l,((p_err*p_err)>error)
s= s+1;           'counter
JP #lc,s<loops;   'recheck error to be within limit
fwdset= tf-n1
#endf
MG "SettleTime=",fwdset
EN