forked from feecat/OpenSML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenSML_Power.txt
91 lines (85 loc) · 2.09 KB
/
OpenSML_Power.txt
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
(* https://github.com/feecat/opensml *)
FUNCTION_BLOCK OpenSML_Power
VAR_IN_OUT
Axis:OpenSML_Axis;
END_VAR
VAR_INPUT
xEnable: BOOL;
xEmergencyStop: BOOL;
END_VAR
VAR_OUTPUT
xDone: BOOL;
xError: BOOL;
END_VAR
VAR
iState:INT;
tonTimeout:TON;
tTimeOut:TIME:=T#200MS;
END_VAR
(*
MC_Power
Can Also be used MC_Reset, just trigger xEnable.
It is Highly Recommend to use OpenSML_Stop to force stop movements.
*)
Axis.ControlWord.2:=xEmergencyStop;//QuickStop
CASE iState OF
0://start
xDone:=FALSE;
xError:=FALSE;
IF xEnable THEN
Axis.ControlWord.0:=FALSE;//SwitchOn
Axis.ControlWord.1:=FALSE;//EnableVoltage
Axis.ControlWord.3:=FALSE;//EnableOperation
Axis.ControlWord.7:=FALSE;//FaultReset
IF Axis.StatusWord.3 THEN iState:=10;//If there have error, Reset first
ELSE iState:=20;//No error, go go
END_IF
END_IF
10://reset
Axis.ControlWord.7:=TRUE;//bit7 faultreset
tonTimeout(IN:=TRUE,PT:=tTimeOut);
IF tonTimeout.Q AND NOT Axis.StatusWord.3 THEN//not fault
Axis.ControlWord.7:=FALSE;//bit7 faultreset
tonTimeout(IN:=FALSE);
iState:=20;
ELSIF tonTimeout.Q THEN iState:=999;//error
END_IF
20://Enable Voltage
Axis.ControlWord.1:=TRUE;
tonTimeout(IN:=TRUE,PT:=tTimeOut);
IF Axis.StatusWord.0 THEN//ReadyToSwitchOn
tonTimeout(IN:=FALSE);
iState:=30;
ELSIF tonTimeout.Q THEN iState:=999;//error
END_IF
30://Switch ON
Axis.ControlWord.0:=TRUE;
tonTimeout(IN:=TRUE,pt:=tTimeOut);
IF Axis.StatusWord.1 THEN
tonTimeout(IN:=FALSE);
iState:=40;
ELSIF tonTimeout.Q THEN iState:=999;//error
END_IF
40://EnableOperation
Axis.ControlWord.3:=TRUE;
tonTimeout(IN:=TRUE,pt:=tTimeOut);
IF Axis.StatusWord.2 THEN
tonTimeout(IN:=FALSE);
iState:=50;
ELSIF tonTimeout.Q THEN iState:=999;//error
END_IF
50://Success
xDone:=TRUE;
IF NOT xEnable THEN
iState:=0;
END_IF
IF Axis.StatusWord.3 THEN
iState:=999;//Error when running
END_IF
999://Error wait
tonTimeout(IN:=FALSE);
xError:=TRUE;
IF NOT xEnable THEN
iState:=0;
END_IF
END_CASE