Está en la página 1de 50

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Targeting the Scicos Codegenerator for


embedded applications
Ing. Roberto Bucher
Scuola Universitaria Professionale della Svizzera Italiana (SUPSI)

Paris - 1.7.2009

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Objectives

(Prices in Euro)
Core SW
Control SW
Graphical GUI
Code generator
RT target

Commercial
Control design environment
1950.1000.3000.7500.3000.-

Proposed
solution
0.0.0.0.0.-

Conclusions

Rapid Controller Prototyping

Objectives

Linux RTAI

Scicos

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Outline

Rapid Controller Prototyping

Linux RTAI

Scilab/Scicos and Linux RTAI

Implementation

Examples

Conclusions

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Introduction

Control Design Loop


specification

verification

modelling
identification

implementation

control
design

simulation

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Introduction

Rapid Controller Prototyping - Requirements

2 main components
1
2

An OS with hard real-time features


A Computer Aided Control System Design environment
including a code generator

Linux RTAI + RTAI-Lab + Scilab/Scicos

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Basics

The Linux RTAI project

Hard real-time extension to the Linux OS


Based on the ADEOS pipeline (with some improvements!)
Free Open Source Software (FOSS)
Implementation of hard real-time controllers using general
purpose hardware
Same PC for the controller design, the hard real-time
controller task and the soft real-time monitor task
Hard real-time in kernel and user space
Distributed control through the net rpc module

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Basics

Linux RTAI - Features

Latency: < 10s depending on the HW


Typical sampling frequencies: 1 . . . 10kHz

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

RTAI-Lab

The GUI application - xrtailab

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

RTAI-Lab

The GUI application - xrtailab

PC with HRT task and xrtailab

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

RTAI-Lab

The GUI application - xrtailab

PC with HRT task

PC with xrtailab

Network

UDP/IP

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

RTAI example 1

Systems controlled with Linux RTAI

Cycab (INRIA)
Biped Robot (INRIA)
http://www.inrialpes.fr/sed

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

RTAI example 2

National Radio Astronomy Observatory controlled with


Linux RTAI - West Virginia

http://www.gb.nrao.edu/43m/

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Add-ons

Add-ons for Scilab/Scicos

The link between Scilab/Scicos and Linux RTAI is implemented


through:
A code generator RTAICodeGen .sci.
A rtmain.c (main file for the real-time task) specific for the
Scilab/Scicos environment.
An external template Makefile
A new scicos palette RTAI-Lib.cosf.
Macros for the new blocks (Scicos interface functions).
A RTAI library specific for the new Scicos blocks (Scicos
implementation functions).

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

The code generator

RTAICodeGen .sci

The code generator used in RTAI is a modification of the standard


Scicos code generator
Only stand-alone generation with specific main procedure
(rtmain.c)
Sensors and actuators are integrated in the Scicos block
diagram as specific custom peripheral blocks
Each block can be identified by a name which is then referred
in RTAI-Lab

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

The code generator

Code generation
Design

Sine
COMEDI A/D
comedi0 CH0

COMEDI D/A
comedi0 CH0

Scope
SCOPE

Rapid Controller Prototyping


The code generator

Code generation
Design

Superblock

Linux RTAI

Scicos

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

The code generator

Code generation
Design

Superblock
RTAICodegen .sci

Code

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

The code generator

Code generation
Design

Superblock
Compiling and Link

Code

rtmain.c

libsciblk.a

Scilab lib

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

The code generator

Code generation
Design

Superblock
Hard real-time stand-alone executable

Code

rtmain.c

libsciblk.a

RT exec

Scilab lib

Rapid Controller Prototyping

Linux RTAI

The code generator

Code generation -Details

Superblock

Scicos

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

The code generator

Code generation -Details

rtai.gen

Superblock

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

The code generator

Code generation -Details

rtai.gen

Superblock

standalone.cmd

rtai.mak

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

The code generator

Code generation -Details

rtai.gen

Superblock

standalone.cmd

rtai.mak

model.c

model Cblocks.c

Makefile

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

The code generator

Target specific files - The gen file

rtai.mak
standalone.cmd

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

The code generator

Target specific files - The cmd file

[CCode,FCode]=gen_blocks()
[Code,Code_common]=make_standalone42();
files=write_code(Code,CCode,FCode,Code_common);
Makename=rt_gen_make(rdnom,files,archname);
ok=compile_standalone();

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

The code generator

Target specific files - The mak file


all: ../$$MODEL$$
...
CC = gcc
CC_OPTIONS = -O -DNDEBUG -Dlinux -DNARROWPROTO -D_GNU_SOURCE
MODEL = $$MODEL$$
OBJSSTAN = rtmain.o common.o $$MODEL$$.o $$OBJ$$

SCILIBS = $(SCIDIR)/libs/scicos.a $(SCIDIR)/libs/poly.a $(SCIDIR)/libs/calelm.a


OTHERLIBS =
ULIBRARY = $(RTAIDIR)/lib/libsciblk.a $(RTAIDIR)/lib/liblxrt.a

CFLAGS = $(CC_OPTIONS) -O2 -I$(SCIDIR)/routines -I$(SCIDIR)/routines/scicos $(C


rtmain.c: $(RTAIDIR)/share/rtai/scicos/rtmain.c $(MODEL).c
cp $< .

../$$MODEL$$: $(OBJSSTAN) $(ULIBRARY)


gcc -static -o $@ $(OBJSSTAN) $(SCILIBS) $(ULIBRARY) -lpthread $(COMED
@echo "### Created executable: $(MODEL) ###"

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Scicos blocks

The new Scicos palette

Sine

Scope
SCOPE

Mbx Send Ovw


MBX1

COMEDI A/D
comedi0 CH0

Square

Meter
METER

Mbx Rcv no blk


MBX1

COMEDI D/A
comedi0 CH0

Step

Led
LED

Mbx Send if
MBX1

COMEDI DI
comedi0 CH0

extdata
test.dat

SENSOR
SENS

Mbx rcv blk


MBX1

ACTUATOR
ACT

Fifoout
0

COMEDI DO
comedi0 CH0

Fifoin
0

SEM wait
SEM1

SEM signal
SEM1

C RTAI
Block

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Scicos blocks

Specific blocks for RTAI-Lab


Scope
SCOPE

Meter
METER

LED
LED

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Scicos blocks

Specific blocks for RTAI-Lab


Scope
SCOPE

Meter
METER

LED
LED

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Scicos blocks

Specific blocks for RTAI-Lab


Scope
SCOPE

Meter
METER

LED
LED

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Scicos blocks

Specific blocks for RTAI-Lab


Scope
SCOPE

Meter
METER

LED
LED

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Other palettes

Additional palettes

Scicos

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

The main file

The main file rtmain.c

3 threads:
Main thread rtMain
Hard RT thread rt BaseRate
Communication thread with the GUI client application
rt HostInterface

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

The main file

The rt BaseRate thread


NAME(MODEL,_init)();

SOFT realtime

WaitTimingEvent

NAME(MODEL,_isr)(double t);

HARD realtime

N
End?
Y

NAME(MODEL,_end)();

SOFT realtime

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Adding new blocks

Adding a new block

Each new block needs


An interface function (.sci)
An implementation function (.c)

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

The inverted pendulum

The Inverted Pendulum

Scicos

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

The inverted pendulum

The Inverted Pendulum


Particular of the RF encoder

Conclusions

Rapid Controller Prototyping

Linux RTAI

The inverted pendulum

The Inverted Pendulum

Scicos

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

The inverted pendulum

The Inverted Pendulum

Encoder+RF sender
Driver

RF
receiver
i1

M1

1
CAN BUS

PC with HRT
controller

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

The inverted pendulum

The Inverted Pendulum

y
u

Klqr

Reduced order
obsever

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

The inverted pendulum

The Inverted Pendulum


The Scicos scheme
1

Switch
1
0.2

Scope
SCOPE
Safety block

Real Plant

ABS

Input_ref

LQR_controller

Sine
Swingup_controller

Rapid Controller Prototyping


Ball on beam

Ball on Beam

Linux RTAI

Scicos

Implementation

Examples

Conclusions

Rapid Controller Prototyping


Ball on beam

Ball on Beam

Linux RTAI

Scicos

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

Ball on beam

Ball on Beam
The Scicos scheme

extdata
siginp.dat

Scope
SCOPE

K
Controllore + Osservatore

Ball on beam

Scope

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

Ball on beam

Ball on Beam
The anti-windup controller

1
x+=Ax+Bu
y=Cx+Du

2
3

Mux

C + O Direct

+
1

+
Sum

Saturazione
x+=Ax+Bu
y=Cx+Du

C + O Feedback

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

Ball on beam

Ball on Beam
The CANopen blocks

Epos
canopen
sync

Epos Analog
0x02
0

Epos
motor I
0x02

Mathemati..
Expression

INIT ENC
1s
X0

Epos
encoder
0x02

INIT ENC
1s
PHI0

num(z)
den(z)

Rapid Controller Prototyping


Ball on beam

Videos

Sample Videos

Linux RTAI

Scicos

Implementation

Examples

Conclusions

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Examples

Conclusions

Conclusions

Conclusions

Open source!!!
Complete and stable.
Able to solve complex control problems in a simple way.
It runs parallel to a MATLAB/Simulink/RTW environment in
my student laboratory

Rapid Controller Prototyping

Linux RTAI

Scicos

Implementation

Questions

Questions?

Thank You
www.rtai.org
www.dti.supsi.ch/bucher/scilab.html
www.dti.supsi.ch/smt/laboO4.html

Examples

Conclusions

También podría gustarte