Simulink Tutorial
Simulink Tutorial
Andrew C. Smith
07/23/2007
Simulink Tutorial
07/23/2007
Introduction
1.1
General description
Simulink Tutorial
07/23/2007
Full access to MATLAB for analyzing and visualizing data , developing graphical user interfaces, and creating model data and
parameters
Model analysis and diagnostics tools to ensure model consistency
and identify modeling errors
1.2
Getting started
2.1
Opening Simulink
Simulink Tutorial
07/23/2007
simulation buttons. The simulation stop time indications how long (in
seconds) the simulation will be run. The start/stop simulation buttons
do what youd think. Make sure you locate these items.
Simulink Tutorial
07/23/2007
2.2
Since you have found these blocks, put one of each into your model
window. This can be done using one of the following methods:
Highlight the block and click Edit, Add to the current model
5
Simulink Tutorial
07/23/2007
(a) Integrator
(b) Step
(c) Gain
(d) Scope
Simulink Tutorial
07/23/2007
We now have a bunch of blocks in our model but blocks by themselves wont do us any good, we need to connect them to indicate the
flow of information. Blocks can be connected in three ways:
1. Moving the cursor overtop of the input/output of a block. The
cursor will change from a pointer to a crosshair. Click and drag
a line from the input/output of one block to the output/input of
another block. When youve reached the other connection point
the crosshair will change to a double crosshair, release the mouse
button.
2. Click on one block, then while that block is highlighted, hold down
CTRL and click on the block you would like to connect it to.
3. If a connection already exists between two blocks, you can drag a
new block in between them to make a connection to both blocks
from the new one.
Lets give this a try on our model. Use method 1 to connect your Step
and Integrator blocks. Remember not to click and drag until you
see the crosshairs and dont release the mouse until you see a double crosshair. If you mess up, dont worry you can always click on the
line and hit delete to remove it. If you let go of the mouse button too
early and the line didnt make it to the next block, you can click on the
open end of the line and continue dragging that to your desired point.
Now youve got one connection, good stuff. Lets try connecting our
Integrator with our Scope. To do this well use method 2. This is a
really quick way to make connections. Click on the Integrator block
so its selected, you dont need to click and hold. Now press down and
hold the CTRL button. With the CTRL button depressed, click on the
Scope block. You should see a line now connecting your Integrator
and Scope blocks. Your model should now look similar to Figure 5.
Ok, so weve got one final connection to make, we need to place
the Gain block in between our Integrator and Scope. You could just
delete the current connection and make two new connections. Instead,
lets try connection method 3 from above. To do this, click, hold and
drag the Gain block over top of the present connection between the Integrator and Scope. Once you are over top of the connection, release
the mouse button and your Gain block should be inline between the
Integrator and Scope.
7
Simulink Tutorial
07/23/2007
2.3
Now that we have our block all ready to go, its time we simulated it
and see what the output is. Follow these steps to run this system and
plot the output:
1. Confirm that your simulation is set to run for a duration of 10.0
seconds. This duration is set in the Simulation stop time, found
near the top of the window.
2. Click on the Start simulation button, located to the left of the
Simulation stop time. Alternatively, you could use the menu,
8
Simulink Tutorial
07/23/2007
Homework model
Now that you are completely familiar with the Simulink model window
and the Simulink Library Browser, its time we built our first control
9
Simulink Tutorial
07/23/2007
system. We are going to construct the model required for your next
homework. We have several parts from it already and now just need to
add a few details. We are asked to simulate the system
Plant
1
G(s) =
s
Nominal PI controller
kp s + kI
D(s) =
s
and the system is in unity feedback. As well, to simulate the saturation
of the integral controller, well need to add a saturation block. So to
complete your model, follow these steps
1. Remove all of your existing connections, so were back with just
our four blocks.
2. Space all your blocks out a bit, so weve got some room to put stuff
in between them. To do this you can just click and drag the blocks
around the window.
3. Double click on your Step block, change the final value back to 1.
4. In most systems we would need to add a Transfer Fcn block for
the plant dynamics. This block can be found in the Continuous group of blocks and is shown in Figure 7(a). However, since
our plant is just a 1s plant, we can just use our integrator block.
Make a copy of your Integrator block by holding down the CTRL
button, clicking and dragging the Integrator block, then release.
This should place a copy of the integrator in your model. Place
this integrator block to the right of the other one and to the left of
the scope.
5. Find the Saturation block, located in the Discontinuities set
and shown in Figure 7(b). Put this block between the two Integrator blocks.
6. Double click on the Saturation block. Change the Upper limit
and Lower limit fields to 1 and -1, respectively. Click OK.
10
Simulink Tutorial
07/23/2007
7. As youll notice we have already implemented part of our controller, namely ksI using the Gain and Integrator blocks. Change
the value of the gain block to 4. Now we need to add the proportional part. Make a copy of the gain block (either by dragging in
a new one, CTRL dragging the original one or copy and pasting),
place it above the other one. Change the value of the gain to 2.
At this point you should have a model looking like Figure 8.
(b) Saturation
(c) Sum
Simulink Tutorial
07/23/2007
Simulink Tutorial
07/23/2007
crosshair. Connect the output of the kp block to the positive summer. Having ample amount of space between your sum blocks
helps here.
10. Do similar steps to connect the sum and Ka blocks.
11. Connect the negative terminal on the first Sum block to the output of the Transfer Fcn. Do this using the connection method 1
described above and reviewed again here.
(a) Hover over the negative terminal of the Sum block. You will
see your cursor change to a crosshair. Draw a line straight
down from the negative terminal, doesnt matter how long it
is and release the mouse button.
(b) You will now have a dashed line going into the Sum block.
Hover over the free end and again youll see a crosshair. Click
and drag a line up to a point between the last Integrator
and Output (Scope) blocks. Youll notice that this line is
not drawn straight, but rather as two perpendicular lines,
this looks much better. While still dragging, hover over the
connection between the Integrator and Output blocks. You
will see your curser change to a double crosshair. Release
your mouse button and you will see that this has become a
pick off point for your feedback.
12. Finally, connect the Control (Scope) block to a point between
the Saturation and last Integrator block.
Your initial model is now complete. Select File, Save and save with
an appropriate file name. If you followed the directions properly, you
should be left with a model that looks like Figure 9. Give the simulation
a test run, open up the Output and you should see a plot like Figure 10.
When it comes time for comparing results, there are several ways to
represent and plot the data. One very common way to plot several
outputs at the same time is to multiplex (merge) the signals. This is
done with the Mux block, shown in Figure 11(a), found in the Signal
Routing set. Place this block in front of the Scope block and add
in as many signals as youd like, all of which will be plotted in the
Scope. Alternatively, you can output signals to the workspace using
13
Simulink Tutorial
07/23/2007
14
Simulink Tutorial
07/23/2007
(a) Mux
(b) To Workspace
15