-
Notifications
You must be signed in to change notification settings - Fork 2
/
MC_MoveJog.scl
426 lines (407 loc) · 11.9 KB
/
MC_MoveJog.scl
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
FUNCTION_BLOCK FB103
TITLE ='Move the axis using directional inputs (jogging)'
AUTHOR : EMC
FAMILY : EMC2
NAME : MC_Jog
VERSION : '2.0'
VAR_INPUT
JogPos : BOOL ; //1=Jog positive
JogNeg : BOOL ; //1=Jog negative
Velocity : REAL := 1.000000e-001; //Maximum velocity [u/s]
Acceleration : REAL := 1.000000e-001; //Acceleration [u/sІ]
Deceleration : REAL := 1.000000e-001; //Deceleration [u/sІ]
END_VAR
VAR_OUTPUT
Busy : BOOL ; //1=Moving
Done : BOOL ; //1=Motion complete
CommandAborted : BOOL ; //1=Command was aborted by another command
Error : BOOL ; //1=Error has occurred within FB
END_VAR
VAR_IN_OUT
Axis : UDT1 ; //Global axis data
Init : BOOL := TRUE; //1=Initialize block
END_VAR
VAR
v_max : REAL ; //internal use
v_max_B AT v_max : ARRAY[0..31] OF BOOL;
a_1 : REAL ; //internal use
a_1_B AT a_1 : ARRAY[0..31] OF BOOL;
b : REAL ; //internal use
b_B AT b : ARRAY[0..31] OF BOOL;
ta : REAL ; //internal use
taHalbe : REAL ; //internal use
Richtung : INT ; //internal use
b0 : REAL ; //internal use
bk1 : REAL ; //internal use
Grenze : REAL ; //internal use
Zustand : INT ; //internal use
Bereich : INT ; //internal use
Coord : DINT ; //internal use
aufl : REAL ; //internal use
AchsLaenge : REAL ; //internal use
END_VAR
VAR_TEMP
over : REAL ; //internal use
vk : REAL ; //internal use
vk_B AT vk : ARRAY[0..31] OF BOOL ;
sk : REAL ; //internal use
vk1 : REAL ; //internal use
sk1 : REAL ; //internal use
Bremspunkt : REAL ; //internal use
vv : REAL ; //internal use
v_over : REAL ; //internal use
Hilf_R : REAL ; //internal use
Hilf_DI : DINT ; //internal use
RundKorrektur_DI : DINT ; //internal use
Err_DW : DWORD ; //internal use
Err_w AT Err_DW : STRUCT
w0 : WORD;
w1 : WORD;
END_STRUCT ;
Err_DW_str AT Err_DW : STRUCT
SWLimitMinExceeded : BOOL ; //1=Min. SW limit switch exceeded
SWLimitMaxExceeded : BOOL ; //1=Max. SW limit switch exceeded
TargetErr : BOOL ; //1=Target beyond travel range
NoSync : BOOL ; //1=Axis not synchronized
DirectionErr : BOOL ; //1=Motion not allowed in direction entered
DataErr : BOOL ; //1=Invalid motion FB parameter
StartErr : BOOL ; //1=Start not possible in current axis state
DistanceErr : BOOL ; //1=Motion is too far
MasterErr : BOOL ; //1=Master axis error with hard stop or wrong axis status
bit09 : BOOL ;
bit10 : BOOL ;
bit11 : BOOL ;
bit12 : BOOL ;
bit13 : BOOL ;
bit14 : BOOL ;
bit15 : BOOL ;
StoppedMotion : BOOL ; //1=Axis is in stop and must be acknowledged
EnableDriveErr : BOOL ; //1=Drive enable missing
FollowingDistErr : BOOL ; //1=Max. following distance exceeded
StandstillErr : BOOL ; //1=Outside standstill range
TargetApproachErr : BOOL ; //1=Target approach error
EncoderErr : BOOL ; //1=Encoder error
OutputErr : BOOL ; //1=Output driver error
ConfigErr : BOOL ; //1=Axis data incorrectly configured
DriveErr : BOOL ; //1=Drive error
bit25 : BOOL ;
bit26 : BOOL ;
bit27 : BOOL ;
bit28 : BOOL ;
bit29 : BOOL ;
bit30 : BOOL ;
bit31 : BOOL ;
END_STRUCT ;
END_VAR
BEGIN
IF Init
THEN
Init:=false;
Done:=false;
Busy:=false;
CommandAborted:=false;
Error:=false;
Zustand:=1;
Bereich:=5;
Richtung:=0;
ta:=Axis.Sample_T;
taHalbe:=ta*5.000000e-001;
aufl:=Axis.aufl;
Grenze:=aufl*1.6777216e+007;
AchsLaenge:=Axis.AchsLaenge;
END_IF;
IF Zustand=1
THEN
IF NOT Busy AND (JogPos OR JogNeg)
THEN
Busy:=true;
Done:=false;
CommandAborted:=false;
Error:=false;
Richtung:=0;
Coord:=Axis.Coord+1;
a_1:=Axis.MaxAcceleration;
b:=Axis.MaxDeceleration;
v_max:=Axis.MaxVelocity;
IF v_max>Velocity THEN v_max:=Velocity; END_IF;
IF a_1>Acceleration THEN a_1:=Acceleration; END_IF;
IF b>Deceleration THEN b:=Deceleration; END_IF;
Err_DW_str:=Axis.Err;
Err_DW_str.SWLimitMinExceeded:=false;
Err_DW_str.SWLimitMaxExceeded:=false;
Axis.Err.StartErr:=Err_DW<>DW#16#0 OR
Axis.AxisState=6 OR
Axis.AxisState=8 OR
(JogPos AND JogNeg)OR
Axis.ManEnable;
IF NOT Axis.Err.StartErr
THEN
Err_DW_str:=Axis.Err;
IF Err_DW_str.SWLimitMinExceeded AND JogPos
THEN
Err_DW_str.SWLimitMinExceeded:=false;
END_IF;
IF Err_DW_str.SWLimitMaxExceeded AND JogNeg
THEN
Err_DW_str.SWLimitMaxExceeded:=false;
END_IF;
Axis.Err.DataErr:= (v_max<=0.0 OR
a_1<=0.0 OR
b<=0.0) OR
(Axis.LastNomDeceleration<>b AND
Axis.LastNomVelocity<>0.0);
Axis.Err.DirectionErr:=Err_DW_str.SWLimitMinExceeded OR
Err_DW_str.SWLimitMaxExceeded;
END_IF;
Err_DW_str:=Axis.Err;
Err_DW_str.SWLimitMinExceeded:=false;
Err_DW_str.SWLimitMaxExceeded:=false;
IF Err_DW<>DW#16#0
THEN
Axis.Error:=true;
Error:=true;
Zustand:=4;
ELSE
sk:=Axis.LastNomPosition;
vk:=Axis.LastNomVelocity;
IF Axis.AxisType
THEN
Hilf_DI:=Axis.LageIstwert_DI;
Axis.LageIstwert_DI:=(Axis.LageIstwert_DI-Axis.PositionOffset) MOD
Axis.AchsLaenge_DI + Axis.PositionOffset;
Hilf_DI:=Hilf_DI-Axis.LageIstwert_DI;
Hilf_R:=DINT_TO_REAL(Hilf_DI)*aufl;
sk:=sk-Hilf_R;
Axis.RundKorrektur:=Axis.RundKorrektur+Hilf_R;
Axis.InternalActPos:=Axis.InternalActPos-Hilf_R;
END_IF;
Axis.InternalPosOffset:=Axis.InternalPosOffset+sk;
Axis.LastInternalPosOffset:=Axis.LastInternalPosOffset+sk;
Axis.InternalActPos:=Axis.InternalActPos-sk;
Axis.VLastNomPosition:=Axis.VLastNomPosition-Axis.LastNomPosition;
Axis.LastNomPosition:=0.0;
IF JogPos
THEN
Richtung:=1;
END_IF;
IF JogNeg
THEN
Richtung:=-1;
END_IF;
Axis.LastNomDeceleration:=b;
IF vk=0.0
THEN
IF Richtung=-1
THEN
a_1:=-a_1;
b:=-b;
v_max:=-v_max;
END_IF;
b0:=0.0;
bk1:=b;
ELSE
a_1_B[7]:=vk_B[7];
b_B[7]:=vk_B[7];
v_max_B[7]:=vk_B[7];
b0:=b;
bk1:=b;
Richtung:=1;
IF vk<0.0
THEN
Richtung:=-1;
END_IF;
END_IF;
Zustand:=2;
Axis.Coord:=Coord;
Axis.AxisState:=4;
Axis.RemainingDistance:=0.0;
END_IF;
END_IF;
END_IF;
IF Zustand=2 OR Zustand=3
THEN
vk:=Axis.LastNomVelocity;
sk:=Axis.LastNomPosition;
IF Richtung<>0
THEN
Bremspunkt:=vk*vk*0.5/b+sk;
IF ABS(Bremspunkt)>=Grenze
THEN
Axis.Error:=true;
Axis.Err.DistanceErr:=true;
END_IF;
IF NOT Axis.AxisType AND Axis.Sync AND Axis.SWLimitEnable
THEN
Bremspunkt:=Bremspunkt+Axis.InternalPosOffset;
IF (Bremspunkt>=Axis.AxisLimitMax AND Richtung=1) OR
(Richtung=-1 AND Bremspunkt<=Axis.AxisLimitMin)
THEN
Axis.Error:=true;
Axis.Err.DistanceErr:=true;
END_IF;
END_IF;
END_IF;
IF Axis.Error
THEN
Err_DW_str:=Axis.Err;
IF Richtung=1 AND Err_DW_str.SWLimitMinExceeded
THEN
Err_DW_str.SWLimitMinExceeded:=false;
END_IF;
IF Richtung=-1 AND Err_DW_str.SWLimitMaxExceeded
THEN
Err_DW_str.SWLimitMaxExceeded:=false;
END_IF;
IF Err_DW<>DW#16#0
THEN
Error:=true;
IF Err_w.w1<>W#16#0
THEN
Zustand:=4;
ELSE
IF Zustand=2
THEN
Richtung:=0;
b0:=0.0;
END_IF;
END_IF;
END_IF;
END_IF;
IF Axis.Coord<>Coord OR Axis.ManEnable
THEN
CommandAborted:=true;
Zustand:=4;
END_IF;
END_IF;
IF Zustand=2
THEN
over:=ABS(Axis.Override)/100.0;
IF over>1.0
THEN
over:=1.0;
END_IF;
v_over:=v_max*over;
IF v_over<>0.0
THEN
vv:=vk/v_over;
ELSE
vv:=2.0;
END_IF;
IF (Richtung=1 AND JogPos) OR (Richtung=-1 AND JogNeg)
THEN
b0:=0.0;
IF vv<1.0
THEN
Bereich:=1;
vk1:=a_1*ta+vk;
ELSIF vv=1.0
THEN
Bereich:=2;
vk1:=vk;
ELSE
Bereich:=6;
vk1:=vk-bk1*ta;
IF vk1*vk<=0.0 OR
(vk=0.0 AND v_over=0.0)
THEN
vk1:=0.0;
END_IF;
END_IF;
ELSE
IF b0<>0.0
THEN
Bereich:=4;
bk1:=b0;
ELSE
Bereich:=3;
END_IF;
END_IF;
IF Bereich=1 OR Bereich=2 OR Bereich=6
THEN
IF (vk1-v_over)*
(vk-v_over)<=0.0 AND
vk<>v_over
THEN
vk1:=v_over;
END_IF;
sk1:=(vk+vk1)*taHalbe+sk;
END_IF;
IF Bereich=3
THEN
vk1:=vk-bk1*ta;
IF vk1*vk<=0.0 OR
(vk=0.0 AND v_over=0.0)
THEN
vk1:=0.0;
END_IF;
sk1:=(vk+vk1)*taHalbe+sk;
IF vk1=0.0 AND v_over<>0.0
THEN
Zustand:=3;
Bereich:=5;
END_IF;
ELSIF Bereich=4
THEN
vk1:=vk-bk1*ta;
IF vk1*vk<=0.0
THEN
vk1:=0.0;
b0:=vk1;
a_1:=-a_1;
b:=-b;
bk1:=b;
v_max:=-v_max;
Richtung:=-Richtung;
END_IF;
sk1:=(vk+vk1)*taHalbe+sk;
END_IF;
IF Axis.AxisType
THEN
IF ABS(sk1)>=AchsLaenge
THEN
RundKorrektur_DI:=TRUNC(sk1/AchsLaenge);
Axis.LageIstwert_DI:=Axis.LageIstwert_DI-RundKorrektur_DI*Axis.AchsLaenge_DI;
Axis.RundKorrektur:=DINT_TO_REAL(RundKorrektur_DI)*AchsLaenge;
sk1:=sk1-Axis.RundKorrektur;
Axis.LastNomPosition:=Axis.LastNomPosition-Axis.RundKorrektur;
Axis.VLastNomPosition:=Axis.VLastNomPosition-Axis.RundKorrektur;
Axis.InternalActPos:=Axis.InternalActPos-Axis.RundKorrektur;
END_IF;
END_IF;
Axis.InternalNomPosition:=sk1;
Axis.NomVelocity:=vk1;
ELSIF Zustand=3
THEN
IF Axis.AxisState=2
THEN
IF NOT Axis.Error
THEN
Done:=true;
END_IF;
Busy:=false;
Zustand:=5;
ELSIF Error
THEN
Axis.AxisState:=8;
ELSE
Axis.AxisState:=5;
END_IF;
ELSIF Zustand=4
THEN
Busy:=false;
Richtung:=0;
Zustand:=5;
ELSIF Zustand=5
THEN
IF (NOT JogPos AND Richtung=1) OR
(NOT JogNeg AND Richtung=-1) OR
(NOT JogPos AND NOT JogNeg)
THEN
Done:=false;
CommandAborted:=false;
Error:=false;
Busy:=false;
Zustand:=1;
END_IF;
END_IF;
END_FUNCTION_BLOCK