RTAI installation on Linux (Kind of ultimate tutorial)

Well, I think this might be of interest to some people working with control systems in real time. Linux could be a good choice depending how skilled you are with it (the truth is, everything in Linux requires you to be a. very skilled and b. very patient).
A brief description:
RTAI: Real-time environment for Linux ( )
COMEDI: It's an interface for sensing and control devices (
Scilab/Scicos: A computational package, kind of a Matlab-Simulink, but open source (
HART Toolbox: A group of modules to work with RTAI using Scicos ( )

I spent several weeks trying to make it work all together so no, it's not straight forward always (but, who knows, you could be lucky). But this tutorial can make it easier (I hope)

Most of it is taken from and adapted to solve some of the most common problems.Without further introduction, here is the tutorial:

Installation RTAI


UBUNTU 10.04

Install the following packages to proceed:


sudo apt-get install cvs subversion build-essential


sudo apt-get install libtool automake libncurses5-dev


sudo apt-get install bison flex


sudo apt-get install libboost-dev libboost-program-options-dev libgsl0-dev

scilab 4.1.2:

sudo apt-get install gfortran sablotron tcl8.5-dev tk8.5-dev xaw3dg-dev libpvm3 pvm-dev libgtkhtml2-dev libvte-dev ocaml-native-compilers


sudo apt-get install libqt4-dev libqwt5-qt4-dev

Installation of all components

RTAI kernel from EMC

echo deb lucid base emc2.4 > /tmp/linuxcnc.list

echo deb-src lucid base emc2.4 >> /tmp/linuxcnc.list

sudo mv /tmp/linuxcnc.list /etc/apt/sources.list.d/

gpg --keyserver --recv-key 8F374FEF

gpg -a --export 8F374FEF | sudo apt-key add -

sudo apt-get update

sudo apt-get install linux-headers-2.6.32-122-rtai linux-image-2.6.32-122-rtai

If there is a problem downloading the patched Kernel, you can try this (taken from

sudo wget

Decompress the downloaded file, navigate into the subfolder “kernel” inside realtimesuit-1.0, and run the .deb installers

Reboot in the new installed RTAI-kernel.

RTAI ( #1


cd /usr/src

sudo cvs co magma

sudo ln -s magma rtai


cd /usr/src

sudo wget --no-check-certificate

sudo tar xjvf rtai-3.8.1.tar.bz2

sudo ln -s rtai-3.8.1 rtai

Installation of RTAI

cd /usr/src/rtai

sudo make menuconfig

Ensure directories are correct:

Installation: /usr/realtime

Linux source tree: /usr/src/linux-headers-2.6.32-122-rtai

Under Machine, choose number of CPUs (check running cat /proc/cpuinfo and verifying how many processors are listed)

sudo make

sudo make install

sudo sed -i 's/\(PATH=\"\)/\1\/usr\/realtime\/bin:/' /etc/environment

now run export PATH=/usr/realtime/bin:$PATH for each open shell or do logout and login Now we need to load the rtai modules.

/sbin/insmod /usr/realtime/modules/rtai_smi.ko

/sbin/insmod /usr/realtime/modules/rtai_hal.ko

/sbin/insmod /usr/realtime/modules/rtai_lxrt.ko

/sbin/insmod /usr/realtime/modules/rtai_fifos.ko

/sbin/insmod /usr/realtime/modules/rtai_sem.ko

/sbin/insmod /usr/realtime/modules/rtai_mbx.ko

/sbin/insmod /usr/realtime/modules/rtai_msg.ko

/sbin/insmod /usr/realtime/modules/rtai_netrpc.ko

/sbin/insmod /usr/realtime/modules/rtai_shm.ko

Copy the lines to /usr/local/bin/start_rtai

Do a sudo chmod a+x /usr/local/bin/start_rtai

If there is trouble inserting the rtai_hal.ko module then:

Go to boot/grub/menu.lst or boot/grub/grub.cfg and add “lapic” at the end of this line:

kernel /boot/vmlinuz-2.6.22-realtime root=UUID=45d21232-cf0d-cc3d-87ce-8453214d7a6f ro quiet splash vga=794 lapic


cd /usr/local/src

sudo cvs -d login

sudo cvs -d co comedi

sudo cvs -d co comedilib

sudo cvs -d co comedi_calibrate

sudo cvs -d co comedi-nonfree-firmware

If the comedi server is down, you can also find the packages in:

Download them and decompress to /usr/local/src


cd /usr/local/src/comedilib

sudo sh

sudo ./configure

sudo make

sudo make install

sudo mkdir /usr/local/include/linux


cd /usr/local/src/comedi

sudo sh

sudo ./configure --with-linuxdir=/usr/src/linux-headers-2.6.32-122-rtai --with-rtaidir=/usr/realtime

sudo make

sudo make install

sudo make dev

sudo ldconfig

sudo depmod -a


cd /usr/local/src/comedi_calibrate

sudo autoreconf -i -B m4

sudo ./configure

sudo make

sudo make install


sudo cp /usr/local/src/comedi/include/linux/comedi.h /usr/local/include/

sudo cp /usr/local/src/comedi/include/linux/comedilib.h /usr/local/include/

sudo ln -s /usr/local/include/comedi.h /usr/local/include/linux/comedi.h

sudo ln -s /usr/local/include/comedilib.h /usr/local/include/linux/comedilib.h

cd /usr/src/rtai

sudo make menuconfig

Under “Add-Ons”, select “Real Time COMEDI support in user space”

Check COMEDI installation directory, it should be /usr/local/

sudo make

sudo make install

sudo cp /usr/local/src/comedilib/include/comedilib.h /usr/local/include/

Now we need to load the comedi-modules. All rtai modules have to be loaded before! This is a example for the ni 6024e.

modprobe comedi

modprobe kcomedilib

modprobe comedi_fc

modprobe ni_mio_cs

insmod /usr/realtime/modules/rtai_comedi.ko

comedi_config -v /dev/comedi0 ni_mio_cs 0x0100

comedi_calibrate --calibrate

chmod a+rw /dev/comedi0

Copy the lines to /usr/local/bin/load_daq

Do a sudo chmod a+x /usr/local/bin/load_daq

If there is a error message "comedi.o not loaded", then you have to create and edit /etc/modprobe.d/comedi and add one of the following lines:

options comedi comedi_num_legacy_minors=4

(you can change the number 4 if you want), or:

options comedi comedi_autoconfig=0

The first option, comedi_num_legacy_minors=4 reserves 4 comedi devices for use by non-autoconfigured devices. The second option comedi_autoconfig=0 disables auto-configuration completely.

If there is this error:

comedi_calibrate: error while loading shared libraries: cannot open shared object file: No such file or directory

Then do:

cd /lib/

ln -s /usr/local/lib/libcomedi*

SCILAB 4.1.2

cd /opt

sudo wget

sudo tar xvzf scilab-4.1.2.bin.linux-i686.tar.gz

cd /opt/scilab-4.1.2

sudo wget

sudo tar xvzf scilablibs.tar.gz

sudo make

sudo ln -s /opt/scilab-4.1.2/bin/scilab /usr/local/bin/scilab


(svn -version)

cd /usr/local/src

sudo svn co qrtailab

(tar.gz - version)

cd /usr/local/src

sudo wget

sudo tar xvzf QRtaiLab-0.1.12.tar.gz

If you use a tar.gz-version please replace qrtailab with qrtailab-x.x.x (x.x.x is the number of your installed version )

cd /usr/local/src/qrtailab

Edit qrtailab.config and replace '/usr/include/qwt/' with '/usr/include/qwt-qt4/' and '-lqwt' with '-lqwt-qt4'

sudo qmake-qt4

sudo make

sudo make install

HART Toolbox (

Chose a directory (/home/username/software, ...)

(svn -version)

svn co hart

(tar.gz -version)


tar xvzf hart_0.4.1-src.tar.gz

Go in your hart-directory.

Edit Makefile and set 'SCILAB = ...' to the binary file of scilab 4.1.2

Warning: sudo make will not install RTAI module! Either be a normal user and install HART or change to root (using sudo su) and then do make.


cd /..../scilab-xxx/contrib

sudo ln -s {link to hart-toolbox} .

No comments:

Post a Comment