Advanced topics
What is EtherCAT ?
EtherCAT (Ethernet for Control Automation Technology) is an Ethernet-based fieldbus system, invented by Beckhoff Automation. The protocol is standardized in IEC 61158 and is suitable for both hard and soft real-time computing requirements in automation technology.
To learn more over EtherCAT, you can see this page.
Available EtherCAT software.
This page resumes characteristics for the two most interesting EtherCAT software.
Details on SOEM implementation
This page gives some explanation on ethercat master implementation using SOEM.
What is CANopen ?
CANopen is a communication protocol and device profile specification for embedded systems used in automation. The CANopen standard consists of an addressing scheme, several small communication protocols and an application layer defined by a device profile. The communication protocols have support for network management, device monitoring and communication between nodes, including a simple transport layer for message segmentation/desegmentation. The lower level protocol implementing the data link and physical layers is usually Controller Area Network (CAN), although devices using some other means of communication (such as Ethernet Powerlink, EtherCAT) can also implement the CANopen device profile.
To learn more over CANopen specifications, you can see this page.
About permissions to run code
When running an ethercatcpp executable you undirectly use SOEM. This library use RAW sockets to communicate over the ethernet link. By default, using this type of socket is not permitted, so the usual and easy way to overcome that problem is to run the program as superuser:
sudo /path/to/my_super_ethercatcpp_program
This works but is obviously not a good idea, mainly because it can create other permission issues but also because any resource generated by your program will be owned by the root user. You should consider using this option only during drivers development process. So basically it means running driver applications in build tree using sudo, something like:
cd /path/to/workspace/packages/ethercatcpp_package
sudo ./build/release/apps/ethercatcpp_package_driver
When a driver has been correctly programmed it is better to use the linux capability CAP_NET_RAW (and maybe also CAP_NET_ADMIN) in order to let your program configure and use raw sockets without restrictions. This should usually be performed on programs in install tree, something like:
sudo setcap 'cap_net_raw,cap_net_admin=eip' /path/to/workspace/install/x86_64_linux_stdc++/ethercatcpp_package/<version>/bin/driver
Starting from now you can freely execute your program as normal:
/path/to/workspace/install/x86_64_linux_stdc++/ethercatcpp_package/<version>/bin/driver
But maybe you may face troubles in most of programs using ethercatcpp, not directly due to ethercatcpp itself but due to other tools commonly used. The main tool always used in our examples is the pid-realtime library from pid-os-utilities package.
auto memory_locker = pid::make_current_thread_real_time();
This later piece of code changes the scheduling policy and priority of threads wich is a restricted operation. In this case you will need to set capabilities: CAP_IPC_LOCK, CAP_SYS_NICE (and optionnally CAP_SYS_ADMIN, so we set it). So you have to add these capabilities by doing:
sudo setcap 'cap_ipc_lock,cap_sys_nice,cap_sys_admin,cap_net_raw,cap_net_admin=eip' /path/to/my_super_ethercatcpp_program
That should be enough.
As a conclusion remember that realtime programs often need to interface with hardware and sometimes, this interfacing requires either adding capabilities or registering the user as a member of a specific group. For instance if you need to access a USB serial device:
ls -l /dev/ttyUSB0
# output is something like "crw-rw---T 1 root dialout 188, 0 Feb 12 12:01 /dev/ttyUSB0"
# need to be member of dialout group to access the device
sudo usermod -a -G dialout $USER
#then need reboot to take effect
Or annother example for comedi:
ls -l /dev/comedi0*
# output is something like "crw-rw---T 1 root dialout 188, 0 Feb 12 12:01 /dev/ttyUSB0"
# crw-rw---- 1 root iocard 98, 0 2024-10-10 00:00 /dev/comedi0
# crw-rw---- 1 root iocard 98, 48 2024-10-10 00:00 /dev/comedi0_subd0
# crw-rw---- 1 root iocard 98, 49 2024-10-10 00:00 /dev/comedi0_subd1
# need to be member of iocard group to access the device
sudo usermod -a -G iocard $USER
#then need reboot to take effect