Rapid Controller Prototyping at the SUPSI...

82
DTI / ISEA / LSM / Titolo principale della presentazione Rapid Controller Prototyping at the SUPSI laboratory Prof. Roberto Bucher SUPSI - ISEA – SMT Manno 9.05.2014

Transcript of Rapid Controller Prototyping at the SUPSI...

Page 1: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Rapid Controller Prototyping at the SUPSI laboratory

Prof. Roberto BucherSUPSI - ISEA – SMT

Manno 9.05.2014

Page 2: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Outline

• The mechatronics laboratory at SUPSI• The SUPSI Rapid Control Prototyping System• Linux RT systems and other targets• The Computer Aided Control System Design environments• The CAN bus approach• Examples• Conclusions

Page 3: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Introduction – SUPSI Labor Place

Page 4: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

The Control Design Loop

Page 5: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

The RCP system

• A general purpose PC• Different OS's with real-time features• Different CACSD environments including a code generator• Plants built on commercial CAN bus capable devices• A physical CAN bus interface

Page 6: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

The RCP system

CACSD: Matlab/SimulinkScicoslabScilab/xCosPython/gEDA

OS: Linux RTAILinux Preempt-RT

Page 7: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

The RCP system

Page 8: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

RCP methods

• Design of the controller in the CACSD environment (Matlab, Scilab, Scicoslab, Python)

• Hybrid (discrete controller, continous plant) simulation of the controller with the dynamic model of the plant

• Substitute the model of the plant with sensors and actuators blocks

• Substitute the scopes with RT scopes• Generate and compile the code• Verify the controller on the real plant

Page 9: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

RCP methods

Page 10: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

RCP methods

Page 11: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

The RT targets

Page 12: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

The Linux RTAI project

• Hard real-time extension to the Linux OS• Project from Dipartimento di Ingegneria Aerospaziale del Politecnico di Milano• SUPSI is involved in project since 2002 (first automatic generation of a kernel

task from a Simulink block diagram)• Free Open Source Software (FOSS) • Same PC for the controller design, for the hard real-time controller task and

for the soft real-time monitoring task• Hard real-time in kernel and user space• RTAI API• Distributed control through the net_rpc modul• Latency: < 15 µs on modern HW• Typical sampling frequencies: 1 ... 10 kHz

Page 13: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

RTAI projects

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

http://www.inrialpes.fr/sed

Page 14: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

RTAI projects

http://www.alma.nrao.edu/

Page 15: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

RTAILab

Page 16: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

RTAILab

Page 17: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

RTAILab

Page 18: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

RTAI-XML

http://www.rtaixml.net/realtime-suite

Page 19: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

RTAI-XML

http://www.rtaixml.net/realtime-suite

Page 20: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

The Linux Preempt-RT project

• Real-time extension to the Linux OS (Ingo Molnar - RedHat, Thomas Gleixner - Pengutronix)

• Free Open Source Software (FOSS) • Same PC for the controller design, for the real-time controller

task and for the monitoring task (browser)• real-time in user space• POSIX API• Latency: < 50 µs on modern HW• Typical sampling frequencies: 100 ... 1000 Hz• IBM - WebSphere Real Time (Java RT)

Page 21: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Linux with preempt_rt

www.osadl.org

Page 22: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

XML Browser from Klaus Weichinger

http://bioe.sourceforge.net/

Page 23: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Linux ARM systems (with rt_preempt patch)

Page 24: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

dsPIC

• C-Code• MPLABX project• dsPIC 33FJ64MC810• dsPIC 33FJ64MC804

Page 25: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

The CACSD Environments

Page 26: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Matlab / Simulink / RTW

• Matlab for solving the control design algorithms• Simulink for hybrid simulation• Real Time Workshop for C-Code generation• Linux RTAI as RT target

– RTAI.tlc + RTAI.tmf developed at SUPSI with Dipartimento di Ingegneria Aerospaziale del Politecnico di Milano (DIAPM)

• Commercial licences! (quite expensive)

Page 27: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Matlab/Simulink/RTW

Page 28: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Matlab/Simulink/RTW

disksRT.cdisksRT.hdisksRT_data.c....

rtai.tmf

disksRT.mk

Page 29: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Matlab/Simulink/RTW

disksRT.cdisksRT.hdisksRT_data.c....

rtai.tmf

disksRT.mk

Mathworks libs RTAI and custom libs

Page 30: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Matlab/Simulink/RTW

disksRT.cdisksRT.hdisksRT_data.c....

rtai.tmf

disksRT.mk

Mathworks libs

RT standalone executable

RTAI and custom libs

Page 31: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

CACSD – Matlab / Simulink / RTW

• Matlab / Simulink are “de facto” THE TOOLS in education

Page 32: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

CACSD – Matlab / Simulink / RTW

• Matlab / Simulink are “de facto” THE TOOLS in education

• But...– What happens wenn our (ex-) students have to develop

advanced control systems in little companies?– Mathworks commercial licenses are too expensive for

most little companies!

Page 33: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Scicoslab

• Developed by INRIA Rocquencourt• Fork of the scilab project• Scicos for hybrid simulation• Modelica extension (bond graphs)• Original code generator modified by Roberto Bucher for embedding

in target• Integration with Linux RTAI, Linux preempt_rt and dsPIC embedded

systems possible• Not open source but free

• Next version should be called NSP

Page 34: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Scilab / xCos

• Developed by INRIA Rocquencourt• Xcos for hybrid simulation• Modelica• Original code generator modified by Roberto Bucher for

embedding in target• Integration with Linux RTAI and Linux preempt_rt possible

(CTI project 13910.1 PFIW-IW)• Cecill licence (like GPL licence)

Page 35: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Scicoslab (or scilab+Xcos)

Page 36: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Scicoslab (or scilab+Xcos)

Page 37: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Scicoslab (or scilab+Xcos)

disksRT.c....

rtai.tmf

Makefile

Page 38: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Scicoslab (or scilab+Xcos)

disksRT.c....

rtai.tmf

Makefile

Scicos libs RTAI and custom libs

Page 39: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Scicoslab (or scilab+Xcos)

disksRT.c....

rtai.tmf

Makefile

Scicos libs

RT standalone executable

RTAI and custom libs

Page 40: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Python

• Project started at Centrum Wiskunde & Informatica in the Netherlands (1989)

• Control Toolbox from Richard Murray (Caltech)• Additional functions from Roberto Bucher (SUPSI) for

– Correcting some bugs in Control Toolbox– Solving complex control tasks– Adding hybrid simulation– Code generation (Linux with preempt_rt now)

• Python Software Foundation License (PSFL) (like BSD)

Page 41: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

gEDA tools

• Open source tool for generating block diagram• Custom blocks are possible• From schematics it is possible to generate a netlist• A python tool translate the netlist into python blocks for code

generation (C-Code)

Page 42: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Python / gEDA

Page 43: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Python / gEDA

* Spice netlister for gnetlistDISP 2 4 3 nin:3,nout:0,printBlkSRV nin:0,nout:0,rtxmlServerBlk,Signals Plot1: 'Sig1 Sig2',Signals Plot 2: 'Sig1',Signals Plot 3: 'Sig2',Additional XML Par: '<PAR></PAR>',HTTP port: 3141OUTPOS 4 nin:1,nout:0,rtxmlSigBlk,Signals Name: 'Sig2',Default Value: 0.0OUTREF 2 nin:1,nout:0,rtxmlSigBlk,Signals Name: 'Sig1',Default Value: 0.0ENC2 4 nin:0,nout:1,maxon_EncBlk,Device ID: 0x02,Resolution: 500ENC1 3 nin:0,nout:1,maxon_EncBlk,Device ID: 0x01,Resolution: 500MOTOR 7 nin:1,nout:0,maxon_MotBlk,Device ID: 0x01,Prop. gain: 8000,Integ. gain: 4000CTRFBK 7 6 nin:1,nout:1,dssBlk,System: gss_out,Initial conditions: 0SAT 5 7 nin:1,nout:1,saturBlk,Upper saturation:3000,Lower saturation: -3000B1 1 6 5 nin:2,nout:1,sumBlk,Gains: [1,1]REF 2 nin:0,nout:1,squareBlk,Amplitude: 4,Period: 10,Width: 5,Bias: 0,Delay: 0CTRIN 2 3 4 1 nin:3,nout:1,dssBlk,System: gss_in,Initial conditions: 0.END

Page 44: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Python / gEDA

* Spice netlister for gnetlistDISP 2 4 3 nin:3,nout:0,printBlkSRV nin:0,nout:0,rtxmlServerBlk,Signals Plot1: 'Sig1 Sig2',Signals Plot 2: 'Sig1',Signals Plot 3: 'Sig2',Additional XML Par: '<PAR></PAR>',HTTP port: 3141OUTPOS 4 nin:1,nout:0,rtxmlSigBlk,Signals Name: 'Sig2',Default Value: 0.0OUTREF 2 nin:1,nout:0,rtxmlSigBlk,Signals Name: 'Sig1',Default Value: 0.0ENC2 4 nin:0,nout:1,maxon_EncBlk,Device ID: 0x02,Resolution: 500ENC1 3 nin:0,nout:1,maxon_EncBlk,Device ID: 0x01,Resolution: 500MOTOR 7 nin:1,nout:0,maxon_MotBlk,Device ID: 0x01,Prop. gain: 8000,Integ. gain: 4000CTRFBK 7 6 nin:1,nout:1,dssBlk,System: gss_out,Initial conditions: 0SAT 5 7 nin:1,nout:1,saturBlk,Upper saturation:3000,Lower saturation: -3000B1 1 6 5 nin:2,nout:1,sumBlk,Gains: [1,1]REF 2 nin:0,nout:1,squareBlk,Amplitude: 4,Period: 10,Width: 5,Bias: 0,Delay: 0CTRIN 2 3 4 1 nin:3,nout:1,dssBlk,System: gss_in,Initial conditions: 0.END

from supsictrl.RCPblk import *

DISP = printBlk([2, 4, 3])SRV = rtxmlServerBlk( 'Sig1 Sig2', 'Sig1', 'Sig2', '<PAR></PAR>', 3141)OUTPOS = rtxmlSigBlk([4], 'Sig2', 0.0)OUTREF = rtxmlSigBlk([2], 'Sig1', 0.0)ENC2 = maxon_EncBlk([4], 0x02, 500)ENC1 = maxon_EncBlk([3], 0x01, 500)MOTOR = maxon_MotBlk([7], 0x01, 8000, 4000)CTRFBK = dssBlk([7],[6], gss_out, 0)SAT = saturBlk([5],[7],3000, -3000)B1 = sumBlk([1, 6],[5], [1,1])REF = squareBlk([2], 4, 10, 5, 0, 0)CTRIN = dssBlk([2, 3, 4],[1], gss_in, 0)

blks = [DISP, SRV, OUTPOS, OUTREF, ENC2, ENC1, MOTOR, CTRFBK, SAT, B1, REF, CTRIN]fname = 'disksRT'genCode(fname, 0.01, blks)genMake(fname,'rt.tmf')

Page 45: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Interfacing the real plants

Page 46: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

CAN Bus interface - Motivation

• Teaching environment based on tools found in industry• COTS components (multiple vendors)• Simplified maintenance and reduced costs• Easy expendability and flexibility of didactic activities

Page 47: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

CAN bus – the 4-tier implementation

• Combination of– Different CAN devices

– Different CACSD environments

– Different CAN interfaces

Page 48: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

CAN bus – the 4-tier implementation

• Combination of– Different CAN devices

– Different CACSD environments

– Different CAN interfaces

Complexity for specific SW interfaces unmanageable

Structured approach

Page 49: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

CAN bus – the 4-tier implementation

95% same code

Different CAN interfaces

Message dispatcher

devicespecific

code

PhysicalLayer

interface

CACSDspecific

layersimulink

ScicosXcos

python

Page 50: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Example – Disks And Spring

Page 51: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Example – Disks And Spring

Page 52: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Inverted Pendulum

Page 53: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Inverted Pendulum

Page 54: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Delta haptic manipulator

Page 55: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Delta haptic manipulator

Page 56: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Other projects

Page 57: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Other projects

Page 58: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Other projects

Page 59: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Labo example

Page 60: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Example – Disks and spring

Page 61: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Model identification

Page 62: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Model identification

Page 63: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Controller

Page 64: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Controller

Page 65: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Controller in compact form

Page 66: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Matlab + Simulink

Page 67: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Matlab + Simulink

Page 68: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Scicoslab + Modelica

Page 69: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Scicoslab + Modelica

Page 70: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Scicoslab + Modelica

Page 71: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Python implementation

Page 72: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Code generation

• Find the right block sequence• Generate the C code with 3

functions:– Init

• Initialization– ISR

• Outputs update• States update

– Termination

continous time systems discrete time systems

Page 73: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Block Diagram for simulation

Page 74: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Block Diagram for simulation

Page 75: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Block diagram for RT execution

Page 76: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Python / gEDA / RT execution

Page 77: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Python / gEDA / RT execution

* Spice netlister for gnetlistDISP 2 4 3 nin:3,nout:0,printBlkSRV nin:0,nout:0,rtxmlServerBlk,Signals Plot1: 'Sig1 Sig2',Signals Plot 2: 'Sig1',Signals Plot 3: 'Sig2',Additional XML Par: '<PAR></PAR>',HTTP port: 3141OUTPOS 4 nin:1,nout:0,rtxmlSigBlk,Signals Name: 'Sig2',Default Value: 0.0OUTREF 2 nin:1,nout:0,rtxmlSigBlk,Signals Name: 'Sig1',Default Value: 0.0ENC2 4 nin:0,nout:1,maxon_EncBlk,Device ID: 0x02,Resolution: 500ENC1 3 nin:0,nout:1,maxon_EncBlk,Device ID: 0x01,Resolution: 500MOTOR 7 nin:1,nout:0,maxon_MotBlk,Device ID: 0x01,Prop. gain: 8000,Integ. gain: 4000CTRFBK 7 6 nin:1,nout:1,dssBlk,System: gss_out,Initial conditions: 0SAT 5 7 nin:1,nout:1,saturBlk,Upper saturation:3000,Lower saturation: -3000B1 1 6 5 nin:2,nout:1,sumBlk,Gains: [1,1]REF 2 nin:0,nout:1,squareBlk,Amplitude: 4,Period: 10,Width: 5,Bias: 0,Delay: 0CTRIN 2 3 4 1 nin:3,nout:1,dssBlk,System: gss_in,Initial conditions: 0.END

Page 78: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Python / gEDA / RT execution

* Spice netlister for gnetlistDISP 2 4 3 nin:3,nout:0,printBlkSRV nin:0,nout:0,rtxmlServerBlk,Signals Plot1: 'Sig1 Sig2',Signals Plot 2: 'Sig1',Signals Plot 3: 'Sig2',Additional XML Par: '<PAR></PAR>',HTTP port: 3141OUTPOS 4 nin:1,nout:0,rtxmlSigBlk,Signals Name: 'Sig2',Default Value: 0.0OUTREF 2 nin:1,nout:0,rtxmlSigBlk,Signals Name: 'Sig1',Default Value: 0.0ENC2 4 nin:0,nout:1,maxon_EncBlk,Device ID: 0x02,Resolution: 500ENC1 3 nin:0,nout:1,maxon_EncBlk,Device ID: 0x01,Resolution: 500MOTOR 7 nin:1,nout:0,maxon_MotBlk,Device ID: 0x01,Prop. gain: 8000,Integ. gain: 4000CTRFBK 7 6 nin:1,nout:1,dssBlk,System: gss_out,Initial conditions: 0SAT 5 7 nin:1,nout:1,saturBlk,Upper saturation:3000,Lower saturation: -3000B1 1 6 5 nin:2,nout:1,sumBlk,Gains: [1,1]REF 2 nin:0,nout:1,squareBlk,Amplitude: 4,Period: 10,Width: 5,Bias: 0,Delay: 0CTRIN 2 3 4 1 nin:3,nout:1,dssBlk,System: gss_in,Initial conditions: 0.END

from supsictrl.RCPblk import *

DISP = printBlk([2, 4, 3])SRV = rtxmlServerBlk( 'Sig1 Sig2', 'Sig1', 'Sig2', '<PAR></PAR>', 3141)OUTPOS = rtxmlSigBlk([4], 'Sig2', 0.0)OUTREF = rtxmlSigBlk([2], 'Sig1', 0.0)ENC2 = maxon_EncBlk([4], 0x02, 500)ENC1 = maxon_EncBlk([3], 0x01, 500)MOTOR = maxon_MotBlk([7], 0x01, 8000, 4000)CTRFBK = dssBlk([7],[6], gss_out, 0)SAT = saturBlk([5],[7],3000, -3000)B1 = sumBlk([1, 6],[5], [1,1])REF = squareBlk([2], 4, 10, 5, 0, 0)CTRIN = dssBlk([2, 3, 4],[1], gss_in, 0)

blks = [DISP, SRV, OUTPOS, OUTREF, ENC2, ENC1, MOTOR, CTRFBK, SAT, B1, REF, CTRIN]fname = 'disksRT'genCode(fname, 0.01, blks)genMake(fname,'rt.tmf')

Page 79: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Conclusions

Page 80: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Conclusions

• Investment of resources !– Gain of experience

– Gain of knowledges

• Appreciated by the students• Forms students with reusable skills• Easy to maintain and to develop• Synergies with research activities

Page 81: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Other useful links

• www.rtai.org• www.osadl.org• robertobucher.dti.supsi.ch/• www.dti.supsi.ch/~smt/laboO4.html

Page 82: Rapid Controller Prototyping at the SUPSI laboratoryrobertobucher.dti.supsi.ch/.../uploads/2017/03/PresentazioneRCP2.pdf · Rapid Controller Prototyping at the SUPSI laboratory Prof.

DTI / ISEA / LSM / Titolo principale della presentazione

Questions?