State Machine
Overview
This chapter provides a general overview of the state machine.
The application starts in CONFIG.
As the name suggests, the user can do configuration here.
For example, the measurement range of an analog input slave can be configured with SDOs.
EtherCAT states up to SAFEOP can be entered without leaving CONFIG.
When an error occurs in this state, ERROR is entered directly.
When the user is done with configuration, they can request OP.
As soon as OP is reached, ACTIVE is entered.
If the master leaves OP again, e.g. because the user requests SAFEOP, the application returns to CONFIG.
When an error occurs in ACTIVE, ERROR TRANSITION is entered.
This gives the user time to bring the bus to a safe state before ERROR is entered and SAFEOP is requested.
For example, when a multi-axis robot is controlled, the user may want to bring it to a controlled stop to not overload the gearboxes instead of just requesting SAFEOP.
The application stays in ERROR TRANSITION until the configured transition timeout expires and then enters ERROR.
With the default transition timeout of 0 ms, ERROR TRANSITION lasts a single cycle, so ERROR is entered right away.
In ERROR, the bus is kept in a safe state.
On entry, the master is requested to SAFEOP if it was in OP, otherwise it keeps its current, lower state.
Slaves that were not reachable during that transition and reconnect in a higher state are brought back to the master’s state.
To enter CONFIG again, Reset is called once the network no longer generates cyclic communication faults, see Reset.
Cyclic Communication Faults
In every master state except INIT, the master checks the result of each cycle.
A cycle counts as faulty when the frame was lost, a slave did not respond correctly, the working counter is wrong, the number of slaves on the bus does not match the ENI file, or a slave is not in the master’s state.
Below OP, a wrong working counter is only reported as a warning when the --relax-wkc-check option is set (see Configuration).
The faults are accumulated in the cyclic fault indicator, which is published as CyclicFaultIndicator on the status port and the OPC UA server.
Every faulty cycle raises the indicator and every good cycle lowers it until it reaches zero.
ERROR is entered when the indicator exceeds a threshold.
A single lost frame therefore does not cause ERROR, while faults that persist over several cycles do.
How much a cycle raises or lowers the indicator and where the threshold lies are implementation details for now.
Clients should only rely on the indicator being zero while the communication is healthy and being greater than zero while faults were detected recently.
Reset requires the indicator to be zero, see Reset.
Commands
The state machine is controlled with two commands, which are available on the control port (Control and Status Ports) and the OPC UA server (OPC UA Server).
RequestMasterState
RequestMasterState requests an EtherCAT state for the master and accepts INIT, PREOP, SAFEOP and OP.
On the OPC UA server this command is the method requestState of the Master object.
It is refused in SHUTDOWN and FINAL.
In ERROR and ERROR TRANSITION a request for OP is refused, while INIT, PREOP and SAFEOP are accepted.
Reset
Reset is accepted only in ERROR and only while the cyclic fault indicator is zero (see Cyclic Communication Faults).
It clears the error and returns the application to CONFIG.
If faults persist, the error condition first needs to be removed.
For example, if ERROR was entered because one device power cycled and is now in INIT, Reset is refused because cyclic communication faults are still detected.
Most error conditions can be recovered (if physically possible) by requesting INIT (and optionally SAFEOP again) before resetting.
The indicator decays with every good cycle, so Reset is accepted shortly after the faults disappear.
States
State |
Description |
|---|---|
CONFIG |
OPC-UA server is running and the EtherCAT master is activated. EtherCAT communication is initiated. The user can do configuration here. Once the master is in OPERATIONAL state, the application will transition to ACTIVE state. |
ACTIVE |
EtherCAT master is in state OPERATIONAL. |
ERROR TRANSITION |
An error ocurred in ACTIVE state. The master will try to keep EtherCAT communication active for a configured time period before transitioning to ERROR state. |
ERROR |
An error occurred (and the transition timeout is expired). EtherCAT master is in SAFEOP or lower (depending on the state at the time of the error). Slaves that are in higher states than the master (e.g. because they were not reachable during the transition) are requested to the master’s state as soon as they are reachable. |
SHUTDOWN |
The EtherCAT master application is shutting down (including OPC-UA server). |
FINAL |
Final state while the process is being terminated. |
State Chart
Transitions
Transition |
Conditions |
|---|---|
|
HasError |
|
IsMasterOperational |
|
HasError or not IsMasterRunning |
|
not IsMasterOperational |
|
not IsErrorTimerActive |
|
IsResetRequested |
|
not IsMasterRunning |
|
IsShutdownRequested |
Conditions
Condition |
Description |
|---|---|
IsMasterRunning |
The EtherCAT master is running, i.e. correctly initialised. EtherCAT communication does not need to be initiated. |
IsMasterOperational |
EtherCAT master is in state OPERATIONAL (‘OP’). |
HasError |
An error has occurred. |
IsErrorTimerActive |
In ERROR TRANSITION state: the timer for the transition period is still active (not expired). |
IsResetRequested |
The user app requested ‘Reset’ in ERROR state. |
IsShutdownRequested |
Shutdown was requested by the operating system. |