-
Notifications
You must be signed in to change notification settings - Fork 2
/
MC_StopMotion.scl
176 lines (165 loc) · 4.96 KB
/
MC_StopMotion.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
FUNCTION_BLOCK FB105
TITLE ='Stop any motion'
AUTHOR : EMC
FAMILY : EMC2
NAME : MC_Stop
VERSION : '2.0'
VAR_INPUT
Execute : BOOL ; //Start the action at rising edge
Deceleration : REAL ; //Deceleration [u/sІ]
END_VAR
VAR_OUTPUT
Busy : BOOL ; //1=Moving
Done : BOOL ; //1=Zero velocity has been reached
CommandAborted : BOOL ; //1=Command was aborted by manual mode
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
ziel : REAL ; //internal use
b : REAL ; //internal use
taHalbe : REAL ; //internal use
Zustand : INT ; //internal use
Coord : DINT ; //internal use
END_VAR
VAR_TEMP
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;
END_IF;
IF Zustand=1 THEN
IF NOT Busy AND Execute THEN
Busy:=true;
Done:=false;
CommandAborted:=false;
Error:=false;
taHalbe:=Axis.Sample_T*0.5;
Coord:=Axis.Coord+1;
b:=Axis.MaxDeceleration;
IF Deceleration>0.0 THEN
b:=Deceleration;
IF Axis.LastNomDeceleration>b AND Axis.LastNomVelocity<>0.0 THEN
b:=Axis.LastNomDeceleration;
END_IF;
END_IF;
IF Axis.AxisState=1 OR
(Axis.AxisState>=6 AND Axis.AxisState<=8) OR
Axis.ManEnable
THEN
Axis.Err.StartErr:=true;
Axis.Error:=true;
Error:=true;
Zustand:=4;
ELSE
Zustand:=2;
Axis.Coord:=Coord;
Axis.AxisState:=6;
Axis.LastNomDeceleration:=b;
IF Axis.LastNomVelocity<0.0 THEN
b:=-b;
END_IF;
ziel:=Axis.LastNomVelocity*Axis.LastNomVelocity*0.5/b+Axis.LastNomPosition;
IF Axis.RemainingDistance<>0.0 THEN
Axis.RemainingDistance:=Axis.InternalNomPosition-Axis.LastNomPosition+Axis.RemainingDistance;
END_IF;
END_IF;
END_IF;
END_IF;
IF Zustand=2 OR Zustand=3 THEN
IF Axis.Error THEN
Err_DW_str:=Axis.Err;
IF Err_w.w1<>w#16#0 THEN
Zustand:=4;
Error:=true;
END_IF;
END_IF;
IF Axis.ManEnable THEN
Zustand:=4;
CommandAborted:=true;
END_IF;
END_IF;
IF Zustand=2 THEN
Axis.NomVelocity:=Axis.LastNomVelocity-b*Axis.Sample_T;
IF Axis.NomVelocity*Axis.LastNomVelocity<=0.0 THEN
Axis.NomVelocity:=0.0;
END_IF;
Axis.InternalNomPosition:=(Axis.LastNomVelocity+Axis.NomVelocity)*taHalbe+Axis.LastNomPosition;
IF Axis.NomVelocity=0.0 THEN
Axis.InternalNomPosition:=ziel;
Zustand:=3;
END_IF;
IF Axis.RemainingDistance<>0.0 THEN
Axis.RemainingDistance:=Axis.RemainingDistance-(Axis.InternalNomPosition-Axis.LastNomPosition);
END_IF;
ELSIF Zustand=3 THEN
IF Axis.AxisState=2 THEN
IF NOT Axis.Err.TargetApproachErr THEN
Done:=true;
END_IF;
Busy:=false;
Zustand:=5;
ELSE
Axis.AxisState:=8;
END_IF;
ELSIF Zustand=4 THEN
Busy:=false;
Zustand:=5;
ELSIF Zustand=5 THEN
IF NOT Execute THEN
Done:=false;
CommandAborted:=false;
Error:=false;
Busy:=false;
Zustand:=1;
END_IF;
END_IF;
END_FUNCTION_BLOCK