DTI / ISEA / LSM / Titolo principale della presentazione CACSD with Python Prof. Roberto Bucher SUPSI - ISEA – SMT Rapperswil 28.01.2014 SGA Meeting und Preisübergabe Förderpreis 2013 DTI / ISEA / LSM / Titolo principale della presentazione Outline • • • • • • • Introduction CACSD environment Python Examples Comparison Matlab – Scicoslab -Python Code generation Conclusions DTI / ISEA / LSM / Titolo principale della presentazione Introduction • 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 licenses are too expensive for most little companies! DTI / ISEA / LSM / Titolo principale della presentazione CACSD - Matlab alternatives CACSD Tool Matrix/Algebra Hybrid Simulator Discrete Events Code generation for emb. Sys. Matlab ✔ Matlab ✔ Simulink ✔ Stateflow ✔ RTW Scicoslab/NSP ✔ Scilab ✔ Scicos ✔ SMCube1 Scilab ✔ Scilab ✔ xCos - (-)3 Octave ✔ Matlab like - - - 1 Commercial Free + Commercial (RTAICodeGen, E4Coder) 3 Modified RTAICodeGen, Scilab 6.x 2 ✔ 2 DTI / ISEA / LSM / Titolo principale della presentazione CACSD - Matlab alternatives CACSD Tool Matrix/Algebra Hybrid Simulator Discrete Events Code generation for emb. Sys. Matlab ✔ Matlab ✔ Simulink ✔ Stateflow ✔ RTW Scicoslab/NSP ✔ Scilab ✔ Scicos ✔ SMCube1 Scilab ✔ Scilab ✔ xCos - (-)3 Octave ✔ Matlab like - - - Python ✔ (✔) Simpy4 (✔) 1 Commercial Free + Commercial (RTAICodeGen, E4Coder) 3 Modified RTAICodeGen, Scilab 6.x 4 No graphical editor 2 ✔ 2 DTI / ISEA / LSM / Titolo principale della presentazione Python DTI / ISEA / LSM / Titolo principale della presentazione Python • Python is a general-purpose, high-level, object oriented programming language similar to Matlab, Scicoslab, Scilab and Octave. • Its implementation was started in December 1989 (Guido van Rossum at Centrum Wiskunde & Informatica in the Netherlands) • Python is often used as a scripting language, but is also used in a wide range of non-scripting contexts. • Distributed under the Python Software Foundation License (PSFL) similar to BSD license. • Very large community of developers! DTI / ISEA / LSM / Titolo principale della presentazione Python • Numpy numeric array • Scipy scientific functions – FFT, Integrate, Interpolate, Optimize, Signal, Sparse, Statistic • Matplotlib Plot functions • PyQt Integration with Qt Libraries • Python-Qwt5 Integration with Qt Widgets • ... • Python Control Systems Library (python-control) DTI / ISEA / LSM / Titolo principale della presentazione Python for Matlab users • The python scripting language is similar to Matlab – http://wiki.scipy.org/NumPy_for_Matlab_Users • Main differencies: – Indexing (Python is 0 based!) – Array/Matrix distinction (linear algebra operations!) – Importing of functions • from np.linalg import * • from control.matlab import ss, tf DTI / ISEA / LSM / Titolo principale della presentazione Python Control Systems Library (python-control) • • 2009-2011 – Richard Murray1 – Caltech • Control-0.3a – Continous Time systems – SISO Systems 2011 – Roberto Bucher (SUPSI) • yottalab.py – MIMO systems – Discrete Time systems (Field Tsamp!) – Set of functions to handle discrete time systems. – Design of complex discrete controllers was possible! – yottalab.py distributed with control toolbox as separate toolbox 1 Aström and Murray – Feedback Systems DTI / ISEA / LSM / Titolo principale della presentazione Python Control Systems Library (python-control) • Situation 2014 – Richard Murray (Caltech) • Control-0.6c – Some ideas and functions migrated from yottalab to python-control – Discrete Time systems (dt: sampling time) – Functions related to discrete time systems – Roberto Bucher (SUPSI) • Supsictrl – yottalab.py » Few functions not cleanly implemented by Richard Murray » Some additional functions to simplify the controller design (observer, reduced order observer, controllers in compact form, anti windup design, etc.) – RCPblk.py » Toolbox for Rapid Controller Prototyping, hybrid simulation and Code generation for RT systems DTI / ISEA / LSM / Titolo principale della presentazione Python for control – Other related projects • Ryan Krauss (Southern Illinois University Edwardsville) – controls.py • Some routines related to transfer functions (continous and discrete) only for education purposes. • Python control systems, with only one developper, Rafael G. Martins (only for education purposes) Stephen Boyd and Lieven Vandenberghe are now mostly developing optimization libraries, but a few applications specific to control systems can be found on their page • DTI / ISEA / LSM / Titolo principale della presentazione Python for Control • Files – Ipython – Numpy – Scipy – Matplotlib – Avventi Slycot – Control-0.6c – Yottalab.py – RCPblk.py – pyBlockEdit DTI / ISEA / LSM / Titolo principale della presentazione Python for Control • Files – Ipython – Numpy – Scipy – Matplotlib – Avventi Slycot – Control-0.6c – Yottalab.py – RCPblk.py – pyBlockEdit DTI / ISEA / LSM / Titolo principale della presentazione Python for Control • Files – Ipython – Numpy – Scipy – Matplotlib – Avventi Slycot – Control-0.6c – Yottalab.py – RCPblk.py – pyBlockEdit DTI / ISEA / LSM / Titolo principale della presentazione Python for Control • Files – Ipython – Numpy – Scipy – Matplotlib – Avventi Slycot – Control-0.6c – Yottalab.py – RCPblk.py – pyBlockEdit DTI / ISEA / LSM / Titolo principale della presentazione Comparison Matlab / Scicoslab / Python DTI / ISEA / LSM / Titolo principale della presentazione Matlab + Simulink DTI / ISEA / LSM / Titolo principale della presentazione Matlab + Simulink DTI / ISEA / LSM / Titolo principale della presentazione Scicoslab + Modelica DTI / ISEA / LSM / Titolo principale della presentazione Scicoslab + Modelica DTI / ISEA / LSM / Titolo principale della presentazione Scicoslab + Modelica DTI / ISEA / LSM / Titolo principale della presentazione Python Demo 1 DTI / ISEA / LSM / Titolo principale della presentazione Python + CodeGen + Simulation fname = 'disks' genCode(fname,4,0.01,[sq1, Plant, contr, prnt]) genMake(fname) DTI / ISEA / LSM / Titolo principale della presentazione Python + CodeGen + Simulation fname = 'disks' genCode(fname,4,0.01,[sq1, Plant, contr, prnt]) genMake(fname) DTI / ISEA / LSM / Titolo principale della presentazione Python + CodeGen + Simulation fname = 'disks' genCode(fname,4,0.01,[sq1, Plant, contr, prnt]) genMake(fname) 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 DTI / ISEA / LSM / Titolo principale della presentazione Code generation Standard C-Code DsPIC board Linux ARM PC with Linux RTAI or PREEMPT RT DTI / ISEA / LSM / Titolo principale della presentazione Python Demo 2 DTI / ISEA / LSM / Titolo principale della presentazione Real-time execution • • • State feedback controller with integral part Code generated from Python as PREEMPT_RT executable 10 ms Sampling time DTI / ISEA / LSM / Titolo principale della presentazione Real-time execution • • • State feedback controller with integral part Code generated from Python as PREEMPT_RT executable 10 ms Sampling time DTI / ISEA / LSM / Titolo principale della presentazione Real-time execution • • • State feedback controller with integral part Code generated from Python as PREEMPT_RT executable 10 ms Sampling time DTI / ISEA / LSM / Titolo principale della presentazione Conclusions • Which alternatives to Matlab / Simulink / RTW? • Python for control is promising, but not enough mature yet • Python control is an education toolbox, but not ready for industrial development • But Freedom to develop what we want and need • Urgent – Rewrite some functions (ex. Pole placement for MIMO system gives bad results) – Graphical editor for block diagram! DTI / ISEA / LSM / Titolo principale della presentazione Questions?