Real-time programming with ROS 2

ROScon 2023

Shuhao Wu, Jan Staschulat
Stephanie Eng, Oren Bell


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: Oct 11th 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. We are pleased to be able to loan some Raspberry Pi 4s to the attendees, but you are also welcome to bring your own.

Prior to the workshop, we would appreciate if everyone can follow the instructions here to setup your laptops with the appropriate Docker image. If you are bringing your own Raspberry Pi 4s, there are also instructions to set that up.

You should bring:

A laptop running Ubuntu 22.04 with Docker engine installed. You should follow instructions on this page to set it up.
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 a Raspberry Pi.

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

Your own Raspberry Pi 4, the associated power supply, and a microSD card (>=32GB).
The SD card should have the ROScon workshop image pre-flashed as noted on this page.

Preliminary agenda

NOTE: schedule is preliminary and subject to change!


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

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

8:45 - 9:15: Exercise 1: measure hardware and OS latency

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

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

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

10:30 - 11:00: Break

10:15 - 10:30, 11:00 - 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 in production.

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:30: Real-time with mainline ROS 2

Best practices that minimize latency with mainline ROS 2 executors.

15:30 - 16:00: Break

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