Getting Started with Simulink
eBook - ePub

Getting Started with Simulink

  1. 132 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Getting Started with Simulink

About this book

In Detail

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.

Approach

This practical and easy-to-understand learning tutorial is one big exciting exercise for students and engineers that are always short on their schedules and want to regain some lost time with the help of Simulink.

Who this book is for

This book is aimed at students and engineers who need a quick start with Simulink. Though it's not required in order to understand how Simulink works, knowledge of physics will help the reader to understand the exercises described.

Trusted by 375,005 students

Access to over 1 million titles for a fair monthly price.

Study more efficiently using our study tools.

Getting Started with Simulink


Table of Contents

Getting Started with Simulink
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Instant Updates on New Packt Books
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Simulink Facts
What is Simulink?
Programming
Graphical
Problems solved by Simulink
Software specification
Software development
Software testing
Simulink drawbacks
Where Simulink excels
Summary
2. Creating a Model
The MATLAB environment
Command Window – how MATLAB talks to us
The workspace – our treasury chest
The working folder – where MATLAB saves our work
The path – where MATLAB finds the tools
The Simulink interface
Our first model – a cruise controller
Step 1 – create and save the model
Step 2 – do comment the code!
Step 3 – open Simulink Library Browser
Step 4 – add blocks to the model from Library Browser
Step 5 – rename the blocks
Step 6 – implement the algorithm
Step 7 – nest the logic into subsystems
Step 8 – declare workspace variables
Step 9 – do a first simulation
Our second model – the Alfa Romeo 147 GTA
Getting the speed – Newton's laws
The aerodynamic drag equation
The rolling resistance approximation
The engine force – engine, wheels, and transmission
Gearbox and differential
Wheel to RPM
Engine
Torque to force
The finishing touches
Summary
3. Simulating a Model
The mandatory theory
The simulation times – when the math is done
The solvers – these great unknown
Variable-step versus fixed-step solvers
Continuous versus discrete
Stiff versus nonstiff
Build the complete closed-loop system
Configuring the simulation
Simulation times
Solvers
Run our first serious simulation
Calibrate the PI controller
Calibrating Kp
Calibrating Ki
Test with other sources
Sine Wave
Ramp
Signal Builder
Summary
4. Using the Model
The external software – a Qt5 application
The Swiss army knife – S-functions
The simulation phases
Level 2 MATLAB S-function callbacks
The mandatory callbacks
The most useful optional callbacks
The work vector – DWork
MATLAB S-functions – file source and sink blocks
The filesink_msfun block
The MATLAB code
The filesource_msfun block
The MATLAB code
A quick test
Simulink and the real world
Forcing Simulink to sync
Preparing the cruise controller model
Running the simulation on the target application
Going further – C MEX S-functions
Setting up the mex tool
UNIX-like systems (GNU/Linux in particular)
Microsoft Windows systems
How C MEX S-functions work
The required callbacks
mdlInitializeSizes
mdlInitializeSampleTimes
mdlOutputs
mdlTerminate
The most useful optional callbacks
mdlStart
mdlInitializeConditions
mdlUpdate
The DWork vector
The elementary work vectors
The filesource S-function
The beginning – headers and includes
Block properties and memory usage – mdlInitializeSizes
Timings – mdlInitializeSampleTimes
Initial tasks – mdlStart
Core logic – mdlOutputs
Update memories – mdlUpdate
Cleanup – mdlTerminate
The happy ending
Compiling the S-function
Exercise – the filesink S-function
A quick test
Go for another ride
Summary
Index

Getting Started with Simulink

Copyright © 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: October 2013
Production Reference: 1181013
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78217-138-6
www.packtpub.com
Cover Image by Irene Sánchez Guillén ()

Credits

Author
Luca Zamboni
Reviewers
Robin T. Bye
Marco Caputano
Mohamed H. Zaher
Acquisition Editors
Edward Gordon
Kevin Colaco
Commissioning Editor
Poonam Jain
Technical Editors
Pramod Kumavat
Krutika Parab
Nadeem N. Bagban
Copy Editors
Dipti Kapadia
Gladson Monteiro
Sa...

Table of contents

  1. Getting Started with Simulink

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Getting Started with Simulink by Luca Zamboni in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Science General. We have over one million books available in our catalogue for you to explore.