0% found this document useful (0 votes)
118 views19 pages

MECH 370 Exp#1

This document provides an introduction to using Simulink and Simscape software. It describes how to start a Simulink session, build models using block diagrams, and simulate simple systems. An example of simulating a mass-spring-damper system is also included.

Uploaded by

yhd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views19 pages

MECH 370 Exp#1

This document provides an introduction to using Simulink and Simscape software. It describes how to start a Simulink session, build models using block diagrams, and simulate simple systems. An example of simulating a mass-spring-damper system is also included.

Uploaded by

yhd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

LAB

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.

1. Write the governing equations of the system.

2. Create an intermediate block diagram representing the mathematics of the governing


equations.

3. Use relations between the inputs and outputs of the intermediate block diagram to create a
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING

full simulation model (all-integrator model).

4. Set up block and simulation parameters.

5. Run the simulation.

6. Display and analyze the results.

WRITE THE GOVERNING EQUATIONS.


The first step towards defining the system in Simulink is

determining the governing equations for the system. You should verify that the equation of motion for
the above system is

1-1

CREATE AN INTERMEDIATE BLOCK DIAGRAM.


Rewrite equation (1-1) in the following form.

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

DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING


̈ and x=∫ ẋ dt Thus, you can find the variables ẋ and x through the integration of ẍ.
(ẋ=∫ xdt

CREATE SIMULINK BLOCK DIAGRAM


Now you can combine above two block diagrams to get system Simulink block diagram as following,

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.

SIMULATE THE SYSTEM.


In order to view the output as the simulation is running, open the block titled Scope and place its window
to the side of the current untitled window so that it can be seen as the simulation is running. To run the
simulation, you can select menu item Simulation and choose Start, or from start simulation button.
You should see the output in the Scope window as the result is generated. You may need to hit the auto-
scale to see whole response. The following is the simulation result at B=4:
DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING

DISPLAY AND ANALYZE THE RESULTS


In order to plot and analyze the system with different damp ratio B, you can modify the above block
diagram by adding clock and to workspaces block as following: the clock can be found in the Sources and
To Worckspace can be found in the Sinks. You can double click To Workspace Displacement block to
change the Variable Name: x, Save format: Array. You can do the same for To Workspace Time t. The
model can be saved as spring_damp.

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:

%this is spring-damp system parameter


M=2; %kg
K=16; %N/m
B=4; %Ns/m

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

%spring-damp system parameter


MECH 370 LABORATORY MANUAL (WINTER 2020): MODELING, SIMULATION AND ANALYSIS OF PHYSICAL SYSTEMS

M=2; %kg
K=16; %N/m
B=4; %Ns/m

nuM=1; deM=[M 0];sysM=tf(nuM, deM) % mass and integrator 1


nuI=1; deI=[1 0];sysI=tf(nuI,deI) % integrator 2
sysMD=feedback(sysM,B) % inner loop feedback
sysMDS=feedback(series(sysMD,sysI),K) % Mass, Damp, spring system

step(sysMDS,10) % step response


DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING

The simulation start time at 0, end at 10 sec. The final step fa is 1 at 0 sec.

We can get Bode diagram by :

bode(sysMDS) % plot Bode diagram, frequence response

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,

DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING

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,

3. Assuming M=0, B=10, K=10. showing the mass's position, velocity,

4. From Q.#3, Change the damping coefficient B to 1 and showing the mass's position, velocity,

DEPARTMENT OF MECHANICAL, INDUSTRIAL AND AEROSPACE ENGINEERING

19 1

You might also like