[Etherlab-users] Measuring the roundtrip time of the EtherCAT packet

Gavin Lambert gavin.lambert at tomra.com
Sat Mar 13 09:04:57 CET 2021


1. Yes, it's a very bad idea to have a busy loop in an RT process.

2. If you're using the EtherCAT-specific drivers then it puts the NIC into a polling-only mode, such that until you make the call to read it, it has no idea that a packet arrived either.  This is usually a good thing as it reduces context switching from interrupts, although it's less important with modern RT kernels unless you're using a very high cycle time.  The generic driver remains interrupt-driven but the library itself still expects you to poll for incoming packets.  If you want a true measurement of the packet latency, the best method is to use Wireshark on an external "monitoring" system.

3. By design, you are supposed to provide configuration of the slaves up-front in the code without use of ecrt_master_get_pdo_entry etc, only using ecrt_slave_config_* calls.  This allows the application and the network to start up while the slaves are powered off or otherwise not yet connected.  Typically you should perform any needed pre-configuration interactively with the "ethercat" command line tool, and then finish up with "ethercat cstruct" to capture the live configuration into data tables that can be used directly in your code.  (Of course, more dynamic methods are possible as well for more complex situations, but you should be able to do whatever it is without relying on the slave hardware being connected at the time of application startup.)

4. This task is already done by ecrt_domain_reg_pdo_entry_list based on those tables from above.


Gavin Lambert
Senior Software Developer

 


COMPAC SORTING EQUIPMENT LTD | 4 Henderson Pl | Onehunga | Auckland 1061 | New Zealand
Switchboard: +49 2630 96520 | https://www.tomra.com

The information contained in this communication and any attachment is confidential and may be legally privileged. It should only be read by the person(s) to whom it is addressed. If you have received this communication in error, please notify the sender and delete the communication.
-----Original Message-----
From: Fontana Nicola
Sent: Friday, 12 March 2021 11:31 pm
To: etherlab-users at etherlab.org
Subject: [Etherlab-users] Measuring the roundtrip time of the EtherCAT packet

This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Hi all,

I'm new to to the EtherLab project, and to the EtherCAT world in general, so my apologies in advance if the questions are dumb.

I'm interested in master development, so I checked the two more popular opensource choices: SOEM and this one (I called it IgH ethercat).
To have a real taste, I implemented two similar test programs on top of both. The full source code is available on Github:

    https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fntd%2Fethercatest&data=04%7C01%7Cgavin.lambert%40tomra.com%7C7ab74df01209434ba61d08d8e541fe44%7C4308d118edd143008a37cfeba8ad5898%7C0%7C0%7C637511418914783843%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=H6%2FCl5YoNMGoOV6IjQF2yxfa8zUbunQkk2WnyjIJJ5k%3D&reserved=0

To measure the roundtrip time, i.e. the time needed to send a packet and receive its response, I have something similar to this pseudocode:

    start = g_get_monotonic_time();

    ecrt_domain_queue(domain);
    ecrt_master_send(master);
    do {
        g_usleep(5);
        ecrt_master_receive(master);
        ecrt_domain_process(domain);
        ecrt_domain_state(domain, &state);
    } while (state.wc_state != EC_WC_COMPLETE);

    roundtrip = g_get_monotonic_time() - start;

Here are my questions.

1. I had to add a 5 us delay to avoid hogging the CPU. Without it,
   every 5/10000 iteration, I was getting a 40 ms (milliseconds!)
   roundtrip. This maybe has nothing to do with EtherLab but... has
   anyone experienced this kind of behavior?

2. Is there a way to do the same without this awful polling loop?
   Callbacks? Anything else?

3. I have a function (fieldbus_automapping) that clears any previous
   PDO mapping and remap everything by using what returned by
   ecrt_master_get_pdo_entry(). This seems quite an obvious candidate
   for `libethercat` but, being a novice in EtherCAT, I'm fearing to say
   rubbish. Does that function existence make any sense? Is it worth to
   be included in `libethercat`?

4. Similar to the previous question: I have a function
   (fieldbus_autoconfigure, more a proof-of-concept than a real
   function) that sequentially registers the outputs and the inputs
   into the process data. Is it too much "high-level" to be upstreamed?

Ciao.
--
Nicola


--
Etherlab-users mailing list
Etherlab-users at etherlab.org
https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.etherlab.org%2Fmailman%2Flistinfo%2Fetherlab-users&data=04%7C01%7Cgavin.lambert%40tomra.com%7C7ab74df01209434ba61d08d8e541fe44%7C4308d118edd143008a37cfeba8ad5898%7C0%7C0%7C637511418914783843%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=%2FD%2Be9NPfENZIGP5RrgY7Y%2BKAUO67QbHRl1DzUmRh%2B9A%3D&reserved=0


More information about the Etherlab-users mailing list