Abstract: EtherCAT, the industrial Ethernet fieldbus, is increasingly used in industrial control. A key technology for applying EtherCAT to industrial control systems is building an EtherCAT master station. This paper designs a solution for an EtherCAT master station based on the Freescale i.MX6Q processor. First, a dual-kernel real-time operating system (Linux and Xenomai) is built on the i.MX6Q processor. Then, the open-source IgHEtherCATMaster is used to build an embedded real-time EtherCAT master station. Finally, the designed EtherCAT master station is used to develop synchronous clock functions, SYNC interrupt, and PDI interrupt relative position adjustment functions on a Newstar servo driver. Test results show that the EtherCAT master station built on the Freescale i.MX6Q processor with a Linux+Xenomai dual-kernel real-time operating system can meet the requirements of high-precision multi-axis control system linkage control.
With the rapid development of high-speed and high-precision control systems, industrial Ethernet fieldbus is increasingly widely used in control systems [1]. Among them, EtherCAT is a real-time industrial Ethernet technology applied in the field of industrial automation. It has wide applicability, fully complies with Ethernet standards, and can coexist with other Ethernet devices and protocols on the same bus, thereby maximizing the use of Ethernet bandwidth for user data transmission. At the same time, EtherCAT's refresh cycle of less than 100 microseconds makes it suitable for low-level closed-loop control in servo technology. EtherCAT also has good synchronization performance. By using the "distributed clock" mechanism, it can achieve clock synchronization accuracy of less than 1 microsecond between each slave node, which is extremely important in situations where distributed systems are required to work simultaneously [2].
Meanwhile, ARM embedded microprocessors are evolving towards high performance and low power consumption, with increasingly higher clock speeds, richer interface functions, and lower prices. Therefore, compared to industrial PCs, they are more flexible, consume less power, and are less expensive. From a software perspective, on the one hand, the embedded Linux operating system has a simple structure, abundant software resources, and strong reliability and reconfigurability. Its only drawback is its lack of inherent real-time performance, but with real-time extensions or modifications, it can meet the stringent real-time requirements of robot control systems. On the other hand, mature open-source EtherCAT master software, such as Etherlab's IgHEtherCATMaster, makes it easy to build a complete EtherCAT master on an embedded Linux system.
Therefore, this paper adopts a dual-kernel real-time operating system solution of embedded Linux and Xenomai, combined with a high-performance embedded quad-core processor i.MX6Q, to implement an embedded real-time operating system based on i.MX6Q. On this basis, an embedded real-time EtherCAT master station is built using the IgHEtherCATMaster open-source component. The performance of multi-axis synchronous control, as well as the relative position adjustment functions of SYNC interrupt and PDI (Process Data Interface) interrupt, are tested on the built embedded EtherCAT master station.
1. Implementation of an Embedded Real-Time Linux System
There are two main methods for improving the real-time performance of Linux systems [3]. One is to adopt a dual-kernel structure, that is, to nest a real-time kernel in the standard Linux kernel and transform it into a heterogeneous system with dual kernels. All real-time tasks run on the microkernel, while the non-real-time Linux is used as the lowest priority task of the real-time kernel to manage all non-real-time tasks. Typical examples include RTAI and Xenomai. The other is to directly modify the Linux kernel, such as interrupt threading and preemptible spinlocks. A representative example is PREEMPT_RTLinux.
Among these technologies for improving Linux real-time performance, RTAI has good real-time performance, but its support for ARM is not perfect; PREEMPT_RTLinux is a general-purpose, portable real-time patch designed for the standard Linux kernel, but its real-time performance is poor; Xenomai supports many architectures and has relatively good support for the Freescalei.MX6Q processor used in this paper, making it more suitable for building embedded real-time Linux systems.
1.1 Xenomai Live Patch
Xenomai[4], as a free software project, fully complies with the GNU/Linux free software license. Xenomai's implementation is mainly based on ADOES (Adaptive Domain Environment for Operating Systems). By inserting a software-implemented ADOES layer between the operating system and the hardware, it manages and distributes interrupt signals generated by the hardware layer. Multiple kernel domains can exist above ADOES, and the priority of each domain can be set to achieve the purpose of prioritizing task processing. Xenomai can provide a variety of simulators for traditional real-time operating systems. These simulators can provide the APIs required for running corresponding real-time programs. Xenomai currently supports APIs of a variety of mature real-time operating systems such as Vxworks, pSOS+, POSIX, and VRTX.
1.2i.MX6Q processor
The i.MX6Q[5] processor is a high-performance quad-core processor based on ARM Cortex-A9 from Freescale, with a clock speed of up to 1.2GHz. It features 32KB/32KB L1 instruction/data cache; dynamic voltage and frequency regulation; built-in power management module; powerful image acceleration; and Freescale provides it with a complete Linux board support package, making it very easy to build an embedded Linux system.
1.3 Building an Embedded Real-Time Linux System
The Linux+Xenomai dual-kernel real-time operating system was built using the i.MX6Q hardware platform and the imx_3.0.35_4.0.0 and xenomai-2.6.3 from the Freescale board support package. The steps are as follows.
Unzip the Linux kernel source code and Xenomai source code, and enter the Xenomai source code directory. Apply the Xenomai patch to the Linux kernel and configure the kernel. Execute the following commands in sequence:
$./scripts/prepare-kernel.sh\--linux=~/imx_3.0.35_4.0.0\--adeos=~/xenomai-2.6.3/ksrc/arch/arm/patches/mxc/adeos-ipipe-3.0.43-mx6q-1.18-12-pre.patch\
--arch=arm
$./scripts/prepare-kernel.sh\--linux=~/imx_3.0.35_4.0.0\
--adeos=~/xenomai-2.6.3-imx6q/ksrc/arch/arm/patches/mxc/adeos-ipipe-3.0.43-arm-1.18-13.patch\
--arch=arm
$./scripts/prepare-kernel.sh\--linux=~/imx_3.0.35_4.0.0\--adeos=~/xenomai-2.6.3-imx6q/ksrc/arch/arm/patches/mxc/adeos-ipipe-3.0.43-mx6q-1.18-12-post.patch\
--arch=arm
After successful build, compile the Linux kernel source code that has been patched with the Xenomai real-time patch, flash the Linux image and root file system, and power on the EtherCAT master station. Use the dmesg command to check the Xenomai real-time kernel loading status, as shown in Figure 1.
Figure 1. Real-time kernel print information from Xenomai
Finally, a real-time task scheduling latency test was conducted in Xenomai user space [6]. The test results are shown in Table 1.
Through testing, it can be seen that in the Xenomai domain user space, the scheduling latency of real-time tasks is not affected by the Linux domain load; the maximum task scheduling latency is about 10 microseconds, and the average latency is about 3.5 microseconds. The real-time response performance is excellent and can meet the linkage control requirements of high-precision multi-axis control systems.
2. Implementation of Embedded EtherCAT Master
2.1 IgHEtherCATMaster
IgHEtherCATMaster[7] is an open-source EtherCAT master software based on the Linux operating system. It can be used to easily implement EtherCAT master software. It supports real-time extensions of Linux such as RTAI, Xenomai, and PREEMPT_RT. In addition, it provides common Ethernet EtherCAT network card drivers, as well as generic drivers based on the Linux kernel protocol stack. The distributed clock function can synchronize the slave clock to the reference clock, and can also synchronize the slave clock to the master clock. It also supports protocols such as CoE (CANopen over EtherCAT), EoE (Ethernet over EtherCAT), FoE (FileAccess over EtherCAT), and SoE (ServoProfile over EtherCAT).
2.2 Building an Embedded EtherCAT Master Station
IgHEtherCATMaster is designed for general PC platforms and supports x86 architecture processors and PCI interface network cards by default. Therefore, the key technical challenge is to port the local EtherCAT network card device driver for ARM architecture i.MX6Q processors and embedded network cards.
2.2.1 Porting the local EtherCAT network card device driver
There is no unified standard method for modifying the network device driver of the i.MX6Q processor to be compatible with EtherCAT based on the implementation principle of the local EtherCAT network card device driver. There are only some general rules, which are summarized as follows:
(1) The netif_*() function must be avoided for all EtherCAT devices because EtherCAT devices do not go through the Linux kernel’s network protocol stack, so these interfaces provided by the network protocol stack cannot be called.
(2) The EtherCAT device driver works in polling mode. All operations on the EtherCAT device are performed without interruption. Therefore, interruption and calling the interrupt registration program should be avoided. At the same time, the network card driver uses polling mode without interruption. The interrupt handling function and the data packet sending function will not be executed concurrently, and spinlock protection of the sending buffer is no longer needed.
(3) During initialization, the master station allocates two fixed socket buffers. Each time a data packet is sent, a new EtherCAT data frame is first filled into this socket buffer and then passed to the ndo_start_xmit callback function. No new socket buffers are created during the entire process, so the network device driver cannot release the socket buffers as usual.
Figure 26 Axis Synchronous Test Platform
2.2.2 EtherCAT Master Station Compilation and Porting
Unzip the EtherCATMaster source code, and navigate to the EtherCATMaster directory to configure, compile, and install it. Execute the following commands in sequence:
$./configure\
--prefix=~/ethercat-1.5.2/install
--enable-rtdm\
--with-xenomai-dir=~/xeno/usr/xenomai\
--enable-hrtimer\
--enable-generic=no\
--enable-8139too=no\
--enable-fec=yes\
--with-linux-dir=~/imx_3.0.35_4.0.0\
--build=i686-pc-linux-gnu\
--host=arm-linux-gnueabihf\
$make;makemodules
$makeinstall;makemodules_install
In the configuration, the installation path is specified via the `--prefix` option; `--enable-rtdm` indicates the use of Xenomai real-time patching; `--with-xenomai-dir` specifies the directory where the Xenomai library and header files are located; `--enable-hrtimer` indicates the use of the kernel's high-resolution timer; `--enable-fec` indicates enabling the local EtherCAT network device driver for the i.MX6Q processor; `--with-linux-dir` specifies the path to the Linux kernel; `--build` and `--host` respectively indicate the platform used to compile the EtherCATMaster source code and the platform on which the compiled image will run.
2.3 EtherCAT Master Synchronization Performance Test
In robot control systems, multi-axis synchronization performance directly determines the accuracy of multi-axis linkage. EtherCAT can achieve precise clock synchronization control between slave stations. Therefore, this paper focuses on testing the multi-axis synchronization control performance after applying an embedded real-time EtherCAT master station to the robot control system. The test platform is shown in Figure 2. The EtherCAT slave stations use RS2200 and RS2303 servo drivers from STEP, the master station communication mode is set to DC mode, and the servo driver operation mode adopts periodic synchronization position mode with a period of 1ms. A dual-channel oscilloscope is used to test the relative time difference of the SYNC interrupt between the first and last servo drivers.
Multiple measurements of the SYNC interrupt time difference between the first and last servo drives showed a value less than 60ns, meeting the clock synchronization requirements. This indicates that the real-time embedded EtherCAT master constructed in this paper can achieve precise multi-axis synchronous control. (See Figure 3)
Figure 3 SYNC interruption time difference
2.4 Algorithm for Relative Position Adjustment of SYNC Interrupt and PDI Interrupt
While the IgHEtherCATMaster master source code synchronizes the EtherCAT master clock to the first EtherCAT slave clock with DC (Distributed Clocks) functionality, and also synchronizes the EtherCAT slave clock to the EtherCAT master clock, it does not implement the SYNC interrupt and PDI relative position offset in the ET1100 EtherCAT controller chip within the servo driver. To achieve this, this paper modifies the IgHEtherCATMaster source code: the time tsync_start, sent to the ET1100 to start the SYNC interrupt in the EtherCAT source code driver, is encapsulated as an API for user-space programs to call. When the user-space program enters a periodic task, after processing the master clock to reference slave clock synchronization algorithm, the relative position offset of the SYNC interrupt and PDI interrupt no longer changes, meaning the EtherCAT master clock has been synchronized to the reference slave clock. At this point, we can obtain the reference slave time tref_time, and the relative position offset Toffset can be calculated using the following formula 1, where T is the communication period.
(1)
Suppose we want the PDI interrupt to be offset by 50% relative to the SYNC interrupt, that is, the PDI interrupt is in the middle of the two SYNC interrupts, where Tsleep is the sleep time of the periodic task in the next cycle, we can apply the following formula 2:
(2)
Multiple tests have shown that after processing with the above algorithm, the position of the PDI interrupt relative to the SYNC interrupt is indeed at the position we set, with an error range of -40us to 40us. The specific effect is shown in Figure 4.
Figure 4 shows the relative positions of SYNC interrupt and PDI interrupt.
3. Conclusion
This paper first analyzes the implementation mechanism of Xenomai real-time patching, and then constructs an embedded real-time system based on the Freescale i.MX6Q processor using the Xenomai real-time patching extension method.
This paper describes the Linux operating system and details the functionalities of the IgHEtherCATMaster open-source software modules. It then ports this module to a pre-built embedded real-time system, implementing an embedded real-time EtherCAT master station. Multi-axis synchronous control performance, as well as the relative position adjustment functions via SYNC and PDI interrupts, are then tested on the embedded EtherCAT master station. Experimental results show that the embedded real-time EtherCAT master station built on Linux + Xenomai + i.MX6Q processor exhibits good real-time performance and accurate multi-axis synchronous control, meeting the requirements of robot control systems.