Preparing Ubuntu 18.04 for Real-time and ROS 2

I’ve been setting up ROS 2 for one of my recent robotics projects that I am expecting will have important deterministic requirements. Surprisingly, while Dashing Diademata is the first LTS version with Ubuntu 18.04 as Tier 1, there isn’t much documentation on getting your operating system ready for real-time stuff, so I thought I might as well document my process. So as of writing this post, I am working with Ubuntu 18.04.2 which comes with the kernel version 4.18.0-15-generic.

Download Compatible Kernel and Patch

The idea is to modify your Linux kernel with a version where PREEMPT_RT is supported. According to the Linux Foundation Page, as of this post, the stable version is 4.19-rt. So, we want to obtain this stable version, as well as the corresponding Linux kernel.

To keep things a bit more manageable, let’s first create a kernel folder in your home folder and download, extract, and patch everything in there. First, let’s download the latest patch.

Edit: As of August 4, 2019, the above link no longer works as a new version has come out. To exactly replicate this post, run instead the following:

Then, from the Linux kernel page, also download the corresponding kernel version.

Because recent Debian versions surprisingly do not include bison or flex in build-essential, you need to install those two to copy your old config file over.

Once all the files have been downloaded and packages have been installed, let’s unpack the kernel and rename it so that it matches the patch name.

Patch Kernel

Now, inside the kernel folder linux-4.19.50-rt22, patch the kernel.

Next, we copy over the current OS configuration files, install some tools, and proceed with enable the preemptible kernel.

Now comes the step that has been slightly modified from previous versions because of the relocation of the option to select the Fully Preemptible Kernel (RT). Under General setup exists Preemptible Model. Select the Fully Preemptible Kernel (RT). (Note that this is NOT under Processor type and features)

Make and Install RT Kernel

Exit out of menuconfig and let’s make and install the kernel. Note that this process can take a while depending on the computer you are working on.

Once everything is done, reboot your computer. Your new kernel should show as 4.19.50-rt22.

Leave a Reply

Your email address will not be published. Required fields are marked *