Page 851 - Mechatronics with Experiments
P. 851
®
®
MATLAB , SIMULINK , STATEFLOW, AND AUTO-CODE GENERATION 837
®
®
4. Run the simulation in Simulink and analyze the results. Simulink also has a built
in “Debugger” which is accessed from the Tools → Debugger menu item of the model
window.
®
Simulink is a numerical modeling and time domain simulation software that allows
us to mix linear, nonlinear, analog, and digital systems in the model using interconnected
®
blocks. In Simulink , the dynamic model and control algorithm are modeled using inter-
connected blocks. The user interface is a graphical one. In order to simulate the system
response for given input conditions, inputs are connected to various source blocks (i.e.,
function generator block, step input block). The response is recorded by connecting various
output signals to sink blocks (i.e., scope block). The simulation start time, stop time,
®
sampling time and integration method are selected in the Simulink > Simulation setup
window. The Simulink ® model simulates an analog PD controller for the mass-force
system. The controller is sampled at the same rate that the integration algorithm uses for
®
the solution of the mass-force model. In Simulink models, the input–output relationships
are described by interconnected blocks. The individual blocks may represent linear or
nonlinear functions between its input and output, transfer functions in Laplace transform
form for analog systems and z-transforms form for digital systems. Input functions for the
simulated case are represented in time domain form. The responses of the system are also
time domain functions.
®
®
Simulink is started by typing “simulink” in the MATLAB prompt, or placing that
command in the “Startup.m” file, or it can be launched from the “Launch Pad Window” of
®
MATLAB .
>> simulink
Once Simulink ® starts, it brings up the “Simulink ® Library Browser” window
(Figure A.10). A new model is developed by selecting File → New menu item and saved
by selecting File → Save As menu. The default name for a newly opened model file
is “Untitled.mdl.” A Simulink ® model is saved in a file with “.mdl” extension. All the
hierarchical levels of the model are saved in one file.
®
To build a model, different blocks are selected from the Simulink “Block Library”
and copied over to the “Model Window,” in one of two ways:
1. copy/paste menu items of the Edit menu item, or
2. a block can be selected from the “Block Library” and dragged over to the “Model
Window,” which is the preferred method.
Then the connections between the blocks are made to define the relationship between blocks
to form the complete model.
®
Preferences in Simulink provides a window of many menu items to configure the
®
Simulink environment. For most applications, the default settings work well. It is accessed
from the File > Preferences menu item.
The parameters of a block can be modified by double clicking on the block once it is
in the model window. A menu comes up associated with the block. The parameters can be
set to either to
1. a constant value, or
®
2. a variable to be defined in the MATLAB workspace later on.