User Tools

Site Tools


robotsoftware:mobotware:install:rtai

RTAI and MobotWare

First a special thanks to Martin Wies for helping with the installation.

In order to run MobotWare you need RTAI. Here is a guide on how to install and start RTAI. This guide is based on info from:

<note warning>This guide has until now only worked with

  • Ubuntu 11.10
  • RTAI 3.8.1
  • Linux Kernel 2.6.32.57

</note>

Installing RTAI

Here are the steps you need to take in order to install RTAI:

  1. From a fresh installation of Ubuntu (or any other distribution you prefer), install the packages needed for compiling kernels and other packages needed for RTAI.
  2. Get corresponding versions of RTAI and the vanilla Linux kernel.
  3. Patch the Linux kernel with RTAI.
  4. Configure and compile your new Linux kernel.
  5. Reboot into the new real-time kernel.

/* - Configure and install RTAI without COMEDI support. - Configure and install COMEDI. - Reconfigure and install RTAI with COMEDI support. */

How To

Login as root

sudo su

To make it easier to do all commands

Please have a look at the README.INSTALL file in the RTAI distribution for detailed instructions how to install RTAI.

Afterwards read the Installation Guide. There might be some things that does not fit entirely to your setup. Then just adapt the command so they match you setup.

Using the steps listed above combined with the guide the installation is going to work. Or at leaast we made it work.

In the following section you find the modification we made to install RTAI. Therefore this page should be considered as expansion to the installation guide.

Packages needed

We assume you have installed the packages for MobotWare and ROS. Therefore only the rtai packages are listed here.

rtai
rtai-doc
rtai-source
python-rtai
librtai-dev
librtai1

Kernel and RTAI

Download the kernel that matches with RTAI. In our package we use kernel 2.6.32.57 and RTAI

The latest stable RTAI packages can also be downloaded via Synaptic Package Manager, apt or aptitude.

<note tip>You need to install all the rtai packages from the repositories, because the source is not included in the RTAI download.</note>

Patch the Kernel

We used the following commands to patch the kernel:

zcat ../kernel-patches/diffs/rtai/hal-linux-2.6.32.11-x86-2.6-03.patch.gz | patch -p 1 --dry-run

This commands test if the kernel can be patched with the current patch.

The just remove –dry-run to apply the patch

zcat ../kernel-patches/diffs/rtai/hal-linux-2.6.32.11-x86-2.6-03.patch.gz | patch -p 1

Compiling the kernel

There are many guides on the internet on how to compile a kernel. Here are link to a few to get you started, otherwise search for “compiling kernel” to get the answers you need.

These links may not be what you are looking for. It you have better links let me know and I will add/change the links.

When you understand how to compile a kernel follow the instructions in the guide.

  1. Unpack kernel in /usr/src/
  2. copy the configuration file from the current kernel
  3. patch the kernel
  4. Make the changes from the RTAI installation guide
  5. compile

The command we used to compile the kernel was

make-kpkg --initrd --append-to-version=rtai  buildpackage

If you are using an older RTAI patch you may get the following error:

include/linux/ipipe.h:76:2: error: #error "CONFIG_NR_CPUS is too large, please lower it."

To fix this disable sparse irq numbering (CONFIG_SPARSE_IRQ=n): Processor type and features —> Support sparse irq numbering —> disabled

Compiling RTAI

We had alot of trouble when compiling RTAI. So test with differet configuration to get it compiled.

One big problem was the paths tho different libs. That was solved with the following script:
Problem

/usr/include/features.h:323:26: fatal error: bits/predefs.h: No such file or directory

Solution

ad_cpath.sh
#!/bin/bash
export C_INCLUDE_PATH=/usr/include/i386-linux-gnu/
export CPLUS_INCLUDE_PATH=/usr/include/i386-linux-gnu/

place it in

/root/add_cpath.sh

remember to make it runable with

chmod a+x ad_cpath.sh

Make sure you run the script. Or else the problem is not solved.

Kernel Modules

RTAI is very much module oriented. So to understand and be able to use RTAI is necessary to know the dynamically loadable modules for Linux.

The Linux kernel design is similar to that of classic Unix systems: it uses a monolithic architecture with file systems, device drivers, and other pieces statically linked into the kernel image to be used at boot time. The use of dynamic kernel modules allows you to write portions of the kernel as separate objects that can be loaded and unloaded on a running system.

A kernel module is simply an object file containing routines and/or data to load into a running kernel. When loaded, the module code resides in the kernel's address space and executes entirely within the context of the kernel. Technically, a module can be any set of routines, with the one restriction that two functions, init_module() and cleanup_module(), must be provided. The first is executed once the module is loaded, and the second, before the module is unloaded from the kernel.

The main functions to use to load /unload and inspect kernel modules are contained in the modutils package. They are:

/sbin/insmod (insert a module into the running kernel)
/sbin/rmmod (remove a module from the running kernel)
/sbin/lsmod (inspect modules in the running codes) 

RTAI Modules

To use RTAI, you have to load the modules that implement whatever RTAI capabilities you need. In version 3.8.1 the available core modules are the following:

  • latency_rt.ko
  • rtai_ksched.ko
  • rtai_netrpc.ko
  • rtai_tasklets.ko
  • Module.symvers
  • rtai_lxrt.ko
  • rtai_sched.ko
  • rtai_tbx.ko
  • preempt_rt.ko
  • rtai_math.ko
  • rtai_sem.ko
  • rtai_up.ko
  • rtai_bits.ko
  • rtai_mbx.ko
  • rtai_serial.ko
  • rtai_wd.ko
  • rtai_calibrate.ko
  • rtai_mq.ko
  • rtai_shm.ko
  • switches_rt.ko
  • rtai_fifos.ko
  • rtai_msg.ko
  • rtai_smi.ko
  • rtai_hal.ko
  • rtai_mup.ko
  • rtai_smp.ko

Let's examine one by one. (This description is from ver. 1.3 so it needs to be updated)

1) It is the really core module and nothing about the real time services can be done without it.

   rtai initializes all of its control variables and structures, makes a copy of the idt_table and
   of the Linux irq handlers entry addresses and initializes the interrupts chips (ic) management
   specific functions. But when you install rtai with the usual insmod rtai command nothing
   happens, as rtai is a dormant module. You must specifically mount it when is needed by
   other modules calling rt_mount_rtai() to activate it. You must unmount it as well when
   it is not required anymore, by calling rt_umount_rtai(), which put rtai back into its
   bed to sleep. The mount call activates rtai and, even if you do not use any of its services Linux
   work toward the hardware is filtered by rtai. The most important thing happening when you
   mount RTAI is that from that very instant Linux is no more in power of disabling/enabling
   interrupts. From that point on rtai will assure that interrupt enables/disables will be consistent
   intra Linux but Linux could be preempted at any time by the higher authority of rtai, the only
   master of the hardware.

2) The real time scheduler module, which is in charge of distributing the CPU to different tasks

   present in the system, including Linux. The scheduling occurs when tasks perform certain
   system calls and on timer handler activation (each 8254 interrupt) (for an explanation of timers
   and interrupts see  RTAI Timers and Interrupts ). The scheduler makes it elected the first
   highest priority task in a READY state. RTAI considers the priority 0 as the highest priority
   and 0x3fffFfff the lowest. Linux is given priority 0x7fffFfff. Given a priority level,
   the first initialized task will be the first elected and will run to completion unless a task with a
   higher priority is elected or it terminates or the task calls a blocking system function. RTAI
   supports both periodic and oneshot mode for the real time scheduler.
   You have three different schedulers:
   - UP , only for uniprocessors
   - SMP , for multiprocessors
   - MUP , only for multiprocessors
   The scheduler services are:
   - Task functions
   - Timing functions
   - Semaphore functions
   - Mailbox functions
   - Intertask communication functions
   All the functions can be used with any scheduler. Note that when you load rtai_sched,
   automatically rtai is mounted.

3) The module that implements the fifo services for RTAI. Many applications appear to

   benefit from a synergy between the real-time system side and the Linux side, for example
   for managing the data logging and displaying. Simple fifo buffers are used to do this; they are
   called real time fifos. The real-time task interface includes creation, destruction, reading and
   writing functions, performed by the rtai_fifos module. Linux user processes, on the other
   hand, see rt-fifos as ordinary character devices. Note that on the module side you always have
   only non blocking put/get, so that any different policy should be enforced by using appropriate
   user handler functions. Available are an old and a new (strongly recommended) fifo
   implementation. The last one is based on the mailboxes concepts, symmetrically usable from
   kernel modules and Linux processes. Even if fifos are strictly no more required in RTAI,
   because of the availability of LXRT (see below), fifos are kept for both compatibility reasons
   and because they are very useful tools to be used to communicate with interrupt handlers,
   since they do not require any scheduler to be installed. In this sense
   you can see this new implementation of fifos as a kind of universal form of device drivers,
   since once you have your interrupt handler installed you can use fifo services to do all the rest.

4) The RTAI specific module that allows sharing memory among different real time tasks and

   Linux processes, simoultaneously (it is another mechanism available to users, in addition
   to fifos). The services are symmetrical, i.e. the same calls can be used both in real time tasks,
    i.e. within the kernel, and Linux processes. The first allocation does a real allocation, any
   subsequent call to allocate with the same name from Linux processes just maps the area
   to the user space or return the related pointer to the already allocated space in kernel space.
   Analogously the freeing calls have just the effect of unmapping till the last is done, as that is
   the one the really frees allocated memory. Clearly cooperating users have to use the same
   name.

5) The LX(Linux)RT(RealTime) module, which implements services to make available any

   of the RTAI schedulers functions to Linux processes, so that a fully symmetric implementation
   of real time services is possible. To state it more clearly, that means that you can share memory,
   send messages, use semaphores and timings: Linux<->Linux, Linux<->RTAI and, naturally,
   RTAI<->RTAI.

6x) Posix RTAI modules. rtai_pthread.o provides hard real-time threads, where each

     thread is a RTAI task. All threads execute in the same address space and hence can work
     concurrently on shared data. rtai_pqueue.o provides kernel-safe message queues.
     

RTAI API

robotsoftware/mobotware/install/rtai.txt · Last modified: 2021/08/14 04:21 (external edit)