Targeting the Scicos Codegenerator for embedded applications
Transcript of Targeting the Scicos Codegenerator for embedded applications
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Targeting the Scicos Codegenerator forembedded applications
Ing. Roberto Bucher
Scuola Universitaria Professionale della Svizzera Italiana (SUPSI)
Paris - 1.7.2009
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Objectives
(Prices in Euro) Commercial ProposedControl design environment solution
Core SW 1950.- 0.-
Control SW 1000.- 0.-
Graphical GUI 3000.- 0.-
Code generator 7500.- 0.-
RT target 3000.- 0.-
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Outline
1 Rapid Controller Prototyping
2 Linux RTAI
3 Scilab/Scicos and Linux RTAI
4 Implementation
5 Examples
6 Conclusions
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Introduction
Control Design Loop
specification
modellingidentification
controldesign
simulation
implementation
verification
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Introduction
Rapid Controller Prototyping - Requirements
2 main components1 An OS with hard real-time features2 A Computer Aided Control System Design environment
including a code generator
→ Linux RTAI + RTAI-Lab + Scilab/Scicos
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
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 generalpurpose hardware
Same PC for the controller design, the hard real-timecontroller task and the soft real-time monitor task
Hard real-time in kernel and user space
Distributed control through the net rpc module
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Basics
Linux RTAI - Features
Latency: < 10µs depending on the HW
Typical sampling frequencies: 1 . . . 10kHz
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
RTAI-Lab
The GUI application - xrtailab
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
RTAI-Lab
The GUI application - xrtailab
PC with HRT task and xrtailab
PC with HRT task PC with xrtailab
Network
UDP/IP
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
RTAI-Lab
The GUI application - xrtailab
PC with HRT task and xrtailab
PC with HRT task PC with xrtailab
Network
UDP/IP
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
RTAI example 1
Systems controlled with Linux RTAI
http://www.inrialpes.fr/sed
Cycab (INRIA)
Biped Robot (INRIA)
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
RTAI example 2
National Radio Astronomy Observatory controlled withLinux RTAI - West Virginia
http://www.gb.nrao.edu/43m/
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Add-ons
Add-ons for Scilab/Scicos
The link between Scilab/Scicos and Linux RTAI is implementedthrough:
A code generator → RTAICodeGen .sci.
A rtmain.c (main file for the real-time task) specific for theScilab/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 (Scicosimplementation functions).
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 standardScicos code generator
Only stand-alone generation with specific main procedure(rtmain.c)
Sensors and actuators are integrated in the Scicos blockdiagram as specific custom peripheral blocks
Each block can be identified by a name which is then referredin RTAI-Lab
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The code generator
Code generation
SineSine
SCOPEScopeSCOPEScope
comedi0 CH−0COMEDI A/Dcomedi0 CH−0COMEDI A/D
comedi0 CH−0COMEDI D/Acomedi0 CH−0COMEDI D/A
Design
Superblock
RTAICodegen .sci
Code
Compiling and Link
rtmain.c libsciblk.a Scilab lib
Hard real-time stand-alone executable
RT exec
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The code generator
Code generation
SineSine
SCOPEScopeSCOPEScope
comedi0 CH−0COMEDI A/Dcomedi0 CH−0COMEDI A/D
comedi0 CH−0COMEDI D/Acomedi0 CH−0COMEDI D/A
Design
Superblock
RTAICodegen .sci
Code
Compiling and Link
rtmain.c libsciblk.a Scilab lib
Hard real-time stand-alone executable
RT exec
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The code generator
Code generation
SineSine
SCOPEScopeSCOPEScope
comedi0 CH−0COMEDI A/Dcomedi0 CH−0COMEDI A/D
comedi0 CH−0COMEDI D/Acomedi0 CH−0COMEDI D/A
Design
Superblock
RTAICodegen .sci
Code
Compiling and Link
rtmain.c libsciblk.a Scilab lib
Hard real-time stand-alone executable
RT exec
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The code generator
Code generation
SineSine
SCOPEScopeSCOPEScope
comedi0 CH−0COMEDI A/Dcomedi0 CH−0COMEDI A/D
comedi0 CH−0COMEDI D/Acomedi0 CH−0COMEDI D/A
Design
Superblock
RTAICodegen .sci
Code
Compiling and Link
rtmain.c libsciblk.a Scilab lib
Hard real-time stand-alone executable
RT exec
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The code generator
Code generation
SineSine
SCOPEScopeSCOPEScope
comedi0 CH−0COMEDI A/Dcomedi0 CH−0COMEDI A/D
comedi0 CH−0COMEDI D/Acomedi0 CH−0COMEDI D/A
Design
Superblock
RTAICodegen .sci
Code
Compiling and Link
rtmain.c libsciblk.a Scilab lib
Hard real-time stand-alone executable
RT exec
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The code generator
Code generation -Details
Superblock
rtai.gen
standalone.cmd rtai.mak
model.c model Cblocks.c Makefile
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The code generator
Code generation -Details
Superblock
rtai.gen
standalone.cmd rtai.mak
model.c model Cblocks.c Makefile
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The code generator
Code generation -Details
Superblock
rtai.gen
standalone.cmd rtai.mak
model.c model Cblocks.c Makefile
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The code generator
Code generation -Details
Superblock
rtai.gen
standalone.cmd rtai.mak
model.c model Cblocks.c Makefile
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The code generator
Target specific files - The “gen” file
rtai.makstandalone.cmd
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
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();
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$(SCIDIR)/libs/blas.a $(SCIDIR)/libs/lapack.a $(SCIDIR)/libs/os_specific.a
OTHERLIBS =
ULIBRARY = $(RTAIDIR)/lib/libsciblk.a $(RTAIDIR)/lib/liblxrt.a
CFLAGS = $(CC_OPTIONS) -O2 -I$(SCIDIR)/routines -I$(SCIDIR)/routines/scicos $(C_FLAGS) -DMODEL=$(MODEL) -DMODELN=$(MODEL).c
rtmain.c: $(RTAIDIR)/share/rtai/scicos/rtmain.c $(MODEL).c
cp $< .
../$$MODEL$$: $(OBJSSTAN) $(ULIBRARY)
gcc -static -o $@ $(OBJSSTAN) $(SCILIBS) $(ULIBRARY) -lpthread $(COMEDILIB) -lm
@echo "### Created executable: $(MODEL) ###"
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Scicos blocks
The new Scicos palette
Sine
Square
Step
test.datextdata
SENS
SENSOR
SCOPEScope
METERMeter
LEDLed
ACTACTUATOR
MBX1Mbx Send Ovw
MBX1Mbx Rcv no blk
MBX1Mbx Send if
MBX1Mbx rcv blk
comedi0 CH−0COMEDI A/D
comedi0 CH−0COMEDI D/A
comedi0 CH−0COMEDI DI
comedi0 CH−0COMEDI DO
SEM1
SEM wait
SEM1SEM signal
BlockC RTAI
0Fifoout
0Fifoin
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Scicos blocks
Specific blocks for RTAI-Lab
SCOPEScopeSCOPEScope
METERMeterMETERMeter
LEDLEDLEDLED
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Scicos blocks
Specific blocks for RTAI-Lab
SCOPEScopeSCOPEScope
METERMeterMETERMeter
LEDLEDLEDLED
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Scicos blocks
Specific blocks for RTAI-Lab
SCOPEScopeSCOPEScope
METERMeterMETERMeter
LEDLEDLEDLED
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Scicos blocks
Specific blocks for RTAI-Lab
SCOPEScopeSCOPEScope
METERMeterMETERMeter
LEDLEDLEDLED
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Other palettes
Additional palettes
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The ”main” file
The main file rtmain.c
3 threads:
Main thread rtMain
Hard RT thread rt BaseRate
Communication thread with the GUI client applicationrt HostInterface
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The ”main” file
The rt BaseRate thread
WaitTimingEvent
End?
Y
N
HARD real−time
SOFT real−time
SOFT real−time
NAME(MODEL,_isr)(double t);
NAME(MODEL,_init)();
NAME(MODEL,_end)();
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Adding new blocks
Adding a new block
Each new block needs
An interface function (“.sci”)
An implementation function (“.c”)
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The inverted pendulum
The Inverted Pendulum
Particular of the RF encoder
M1
i1 φ1
RF
receiver
Driver
CAN BUS
PC with HRT
controller
Encoder+RF sender
Reduced orderobsever
Klqr
y
φ
u
The Scicos scheme
SCOPEScope
Safety block
11
Real Plant
LQR_controller Input_ref
Swingup_controller
Sine
0.21Switch
ABS
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The inverted pendulum
The Inverted Pendulum
Particular of the RF encoder
M1
i1 φ1
RF
receiver
Driver
CAN BUS
PC with HRT
controller
Encoder+RF sender
Reduced orderobsever
Klqr
y
φ
u
The Scicos scheme
SCOPEScope
Safety block
11
Real Plant
LQR_controller Input_ref
Swingup_controller
Sine
0.21Switch
ABS
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The inverted pendulum
The Inverted Pendulum
Particular of the RF encoder
M1
i1 φ1
RF
receiver
Driver
CAN BUS
PC with HRT
controller
Encoder+RF sender
Reduced orderobsever
Klqr
y
φ
u
The Scicos scheme
SCOPEScope
Safety block
11
Real Plant
LQR_controller Input_ref
Swingup_controller
Sine
0.21Switch
ABS
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The inverted pendulum
The Inverted Pendulum
Particular of the RF encoder
M1
i1 φ1
RF
receiver
Driver
CAN BUS
PC with HRT
controller
Encoder+RF sender
Reduced orderobsever
Klqr
y
φ
u
The Scicos scheme
SCOPEScope
Safety block
11
Real Plant
LQR_controller Input_ref
Swingup_controller
Sine
0.21Switch
ABS
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The inverted pendulum
The Inverted Pendulum
Particular of the RF encoder
M1
i1 φ1
RF
receiver
Driver
CAN BUS
PC with HRT
controller
Encoder+RF sender
Reduced orderobsever
Klqr
y
φ
u
The Scicos scheme
SCOPEScope
Safety block
11
Real Plant
LQR_controller Input_ref
Swingup_controller
Sine
0.21Switch
ABS
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
The inverted pendulum
The Inverted Pendulum
Particular of the RF encoder
M1
i1 φ1
RF
receiver
Driver
CAN BUS
PC with HRT
controller
Encoder+RF sender
Reduced orderobsever
Klqr
y
φ
u
The Scicos scheme
SCOPEScope
Safety block
11
Real Plant
LQR_controller Input_ref
Swingup_controller
Sine
0.21Switch
ABS
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Ball on beam
Ball on Beam
The Scicos scheme
Scope
SCOPEScope
Ball on beamControllore + Osservatore
11
−K−siginp.datextdata
The anti-windup controller
Saturazione
11
11
2211
Mux C + O Direct
y=Cx+Dux+=Ax+Bu
Sum
+
+
C + O Feedback
y=Cx+Dux+=Ax+Bu
33
The CANopen blocks
ExpressionMathemati..
0x02encoderEpos
0x02motor IEpos
00x02Epos Analog
11
2211
11
X01sINIT ENC
PHI01sINIT ENC
den(z)num(z)sync
canopenEpos
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Ball on beam
Ball on Beam
The Scicos scheme
Scope
SCOPEScope
Ball on beamControllore + Osservatore
11
−K−siginp.datextdata
The anti-windup controller
Saturazione
11
11
2211
Mux C + O Direct
y=Cx+Dux+=Ax+Bu
Sum
+
+
C + O Feedback
y=Cx+Dux+=Ax+Bu
33
The CANopen blocks
ExpressionMathemati..
0x02encoderEpos
0x02motor IEpos
00x02Epos Analog
11
2211
11
X01sINIT ENC
PHI01sINIT ENC
den(z)num(z)sync
canopenEpos
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Ball on beam
Ball on Beam
The Scicos scheme
Scope
SCOPEScope
Ball on beamControllore + Osservatore
11
−K−siginp.datextdata
The anti-windup controller
Saturazione
11
11
2211
Mux C + O Direct
y=Cx+Dux+=Ax+Bu
Sum
+
+
C + O Feedback
y=Cx+Dux+=Ax+Bu
33
The CANopen blocks
ExpressionMathemati..
0x02encoderEpos
0x02motor IEpos
00x02Epos Analog
11
2211
11
X01sINIT ENC
PHI01sINIT ENC
den(z)num(z)sync
canopenEpos
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Ball on beam
Ball on Beam
The Scicos scheme
Scope
SCOPEScope
Ball on beamControllore + Osservatore
11
−K−siginp.datextdata
The anti-windup controller
Saturazione
11
11
2211
Mux C + O Direct
y=Cx+Dux+=Ax+Bu
Sum
+
+
C + O Feedback
y=Cx+Dux+=Ax+Bu
33
The CANopen blocks
ExpressionMathemati..
0x02encoderEpos
0x02motor IEpos
00x02Epos Analog
11
2211
11
X01sINIT ENC
PHI01sINIT ENC
den(z)num(z)sync
canopenEpos
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Ball on beam
Ball on Beam
The Scicos scheme
Scope
SCOPEScope
Ball on beamControllore + Osservatore
11
−K−siginp.datextdata
The anti-windup controller
Saturazione
11
11
2211
Mux C + O Direct
y=Cx+Dux+=Ax+Bu
Sum
+
+
C + O Feedback
y=Cx+Dux+=Ax+Bu
33
The CANopen blocks
ExpressionMathemati..
0x02encoderEpos
0x02motor IEpos
00x02Epos Analog
11
2211
11
X01sINIT ENC
PHI01sINIT ENC
den(z)num(z)sync
canopenEpos
Rapid Controller Prototyping Linux RTAI Scicos Implementation Examples Conclusions
Ball on beam
Videos
Sample Videos
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 inmy student laboratory