Getting Started with Simulink Overview of MATLAB Modeling/ g Simulation Environment Greater Victoria Chamber of Commerce | March 2008 | David H. Turpin, PhD, FRSC Orientation 2008 | Jamie Cassels, QC, Vice-President Academic and Provost MATLAB/Simulink Applications Mechanical System Automotive Controls Robotics Aerospace and Defense Communications Electronics and Signal Processing Medical Instrumentation Model-Based Model Based Design Faster, more cost-effective development of dynamic systems (e.g. control systems, vehicles, etc.) A system model is at the center of the development process from requirements development process, development, through design, implementation, and testing. Model - an executable specification p ((MATLAB codes, or a block diagram and specified parameters) that is continually refined (optimized) throughout the development. Simulation – test whether the model works correctly correctly, and obtain results. Software and hardware implementation – automatic code generation MATLAB Codes – Simulink Block & Block Parameters Modeling Process On Paper: 1 Defining the System 2 Identifying System Components 3 Modeling the System with Equations Using MATLAB/Simulink: 4 Building the Simulink Block Diagram 5 Running the Simulation 6 Validating the Simulation Results The leading environment for technical computing • The de ffacto industry-standard, y high-level programming language for algorithm development • Numeric computation • Data analysis and visualization • Toolboxes for signal and image processing, statistics, optimization, symbolic math math, and other areas • Foundation of MathWorks products from Bryan Zocco & Doug Eastman’s Presentation The leading environment for system-level modeling, simulation, and verification of communications and electronic systems • • • • • • Multidomain system-level design and verification Digital, analog, and mixed-signal simulation using discrete-time, continuous-time, state machine, and discrete event modeling Floating- and fixed-point algorithm development using MATLAB, Simulink blocks, or existing C code Blocksets for signal processing, video processing, p g, communications,, and RF Open architecture with links to third-party tools and development boards, and instrumentation C and HDL code generation for DSPs, embedded processors, processors and FPGAs from Bryan Zocco & Doug Eastman’s Presentation Object Detection From Research to Development and Test DATA ANALYSIS VALIDATION/VERIFICATION SYSTEM-LEVEL DESIGN Test and Verification Data I/O Data Analysis, y , Modeling & Visualization System Modeling, g, Simulation and Partitioning Algorithm Development & Simulation Mathematical Modeling Environment Effects Embedded Algorithms System Components Hardware-inHardware in the-Loop Test Automatic Code Generation Embedded Software Embedded Hardware IMPLEMENTATION Other Design D i Flows from Bryan Zocco & Doug Eastman’s Presentation Graphical Layout of Functional Modules Complex p System y Model from Basic Building g Blocks Vehicle and Control Simulink Library (blocks) Key Multiphysics Modeling Toolbox Stateflow™ Stateflow Design and simulate state machines and control logic. SimMechanics™ Model and simulate mechanical systems. Si P SimPowerSystems™ S t ™ M d l and Model d simulate i l t electrical l t i l power systems. t Simulink® Control Design™ Design and analyze control systems in Simulink. SimScape™ Provides expanded capabilities for modeling physical systems (mechanical, electrical, hydraulic, and other physical domains as physical networks) SimDriveline™ Modeling and simulating the mechanics of driveline (drivetrain) systems Modeling Dynamic Systems in Simulink Modeling Approaches First Principles Modeling Simulink Simscape SimMechanics SimDriveline SimHydraulics SimPowerSystems Simulink Design O ti i ti Optimization Data-Driven Modeling System Identification T lb Toolbox Neural Network T lb Toolbox Tools for Modeling Dynamic Systems ADVISOR PSAT/Autonomie SimDriveline Tools for Modeling Vehicle Powertrains Po ertrains Modified from Bryan Zocco & Doug Eastman’s Presentation SimDriveline™ Model SimDriveline Simulink Online Help Simulink Getting Started Guide Simulink User’s Guide Simulink Reference Writing S-Functions Simulink Release Notes Other Posted References Homework: build the Simulink models following the model building examples Getting started with Simulink An introductory tutorial ES205 Analysis and Design of Engineering Systems Rose-Hulman Institute of Technology © R. Layton 2001 Launch Simulink In the MATLAB command window, at the >> prompt, type simulink and press Enter Create a new model Click the new-model icon in the upper left corner to start a new Simulink file Select the Simulink icon to obtain elements of the model Your workspace Library of elements Model is created in this window Save your model You might create a new folder, like the one shown below, called simulink_files Use the .mdl suffix when saving Example 1: a simple model Build a Simulink model that solves the q differential equation x 3 sin 2t Initial condition x(0) 1. First, sketch a simulation diagram of thi mathematical this th ti l model d l (equation) ( ti ) (3 min.) Simulation diagram Input is the forcing function 3sin(2t) Output is the solution of the differential x(0) 1 equation x(t) 3sin(2t) (input) x 1 s x x(t) (output) integrator Now build this model in Simulink Select an input block Drag a Sine Wave block from the Sources library to the model window Select an operator block Drag an Integrator block from the Continuous libraryy to the model window Select an output block Drag a Scope block from the Sinks library to the model window Connect blocks with signals Place your cursor on p port p (>) ( ) of the output the Sine Wave block Drag from the Sine Wave output to the Integrator input Drag from f the h Integrator output to p input p the Scope Arrows indicate the direction of the signal flow. Select simulation parameters Double-click on the Sine Wave block to set amplitude = 3 and freq = 2. This produces p od ces the desired input of 3sin(2t) Select simulation parameters Double-click on the Integrator block to set initial condition = -1. This sets our IC x(0) = -1. Select simulation parameters Double-click on the Scope to view the simulation results Run the simulation In the model window from the window, Simulation pulldown menu,, select Start View the output x(t) in the Scope window. window Simulation results To verify that this plot represents p p the solution to the problem, solve the equation analytically. analytically The analytical result, x(t ) 12 32 cos2t matches the p plot (the simulation result) exactly. Example 2 Build a Simulink model that solves the g differential equation q (ODE) ( ) following 2nd-order mass-spring-damper system zero ICs input f(t) is a step with magnitude 3 parameters: m = 0.25, 0 25 c = 0.5, 05 k=1 mx cx kx f (t ) Create the simulation diagram On the following slides: The simulation diagram for solving the ODE is created step by step. After each step, elements are added to the Simulink model. Optional exercise: first, sketch the complete diagram (5 min.) mx cx kx k f (t ) (continue) First, solve for the term with highestorder derivative mx f (t ) cx kx Make the left-hand left hand side of this equation the output of a summing block mx summing block Drag a Sum block from tthe e Math at library bay Double-click to change the block parameters to rectangular and + - - (continue) Add a gain (multiplier) block to p eliminate the coefficient and produce the highest-derivative alone mx summing block 1 m x Drag a Gain block from tthe e Math at library bay The gain is 4 since 1/m=4. Double-click to change the block parameters. Add a title. title (continue) Add integrators to obtain the desired p variable output mx summing block 1 m x 1 s x 1 s x Drag Integrator blocks from the Continuous library Initial Conditions (ICs) on the integrators are zero. Add a scope from the Sinks library. Connect output ports to input ports. Label the signals by double-clicking on the leader line. (continue) Connect to the integrated signals with gain blocks to create the terms on the right-hand side of the EOM mx summing block x 1 m ccx 1 s x c kx k 1 s x Drag new Gain blocks from o the t e Math at library bay To flip the gain block, select it and choose Flip Block in the Format pull-down menu. Double-click on gain blocks to set parameters Connect from the gain block input backwards up to the branch point. Re-title the gain blocks. c=0 5 c=0.5 k=1.0 Complete the model f(t) input Bring all the signals and inputs to the summing block. Check signs on the summer. + - mx 1 m x cx k kx 1 s x 1 s x x c k x x(t) output Double-click on Step block to set parameters parameters. For a step input of magnitude 3, set Final value to 3 Final Simulink model Run the simulation Results Underdamped response. Overshoot of 0.5. Final value of 3 (g (gain = 1). ) Is this expected? System design – adjust m, c, k values to get different system response Paper-and-pencil Paper and pencil analysis based on the equations of motion Standard form k x m 1 c x x f (t ) k k Nat’l freq. k n 2.0 m Damping ratio 2 Static gain c 0.5 n k K 1 1 k Check simulation results Damping ratio of 0.5 is less than 1. Expect p the system y to be underdamped. p Expect to see overshoot. Static gain is 1. Expect output magnitude to equal input magnitude. Input has magnitude 3, so does output. Simulation results conform to expectations.