64

I know it runs Linux and there are real time patches available for Linux. Would those patches work?

Has anybody tried another real-time-os on the Raspberry Pi?

The idea is to use the board for regulation and control jobs that are time critical.

Avio
  • 1,217
  • 2
  • 14
  • 25
Lars Pötter
  • 1,078
  • 2
  • 9
  • 13
  • 2
    I would think the only unique reason that comes to mind why you couldn't would be if the closed GPU solution were to get in the way. Provided you can decided to just ignore the GPU while in your realtime tasks, I would think the realtime extensions could be made to work. – Chris Stratton Aug 02 '12 at 20:45
  • @ChrisStratton What do you mean? What does this have to do with the GPU? – Jivings Aug 03 '12 at 16:01
  • 7
    The entire raspberry pi system is not open for you to modify; the question would be if the part which isn't (the GPU) would be willing to stay out of the way while you are running your realtime tasks, or if that is unavoidably going to demand either bus cycles to access ram or even "attention" from the ARM core in a way that would frustrate hard timing goals. – Chris Stratton Aug 03 '12 at 16:32
  • 4
    Apparently RISCOS is quite well suited to certain realtime applications and it's Raspberry Pi port is going well. *8') – Mark Booth Aug 06 '12 at 12:06
  • 4
    RISCOS is not a real-time os(according to your Wikipedia link) so how could it help ? – Lars Pötter Aug 07 '12 at 21:33
  • 4
    The CONFIG_PREEMPT_RT Patch has been demonstrated on several ARM processors running Linux. There may be some latency issues, but these should be measurable on the order of microseconds. – Breakthrough Aug 08 '12 at 15:34
  • Any news with this issue? I am interested for optimizing audio. – mrkva Oct 14 '12 at 23:09
  • 1
    "regulation and control jobs that are time critical." what do you mean by "time critical" ? which regulation's period do you need ? –  Jan 31 '13 at 08:19

9 Answers9

22

In Linux kernel, enabling PREEMPT_RT will provide bounded latencies and realtime APIs. Besides configuring PREEMPT_RT, the SCHED_FIFO and SCHED_RR policies also need to be selected. And the applications need to set realtime parameters by calling appropriate APIs or by using appropriate utilities.

According to a free-electrons training: Realtime in Embedded Linux, PREEMPT_RT was a project that brings realtime capability into kernel. It has folded fully into 2.6.33 and 3.0 kernel stream. See the document you'll find everything.

Basically there have been two approaches to bring realtime capability to Linux kernel:

  • Modify inside the kernel, that is PREEMPT_RT project.
  • Run the realtime part side-by-side with a normal kernel and below the normal kernel, there have been three generations: RTLinux, RTAI, and Xenomai. (Aedos as Avio mentions below?)

Edit:

minghua
  • 341
  • 1
  • 5
  • 2
    Welcome to Raspberry Pi, nice answer! The RT PREEMPT patch by Ingo Molnar used together with High Resolution Timers (HRT) support, allow the kernel to achieve hard-realtime capabilities. At present, its support reaches 3.4.11 kernels, and the "good news" are that the patch "is shrinking", so it seems that most of it is getting included in the mainstream kernel sources. You can find an excelent tutorial for how to apply and use it here. – Avio Sep 29 '12 at 17:26
  • 1
    Uh, and don't forget to cite Adeos amongst the alternatives to provide hard real-time support in Linux. – Avio Sep 29 '12 at 17:31
  • 2
    I must mention that getting PREEMPT_RT working with the Raspberry Pi kernel is not a straighforward matter, simply applying the patch produces a non-working kernel. Also, there are a lot of new drivers in the Raspberry Pi kernel, and these drivers have not been tested with PREEMPT_RT, nor have they been cleared of overly long blocking sleeps. This is very much a work in progress, that is. – Nakedible Sep 29 '12 at 18:05
  • 2
    Any updates on this one? Are the drivers now stable enough to use this kernel patch? I'd love a working tutorial for people who have not yet compiled a kernel. – fabb Jan 13 '13 at 16:44
  • @fabb: Even after many years there will still be drivers that have glitchs against the rt requirement. You will only find out by running it. By the way, recently I see some network glitch once bumped up priorities of some user space applications, that is unexpected. Though all these kind of situations are highly configuration and application specific. – minghua Jan 26 '13 at 18:58
  • There is now a disto that comes with a pre-installed realtime kernel: https://github.com/guysoft/RealtimePi/ – GuySoft Oct 09 '17 at 13:54
18

You may be interested in running Xenomai on RaspberryPi. Here you can find a tutorial on how to do this. In a nutshell, Xenomai is a project that created custom Linux kernel (they provide patches that has to be applied to the kernel sources) enabling it to run another kernel (Xenomai core) that is a realtime one. This makes it possible to run Xenomai applications on wide range of hardware without the need to write drivers for them (since Linux is working on very wide range of hardware). This allows writing RT userspace applications using couple different RT APIs available.

Krzysztof Adamski
  • 9,615
  • 1
  • 37
  • 53
  • 1
    Which is the maximum frequency I can get with this tool? I am interested on controlling a DC motor at a rate rounding 1 kHz – Nicolás Arias Sep 25 '16 at 00:55
8

Wyolum mas the aLaMode (I call it the Almond Pi) to fit on top of the Pi in a stackable manner. It has a real-time clock, uses a aTiny 328, feeds of the GPIO Real UART / power and is flashable in various ways. It is great because the Pi can do whatever you want it do , web server/database while the Arduino runs in real-time interrupt.

enter image description here

Piotr Kula
  • 17,307
  • 6
  • 65
  • 104
  • 1
    Might seem a little bit impractical to have 2 microcontrollers running, but on the other hand this ensures real-time operation if the other approaches are not fast enough. – fabb Jan 15 '13 at 09:46
  • 1
    Any hints on how the RPi would cleanly communicate with the other µC without slowing its control loop down? – fabb Jan 15 '13 at 09:49
  • Hardware UART on the GPIO pins? – Piotr Kula Jan 15 '13 at 11:22
  • 1
    Yes, but the µC would have to poll the UART I guess in order to not let UART interrupts postpone the control loop timer interrupt. Would I then poll the UART at the beginning of the control loop and make sure I don't read to many bytes so it does not take too long? Or could the UART buffers overflow too easily that way? Or would the control loop frequency be so much higher than the UART speed that reading one byte each loop, if available, would be more than enough? – fabb Jan 15 '13 at 11:35
  • Not sure what you mean exactly? Possibly asking a very technical question that I am oblivious too? the Atmega has a built in uart buffer that will interrupt your main if you attach to it, or you can call check uart buffer when you want it to. If you do not like uart you can use I2C but the Pi does not support that properly yet. The uart on the Pi- well you run it a a separate thread to read/write/respond to whatever you want. If you were bitbanging then it would complicate stuff. – Piotr Kula Jan 15 '13 at 11:41
  • 1
    Nice suggestion. BTW Raspberry Pi Alamode is already a pun. Ala mode is when you put ice cream on pie. – Dan Oct 01 '16 at 23:46
  • 1
    Really ? Hehe. I wondered what that meant. Makes sense now :) – Piotr Kula Oct 02 '16 at 11:01
2

Since 2018, the Pi kernel comes with a set of -rt branches on github: this is what I'd try first if I wanted to test a realtime kernel on the Pi. Currently the patched kernel version is 4.19. Clicking on "Switch branches/tags" and typing "rt" in the search box will reveal the latest patched version.

Dmitry Grigoryev
  • 27,928
  • 6
  • 53
  • 144
2

The best solution I've seen to this is the X10i - Real Time Control Board for Raspberry Pi from Heber.

X10i is a universal, powerful and secure real-time controller that permits control over multiple inputs/outputs, via USB, from any PC system. Heber now offers support in many programming languages to make it even easier for programmers, inventors and developers to connect with the outside world from their PC.

The link above provides excellent and extensive documentation and they try and keep the drivers up to date with the latest version of Debian for Pi.

Jivings
  • 22,538
  • 11
  • 90
  • 139
  • SO you need a ribbon connector from the Pi to this? Can't find a hires photo of the thing but it looks really bulky. It has allot of examples so that is good I suppose . +1 – Piotr Kula Jan 15 '13 at 11:27
  • I can't say I've used it, but I would expect so, although I seem to remember the guy using a USB interface in the demo. It is pretty bulky though yes. – Jivings Jan 15 '13 at 19:43
1

RODOS is yet another option. It's an Open Source project developed by the German Aerospace Center and Prof. Montenegro's University team and students.

It's using C++, is completely written the object oriented way and supports ARM7, Atmel AVR, STM32/Cortex-M3, Xilinx, Raspberry Pi :), ...

It's currently used in satellite TET and in LoTTo machines if I didn't get that wrong.

Of course I would prefer running it above Linux (what is possible) to have the best of both worlds - but then the REAL TIME questions remain, because I'm not sure if it is possible that Linux can provide the correct API.

To get RODOS one has to write a message to Prof. Sergio Montenegro or the DLR (German Aerospace Center).

Radagast
  • 11
  • 1
  • If I have to write to Professor Sergio to ask for a copy, is it really "open source"? – Carl Smith Feb 17 '20 at 07:38
  • Maybe old school pen and paper open source. Some direct contact. I actually like this guy. Maybe one can get tailored feedback whether it is the right software for the task. I think the German Aerospace Center wants some way of control due to security fears (satellite exploitation). Let's find a compromise: It is "kind of open source". Better than nothing ;-) – Radagast Feb 20 '20 at 23:24
  • Cool. Fair enough :) – Carl Smith Feb 21 '20 at 08:16
1

besides linux, there are real time operating systems. quite popular among the open sourced ones is ChibiOS/RT:

is a complete, portable, open source, compact and extremely fast RTOS (Real-Time Operating System)

a brief introduction is at http://chibios.org/dokuwiki/doku.php?id=chibios:documents:introduction. being different from linux you might also like the readings of

Well, there are some design choices that should be explained and contribute to make ChibiOS/RT a peculiar design. Nothing really new in itself but the whole is interesting.

or not. if you do like it - experimenting on the pi might be worth the experience at https://github.com/steve-bate/ChibiOS-RPi:

ChibiOS fork for Raspberry PI experimentation.

the author adds a nice guide at

http://www.stevebate.net/chibios-rpi/GettingStarted.html

personally, when it comes to rtos, for me linux is like carrying cross-alpine equipment for plain country needs. you might just not need it. even a pi might be too much. check out http://forum.arduino.cc/index.php?topic=144715.0 for even less weight :)

jitter
  • 258
  • 1
  • 7
1

Here is an article (french translated by google translate) on Raspberry Pi running with Xenomai.

  • 5
    Hi there. Typically we discourage answers that are simply links in case the linked page moves. Could you summarise the information on that page in your answer? You can then include the link as a reference. Thanks! – Jivings Oct 26 '12 at 17:00
0

See this version of Hypriot Raspbian with RT_PREEMPT_FULL:

http://www.ehu.eus/ehusfera/pablogn/2016/01/20/real-time-kernel-for-the-raspberry-sbc/

Pablo
  • 1