-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotion
More file actions
218 lines (218 loc) · 4.89 KB
/
Motion
File metadata and controls
218 lines (218 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
'*************************************************
' AUTO runs on RS and at power up
' Sets intial values
'*************************************************
'
#AUTO;' Initalize Loader for motion
MO;' Motor Off
CE 0;' Main Encoder Type (Normal quadrature)
MT 1;' Motor Type (Servo motor)
BR -1;' Brush Axis Type (Configured for external drive)
OE 1;' !!! Enable Off-On-Error !!! DO NOT REMOVE !!!
CN ,,,,,1;' Configure Digital Output 4 for Drive Enable
OF 0;' Set DAC Offset to 0 Volts
TL 9.999;' +/- 10 Volt DAC Limit
TK 0;' Peak Torque - Not Used - TL is Max Limit
BW 1500;' Loader Brake to set Delay msec
ER 10000;' Set Follow Error counts
KP 1;' P
KI 0;' I
KD 6;' D
FV 35;' Feed Forward Velaocity
AC 50000;' Intial Acceleration counts/sec
DC 50000;' Initial Deceleration coutns/sec
WT 1000;' Wait for a second
XQ #plcscan,1;' Start PLC Thread 1
XQ #filter,3;' Start Analog In Filter Thread 3
TW 2000;' Motion Complete Time-Out msec
DA *[];' Deallocate all arrays
DM data[20];' Create Array to send to Perl program
CB 3;' Clear Error Output to Mill PLC
jogIn=0;' Varible Jogging In
jogRet=0;' Varible Jogging Out
posTol = 8182 ;' Tolerance Counts for Full In & Out
fullIn=1024000;' Loader Fully In Setpoint Counts
fullOut=0;' Loader Fully Out Setpoint Counts
inBit = 0
outBit = 0
inPls=fullIn+posTol
inMns=fullIn-posTol
outPls=fullOut+ posTol
outMns=fullOut-posTol
maxVel= 140000
velocity = 140000
EN
'
'*************************************************
' This Thread acts like a PLC loop scan
' Scan time is set by the AT command in msec
'*************************************************
'
#plcscan
AT0;'
#scan
AT-25;'
'GENERAL STOP MOTION
IF (@IN[4]=0);'Input 4
STX
ENDIF
'
'JOG INSERT LOADER
IF ((@IN[5]=0)&(_BGA=0))
jogIn=1
AC 90000
DC 90000
JG 40000
SH
BG
ENDIF;
'
IF ((@IN[5]=1)&(jogIn=1))
STX
MC
MO
jogIn=0
ENDIF;
'JOG RETRACT LOADER
IF ((@IN[6]=0)&(_BGA=0))
jogRet=1
AC 90000
DC 90000
JG -40000
SH
BG
ENDIF;
IF ((@IN[6]=1)&(jogRet=1))
STX
MC
MO
jogRet=0
ENDIF;
'RE-DEFINE LOADER POSITION
IF (@IN[3]=0);'
DP 0
IF (_XQ2 = -1)
XQ #motion,2;'Start Motion Thread if not running
SB 3;' Set Digital Output 3 No Error to Mill PLC
ENDIF;
ENDIF;
'
' SET/CLEAR BIT FOR IN POSITION TO MILL PLC
IF ((_TPA < inPls)&(_TPA > inMns))
inBit = 1;
ELSE
inBit = 0;
ENDIF
IF ((_TPA < outPls)&(_TPA > outMns))
outBit = 1;
ELSE
outBit = 0;
ENDIF
IF ((inBit=1)|((outBit=1)&(_BGA=0))
SB2;' Output 2 to MIll PLC Fully In or Out
ELSE
CB2
ENDIF
'
' CLEAR OK STATUS BIT TO MILL PLC
IF ((_XQ2 = -1)|((_XQ2 = -1))
CB 3
ENDIF;
' Data to PERL program
data[0] = _RPA
data[1] = _SCA
data[2] = _TC
data[3] = _TEA
data[4] = _TPA
data[5] = _TTA
data[6] = _TVA
data[7] = _ZAA
data[8] = @OUT[1]
data[9] = _MOA
data[10] = _XQ0;'Thread 0 Status
data[11] = _XQ1;'Thread 1 Status
data[12] = _XQ2;'Thread 2 Status
data[13] = _XQ3;'Thread 3 Status
data[14] = TIME;'Time for Heartbeat
JP#scan
'
'*************************************************
'MOTION Thread is started after re-define position
'if the MOTION thread is not already running
'*************************************************
'
#motion
'INSERT LOADER INTO PRESS
' Input 1 Insert Loader from Mill PLC
IF (@IN[1]=0)
AC 50000
DC 50000
PA fullIn
SP 4000
SH
BG
AD 10000;'Nosepiece Contact Counts
SP velocity
MC
WT 500
ENDI
'RETRACT LOADER FROM PRESS
' Input 2 Retract Loader from Mill PLC
IF (@IN[2]=0);'Input 2
AC 50000
DC 50000
PA fullOut
SP velocity
SH
BG
MC
WT 500
ST
MO
ENDIF;
JP #motion
'
' ANALOG INPUT NOISE FILTER & SPEED REQUEST
' This is to smooth out the velocity demand from MIll PLC
'
#filter
an1=@AN[1];'set initial value
k1=1/512;k2=511/512
AT0;'set initial time reference
#loop
an1=(k1*@AN[1])+(k2*an1);AT-2,1
velocity=maxVel * ((an1*.2616705)-.2458133);' Scale 4-20mA to 0-1.000
JP#loop
'
'
'
'
'
#CMDERR
MG "ALARM: Command Error"
CB 3;' Clear OK status Bit to Mill PLC
HX 2;' Halt Execution Thread 2 (Motion)
ST;' Stop
WT 2000;' Wait 2 seconds
MO ;' Motor Off
RE
'
#MCTIME;' Motion Complete Time-Out Subroutine
MG "ALARM: Loader Failed To Complete Motion Command"
CB 3;' Clear OK status Bit to Mill PLC
HX 2;'Halt Execution Thread 2 (Motion)
ST;' Stop
WT 2000;' Wait 2 seconds
MO ;' Motor Off
RE
'
#POSERR
MG "ALARM: Loader Position Error"
CB 3;' Clear OK status Bit to Mill PLC
HX;' Halt Execution Thread 1&2 (PLC & Motion)
ST;' Stop
WT 2000;' Wait 2 seconds
MO;' Motor Off
RE
'
'