Book Image

Getting Started with Simulink

By : Luca Zamboni
Book Image

Getting Started with Simulink

By: Luca Zamboni

Overview of this book

Simulink is an engineer's Swiss army knife: instead of spending the day typing out complex formulas, Simulink enables you to both draw and execute them. Block after block, you can develop your ideas without struggling with obscure programming languages and you don't have to wait to debug your algorithm - just launch a simulation! Getting Started with Simulink will give you comprehensive knowledge of Simulink's capabilities. From the humble constant block to the S-function block, you will have a clear understanding of what modelling really means, without feeling that something has been left out. By the time you close the book, you'll be able to further extend your modelling skills without any help. We''ll start with a brief introduction, and immediately start placing the first blocks. Little by little, you'll build a car cruise controller model, followed by the mathematical model of a sports car in order to calibrate it. Then you'll learn how to interface your Simulink model with the external world. This book will give you an easy understanding of the tools Simulink offers you, guiding you through a complex exercise split into the three main phases of Simulink development: modelling, testing, and interfacing.
Table of Contents (11 chapters)

Index

A

  • aerodynamic drag equation / The aerodynamic drag equation
  • Alfa Romeo 147 GTA
    • about / Our second model – the Alfa Romeo 147 GTA
    • speed, obtaining / Getting the speed – Newton's laws
    • aerodynamic drag equation / The aerodynamic drag equation
    • rolling resistance / The rolling resistance approximation
    • engine force / The engine force – engine, wheels, and transmission
    • finishing touches / The finishing touches
  • algorithm
    • implementing / Step 6 – implement the algorithm

B

  • block object / The MATLAB code
  • blocks
    • adding, to model from Library Browser / Step 4 – add blocks to the model from Library Browser
    • renaming / Step 5 – rename the blocks
  • Bus Creator block
    • about / Build the complete closed-loop system

C

  • callbacks
    • mandatory callbacks / The mandatory callbacks
    • optional callbacks / The most useful optional callbacks
  • C language
    • advantages / Going further – C MEX S-functions
  • cleanup phase / The simulation phases
  • C MEX S-functions
    • mex tool, setting up / Setting up the mex tool
    • working / How C MEX S-functions work
    • required callbacks / The required callbacks
    • optional callbacks / The most useful optional callbacks
    • filesource S-function / The filesource S-function
  • code
    • commenting / Step 2 – do comment the code!
  • Command Window panel / Command Window – how MATLAB talks to us
  • compilers
    • URL / Going further – C MEX S-functions
  • complete closed-loop system
    • building / Build the complete closed-loop system
  • Constant Value field / Step 8 – declare workspace variables
  • Constant value parameter / Getting the speed – Newton's laws, The aerodynamic drag equation
  • continuous solver
    • versus, discrete solver / Continuous versus discrete
    • about / Continuous versus discrete
  • cruise controller
    • about / Our first model – a cruise controller
    • model, creating / Step 1 – create and save the model
    • model, saving / Step 1 – create and save the model
    • code, commenting / Step 2 – do comment the code!
    • Simulink Library Browser, opening / Step 3 – open Simulink Library Browser
    • blocks, adding to model from Library Browser / Step 4 – add blocks to the model from Library Browser
    • blocks, renaming / Step 5 – rename the blocks
    • algorithm, implementing / Step 6 – implement the algorithm
    • logic, nesting into subsystems / Step 7 – nest the logic into subsystems
    • workspace variables, declaring / Step 8 – declare workspace variables
    • simulation, performing / Step 9 – do a first simulation
    • preparing / Preparing the cruise controller model

D

  • Demux block
    • about / Build the complete closed-loop system
  • DirectFeedthrough property / The MATLAB code
  • discrete solver
    • versus, continuous solver / Continuous versus discrete
    • about / Continuous versus discrete
  • DState type vectors / The work vector – DWork
  • Duplicate option / Step 4 – add blocks to the model from Library Browser
  • DWork vector
    • about / The work vector – DWork
    • Generic DWork type vectors / The work vector – DWork
    • DState type vectors / The work vector – DWork
    • Scratch type vectors / The work vector – DWork
    • Mode type vectors / The work vector – DWork
    / The DWork vector

E

  • Edit button / The filesink_msfun block
  • elementary vectors / The elementary work vectors
  • Engine, subsystems
    • about / The engine force – engine, wheels, and transmission, Engine

F

  • fgetl function / The MATLAB code
  • filesink S-function
    • about / Exercise – the filesink S-function
  • filesink_msfun block
    • about / The filesink_msfun block
    • MATLAB code / The MATLAB code
  • filesink_msfun parameter / A quick test
  • filesource S-function
    • headers / The beginning – headers and includes
    • includes / The beginning – headers and includes
    • mdlInitializeSizes function / Block properties and memory usage – mdlInitializeSizes
    • mdlInitializeSampleTimes function / Timings – mdlInitializeSampleTimes
    • mdlStart function / Initial tasks – mdlStart
    • mdlOutputs function / Core logic – mdlOutputs
    • mdlUpdate function / Update memories – mdlUpdate
    • mdlTerminate function / Cleanup – mdlTerminate
    • compiling / Compiling the S-function
  • filesource_msfun block
    • about / The filesource_msfun block
    • MATLAB code / The MATLAB code
  • filesource_msfun parameter / A quick test
  • fixed-step solvers
    • about / Variable-step versus fixed-step solvers
    • versus variable-step solver / Variable-step versus fixed-step solvers
  • fprintf / The MATLAB code
  • free() / The DWork vector

G

  • Gain parameter / The aerodynamic drag equation
  • Gearbox and differential, subsystems
    • about / The engine force – engine, wheels, and transmission, Gearbox and differential
  • Generic DWork type vectors / The work vector – DWork
  • GNU/Linux / UNIX-like systems (GNU/Linux in particular)

H

  • hardware-in-the-loop (HIL) testing / Software testing
  • headers, filesource S-function / The beginning – headers and includes
  • Help button / Step 3 – open Simulink Library Browser

I

  • includes, filesource S-function / The beginning – headers and includes
  • initialization phase / The simulation phases
  • IWork vector / The elementary work vectors

K

  • Ki
    • calibrating / Calibrating Ki
  • Kp
    • calibrating / Calibrating Kp

L

  • Library Browser
    • blocks, adding to model from / Step 4 – add blocks to the model from Library Browser
  • logic
    • nesting, into subsystems / Step 7 – nest the logic into subsystems

M

  • .mdl extension / Step 1 – create and save the model
  • mandatory callbacks
    • about / The mandatory callbacks
    • setup function / The mandatory callbacks
    • Outputs function / The mandatory callbacks
  • MATLAB
    • Command Window panel / Command Window – how MATLAB talks to us
    • workspace / The workspace – our treasury chest
    • working folder / The working folder – where MATLAB saves our work
    • path variable / The path – where MATLAB finds the tools
  • MATLAB Central
    • URL / Forcing Simulink to sync
  • MATLAB code, filesink_msfun block / The MATLAB code
  • MATLAB code, filesource_msfun block / The MATLAB code
  • matlabroot / The path – where MATLAB finds the tools
  • mdlInitializeConditions function / mdlInitializeConditions
  • mdlInitializeSampleTimes function / mdlInitializeSampleTimes, Timings – mdlInitializeSampleTimes
  • mdlInitializeSizes function / mdlInitializeSizes, Block properties and memory usage – mdlInitializeSizes
  • mdlOutputs function / mdlOutputs, Core logic – mdlOutputs
  • mdlStart function / mdlStart, Initial tasks – mdlStart
  • mdlTerminate function / mdlTerminate, Cleanup – mdlTerminate
  • mdlUpdate function / mdlUpdate, Update memories – mdlUpdate
  • mex tool
    • setting up / Setting up the mex tool
    • UNIX-like systems / UNIX-like systems (GNU/Linux in particular)
    • GNU/Linux / UNIX-like systems (GNU/Linux in particular)
    • Microsoft Windows systems / Microsoft Windows systems
  • Microsoft Windows systems / Microsoft Windows systems
  • model
    • creating / Step 1 – create and save the model
    • saving / Step 1 – create and save the model
    • blocks, adding from Library Browser / Step 4 – add blocks to the model from Library Browser
  • model-in-the-loop (MIL) testing / Software testing
  • Mode type vectors / The work vector – DWork
  • Mode vector / The elementary work vectors
  • Mux block
    • about / Build the complete closed-loop system

N

  • Name property / The MATLAB code
  • non-stiff solver
    • about / Stiff versus nonstiff

O

  • ODE (Ordinary Differential Equation solvers) / Continuous versus discrete
  • ode1 solver
    • about / Variable-step versus fixed-step solvers
  • ode45 solver
    • about / Variable-step versus fixed-step solvers
  • optional callbacks
    • PostPropagationSetup / The most useful optional callbacks
    • Start / The most useful optional callbacks
    • Update / The most useful optional callbacks
    • Terminate / The most useful optional callbacks
    • mdlStart function / mdlStart
    • mdlInitializeConditions function / mdlInitializeConditions
    • mdlUpdate function / mdlUpdate
    • DWork vector / The DWork vector
    • elementary vectors / The elementary work vectors
  • Outputs function / The mandatory callbacks
  • output variable / The MATLAB code

P

  • $PATH variable / The path – where MATLAB finds the tools
  • Paste option / Step 4 – add blocks to the model from Library Browser
  • path variable / The path – where MATLAB finds the tools
  • PI controller
    • calibrating / Calibrate the PI controller
  • PI controller constants
    • Kp, calibrating / Calibrating Kp
    • Ki, calibrating / Calibrating Ki
  • PostPropagationSetup / The most useful optional callbacks
  • processor-in-the-loop(PIL) testing / Software testing
  • PWork vector / The elementary work vectors

Q

  • Qt5 application
    • about / The external software – a Qt5 application

R

  • Ramp block
    • using / Ramp
    • about / Ramp
  • RegBlockMethod function / The MATLAB code
  • required callbacks
    • mdlInitializeSizes function / mdlInitializeSizes
    • mdlInitializeSampleTimes function / mdlInitializeSampleTimes
    • mdlOutputs function / mdlOutputs
    • mdlTerminate function / mdlTerminate
  • restoredefaultpath command / The path – where MATLAB finds the tools
  • rolling resistance
    • about / The rolling resistance approximation
  • ruleset
    • URL / Step 4 – add blocks to the model from Library Browser
  • Run button / Step 9 – do a first simulation, The external software – a Qt5 application, Running the simulation on the target application, Go for another ride
  • RWork vector / The elementary work vectors

S

  • .slx extension / Step 1 – create and save the model
  • S-function name parameter / The filesink_msfun block
  • S-functions
    • about / The Swiss army knife – S-functions
    • simulation phases / The simulation phases
    • callbacks / Level 2 MATLAB S-function callbacks
    • DWork vector / The work vector – DWork
    • filesink_msfun block / The filesink_msfun block
    • filesource_msfun block / The filesource_msfun block
    • testing / A quick test
  • scope block parameters
    • editing / The mandatory theory
  • Scratch type vectors / The work vector – DWork
  • setup function / The mandatory callbacks
  • sGetSFcnParam function / Initial tasks – mdlStart
  • Signal Builder block
    • using / Signal Builder
    • about / Signal Builder
  • simulation
    • performing / Step 9 – do a first simulation
    • configuring / Configuring the simulation
    • executing / Run our first serious simulation
    • running, on target application / Running the simulation on the target application
  • simulation configuration
    • about / Configuring the simulation
    • simulation times / Simulation times
    • solvers / Solvers
  • simulation loop / The simulation phases
  • simulation phases
    • initialization phase / The simulation phases
    • simulation loop / The simulation phases
    • cleanup phase / The simulation phases
  • simulation times
    • about / The simulation times – when the math is done
    • examining / The simulation times – when the math is done
    • start time / The simulation times – when the math is done
    • stop time / The simulation times – when the math is done
    • step size / The simulation times – when the math is done
  • Simulink
    • about / What is Simulink?
    • programming / Programming
    • graphical / Graphical
    • issues, resolved / Problems solved by Simulink
    • software, specification / Software specification
    • software, development / Software development
    • software, testing / Software testing
    • drawbacks / Simulink drawbacks
    • use cases / Where Simulink excels
    • forcing, to sync / Forcing Simulink to sync
    • cruise controller, preparing / Preparing the cruise controller model
    • simulation, running on target application / Running the simulation on the target application
  • Simulink.MSFcnRunTimeBlock object / The MATLAB code
  • Simulink interface
    • about / The Simulink interface
  • Simulink Library Browser
    • opening / Step 3 – open Simulink Library Browser
  • Simulink model
    • about / The mandatory theory
    • simulation results, computing / The mandatory theory
  • Sine Wave block
    • using / Sine Wave
    • about / Sine Wave
  • software
    • specification / Software specification
    • development / Software development
  • software-in-the-loop (SIL) testing / Software testing
  • solvers
    • about / The solvers – these great unknown
    • characteristics / The solvers – these great unknown
    • variable-step solver / Variable-step versus fixed-step solvers
    • fixed-step solver / Variable-step versus fixed-step solvers
    • continuous solver / Continuous versus discrete
    • discrete solver / Continuous versus discrete
    • stiff solver / Stiff versus nonstiff
    • non-stiff solver / Stiff versus nonstiff
  • ssGetDWork function / Initial tasks – mdlStart
  • ssGetOutputPortRealSignal function / Core logic – mdlOutputs
  • Start / The most useful optional callbacks
  • stiff solver
    • about / Stiff versus nonstiff
    • versus, non-stiff solver / Stiff versus nonstiff
  • Stop button / Running the simulation on the target application
  • str2double function / The MATLAB code
  • subsystems
    • logic, nesting into / Step 7 – nest the logic into subsystems
    • Gearbox and differential / The engine force – engine, wheels, and transmission
    • Wheel to RPM / The engine force – engine, wheels, and transmission
    • Engine / The engine force – engine, wheels, and transmission
    • Torque to force / The engine force – engine, wheels, and transmission
  • sync
    • Simulink, forcing to / Forcing Simulink to sync

T

  • target application
    • simulation, running on / Running the simulation on the target application
  • Terminate / The most useful optional callbacks
  • Torque to force, subsystems / The engine force – engine, wheels, and transmission, Torque to force

U

  • UNIX-like systems / UNIX-like systems (GNU/Linux in particular)
  • Update / The most useful optional callbacks

V

  • variable-step solver
    • about / Variable-step versus fixed-step solvers
    • versus fixed-step solvers / Variable-step versus fixed-step solvers

W

  • Wheel to RPM, subsystems
    • about / The engine force – engine, wheels, and transmission, Wheel to RPM
  • working folder / The working folder – where MATLAB saves our work
  • workspace / The workspace – our treasury chest
    • variables, declaring / Step 8 – declare workspace variables