'Example program sla4.src  2009-05-27  Ralph Stirling
'I/O:
'	O1: output, READY signal to PLC
'	I1: input, TRIGGER from PLC
'	I2: input, POS1 from PLC
'	I3: input, POS2 from PLC
'	I4: input, POS3 from PLC

'I4 I3 I2
'0  0  0	move to pos#0
'0  0  1	move to pos#1
'0  1  0	move to pos#2
'0  1  1	move to pos#3
'1  0  0	move to pos#4
'1  0  1	move to pos#5
'1  1  0	move to pos#6
'1  1  1	move to pos#7

' Setup servo parameters
KP=400	' proportional gain
KI=30	' integral gain
KD=200	' derivative gain
F	' load parameters

BRKRLS	' release brake

ZS	' clear status word, including limit bits

WHILE 1	' loop forever
	O1=1			' let PLC know we're ready
	WHILE I1==0 LOOP	' wait for trigger from PLC

	d=I2			'xx1 or xx0
	e=I3*2			'x1x or x0x
	f=I4*4			'1xx or 0xx
	g=d+e+f			'all bits together

	O1=0			' not READY now

	IF g==0 h=1000 ENDIF	' pos#0 is 1000 (200 cnts/mm * 5mm)
	IF g==1 h=2000 ENDIF	' pos#1 is 2000
	IF g==2 h=2500 ENDIF	' pos#2 is 2500
	IF g==3 h=4000 ENDIF	' pos#3 is 4000
	IF g==4 h=3000 ENDIF	' pos#4 is 3000
	IF g==5 h=5500 ENDIF	' pos#5 is 5500
	IF g==6 h=6000 ENDIF	' pos#6 is 6000
	IF g==7 h=7000 ENDIF	' pos#7 is 7000

	' do move now

	V=1*32212		' 1 rev/sec (60 RPM)
	A=80			' 10 rev/sec^2

	P=h
	G			' GO!
	TWAIT			' wait for done

	WHILE I1==1 LOOP	' be sure PLC saw our O1=0
	O1=1			' back to READY
LOOP				' loop back to start
END

