顯示具有 Function Block 標籤的文章。 顯示所有文章
顯示具有 Function Block 標籤的文章。 顯示所有文章

9.27.2021

使用ST寫圓盤類程式.md

如何使用ST寫簡易圓盤類PLC程式

什麼是圓盤類機台

簡要定義:

  1. 至少有一個料件輸入站,一個成品輸出站
  2. 至少有一個圓盤
  3. 圓盤依製程有不同的分割數(或稱工位)
  4. 每個分割可放置一或多個工件
  5. 可用人工或送料機輸入料件

網路上找到的:

程式 Layout

一般我會把plc程式的架構切分如下:

  • “Init” 初始化程式碼
  • “Always” 放置常態執行程式碼,含 Function Block 的 Instance
  • “Auto” 自動模式的控制
  • “Manual” 手動模式控制
  • “Error” 錯誤狀態控制碼
  • “St1”
  • “Stx” 各站的週期控制碼

狀態機

手/自動模式的管理,我習慣由統一的狀態機來執行,如圖:

若是較簡單的系統,就會簡化成只有手動/自動的切換,或依各別需求執行。

當然,各站別的動作也是自己的狀態機處理。自動模式時,主狀態機的作用只在喚起各站是否需要執行動作及判斷完成等狀態。

時序圖

  • a:自動的第一個動作都是轉圓盤,後再讓各站作動
  • b:圓盤到位後,St2Cycle才能作業
  • c:St1、St2作業完成後才會再次轉動圓盤

圓盤基本上只有兩個狀態:

  • 轉動中
  • 到位停止中

而各站別基本上有兩種類型,

  • 圓盤到位後才能作動的
  • 可以先動作,圓盤到位後再接續作動

如上圖,St1屬於轉動中可偷跑的,而St2屬於到位後才能作動的。

Sample file

範例檔案

總結

其實有的寫法用ladder的型式去表現會較直覺,但是ST的好處在於方便寫程式碼自動產生器,在開發時能夠縮短不少時間。

寫ST時要注意:

  1. ":=" 等效 “out” 命令
  1. if 指令會佔用較多的steps空間

    如果只有一行指令時,建議轉為單一的命令,雖然可讀性較差,但更省空間…

ST寫作推薦參考:PLC結構化文本設計模式和算法_rediculous的專欄-CSDN博客_plc結構化文本編程

11.12.2019

ST Generator

PLC Structure Text Generator

Recently I wrote a code generator for rotary index drive based control.

This generator helps generate the label declaration, manual control code, even the simple flow process for each station.

By all these process done, it generated more than half code in a cylinder based control project, all you need to do is to optmize the flow control for each station.

Generate code:

Gen code

Generate workflow:

Gen work flow

It’s all based on cylinders, so if we got a station with 3 cylinders like this:

Name Type Group
Down FbCylinder2x1y St8
Forward FbCylinder2x1y St8
Clamp FbCylinder0x1y St8

it generate code below:

With flow process like this:

Name State Group
Down on St1
Clamp on St1
Down off St1
Forward on St1
Down on St1
Clamp off St1
Down off St1

it generate code below:

Written with StackEdit.

10.06.2019

Function Block in PLC

As kind of a newbie in plc programing, though I have some experience in PC based automation control, it’s still many thing I learned from plc programming.

I’ll write some articles to record what I’ve learned from plc.

What’s the purpose when using function block ?

Basically, it’s all because we’re lazy, we don’t want to write those similar piece of code again and again.
Or we can say that it is for modularization, componentization, because of the increasingly complex needs.

Example of simple function block

In here, I’ll describe some very simple function block with mitsubishi Fx series plc.

The control of pneumatic cylinder

Pneumatic cylinder acting
Picture from wikipedia.

Originally, to control a pneumatic cylinder, depends on it’s type, we need a control flag, one or more outputs, some timers to make sure it’s state, some parameters to indicate the time, like this:
PLC control pneumatic cylinder

Thankfully we got function block, we can encapsulate the boring part inside the box.

Usage

With Gx Works2:
Gx Works2 FB

With Gx Works3 FBD:
Gx Works3 FB

With ST language:

The control of vibratory bowl feeder

Bowl Feeder
In the simplest situation to feed individual component parts for assembly on industrial production line, it going to combine bowl feeder with linear feeder.
Basically it’ll have a sensor to indicate if the output of bowl feeder is full or not, a sensor to indicate the output of linear feeder, if it’s on, the next station can pick workpiece from here.

I prefer to write with ST language, the additional benefits of it is we can go further for the creation process, like use some template to auto generate those codes, then we just need to focus on the control flow!

Written with StackEdit.