MECH 370 Exp#1
MECH 370 Exp#1
INTRODUCTION TO
1 SIMULINK & SIMSCAPE
LA B
INTRODUCTION TO
1.1 SIMULINK
OBJECTIVES
In this lab you will learn how to use Simulink to simulate dynamic systems. Simulink runs under MATLAB
and uses block diagrams to represent dynamic systems. Instead of large amounts of code, you can simply
MECH 370 LABORATORY MANUAL (WINTER 2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
drag-and-drop pre-made blocks into a “model” window and connect the blocks’ inputs and outputs to
create a program or simulation. The progress of the simulation can be monitored while the simulation
is running, and the final results can be made available in the MATLAB workspace when the simulation is
complete.
GETTING STARTED
To start a Simulink session, you'd need to bring up Matlab program first. From Matlab command window,
enter:
>> Simulink
Alternately, you may click on the “Simulink” icon located on the toolbar as shown:
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
Simulink's library browser window like one shown below will pop up presenting the block set for model
construction.
To start a model, click on the “New –Blank Model”: A new window will appear on the screen. You will
be constructing your model (Block Diagram) in this window. Also in this window the constructed model
is simulated. A screenshot of a typical working model (Block Diagram) window is shown below:
2
To start a model, click on the “New –Blank Model”: A new window will appear on the screen. You will
be constructing your model (Block Diagram) in this window. Also in this window the constructed model
is simulated. A screenshot of a typical working model (Block Diagram) window is shown below:
MECH 370 LABORATORY MANUAL (WINTER2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
The block diagram in Simulink will have the general form shown in above Figure. They are Source,
Continuous (system), and Sink.
A simple model is used here to introduce some basic features of Simulink. Please follow the steps below
to construct a simple model.
Drag the needed blocks from their library folders to above window. For examples, drag step block from
source fold, scope block from sink fold, and transfer function from continuous fold. You can interconnect
them together, save this block diagram as System1 and use the default parameters to run Simulink. The
block diagram and simulating results are shown below.
3
SIMULATE A SYSTEM USE SIMULINK
As an example Simulink application, we will obtain the time response of the mass-spring-damper system.
MECH 370 LABORATORY MANUAL (WINTER 2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
The steps required to simulate a system using Simulink are listed below.
3. Use relations between the inputs and outputs of the intermediate block diagram to create a
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
determining the governing equations for the system. You should verify that the equation of motion for
the above system is
1-1
The main purpose of this form is to find an equation representing the highest derivative.
1-2
4
The equation (1-2) can be represented by following block diagram:
MECH 370 LABORATORY MANUAL (WINTER2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
The variables x and ẋ can be considered as inputs to the system. The variable ẍ can be considered the
output of the system.
Recognize that the variables ẋ, x can be derived from the output, acceleration, by
The data representing x and ẋ are fed back from the integration into the respective constants (gains). A
scope is attached to the line representing x to show the position with time. In an actual block simulation,
the parameters B, K, and M would be given by their respective values.
5
SET BLOCK PARAMETERS AND SIMULATION ROUTINE.
After all of the connections are made, you will need to set the gains of the gain blocks to the proper
values and set the initial conditions of the integrator. To set the value of the B gain block, double-click on
MECH 370 LABORATORY MANUAL (WINTER 2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
the gain block to open the dialog box and enter the appropriate value. In the same manner, set the value
of the K and M gain block. The source block labeled step must be set up: step time: 1, initial value: 0,
final value: 8.
Now the integration routine parameters must be set. To do so, choose menu item Simulation and select
Configuration Parameters. You can choose default setting or change them as you need.
6
You can write Matlab M-script to plot simulation result with different damp ratio B as following;
MECH 370 LABORATORY MANUAL (WINTER2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
Click “New Script” from “Home” widow, The” Editor” widow will display:
7
Referring to Mass- Damp- spring block diagram, we can get Mass- Damp-Spring system transfer function
by Matlab script as following, save file name as: sysSMD.m
M=2; %kg
K=16; %N/m
B=4; %Ns/m
The simulation start time at 0, end at 10 sec. The final step fa is 1 at 0 sec.
8
EXERCISE:
1. First create a Simulink model of the mass-spring-damper system. Use the following data: M = 2, B =
10 , and K = 10. run your model. showing the mass's position, velocity,
MECH 370 LABORATORY MANUAL (WINTER2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
2. From Q#1, change the damping coefficient B to 1 and showing the mass's position, velocity,
3. Assuming M=0, B=10, K=10. Create a Simulink model of Spring-Damp system. showing the mass's
position, and velocity
4. From Q.#3, Change the damping coefficient B to 1 and showing the mass's position, velocity,
9
MECH 370 LABORATORY MANUAL (WINTER 2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
10
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
LAB
INTRODUCTION TO
1.2 SIMSCAPE
11
OBJECTIVES
In this lab you will learn how to use Simscape to simulate dynamic systems. Simscape™ enables you to
rapidly create models of physical systems within the Simulink® environment. With Simscape you build
MECH 370 LABORATORY MANUAL (WINTER 2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
physical component models based on physical connections that directly integrate with block diagrams
and other modeling paradigms.
You can simply drag-and-drop pre-made blocks into a “model” window and connect the blocks’ inputs
and outputs to create a program or simulation. The progress of the simulation can be monitored while
the simulation is running, and the final results can be made available in the MATLAB workspace when the
simulation is complete.
GETTING STARTED
To start a Simulink session, you'd need to bring up Matlab program first. From Matlab command window,
enter:
> ssc_new
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
12
The Fundation Library:
new blank model will popup
MECH 370 LABORATORY MANUAL (WINTER2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
13
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
1
MECH 370 LABORATORY MANUAL (WINTER 2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
14
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
in follow figure,
Drag all above elements to Model and connect together as shown
MECH 370 LABORATORY MANUAL (WINTER2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
15
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
MECH 370 LABORATORY MANUAL (WINTER 2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
16
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
Run 10 second,
Click scope get the time response.
Step at t=1, from 0 to 8, Mass M=2, Damp :B=4, Spring :K=16
Cursor Measurement --->screen cursor
MECH 370 LABORATORY MANUAL (WINTER2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
17
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
MECH 370 LABORATORY MANUAL (WINTER 2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
18
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING
0.801 s
Steady state valune= 0.498, peak time is 1.235 s, rising time is
EXERCISE: same as 1.1 Simulink
1. From you Simscape model of the mass-spring-damper system. Use the following data: M = 2, B =
10 , and K = 10. run your model. showing the mass's position, velocity,
MECH 370 LABORATORY MANUAL (WINTER2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS
2. From Q#1, change the damping coefficient B to 1 and showing the mass's position, velocity,
4. From Q.#3, Change the damping coefficient B to 1 and showing the mass's position, velocity,
19 1