Implementation of Ethercat master (SOEM)
To use an Ethercat bus, we have to configure master and all slaves.
Configuration needed to init slaves.
Master need to know all slaves connected and its parameters. Slave configuration is valided when slave accept the state change request and change to Operationnal state.
Change from Init to PreOP
Master reads VendorID, ProductCode and RevisionNumber from EEPROM, and configures Station address registers (address 0x0010:0x0011), SyncManagers registers (0x0800 +) for mailbox communication and initialize DC Clock (if supported) request PreOp State.
Station address registers configuration (0x0010:0x0011)
To identify and send message to slaves, we have to fixed an address for node addressing. In SOEM addressing is made automaticaly depending on slave number and it used an offset (“0x1000”) to set address. For example, the fisrt slave address is 0x1001, second 0x1002 etc… This offset can be change with EC_NODEOFFSET in ethercatconfig.h.
SyncManagers registers configurations (0x0800:0x087F)
SyncManager register are mapped from 0x0800:0x0807 to 0x0878:0X087F (for SyncManager 0 to SyncManager 15). Register can only be written if SyncManager is disabled (+0x6[0] = 0).
| Register address offset | length (bytes) | Description |
|---|---|---|
| 0x0:0x1 | 2 | Physical Start Address |
| 0x2:0x3 | 2 | Length (in bytes) |
| 0x4 | 1 | Control register |
| 0x5 | 1 | Status register |
| 0x6 | 1 | Activate |
| 0x7 | 1 | PDI Control |
- Control register description
| Bit | Description | Reset Value | ECAT read/write |
|---|---|---|---|
| 1:0 | Operation Mode: 00: Buffered (3 buffer mode) 01: Reserved 10: Mailbox (single buffer mode) 11: Reserved | 00 | r/(w) |
| 3:2 | Direction: 00: Read: ECAT read access; PDI write access 01: Write: ECAT write access; PDI read access 10: Reserved 11: Reserved | 00 | r/(w) |
| 4 | Interrupt in ECAT event Request Register: 0: Disable 1: Enable | 0 | r/(w) |
| 5 | Interrupt in PDI event Request Register: 0: Disable 1: Enable | 0 | r/(w) |
| 6 | Watchdog Trigger Enable: 0: Disable 1: Enable | 0 | r/(w) |
| 7 | Reserved, write 0 | 0 | r |
- Status register description
This register is in read only. See register specification page 70.
- Activate description
| Bit | Description | Reset Value | ECAT read/write |
|---|---|---|---|
| 0 | SyncManager Enable/Disable 0: disable 1: Enable | 0 | r/w |
| 1 | Repeat Request | 0 | r/w |
| 5:2 | Reserved, write 0 | 0 | r |
| 6 | Latch Event ECAT: 0: No 1: Generate Latch event | 0 | r/w |
| 7 | Latch Event PDI: 0: No 1: Generate Latch event | 0 | r/w |
- PDI Control description
This register is in read only. See register specification page 72.
Change from PreOP to SafeOP
We now have the network up and configured. Master configures Process Data Mapping (if flexible) finish to configure the SyncManager’s and FMMU’s (0x0600 and following) to link the EtherCAT master and the slaves. Then, it request SafeOp State.
Process Data Mapping
The process data mapping (Input/Output map) is done automatically by SOEM. SOEM strives to keep the logical process image as compact as possible. It is done by trying to fit Bit oriented slaves together in single bytes.
FMMU registers (0X0600 +)
Each FMMU entry is described in 16 Bytes from 0x0600:0x060F to 0x06F0:0x06FF.
| Register address offset | length (bytes) | Description |
|---|---|---|
| 0x0:0x3 | 4 | Logical Start Address |
| 0x4:0x5 | 2 | Length (in bytes) |
| 0x6 | 1 | Logical Start bit |
| 0x7 | 1 | Logical Stop bit |
| 0x8:0x9 | 2 | Physical Start Address |
| 0xA | 1 | Physical Start bit |
| 0xB | 1 | Type |
| 0xC | 1 | Activate |
| 0xD:0xF | 2 | Reserved |
For more details on register configuration, go to page 67 on register datasheet
Change from SafeOP to OP
Master sends valid Outputs, if master receives response from slave it requests Operationnal State.
SEOM Slave configuration code
Ethercat configuration slave is made by ( ec_config ). It enumerate, map and init all slaves
ec_config(uint8 usetable, void *pIOmap)
where :
- usetable (param[in]): TRUE when using config table to init slave, FALSE otherwise.
- pIOmap (param[out]): pointer to IOmap.
- return : workcounter of slave discover datagram (number of slaves found)
ec_config call :
- ec_config_init : enumerate and init slaves => ecx_config_init
- ec_config_map : Maps all PDOs from slave IOmap => ec_config_map_group => ecx_config_map_group
Structure and all infos of one SOEM slave is describe here.
All Ethercat register are describe in Ethercat datasheet section 2
SOEM ecx_config_init
for each slave detected :
- read interface type of slave (reg : 0x0140)
- write node address (configadr) (reg : 0x0010). It use an offset of 0x1000 for better readibility (for slave 1 => address = 0x1001, slave 2 = 0x1002, …).
- write first bit of ESC DL control (reg: 0x0100(0) ) (choise for non ethercate frame)
- read alias address (reg: 0x0012) and “supported number of EEPROM read bytes” in EEPROM status bit 6 (reg: 0x0502(6) )
- read EEPROM infos (SII general section) : Manufacturer ID, product ID, rev number, mailbox infos (write/read offset and length and protocol)
- read DC support in ESC features supported reg (reg: 0X0008(2))
- read network topology from DL status (reg: 0x0110)
-
read port descritpion (reg: 0x0007)
- SyncManager config
- if slave has mailbox => set context (master) SyncManager default param for SM0 and SM1. Type and flags from default spec (SM0: write mailbox, SM1: read mailbox, SM2: output, SM3: input). Then start address and length are set from read data (mailbox).
- if slave is configured in table (from ESI)=> set SyncManager (SM2/SM3).
- read SII general section : if exist => read details of COE, FOE, EOE, SOE and EBUS current.
- read SII String section : if exist, extract name of slave else set name with manu and product ID.
- read SII SyncManager section : if there are SM informations, set SM context (master) start address, length and flags for all SM detected (from SII).
-
read SII FMMU section : if there are SM informations, set FMMU function context (master).
-
if mailbox exist => programm SM0 mailbox in and SM1 mailbox out and writing it in slave SM0/SM1 register
- request Pre-OP mode for slave
SOEM ecx_config_map_group
desciption code
Specifics slaves configurations
Shadow Hand configuration
Shadow hand is not EtherCAT Conformant. It will not work with a normal Beckhoff EtherCAT system.
It using the EtherCAT physical and link layer, but not using the same slave configuration system that other EtherCAT modules would use. In particular it don’t have an Ethercat Slave Information file (ESI). This would normally give the host information about the slave device’s functionality and setting.
In our case, the Master only deals with known types of slaves. Each slave reports its etherCAT Manufacturer and product ID, then the Master load the specific configuration for shadowhand.
Shadow hand is composed by 2 slaves. The first is a dummy slave not used and the second is the “real usefull” slave.
The shadow Hand need :
-
Input/output data size Shadow hand use 70 bytes (= 560 bits) to command its different motors (and parameters) and 232 (= 1856 bits) to return its state (fingers position, biotac informations, etc..).
-
FMMU configuration On SOEM FMMU address and configuration are made automaticaly by the I/O mapping process. We only have to configure the number and the type of each FMMU used. For shadow we used 2 FMMUs, the first is type 0x1 (use mapping for read accesses) and second is type 0x2 (use mapping for write accesses).
-
SyncManagers configurations
| | Start Physical addr | Length | Flags | type |
| :--- | :-----------------: | :-------: | :--------: | :---------------------: |
| SM0 | 0x1000 | 58 bytes | 0x00010126 | written from master (3) |
| SM1 | 0x103a | 12 bytes | 0x00010126 | written from master (3) |
| SM2 | 0x1046 | 220 bytes | 0x00010002 | read from master (4) |
| SM3 | 0x1122 | 12 bytes | 0x00010002 | read from master (4) |
-
If configuration with table is used by SOEM, we have to set “configindex” variable ( > 0).
-
For the moment DC is not used so we forced “hasdc” variable on FALSE for the 2 slaves (dummy and usefull).
Simple wrapper for ethercat master (your lib)
- wrapper pour créer simplement de nouveaux drivers ethercat pour des robots (explication, design ,etc)
The different types of possible EtherCAT telegrams (ethercat_device_adressed_telegram)
APRD = 0x01; // Autoincrement Physical read
NPRD = 0x04; // Node addressed Physical read
APWR = 0x02; // Autoincrement Physical write
NPWR = 0x05; // Node addressed Physical write
APRW = 0x03; // Autoincrement Physical read_write
NPRW = 0x06; // Node addressed Physical read-write
ARMW = 0x0d; // Autoincrement Physical write
// Multiple write
BRD = 0x07; // Broadcast Read
BWR = 0x08; // Broadcast Write