EtherCAT状态机----Kithara RTS

本文摘自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


你可能感兴趣的:(EtherCAT状态机----Kithara RTS)