OpenEtherCATsociety / SOEM

Simple Open Source EtherCAT Master
Other
1.31k stars 671 forks source link

Understanding multiple Ethernet frames handling #721

Open PerriAlessandro opened 1 year ago

PerriAlessandro commented 1 year ago

Hello, I'm a student who is using SOEM master for a project work. To be more precise, I'm using EtherCAT protocol to retrieve sensor data from slaves and therefore I have very big Process Data size, which doesn't fit into a single Ethernet maximum size (i.e. 1486 bytes considering only the data part). Hence, the time difference between sending, e.g., 1485 and 1486 bytes should NOT be the same as the time difference between 1486 and 1487 bytes, because a new frame (in this case with just one byte of data) must be prepared and sent through the network, making it more tricky to compute the total communication cycle. By sniffing the network with Wireshark, I noticed that, if multiple frames are sent, the first frame is sent through the network, comes back to the master and only then the second frame is sent and so on. Could anyone please provide me the procedure I should follow to effectively compute the total communication time in case of multiple frames? Thanks in advance, an answer would be very appreciate!

ArthurKetels commented 1 year ago

To answer these questions it is best to look in the code. It is open source after all.

Have a look at ecx_main_send_processdata() in ethercatain.c

It transmits as many packets as needed to get all IOdata out. It does not wait for any of these packets to return. Transmission and reception of PDOs are asynchronous.

It is however possible that non-optimal NIC settings (f.e. coalescing) on your box create the illusion that transmission is sub-optimal. Also running SOEM on Windows does not deliver realtime performance. On a well configured linux box the time separation of two PDO packets should not be more than a few usec.

PerriAlessandro commented 1 year ago

@ArthurKetels thank you for the quick reply! Actually I'm using SOEM on Ubuntu. As you said, I verified that the difference between two consecutive Ethernet frames is almost negligible. Based on SOEM implementation (without distributed clock), is there a way to analitically predict the cycle time (or at least an upper bound) without manually comparing the arrival times on Wireshark, but using info such as the number of slaves, the PDO sizes, the hardware performance etc?
Thank you very much!

ArthurKetels commented 1 year ago

Well, you need to calculate the number of PDO frames being send and the payload.

The first frame has 48 bytes of overhead, every following 28 bytes. Between each packet is 12 bytes of inter gap space.

Then add the slave propagation delay. The exact value can be taken from the slaveinfo output. It measures this delay exactly. The value depends a bit on the hardware used in each slave. When unknown take 340ns per slave.

The last thing to add is the cable propagation delay, only do this when not using the slave info data, because that includes the cable delay. Cable delay is approximately 4.7ns/m.

When you add this all up you get the lower bound of total cycle time. The big unknown is the delay of the computer network stack. It very much depends on hardware and configuration settings.

I have tested SOEM on a slave network with a size of over 1000 units. It works, but delays are quite noticeable.

PerriAlessandro commented 1 year ago

@ArthurKetels Ok, actually my network will have no more than 15 slaves but each one has a very big payload, so I guess that a significant portion of the period will be given by the overall payload. Thank you very much for everything!