AUTh-ARL Core Stack  0.7
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Installing a real-time kernel

Installing the kernel

Instructions for installing a real-time kernel for Ubuntu 16.04.

First install Ubuntu 16.04 in your machine.

Warning
The following instructions assume root access.

First download the kernel and the patch

mkdir -p /usr/src/kernels
cd /usr/src/kernels
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.11.12.tar.gz
sudo tar -xf linux-4.11.12.tar.gz
mv linux-4.11.12 ./linux-4.11.12-rt16
cd linux-4.11.12-rt16
wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/4.11/patch-4.11.12-rt16.patch.gz
gzip -d patch-4.11.12-rt16.patch.gz
sudo gzip -d patch-4.11.12-rt16.patch.gz
patch -p1 <patch-4.11.12-rt16.patch

Configure the kernel:

make menuconfig

If this fails (with an error 'curses.h' missing) install the following:

sudo apt-get install libncurses5-dev

In the configuration set: Processor type and Features > Preemption Model (Fully Preemptible Kernel (RT)) > (Fully Preemptible Kernel (RT))

Then build the kernel:

make
make modules_install install

Reboot and select the new kernel.

In order to show the grub during booting press shift or edit /etc/default/grub file and place a # symbol at the start of line GRUB_HIDDEN_TIMEOUT=0.

Then update grub:

update-grub
reboot

The instructions were based on this [6].

Set the kernel as default

In order to set kernel as the default follow these instructions taken from here [1].

Warning
The following instructions assume root access.

First changed the GRUB_DEFAULT to ‘saved’ in /etc/default/grub by:

cp /etc/default/grub /etc/default/grub.bak
vim /etc/default/grub
...
GRUB_DEFAULT=saved
...

Now create a backup of the grub config for recovery purposes if needed, then rebuild grub:

cp /boot/grub/grub.cfg /boot/grub/grub.cfg.bak
update-grub

Determine what the full kernel name is you want to use. Get the listing by running:

egrep "^[[:space:]]?(submenu|menuentry)" /boot/grub/grub.cfg | cut -d "'" -f2

Result:

Ubuntu
Advanced options for Ubuntu
Ubuntu, with Linux 4.4.0-78-generic
Ubuntu, with Linux 4.4.0-78-generic (recovery mode)
Ubuntu, with Linux 4.4.0-47-generic
Ubuntu, with Linux 4.4.0-47-generic (recovery mode)
Ubuntu, with Linux 4.11.12-rt16
Ubuntu, with Linux 4.11.12-rt16 (recovery mode)

Use the linux-4.11.12-rt16 kernel. Setting that to be the default kernel is simple. However, you MUST prepend ‘Advanced options for Ubuntu’ to the kernel name as shown below since Ubuntu makes use of sub menus in the kernel listing. So set the desired kernel by running:

grub-set-default 'Advanced options for Ubuntu>Ubuntu, with Linux 4.11.12-rt16'

Now verify that the change got applied in the configs by running:

grub-editenv list

Result:

saved_entry=Advanced options for Ubuntu>Ubuntu, with Linux 4.11.12-rt16

Reboot the system so it boots off the older kernel:

reboot

Finally, once the system comes back online, verify the desired kernel is running by:

uname -r
4.11.12-rt16

If the system rebooted, and dropped you into a grub shell with an error, you can boot up off of the backup grub.cfg file that was created by:

 grub2> configfile (hd0,1)/boot/grub2/grub.cfg.bak

Test the RT kernel

The kernel version must now contain the tags PREEMPT and RT such as

uname -v
#42 SMP PREEMPT RT Fri Nov 6 18:55:29 CET 2009

or something went completely wrong, otherwise.

Also you can use the following tool to test that the kernel has real-time capabilities:

Warning
The following instructions assume root access.

Download and build the testing tool

git clone git://git.kernel.org/pub/scm/linux/kernel/git/clrkwllms/rt-tests.git
cd rt-tests
make

If this fails you may need to install the following and make again:

sudo apt-get install libnuma-dev

Run:

./cyclictest -a -t -n -p99

And in another terminal stress the CPU

stress --cpu 1000

On a non-realtime system, you may see something like

T: 0 ( 3431) P:99 I:1000 C: 100000 Min:      5 Act:   10 Avg:   14 Max:   39242
T: 1 ( 3432) P:98 I:1500 C:  66934 Min:      4 Act:   10 Avg:   17 Max:   39661

The rightmost column contains the most important result, i.e. the worst-case latency of 39.242 milliseconds. On a realtime-enabled system, the result may look like

T: 0 ( 3407) P:99 I:1000 C: 100000 Min:      7 Act:   10 Avg:   10 Max:      18
T: 1 ( 3408) P:98 I:1500 C:  67043 Min:      7 Act:    8 Avg:   10 Max:      22

and, thus, indicate an apparent short-term worst-case latency of 18 microseconds.

More info here: [5].

Machine Configuration for running KUKA LWR4+

In order to run KUKA LWR4+ with our interfaces (which use FRILibrary, ROS etc) you need to to provide your user name with real time priority and memlock limits higher than the default ones [3]. You can do it permanently like this:

sudo nano /etc/security/limits.conf

and add these lines:

YOUR_USERNAME hard rtprio 99
YOUR_USERNAME soft rtprio 99
YOUR_USERNAME hard memlock unlimited
YOUR_USERNAME soft memlock unlimited

Then,

sudo nano /etc/pam.d/common-session

and add

session required pam_limits.so

Reboot, open a terminal, and check that ulimit -r -l gives you the values set above.

Finally you can run the gravity compensation example from Core examples to test the above.

roslaunch autharl_description display.launch config:=lwr
rosrun autharl_examples_lwr gravity_compensation_example  # in another terminal