本文摘自Kithara RTS官網對EtherCAT狀态機的介紹
The EtherCAT state machine
EtherCAT狀态機
EtherCAT defines 5 different states BOOT, INIT, PREOP, SAFEOP and OP.These are identified by the Kithara constants KS_ECAT_STATE_BOOT,KS_ECAT_STATE_INIT, KS_ECAT_STATE_PREOP, KS_ECAT_STATE_SAFEOP andKS_ECAT_STATE_OP.
EtherCAt規定了5個不同的狀态,BOOT, INIT, PREOP, SAFEOP 和 OP。
這些不同的狀态在Kithara中被定義為KS_ECAT_STATE_BOOT, KS_ECAT_STATE_INIT, KS_ECAT_STATE_PREOP,KS_ECAT_STATE_SAFEOP and KS_ECAT_STATE_OP.
The EtherCAT standard describes what needs to be done to perform differentstate changes, like setting up mailbox and/or process data communication,initialization of distributed clocks and other things. In general you don'tneed to worry about these things because the Kithara EtherCAT master isperforming most of these things. But you should understand some basics aboutthe state machine to know when which slave configuration is necessary and whenwhich type of communication is possible.
EtherCAT标準描述了怎樣來實作不同狀态的轉變,像是設定郵箱和/或進行資料通訊,初始化分布時鐘等。總之,我們完全不必擔心這些,因為Kithara EtherCAT主機幫我們做了大部分這樣的工作。但是你應該了解關于狀态機的一些基本知識,比如什麼時候哪一個從站需要配置、哪種類型的通訊可行。
To change the state of an EtherCAT slave you use the function KS_changeEcatState. The function requires ahandle, this handle can be an EtherCAT slave, master or dataset. If you pass amaster handle, all connected and created slaves will perform a state change. Ifspecifying a dataset handle, all slaves assigned to this dataset will do thestate change.
我們用函數KS_changeEcatState來改變EtherCAT從站的狀态。該函數需要的參數包括一個句柄,這個句柄可以是EtherCAT的slave,master或是dataset。如果用的是一個master句柄,則所有連接配接和建立的從站狀态都會改變。如果用的是dataset,所有配置設定到這個資料的從站狀态都會改變。
INIT狀态,初始化狀态
If you power on an EtherCAT slave it will be in the state INIT. Also themaster will put every slave into INIT during KS_createEcatMaster unless you forbidthis with the flag KSF_STARTUP_WITHOUT_INIT_STATE. INIT stands forinitialization. Only very basic stuff is possible if a slave is in that state.So one of the few things you can do is getting the slaves identification bycalling KS_queryEcatSlaveState. Also the mailbox isconfigured in this state, but you don't need to worry about that, the masterwill perform this at the state change to PREOP.
打開一個EtherCAT從站,預設以INIT狀态開始。通過KS_createEcatMaster 函數Master可以讓每個Slave處于INIT狀态,除非你用标志位KSF_STARTUP_WITHOUT_INIT_STATE來阻止。隻有所有從站處于該狀态,基本的工作才能進行。實際上在這個狀态下,我們可以進行的操作做很少,其中一個就是通過調用KS_queryEcatSlaveState來查詢從站狀态,當然你也不用擔心Slave的狀态,因為Master在執行Slave轉變到PREOP狀态時會回報Slave的目前狀态。
PREOP,預操作狀态
The state PREOP is basically used for configuring slaves. It is the statebefore it can operate (pre-operational). If you need to configure your slave,like PDO mapping or PDO assignment,this should be done in that state.
Furthermore you can query a slaves information about SDOs and PDOsvia KS_queryEcatSlaveInfo. Also reading andwriting SDOs with the functions KS_postEcatDataObj and KS_readEcatDataObj
Probably most important, process data communication is set up in the statePREOP. This means if you wish to use fast process data communication you have to assign one or more slaves sync managers to a dataset using thefunction KS_assignEcatDataSet.
The configuration you make is not written directly to the slave. Insteadthe master waits for a state change to SAFEOP and writing it down to the slaveas part of the state change.
PREOP狀态是用來配置Slave的。如果要配置Slave,像是PDO映射和PDO配置設定就需要在該狀态下進行。另外,可以通過 KS_queryEcatSlaveInfo來查詢從站有關SDOs和PDOs狀态。
通過函數 KS_postEcatDataObj 和 KS_readEcatDataObj來讀取和寫入SDOs。
可能我們需要知道的最重要的一點就是,過程資料通訊(周期循環)是在PREOP狀态下建立的。這就是說,如果想快速資料通訊,必須用 KS_assignEcatDataSet函數來指定一個或多個從站同步管理給資料集。
配置不是直接寫入從站而是通過主機等待SAFEOP狀态的變化然後作為部分狀态改變寫入從站。
SAFEOP
Here everything is ready to go, but on hold. During start-up you shouldstart your timer containingKS_postEcatDataSet while your slaves arein the state SAFEOP. The slave will answer to everything as if it would be instate OP. You will be able to read PDOs. The slave will not report an error ifyou write a PDO, but it will not actually process writing PDOs while it is inSAFEOP. Also a slave's watchdogs are not enabled while being in that state.
During shutdown the state SAFEOP is the point where you should stop yourtimer.
Note that some slaves need a while after entering SAFEOP before answeringcorrectly toKS_postEcatDataSet. So wait for a successfulreturn of KS_readEcatDataSet before entering OP.
看似都配置好了,但是在進入正式工作前,還需要在這裡等一下。在啟動過程中,還需要從站在SAFEOP狀态時啟動包含KS_postEcatDataSet的定時器。處于SAFEOP模式的Slave會像處于OP狀态一樣響應任何請求。在該模式下也可以讀取PDOs。如果寫入一個PDO,從站不會報錯。實際上,當從站處于SAFEOP狀态時也不會處理寫入的PDOs。另外,從站的看門狗在此狀态也不會有效。
在關閉的過程中,需要再SAFEOP狀态停止定時器。
需要注意的是,進入了SAFEOP狀态之後,某些從站在正确地響應KS_postEcatDataSet之前需要等待一段時間。是以需要正确傳回KS_postEcatDataSet狀态之後才能輸入OP。
OP,opeartion 正常工作狀态
OP like operational. The slave is fully running, watchdogs are enabled anda slave will start process data exchange. For a slave's watchdogs it is important that the process data exchange is performed in a precisely rate. This means ifyou stop your timer containing KS_postEcatDataSet, a slave will fall downinto SAFEOP.
OP是操作的意思。從站成功運作,看門狗激活,從站将會開始資料交換。看門狗會嚴格監視資料的精确傳輸。如果你終止了包含KS_postEcatDataSet的定時器(即主站不再周期性下發資料時),從站将會進去SAFEOP狀态。
BOOT
BOOT is a special slave state which is used to write new firmware into aslave using File over EtherCAT (FoE) with the function KS_downloadEcatFile. Note that not every slavesupports the state BOOT.
BOOT是一個特殊的狀态。在該狀态下,可以使用FoE協定的KS_downloadEcatFile函數給從站下載下傳新的固件。注意:不是所有從站都支援BOOT。
Concluding this, there is an ideally way to get an EtherCAT topology into the state OP. This means normally Kithara API functions would be called in the following order:
這裡給出一個比較簡潔清晰的方法,按照以下順序調用Kithara的API函數,即可使EtherCAT的拓撲結構中的主從站轉換到OP狀态:
· KS_changeEcatState withKS_ECAT_STATE_PREOP
· KS_setEcatPdoMapping (if necessary)
· KS_setEcatPdoAssign (if necessary)
· KS_assignEcatDataSet
· KS_changeEcatState withKS_ECAT_STATE_SAFEOP
· KS_startTimer with a timercontaining KS_postEcatDataSet
· KS_changeEcatState with KS_ECAT_STATE_OP