How to Perform Real-Time Processing on the Raspberry Pi

28
How to Perform Real-Time Processing on the Raspberry Pi Steven Doran SCALE 13X

Transcript of How to Perform Real-Time Processing on the Raspberry Pi

Page 1: How to Perform Real-Time Processing on the Raspberry Pi

How to Perform Real-Time Processing on the Raspberry Pi

Steven DoranSCALE 13X

Page 2: How to Perform Real-Time Processing on the Raspberry Pi

2

Outline

● What is Real-Time?● What is the Raspberry Pi?● Can the Raspberry Pi handle Real-Time (And why would you want

to?● Why would you want to use the Raspberry Pi for Real-Time?● Example Project● Questions

Page 3: How to Perform Real-Time Processing on the Raspberry Pi

3

What is Real-Time?

An application that requires a guaranteed response within a strict timing constraints

Page 4: How to Perform Real-Time Processing on the Raspberry Pi

4

Some Examples of Real-Time

Page 5: How to Perform Real-Time Processing on the Raspberry Pi

5

Soft Real Time vs. Hard Real-Time

● Hard Real-Time – If the event is not processed in a strict timing window then bad things will happen

● Soft Real-Time – If the event is not processed in a not as strict timing window then the system may degrade but its not as bad

Page 6: How to Perform Real-Time Processing on the Raspberry Pi

6

Hard Real-Time Example

Page 7: How to Perform Real-Time Processing on the Raspberry Pi

7

Hard Real-Time Example (Gone Wrong)

Page 8: How to Perform Real-Time Processing on the Raspberry Pi

8

Soft Real-Time Example

Page 9: How to Perform Real-Time Processing on the Raspberry Pi

9

What is Real-Time is NOT!

#1 Software that runs fast

Page 10: How to Perform Real-Time Processing on the Raspberry Pi

10

What is Real-Time is NOT!

Software that runs fast

Example:

A processing Thread w/ a execution requirement of 2.5ms, but the system can only supports 5.0 ms

Page 11: How to Perform Real-Time Processing on the Raspberry Pi

11

What is Real-Time is NOT!

#1 Software that runs fast

Example:

A processing Thread w/ a execution requirement of 2.5ms, but the system can only supports 5.0 ms

#2 Just because it is embedded

Page 12: How to Perform Real-Time Processing on the Raspberry Pi

12

Real-Time Metrics

● Interrupt Latency – Time to process an interrupt

● Scheduling Latency – Time for the OS Scheduler to start a processing task (Nominal and Worst-case)

Page 13: How to Perform Real-Time Processing on the Raspberry Pi

13

What is a Raspberry Pi?

The Raspberry Pi is a small computer w/ 700 Mhz Single Core Atom and up to 512 Mb memory all for $25

Page 14: How to Perform Real-Time Processing on the Raspberry Pi

14

Raspberry Pi (The Good)

● It's cheap● It is easy hacked (Easily Configurable)● It comes with GPIO connectors for device input / output● It supports 1080p video

Page 15: How to Perform Real-Time Processing on the Raspberry Pi

15

Raspberry Pi Projects

Page 16: How to Perform Real-Time Processing on the Raspberry Pi

16

Raspberry Pi (The Bad)

● No Real-Time Clock

– Expects device to be always connected to the internet– Cannot generate deterministic timing pulses to control things

like DC motors● RAM cannot be expanded● The built-in Network Interface is really a USB device and shares

the same bus on any USB device connected to it● Power issues especially with the first hardware version

Page 17: How to Perform Real-Time Processing on the Raspberry Pi

17

●Can the Raspberry Pi handle Real-Time (And why would you want to?)

● Kinda with allot of tweaking

– Current Linux / BSD kernels for the Raspberry Pi do not support real-time

– Standard Linux or BSD install includes services that generate lots of overhead

– No real-time clock

● Because it is cheap and flexible

Page 18: How to Perform Real-Time Processing on the Raspberry Pi

18

A Sample Raspberry Pi Project that benefits from Real-Time – Nerf Tank

● Let's say we want to have a Raspberry Pi control a deadly Nerf Tank

– Pi needs to detect the baddy– Pi needs to move the turret to aim the Nerf gun at the baddy– Pi needs to fire the deadly Nerf projectile at the baddy (if in

range)– Pi needs to make sure the tank does not collide with anything

while it is doing the above steps

Pi needs to do all of the above at the same time (Multi-threaded)

Page 19: How to Perform Real-Time Processing on the Raspberry Pi

19

Nerf Tank Real-Time Problem #1 – No Real-Time Clock

Problem Statement

– Nerf Tank will have timing requirements and will not be always (if ever) connected to the Internet

● Solution

– Add a Real-Time clock

Page 20: How to Perform Real-Time Processing on the Raspberry Pi

20

Nerf Tank Real-Time Problem #2 – Pulse Generation

Problem Statement

– Even with a Real-time clock the Raspberry Pi will not generate the deterministic timing pulses we need to move the drive motors and turret with accuracy

● Solutions

– Connect a AD9850 Pulse generator to the Raspberry Pi– Connect a AdaFruit Servo HAT to the Raspberry Pi

Page 21: How to Perform Real-Time Processing on the Raspberry Pi

21

Nerf Tank Real-Time Problem #2 – Pulse Generation

Page 22: How to Perform Real-Time Processing on the Raspberry Pi

22

●AD9850 Pulse Generator connected to the Raspberry Pi

AD9850

Raspberry Pi

GPIOGPIO

ISR

Page 23: How to Perform Real-Time Processing on the Raspberry Pi

23

Nerf Tank Real-Time Problem #3 – Multi-Threaded Applications

Problem Statement

– The software that will control the Nerf Tank will require multiple processing threads with unique timing and priorities that the stock Raspberry Pi distribution kernels cannot guarantee

– Processing tasks share resources

● Solutions

– Use RTEMS– Build your own real-time Linux kernel from source

● Who uses make menuconfig anymore?– Remove all unused services

Page 24: How to Perform Real-Time Processing on the Raspberry Pi

24

Fun Example of Priority Inversion

Page 25: How to Perform Real-Time Processing on the Raspberry Pi

25

Real Time Executive for Multiprocessor Systems (RTEMS) for Raspberry Pi

● Open Source Real Time Operating System (RTOS) ● Used in Spaceflight, medical, and other real-time embedded

applications● Ported to the Raspberry Pi (w/ some limitations)

Page 26: How to Perform Real-Time Processing on the Raspberry Pi

26

Nerf Tank Real-Time Problem #4 – Maximum CPU Performance

Problem Statement

– The Raspberry Pi's CPU is not set at its maximum performance using default kernels

● Solutions

– Overclock the CPU● Using RaspBian

– Raspi-config● Remove all unneeded services

Page 27: How to Perform Real-Time Processing on the Raspberry Pi

27

Summary

● We discussed what Real-Time means● We described the Raspberry Pi w/ its Pro's and Con's● We used a Nerf Tank example on how to tweak the Raspberry Pi

to perform real-time processing

Page 28: How to Perform Real-Time Processing on the Raspberry Pi

28

Questions