倍福TwinCAT 3 气缸动作程序编写
//干涉
bStateAllow:=TRUE;
CylinderStatus.bInterferenceError:=FALSE;
FOR i:=1 TO 4 BY 1 DO
IF CylinderSignal.bInterference[i] THEN
bStateAllow:=FALSE;
CylinderStatus.bInterferenceError:=TRUE;
END_IF
END_FOR
//气缸控制
IF bStateAllow THEN
IF CylinderControl.nControl=nCylinderReset THEN
CylinderStatus.bOpen:=FALSE;
CylinderStatus.bClose:=FALSE;
ELSIF CylinderControl.nControl=nCylinderClose THEN
CylinderStatus.bOpen:=FALSE;
CylinderStatus.bClose:=TRUE;
ELSIF CylinderControl.nControl=nCylinderOpen THEN
CylinderStatus.bOpen:=TRUE;
CylinderStatus.bClose:=FALSE;
END_IF
//ELSE
//CylinderStatus.bOpen:=FALSE;
//CylinderStatus.bClose:=FALSE;
END_IF
//气缸动作延时
tonCylinderOpen(IN:=(CylinderStatus.bOpen) , PT:=tDelay , Q=> , ET=> );
tonCylinderClose(IN:=(CylinderStatus.bClose) , PT:=tDelay , Q=> , ET=> );
//气缸动作错误
IF tonCylinderOpen.Q
AND NOT CylinderSignal.bOpenSensor
AND NOT CylinderOther.bOpenShield THEN
CylinderStatus.bOpenError:=TRUE;
ELSE
CylinderStatus.bOpenError:=FALSE;
END_IF
IF tonCylinderClose.Q
AND NOT CylinderSignal.bCloseSensor
AND NOT CylinderOther.bCloseShield THEN
CylinderStatus.bCloseError:=TRUE;
ELSE
CylinderStatus.bCloseError:=FALSE;
END_IF
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
//描述信息
ACT_comment();
//干涉(若有则添加)
//气缸功能块控制
FOR i:=1 TO nCylinderMaxNum BY 1 DO
cylinder[i].FB(
CylinderControl:=cylinder[i].control ,
CylinderSignal:=cylinder[i].signal ,
CylinderOther:=cylinder[i].other ,
CylinderStatus=>cylinder[i].status );
END_FOR