Real-time programming with ROS 2

ROScon 2023

Shuhao Wu, Jan Staschulat

Welcome to the informational website for the full-day (8:00 - 17:00) workshop, Real-time programming with ROS 2 scheduled to be held at ROScon 2023 on October 18th, 2023. Detailed agenda, ahead-of-time instructions, and additional resources will be posted here in the coming months.

Last updated: Aug 27th 2023

Program description and goals

Ensuring the worst-case execution time of software to remain within a known bound is challenging, especially given the complexity of modern software and hardware stacks. This workshop aims to teach robotics engineers the basics of real-time programming and how this can be accomplished with ROS 2. The audience should walk out of the workshop with a good grasp of how to approach real-time programs and some hands-on experience with programming real-time applications both in and out of the ROS context.

The workshop is divided into a morning session and an afternoon session. In the morning, the main goal is to introduce the audience to the foundation of real-time programming without ROS. In the afternoon, the main goal is to apply the knowledge to ROS 2 and learn about the concepts and limitations of the execution management of ROS 2 Humble. We intend to both present an experimental, out-of-tree real-time ROS 2 executor that can be used for real-time applications as well as present best practices for achieving real-time behaviors within mainline ROS 2 executors. Finally, we intend to hold a panel discussion about the open challenges for enabling real-time within ROS 2.

The workshop will cover two typical use-cases over a number of hands-on exercises. In the morning, we will present an inverted pendulum controller demo. This allows us to cover the use case of 1000 Hz real-time control-loop with a single ROS 2 node. In the afternoon, we will present a simulated camera safety system constructed with multiple ROS 2 nodes. This allows us to cover the use case of 60 Hz real-time within a larger ROS 2 network. All demo code will be made available during the workshop.

We intend for the workshop to have the following impact on the ROS community: (1) transfer knowledge to robotics engineers about real-time system concepts and ROS 2 execution management; (2) enable robotics engineers to build real-time applications with ROS 2; and (3) spread the knowledge of real-time ROS 2 in the community such that its development can be further accelerated.

Interested? Sign up on the ROScon 2023 website.

Requirements for the workshop exercises

The workshop exercises are designed for groups of 3 to 5 people. We will run all exercises on laptops running Ubuntu 22.04 and ROS 2 Humble as well as Raspberry Pi 4s. Each group should have at least one laptop and one Raspberry Pi 4. Due to cost and logistical challenges, we cannot provide these equipment to all attendees and attendees must bring their own equipment, or join a group with the required equipments. Ahead of the workshop, we will ask attendees who intend to bring their own Raspberry Pi 4s to flash a special workshop-specific image onto the SD cards. This will be communicated at a later time.

Since not everyone will have a Raspberry Pi 4, please note that if you intend to bring your own, you may be asked to form groups with 2 to 4 other people who may not have Raspberry Pi 4s and collaborate with them during the exercises.

You should bring:

A laptop running Ubuntu 22.04 with ROS 2 Humble installed.
This should be a direct installation and not a virtual machine.

We strongly encourage you to bring:

An Ethernet cable (and any associated USB adapters) to connect your laptop directly with the Raspberry Pi.

If possible, it would also be nice if you can bring:

A Raspberry Pi 4, the associated power supply, and a microSD card (>=32GB).
The SD card should have the ROScon workshop image pre-flashed.
This image will be published closer to the workshop date.

Preliminary agenda

NOTE: schedule is preliminary and subject to change!


8:00 - 9:00: Introduction to real-time programming

Introduction to Real-time systems; use-cases in robotics; hardware and operating system latency concepts.

9:00 - 9:30: Exercise 1: measure hardware and OS latency

Measurement of hardware and operating system latency to understand the necessities of a real-time OS.

9:30 - 9:45: Break

9:45 - 10:45: C++ real-time programming

Real-time programming techniques including real-time schedulers, memory management techniques, priority-inheritance mutexes, lockless programming.

10:45 - 11:30: Exercise 2: Running a 1kHz application in real-time

1000-hz real-time demo with a real-time thread running along side ROS 2. Techniques introduced in the earlier sessions are demonstrated.

11:30 - 12:00: Panel discussion

The ROS real-time working group will hold a discussion about the usage of ROS 2 and real-time.

12:00 - 13:00: Lunch


13:00 - 14:00: ROS 2 execution management

Overview of ROS 2 execution management and its effects on real-time and determinism. Presentation of an experimental real-time executor.

14:00 - 14:45: Exercise 3: real-time safety demo

Simulated real-time safety demo running at 60 Hz completely within ROS 2 using the experimental real-time executor. Latency comparison with mainline ROS 2 executor.

14:45 - 15:00: Break

15:00 - 16:00: Real-time with mainline ROS 2

Best practices that minimize latency with mainline ROS 2 executors.

16:00 - 16:45: Exercise 4: Best practices with ROS 2

Excercises with the real-time safety demo written with only mainline ROS 2 executors.

16:45 - 17:00: Summary and conclusion