Simulink Basics SIMULINK Basics Matlab/Simulink Dipl.-Ing. U. Wohlfarth Simulink Basics Content • What’s SIMULINK? • SIMULINK–Libraries Sources, Sinks und Math • Simulation parameters • Algorithm’s for numerical integration • SIMULINK–Libraries Signals&Systems, Subsystems Matlab/Simulink Dipl.-Ing. U. Wohlfarth SIMULINK Basics What’s Simulink? • Graphical modelling of dynamic systems by signal flow graphs • Addition to MATLAB (Toolbox) • Simulink–Additions: Blocksets (SimPower-Systems, SimMechanics) Sine Wave −1 Clock Product1 80 Gain Product3 eu Math Function Product2 −1 Mux gedaempfte Sinusschwingung Gain1 Constant Matlab/Simulink Dipl.-Ing. U. Wohlfarth 1 SIMULINK Basics Starting SIMULINK • Blocks are basic elements • Blocks characterized by input, output, name, icon • Double click opens Block P arameters dialog Matlab/Simulink Dipl.-Ing. U. Wohlfarth 3 SIMULINK Basics SIMULINK block libraries Sources and Sinks Block library Sources: • Generation of signals • Import data from MATLAB workspace • Import of data from files untitled.mat 1 Step Signal Sine Wave Generator From File 1 In1 Constant simin Ramp Repeating Pulse Generator Sequence From Workspace Block library Sinks: • Graphical display of signals • Write data to MATLAB workspace • Write data to files untitled.mat To File Scope XY Graph simout 1 Out1 To Workspace Matlab/Simulink Dipl.-Ing. U. Wohlfarth 4 SIMULINK Basics Example for Sources and Sinks Signal 1 Signal 2 1 s Integrator Scope Signal Builder Signal Builder : bsp sigbuild.mdl Signal Builder Dialog box for group of three signals Matlab/Simulink Dipl.-Ing. U. Wohlfarth 5 SIMULINK Basics SIMULINK block library Math Opertions Block library Math: • Arithmetic, logical and relational operators • Mathematical and trigonometric functions etc. 1 eu Product Math Function Sum Gain AND 1 Logical Operator Slider Gain <= sin Dot Product Trigonometric Function K*u Relational Operator Matrix Gain Matlab/Simulink Dipl.-Ing. U. Wohlfarth 6 SIMULINK Basics Examples for Math Operations Simulink model bspmath.mdl of equation 1 − t f (t) = 80 · e 80 · sin (0.25t + π ) 3 Sine Wave −1 Clock Product1 80 Gain Product3 eu Math Function Product2 −1 Mux gedaempfte Sinusschwingung Gain1 Constant Matlab/Simulink Dipl.-Ing. U. Wohlfarth 7 SIMULINK Basics Simulation: parameters and solvers Configuration Parameters dialog box Solver pane: • Specify start and stop time of simulation • Solvers for numerical integration • Output options Matlab/Simulink Dipl.-Ing. U. Wohlfarth 8 SIMULINK Basics Numerical integration of ODE Inhomogeneous linear ordinary differential equation: u(t) DGL y(t) ẏ(t) = f (u(t), y(t)) tn+1 Z Integration: yn+1 = yn + f (u(t), y(t))dt tn Numerous methods: • • • • • Euler method Heun’s method Other Runge–Kutta–methods Adams–Bashforth methods ··· Matlab/Simulink Dipl.-Ing. U. Wohlfarth 9 SIMULINK Basics Numerical integration of ODE Euler method (explicit) y y1 dy y(t1) y0 hy0 y(t) y0 h t0 t1 t y1 = y0 + h · ẏ0 Matlab/Simulink Dipl.-Ing. U. Wohlfarth 10 SIMULINK Basics Numerical integration of ODE Runge–Kutta method y P P3(t2) = y2 y1 y1 y0 P3(t) y0 h t0 t1 t2 t 2h y2 = y0 + · [ẏ0 + 4ẏ1 + f (u2, y2P )] 6 Matlab/Simulink Dipl.-Ing. U. Wohlfarth 11 SIMULINK Basics Numerical integration of ODE Adams–Bashforth method y yn P2(tn+1) yn-1 P2(t) yn-2 h tn-2 tn-1 tn tn+1 t h yn+1 = yn + · [23ẏn − 16ẏn−1 + 5ẏn−2] 12 Matlab/Simulink Dipl.-Ing. U. Wohlfarth 12 SIMULINK Basics Solver: integration algorithms in MATLAB Variable–step solver: • use variable step size • allow error control & detection of zero crossings • for continuous-time, non-stiff systems: ⇒ ode45 (first try), ode23, ode113 • for continuous-time, stiff systems: ⇒ ode15s, ode23s, ode23t,ode23tb • for discrete-time systems: ⇒ discrete (Variable–step) Matlab/Simulink Dipl.-Ing. U. Wohlfarth 13 SIMULINK Basics Solver: integration algorithms in MATLAB Fixed–step solver: • use fixed step size • no error control • no detection of zero crossings • for continuous-time systems: ⇒ ode5, ode4, ode3, ode2, ode1 • for discrete-time systems: ⇒ discrete (Fixed–step) Matlab/Simulink Dipl.-Ing. U. Wohlfarth 17 SIMULINK Basics Simulation: parameters and solver methods Configuration Parameters dialog box Data Import/Export pane: • Initialization • Load data from Workspace • Write data to Workspace Matlab/Simulink Dipl.-Ing. U. Wohlfarth 18 SIMULINK Basics Simulation: parameters and solver methods Configuration Parameters dialog box Diagnostics pane: • Control of warning and error messages • Set simulation options Matlab/Simulink Dipl.-Ing. U. Wohlfarth 19 SIMULINK Basics Simulation Start and stop of simulation • from SIMULINK window • from MATLAB Command Window – set_param(’sys’, ’SimulationCommand’, ’cmd’) get_param(’sys’, ’SimulationStatus’) – [t,x,y] = sim(’model’, timespan, options, ut) options = simset(property, value, ...) newopts = simset(oldopts, property, value, ...) struct = simget(’model’) Example: [t,x,y] = sim(’m1’,[],simset(simget(’m1’),’Solver’,’ode23’,’MaxStep’,0.01)) Matlab/Simulink Dipl.-Ing. U. Wohlfarth 20 SIMULINK Basics Error handling Simulation Diagnostics Viewer • upper part: error information • lower part: complete text of error message Matlab/Simulink Dipl.-Ing. U. Wohlfarth 23 SIMULINK Basics SIMULINK block library Signal Routing Block library Signal Routing: • Date saving A A A Data Store Memory Data Store Read Data Store Write • Connect and selection of signals etc. [A] Mux Demux Bus Selector Demux Matlab/Simulink Dipl.-Ing. U. Wohlfarth Selector Hit Crossing [1] From IC [A] Goto 24 SIMULINK Basics Subsystems Subsystems: • Structural order of complex models • Combining blocks of similar function • hierarchic structuring • Creation by 1. menue item Edit/Create Subsystem 2. block library Subsystems Matlab/Simulink Dipl.-Ing. U. Wohlfarth 25 SIMULINK Basics SIMULINK block library Subsystems Block library Subsystems: In1 Out1 Subsystem In1 Out1 In1 Atomic Subsystem Triggered Subsystem In1 while { ... } Out1 IC Out1 Function−Call Subsystem In1 Out1 Out1 If Action Subsystem In1 function() In1 Action Out1 if(u1 > 0) While Iterator Subsystem u1 else If Enabled Subsystem etc. Matlab/Simulink Dipl.-Ing. U. Wohlfarth 26 SIMULINK Basics Conditionally executed subsystems / Masking Conditionally Executed Subsystems • Execution controlled by control signal • comprise Enable or Trigger Masking of subsystems • building a new block from a subsystem • easier parametrization of complex subsystems • Setting up of user defined libraries Matlab/Simulink Dipl.-Ing. U. Wohlfarth 27 SIMULINK Basics Masking of subsystems Example bspmask.mdl x y m Steigung ⇒ b Matlab/Simulink Dipl.-Ing. U. Wohlfarth y−Achsenabschnitt y=mx+b 28