ROS2 Real-Time Performance Optimization and Evaluation: Original Article Open Access
ROS2 Real-Time Performance Optimization and Evaluation: Original Article Open Access
Abstract
Real-time interaction with uncertain and dynamic environments is essential for robotic systems to achieve functions
such as visual perception, force interaction, spatial obstacle avoidance, and motion planning. To ensure the reliability
and determinism of system execution, a flexible real-time control system architecture and interaction algorithm are
required. The ROS framework was designed to improve the reusability of robotic software development by provid-
ing a distributed structure, hardware abstraction, message-passing mechanism, and application prototypes. Rich
ecosystems for robotic development have been built around ROS1 and ROS2 architectures based on the Linux
system. However, because of the fairness scheduling principle of the default Linux system design and the complexity
of the kernel, the system does not have real-time computing. To achieve a balance between real-time and non-real-
time computing, this paper uses the transmission mechanism of ROS2, combines it with the scheduling mechanism
of the Linux operating system, and uses Preempt_RT to enhance the real-time computing of ROS1 and ROS2. The
real-time performance evaluation of ROS1 and ROS2 is conducted from multiple perspectives, including throughput,
transmission mode, QoS service quality, frequency, number of subscription nodes and EtherCAT master. This paper
makes two significant contributions: firstly, it employs Preempt_RT to optimize the native ROS2 system, effectively
enhancing the real-time performance of native ROS2 message transmission; secondly, it conducts a comprehensive
evaluation of the real-time performance of both native and optimized ROS2 systems. This comparison elucidates
the benefits of the optimized ROS2 architecture regarding real-time performance, with results vividly demonstrated
through illustrative figures.
Keywords ROS, Real-time system optimization, Preempt_RT, Real-time performance evaluation of ROS2
© The Author(s) 2023. Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which
permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the
original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or
other third party material in this article are included in the article’s Creative Commons licence, unless indicated otherwise in a credit line
to the material. If material is not included in the article’s Creative Commons licence and your intended use is not permitted by statutory
regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this
licence, visit http://creativecommons.org/licenses/by/4.0/.
Ye et al. Chinese Journal of Mechanical Engineering (2023) 36:144 Page 2 of 15
Figure 12 Comparison of real-time performance of ROS1 and ROS2 before and after optimization
Figure 29 Real-time performance of multiple subscriber nodes in the native system ROS2
Furthermore, an in-depth analysis of the latency under real-time constraints. It should be noted that
characteristics of data transmission at various frequen- the latency also depends on the size of the transmit-
cies optimized with Preempt_RT is conducted. Using ted data, which was fixed at 1K byte in this experiment.
the default Fast-DDS as the message passing middle- The maximum latency was less than 150 µs.
ware, we measured the data transmission latency of
sending and receiving messages at different frequencies 4.8 Real‑time Performance of EtherCAT Master
with a fixed message size of 1K byte. Each frequency The EtherCAT master needs to run on a real-time system
was tested 120 times, and the results were plotted in to ensure strict real-time performance. The robot system
a 3D graph in Figure 31 and a corresponding curve
in Figure 32. It can be observed from the figures that
the latency deviation is small at different frequencies
platform (see Figure 2) has one EtherCAT master and with the CPU running at full load. The system dem-
16 EtherCAT slaves. In the experiment, the master sta- onstrated stable real-time performance, running
tion cycle period was set to 1000 µs, and we obtained the for 25.7 h with a maximum latency of 82 µs and an
EtherCAT master’s latency data for a duration of 1613610 average latency of 2 µs.
ms, as shown in Figure 33. The minimum period of the (3) This study compares the real-time performance of
master station was 982.5 µs, the average period was 999.8 ROS1 and ROS2, both located in the application
µs, and the maximum period was 1022.4 µs. It can be layer above the Linux kernel. The real-time perfor-
seen that the EtherCAT master exhibits good real-time mance of the optimized Preempt_RT-Linux-ROS2
performance and can be applied to robot control. is much better than that of the Native-Linux-ROS2.
Additionally, for a single publisher node corre-
5 Conclusions sponding to multiple subscriber nodes, ROS2 dem-
This paper proposes an optimization and assessment of onstrates fairer real-time performance than ROS1
ROS2’s real-time performance, utilizing a method that for multiple subscribers, making ROS2 more suit-
melds fair and first-in-first-out scheduling strategies for able for the development of real-time control sys-
a robotic control system. This method, predicated on the tems.
ROS2’s DDS transmission mechanism, adopts the use (4) The optimized Preempt_RT-Linux maintains stable
of Preempt_RT to construct a fully preemptive, event- performance for both average jitter and maximum
driven system kernel, thereby improving the timeliness jitter at different frequencies, with a timing jitter
and reliability of ROS2’s data transmission. cycle of less than 60 µs. The study also measures
We engage in both qualitative and quantitative evalu- the real-time performance of the EtherCAT master,
ations of the real-time performance of ROS1 and ROS2, with a timing cycle of 1000 us and a worst-case tim-
considering factors such as throughput, transmission ing cycle of 1022.4 us, demonstrating the effective-
methodology, QoS service quality, frequency, quantity of ness of the optimized system.
subscription nodes, and EtherCAT master. Our findings
indicate reliable real-time performance of the optimized
Acknowledgements
ROS2 with Preempt_RT implementation. This research Not applicable.
intuitively demonstrates that, in large-scale data trans-
mission and multiple node subscriptions, ROS2 outper- Authors’ Contributions
YY designed and wrote the paper, XL and ZN completed manuscript revisions,
forms ROS1 in terms of real-time performance. FX provided suggestions and guidance, ZL assisted with programming, and PL
Specific conclusions of the paper are as follows. provided assistance in device construction. All authors read and approved the
final manuscript.
(1) The key to improving the real-time performance of Authors’ Information
ROS2 lies in optimizing the real-time performance Yanlei Ye born in 1991, is currently a Ph.D. candidate at Department of Mechani-
of the operating system. The use of the Preempt_ cal Engineering (DME), Tsinghua University, China. His research interests include
robot operating systems and compliant motion control.
RT patch can reduce the latency in ROS2 message Zhenguo Nie born in 1983, is currently an associate professor at DME, Tsinghua
transmission. Preempt_RT improves the real-time University, China. His research interests include intelligent design and surgical
computing capability of the native Linux kernel robotics.
Xinjun Liu born in 1971, is currently a professor and a Ph.D. candidate supervi-
through high-precision timers, thread interrupt sor at DME, Tsinghua University, China. His research interests include robotics,
handlers, sleep spinlocks, real-time mutexes, and parallel mechanisms, and advanced manufacturing equipment.
RCU synchronization mechanisms. Fugui Xie born in 1982, is currently an associate professor and a Ph.D.
candidate supervisor at DME, Tsinghua University, China. His research interests
(2) The real-time performance of the optimized ROS2 include parallel mechanisms and mobile machining robots.
system was systematically and comprehensively Zihao Li born in 1992, is currently a Ph.D. candidate at DME, Tsinghua University,
evaluated under stringent operating conditions China. His research interests include cooperative robot and teleoperation.
Ye et al. Chinese Journal of Mechanical Engineering (2023) 36:144 Page 15 of 15
Peng Li born in 1989, is currently a Ph.D. candidate at DME, Tsinghua University, [18] W Sim, B Song, J Shin, et al. Data distribution service converter based on
China. His research interests include collaborative robot design and control. the open platform communications unified architecture publish–sub-
scribe protocol. Electronics, 2021, 10(20): 2524.
Funding [19] H Choi, Y Xiang, H Kim. PiCAS: New design of priority-driven chain-aware
Supported by National Key Research and Development Program of China scheduling for ROS2. Real-Time and Embedded Technology and Applica-
(Grant No. 2019YFB1309900), and Institute for Guo Qiang, Tsinghua University tions Symposium, Nashville, TN, USA, May 18-21, 2021: 251-263.
of China (Grant No. 2019GQG0007). [20] T Kronauer, J Pohlmann, M Matthé, et al. Latency analysis of ROS2 multi-
node systems. Multisensor Fusion and Integration for Intelligent Systems,
Karlsruhe, Germany, September 23-25, 2021.
Declarations [21] L Ding, M C Qu, Y L Zhang, et al. Analysis and engineering application of
ROS2. Beijing: Tsinghua University Press, 2019. (in Chinese)
Competing Interests [22] H Choi. On the design and analysis of autonomous real-time systems. Uni-
The authors declare no competing financial interests. versity of California, Riverside, 2021.
[23] B Akesson, M Nasri, G Nelissen, et al. An empirical survey-based study
into industry practice in real-time systems. Real-Time Systems Symposium,
Received: 22 February 2023 Revised: 11 November 2023 Accepted: 12 Houston, TX, USA, December 01-04, 2020: 3-11.
November 2023 [24] H Kopetz, W Steiner. Real-time systems: design principles for distributed
embedded applications. Springer Nature, 2022.
[25] A Barbalace, A Luchetta, G Manduchi, et al. Performance comparison of
VxWorks, Linux, RTAI, and Xenomai in a hard real-time application. IEEE
Transactions On Nuclear Science, 2008, 55(1): 435-439.
References [26] D Dasari, M Becker, D Casini, et al. End-to-end analysis of event chains
[1] F Reghenzani, G Massari, W Fornaciari. The real-time linux kernel: A survey under the qnx adaptive partitioning scheduler. Real-Time and Embedded
on preempt_rt. ACM Computing Surveys (CSUR), 2019, 52(1): 1-36. Technology and Applications Symposium, Milano, Italy, May 04-06, 2022:
[2] S Macenski, T Foote, B Gerkey, et al. Robot Operating System 2: 214-227.
Design, architecture, and uses in the wild. Science Robotics, 2022, 7(66): [27] C Maiza, H Rihani, J M Rivas, et al. A survey of timing verification tech-
eabm6074. niques for multi-core real-time systems. ACM Computing Surveys (CSUR),
[3] S Barut, M Boneberger, P Mohammadi, et al. Benchmarking real-time 2019, 52(3): 1-38.
capabilities of ROS2 and OROCOS for robotics applications. IEEE Interna- [28] D Ramegowda, M Lin. Energy efficient mixed task handling on real-time
tional Conference on Robotics and Automation, Xi’an, China, May 30 -June embedded systems using FreeRTOS. Journal of Systems Architecture, 2022:
05, 2021: 708-714. 131.
[4] R Mittal, A Konno, S Komizunai. Implementation of hoap-2 humanoid [29] R Delgado, B You, B W Choi. Real-time control architecture based on
walking motion in openhrp simulation. International Conference on Xenomai using ROS packages for a service robot. Journal of Systems and
Computing Communication Control and Automation, Pune, India, February Software, 2019, 151: 8-19.
26-27, 2015: 29-34. [30] R Delgado, J Park, B W Choi. Open embedded real-time controllers for
[5] G Metta, P Fitzpatrick, L Natale. YARP: yet another robot platform. Interna- industrial distributed control systems. Electronics, 2019, 8(2): 223.
tional Journal of Advanced Robotic Systems, 2006, 3(1): 43-48. [31] J Arm, Z Bradac, V Kaczmarczyk. Real-time capabilities of Linux RTAI. Ifac-
[6] T Fietzek, H Ü Dinkelbach, F H Hamker. ANNarchy-iCub: An interface for Papersonline, 2016, 49(25): 401-406.
easy interaction between neural network models and the iCub Robot. [32] G K Adam, N Petrellis, L T Doulos. Performance assessment of Linux
Computational Intelligence and Virtual Environments for Measurement Kernels with PREEMPT_RT on ARM-Based embedded devices. Electronics,
Systems and Applications, Chemnitz, Germany, June 15-17, 2022. 2021, 10(11): 1331.
[7] J Jackson. Microsoft robotics studio: A technical introduction. IEEE Robot-
ics & Automation Magazine, 2007, 14(4): 82-87.
[8] P Marion, M Fallon, R Deits, et al. Director: A user interface designed for
robot operation with shared autonomy. Journal of Field Robotics, 2017,
34(2): 262-280.
[9] D Kortenkamp, R Simmons, D Brugali. Robotic systems architectures and
programming. Springer Handbook of Robotics, 2016: 283-306.
[10] M Quigley, K Conley, B Gerkey, et al. ROS: an open-source robot operating
system. ICRA Workshop on Open Source Software, Kobe, Japan, 2009.
[11] T Itsuka, M Song, A Kawamura, et al. Development of ROS2-TMS: new
software platform for informationally structured environment. ROBO-
MECH Journal, 2022, 9(1): 1-19.
[12] Y Maruyama, S Kato, T Azumi. Exploring the performance of ROS2.
Proceedings of the 13th International Conference on Embedded Software,
Pittsburgh, PA, USA, October 02-07, 2016.
[13] M Albonico, M Đorđević, E Hamer, et al. Software engineering research
on the Robot Operating System: A systematic mapping study. Journal of
Systems and Software, 2022.
[14] M Karamousadakis. Real-time programming of EtherCAT master in ROS for a
quadruped robot. National Technical University of Athens, 2019.
[15] H Wei, Z Shao, Z Huang, et al. RT-ROS: A real-time ROS architecture on
multi-core processors. Future Generation Computer Systems, 2016, 56:
171-178.
[16] K Belsare. Micro-ROS//A Koubaa. Robot Operating System (ROS). Cham:
Springer International Publishing, 2023: 3-55.
[17] A Hakiri, P Berthou, A Gokhale, et al. Publish/subscribe-enabled software
defined networking for efficient and scalable IoT communications. IEEE
Communications Magazine, 2015, 53(9): 48-54.