Skip to main content

Robot function-module hot-plug

The six-axis body keeps running. Function modules can be plugged in or removed while it runs. Slaves already in OP are not pushed back to PreOp, and the machine does not stop because another slave appeared or disappeared beside them.

Hot-plug covers two kinds of slaves, and they are handled differently.

Modules already in the DENI: connect only the selected ones this run​

The DENI lists every module this robot will use. A single run connects only a selected subset.

Mark modules that are not selected as optional before the group mapping. An absent optional slave does not count toward whether this run reaches OP. Selected modules stay mandatory: if one is offline, this run cannot enter OP.

Set this flag before the group mapping. If you change it after mapping, the expected WKC has already been fixed for the mandatory slaves at that moment; do not shrink the expected value to accommodate the change.

from darra_ethercat import EtherCATMaster
from darra_ethercat.data.types import EcState

# Station number of the module to connect this time. The base units 1..6 are not in this list; they are always required.
selected = {7, 9}

master = EtherCATMaster(master_index=1)
master.set_eni("robot_all_modules.deni")
master.set_network(adapter)

for slave in master.slaves:
if slave.index <= 6:
continue
slave.optional = slave.index not in selected

if not master.set_state(EcState.OP):
raise RuntimeError("进入 OP 失败:选中的模块或本体没有到齐") # Failed to enter OP: not all of the selected modules or the base unit are present

If setting slave.optional fails it raises RuntimeError; it does not pretend the flag was set. IsOptional in the DENI is the configuration source for the same thing; the runtime assignment decides "which ones this run uses".

For a configured module that was not connected this time, when you plug it back in later, match it to that entry in the DENI by Alias (ESC 0x0012, other than 0 and unique). Once matched, the master configures it according to the declaration and brings it up to OP; the PDO layout is the one already written in the DENI.

An unknown device that suddenly appears on the line​

A slave that is not declared in the DENI is not connected automatically. The master only auto-configures modules that are declared and whose identity verifies; an unknown device is not mapped, no group is enabled, it never reaches OP, and the master reports an error instead of mistaking it for a declared device.

The correct procedure is to declare the device in the DENI (slot, Vendor/Product, optional flag) and then re-scan:

# First change the DENI (declare the module) and reload the configuration, then re-scan.
# Before it is declared, an unknown device is never configured automatically.
master.set_eni("robot_all_modules.deni")
master.set_network(adapter)
if not master.set_state(EcState.OP):
raise RuntimeError("进入 OP 失败:检查声明的槽位与现场设备") # Failed to enter OP: check the declared slots against the devices actually in the field

Constraints:

  • Declared modules: a tail insertion or a re-insertion into a vacant slot is configured and promoted to OP automatically; no manual rebuild is needed.
  • A mid-chain insertion that shifts physical positions makes the master ask for a re-scan; it never rewrites another slot's address.
  • An identity that does not match the declaration (wrong model / old firmware) is refused until the correct device is fitted.
  • Expected WKC is accounted against the real topology. A new station adds its contribution; a removed station truthfully reports a deficit. Never lower the expectation to make the numbers look good.

Automatic rebuild result codes (accounting)​

Result codeMeaningHandling
0The last automatic rebuild succeeded (or never happened)Read the slave table; declared slaves use the PDO layout from the DENI
-20Another automatic rebuild round is in progressThe kernel retries on its own; the application does nothing
-210 slaves reachable after the rescanCheck the receive path; do not treat it as a broken link
-23Slaves are present but not in OPRead the reason for each slave that has not reached OP
-25Resources exhaustedCheck the slave limit / free groups / buffer capacity and report
-1 / -6Invalid master index / master not initializedCheck that master_index starts at 1 and that set_eni succeeded

Reading failures​

SymptomCauseHandling
An unknown slave is connected but the process image is not understoodThat belongs to the user layer. The master provides only the identity and the process image; it does not invent a vendor protocolHandle the PDO in the application according to vendor_id / product_id
A configured module that was not selected this run is offline, so the body cannot enter OPIt was not marked optional before mappingSet slave.optional = True before set_state
Changing the optional flag after mapping makes the WKC mismatchThe optional flag must be set before the group mappingDo not change the expected value. Set the flag before mapping on the next run
A configured module is plugged in but does not enter OPThe identity does not match the declaration (wrong model / old firmware)Check the identity-mismatch event; after the correct device is put back and confirmed, the master promotes it automatically
The numbers still look normal after a selected module drops offlineSomething shrank the expected WKCAccount the expected value against the real topology. Alarm on the loss; do not change the expected value

Difference from tool changing​

On this page, absence of a module that was not selected is allowed, and the body keeps running after an unknown slave is connected. In a tool-change scenario, losing the module in use is a fault: latch it and hold position. Do not use the same logic for both.