学习结构化文本,功能块控制一个"pusher"
Learning Structured Text, function block to controll a "pusher"
我有 PC 编程背景(VB/C# .Net 和 PHP),正在学校学习 PLC 编程。在最近的一次测试中,我们让我们在哪里创建一个功能块,该功能块会将生产线的一个元素推送到容器中。
现在,这很简单,所以我在我的代码中添加了一个警报,如果"pusher"(因为缺少更好的词)将在 10 秒内未完成操作时激活。
我的问题是推送器立即进入警报状态并且它似乎有很多错误:(所以任何答案都会给出一些关于如何更好地构建我的代码的方向,或者弄清楚为什么它会进入警报这么快...
(* INIT *)
(* Drive the pusher back if its out on init *)
IF M8002 THEN
SkyvTilbake := TRUE; (* My "Function"/Step to retract the pusher *)
Ferdig := FALSE; (*Let other components know that the pushers operation has completed *)
SkyverUtMotor := FALSE; (*This is the engine output for driving the pusher out *)
SkyverInnMotor := FALSE; (* This is the engine output for driving the pusher in *)
END_IF;
(* "Aktiver" is a input to activate the pusher *)
IF Aktiver THEN
SkyvTilbake := FALSE;
SkyvUt := TRUE; (* My "Function"/Step" to push the pusher out *)
Ferdig := FALSE;
END_IF;
(* Push out step *)
IF SkyvUt AND NOT SkyvTilbake AND NOT Alarm THEN
TON_1(IN:= SkyvUt ,PT:= AlarmTid ,Q:= Alarm ,ET:= TimeLeft );
SkyverUtMotor := TRUE;
(* When sensor out activates (input), retract the pusher *)
IF SensorUte THEN
SkyvUt := FALSE;
SkyvTilbake := TRUE;
SkyverUtMotor := FALSE;
END_IF;
(* retract the pusher as long as there are no alarms *)
ELSIF SkyvTilbake AND NOT Alarm THEN
TON_2(IN:= SkyvTilbake ,PT:= AlarmTid ,Q:= Alarm ,ET:= TimeLeft );
SkyverInnMotor := TRUE;
(* When it reach the normal position, activate "Ferdig" *)
IF SensorInne THEN
SkyverInnMotor := FALSE;
SkyvTilbake := FALSE;
Ferdig := TRUE;
END_IF;
END_IF;
(* When the alarm activates, stop all the engines *)
IF Alarm THEN
SkyverUtMotor := FALSE;
SkyverInnMotor := FALSE;
END_IF;
(* RESET ALARM *)
IF Reset THEN
Alarm := 0;
SkyvTilbake := TRUE;
END_IF;
附言。测试是在 12 月中旬进行的,但我希望了解更多有关结构化文本和设计 PLC 程序的信息。此外,代码设计为在三菱 FXCPU 中运行,并在 GX Works 2
中编写
我没看到您实际在哪里设置计时器的持续时间 (PT:= AlarmTid)。
另外,我对三菱的PLC不熟悉,请问定时器会自动复位吗?看起来你的定时器一旦打开就永远不会关闭。
您还想研究使用 'CASE . . . WHERE',它可以清理代码。
我有 PC 编程背景(VB/C# .Net 和 PHP),正在学校学习 PLC 编程。在最近的一次测试中,我们让我们在哪里创建一个功能块,该功能块会将生产线的一个元素推送到容器中。
现在,这很简单,所以我在我的代码中添加了一个警报,如果"pusher"(因为缺少更好的词)将在 10 秒内未完成操作时激活。
我的问题是推送器立即进入警报状态并且它似乎有很多错误:(所以任何答案都会给出一些关于如何更好地构建我的代码的方向,或者弄清楚为什么它会进入警报这么快...
(* INIT *)
(* Drive the pusher back if its out on init *)
IF M8002 THEN
SkyvTilbake := TRUE; (* My "Function"/Step to retract the pusher *)
Ferdig := FALSE; (*Let other components know that the pushers operation has completed *)
SkyverUtMotor := FALSE; (*This is the engine output for driving the pusher out *)
SkyverInnMotor := FALSE; (* This is the engine output for driving the pusher in *)
END_IF;
(* "Aktiver" is a input to activate the pusher *)
IF Aktiver THEN
SkyvTilbake := FALSE;
SkyvUt := TRUE; (* My "Function"/Step" to push the pusher out *)
Ferdig := FALSE;
END_IF;
(* Push out step *)
IF SkyvUt AND NOT SkyvTilbake AND NOT Alarm THEN
TON_1(IN:= SkyvUt ,PT:= AlarmTid ,Q:= Alarm ,ET:= TimeLeft );
SkyverUtMotor := TRUE;
(* When sensor out activates (input), retract the pusher *)
IF SensorUte THEN
SkyvUt := FALSE;
SkyvTilbake := TRUE;
SkyverUtMotor := FALSE;
END_IF;
(* retract the pusher as long as there are no alarms *)
ELSIF SkyvTilbake AND NOT Alarm THEN
TON_2(IN:= SkyvTilbake ,PT:= AlarmTid ,Q:= Alarm ,ET:= TimeLeft );
SkyverInnMotor := TRUE;
(* When it reach the normal position, activate "Ferdig" *)
IF SensorInne THEN
SkyverInnMotor := FALSE;
SkyvTilbake := FALSE;
Ferdig := TRUE;
END_IF;
END_IF;
(* When the alarm activates, stop all the engines *)
IF Alarm THEN
SkyverUtMotor := FALSE;
SkyverInnMotor := FALSE;
END_IF;
(* RESET ALARM *)
IF Reset THEN
Alarm := 0;
SkyvTilbake := TRUE;
END_IF;
附言。测试是在 12 月中旬进行的,但我希望了解更多有关结构化文本和设计 PLC 程序的信息。此外,代码设计为在三菱 FXCPU 中运行,并在 GX Works 2
中编写我没看到您实际在哪里设置计时器的持续时间 (PT:= AlarmTid)。
另外,我对三菱的PLC不熟悉,请问定时器会自动复位吗?看起来你的定时器一旦打开就永远不会关闭。
您还想研究使用 'CASE . . . WHERE',它可以清理代码。