matlabsimulink

14
Chapter 4 Simulation 4.1 Introduction to MATLAB/Simulink: MATLAB is a numerical computation and simulation tool that was developed into a commercial tool with a user friendly interface from the numerical function libraries LINPACK and EISPACK, which were originally written in the FORTRAN programming language. As opposed to the well-known computer algebra programs, such as MAPLE or MATHEMATICA, which are capable of performing symbolic operations and, therefore, calculating with mathematical equations as a person would normally do with paper and pencil, in principle MATLAB does purely numerical calculations. Nevertheless, computer algebra functionality can be achieved within the MATLAB environment using the so-called “symbolics” toolbox. Computer algebra programs require complex data structures that involve complicated syntax for the ordinary user and complex programs for the programmer. MATLAB, on the other hand, essentially only involves a single data structure, upon which all its operations are based. This is the numerical field, or, in 33 M V G R College of Engineering

Upload: saroj-babu

Post on 23-Dec-2015

5 views

Category:

Documents


1 download

DESCRIPTION

Matlab simulink tutorial on semi-active suspension system for various road inputs.

TRANSCRIPT

Page 1: Matlabsimulink

Chapter 4

Simulation

4.1 Introduction to MATLAB/Simulink:

MATLAB is a numerical computation and simulation tool that was developed into a

commercial tool with a user friendly interface from the numerical function libraries LINPACK

and EISPACK, which were originally written in the FORTRAN programming language.

As opposed to the well-known computer algebra programs, such as MAPLE or

MATHEMATICA, which are capable of performing symbolic operations and, therefore,

calculating with mathematical equations as a person would normally do with paper and pencil, in

principle MATLAB does purely numerical calculations. Nevertheless, computer algebra

functionality can be achieved within the MATLAB environment using the so-called “symbolics”

toolbox.

Computer algebra programs require complex data structures that involve complicated

syntax for the ordinary user and complex programs for the programmer. MATLAB, on the other

hand, essentially only involves a single data structure, upon which all its operations are based.

This is the numerical field, or, in other words, the matrix. This is reflected in the name:

MATLAB is an abbreviation for MATrix LABoratory.

MATLAB limits itself to the basic data structure of the matrix, then MATLAB syntax

remains very simple and MATLAB programs can be written far more easily than programs in

other high level languages or computer algebra programs. A command interface created for

interactive management without much ado, plus a simple integration of particular functions,

programs, and libraries supports the operation of this software tool. This also makes it possible to

learn MATLAB rapidly.

MATLAB is not just a numerical tool for evaluation of formulas, but is also an

independent programming language capable of treating complex problems and is equipped with

33 M V G R College of Engineering

Page 2: Matlabsimulink

Department of Mechanical Engineering Chapter 4

all the essential constructs of a higher programming language. Since the MATLAB command

interface involves a so-called interpreter and MATLAB is an interpreter language, all commands

can be carried out directly. This makes the testing of particular programs much easier.

MATLAB offers an intuitive language for expressing problems and their solutions both

mathematically and visually.

Typical uses include:

• Numeric computation and algorithm development.

• Symbolic computation (with the built-in Symbolic Math functions).

• Modeling, simulation and prototyping.

• Data analysis and signal processing.

• Engineering graphics and scientific visualization.

4.2 Introduction to simulink:

Simulink has become the most widely used software package in academia and industry for

modeling and simulating dynamical systems. In simulink environment we can easily build

models from scratch, or take an existing model and add to it. Simulations are interactive, so we

can change parameters “on the fly” and immediately see what happens. We have instant access to

all of the analysis tools in MATLAB®, so we can take the results and analyze and visualize them.

Simulink is a software package for modeling, simulating, and analyzing dynamical

systems. It supports linear and nonlinear systems, modeled in continuous time, sampled time, or a

hybrid of the two. Systems can also be multi rate, i.e., have different parts that are sampled or

updated at different rates. For modeling, Simulink provides a graphical user interface (GUI) for

building models as block diagrams, using click-and-drag mouse operations. Simulink includes a

comprehensive block library of sinks, sources, linear and nonlinear components, and connectors.

We can also customize and create our own blocks.

34 M V G R College of Engineering

Page 3: Matlabsimulink

Department of Mechanical Engineering Chapter 4

Models are hierarchical, so we can build models using both top-down and bottom-up

approaches. We can view the system at a high level, and then double-click on blocks to go down

through the levels to see increasing levels of model detail. This approach provides insight into

how a model is organized and how its parts interact.

After we define a model, we can simulate it, using a choice of integration methods, either

from the Simulink menus or by entering commands in MATLAB’s command window. The

menus are particularly convenient for interactive work, while the command-line approach is very

useful for running a batch of simulations. Using scopes and other display blocks, we can see the

simulation results while the simulation is running. In addition, we can change parameters and

immediately see what happens, for “what if” exploration. The simulation results can be put in the

MATLAB workspace for post processing and visualization.

Model analysis tools include linearization and trimming tools, which can be accessed from

the MATLAB command line, plus the many tools in MATLAB and its application toolboxes.

And because MATLAB and Simulink are integrated, we can simulate, analyze, and revise your

models in either environment at any point.

One of the key features of Simulink is that it is built on top of MATLAB. As a result,

Simulink users have direct access to the wide range of MATLAB-based tools for generating,

analyzing, and optimizing systems implemented in Simulink. These tools include MATLAB

Application Toolboxes, specialized collections of M-files for working on particular classes of

problems.

Simulink can be used to explore the behavior of a wide range of real-world dynamic systems,

including electrical circuits, shock absorbers, braking systems, and many other electrical,

mechanical, and thermodynamic systems. Simulating a dynamic system is a two-step process

with Simulink. First, we have to create block diagram, using the Simulink model editor, that

graphically depicts time-dependent mathematical relationships among the system's inputs, states,

and outputs. Then we simulate the system represented by the model from a specified start time to

a specified stop time.

4.3 Simulation of TWV:

35 M V G R College of Engineering

Page 4: Matlabsimulink

Department of Mechanical Engineering Chapter 4

After modeling the vehicle as six degrees of freedom model with single sprung mass and

three un-sprung masses using six linear second order differential equations the vehicle vertical

response has been found when the vehicle is moving at a speed of 45 km-ph on a random road

surface.

In majority cases dynamic systems (that are continuous in time) will be described by

differential equations. Thus in simulink we describe the system with a block diagram and

simulate the reaction of the system to an input signal. In order to find the response of TWV the

linear second order differential equations has to be modeled as a block diagram and the response

of system has been found for road disturbance signal.

The equations have been transformed into the block diagrams using integrator, gain add

blocks from the simulink library. Modeling all the equations in a single system is more complex

and confusing for that each and every mode has been modeled separately in different subsystems

and are connected using bus creators and bus selectors. The parent diagram and simulink models

for each subsystem are presented in annexure iii. The road disturbance that has been modeled as a

longitudinal displacement and corresponding time values are brought to the simulink

environment using from work space block. The response has been found in time domain using

scope block. And the response has been exported to MATLAB for frequency analysis using To

Workspace block. The disturbance has been given to three wheels without any time difference.

The simulation has been carried out for 10 seconds using ode4 (Runge-kutta) solver and

fixed time step. Physical parameters have been set by typing the related commands in the

MATLAB window.

Frequency analysis has been done in MATLAB workspace using fast Fourier transforms.

The goal of spectral estimation is to describe the distribution (over frequency) of the power

contained in a signal, based on a finite set of data. Using pwelch command the response has been

found in frequency domain.

4.3.1 Building the model:

36 M V G R College of Engineering

Page 5: Matlabsimulink

Department of Mechanical Engineering Chapter 4

This system will be modeled by summing the forces acting on the system (body and

suspension) and integrating the accelerations of each mass twice to give velocities and positions.

Newton's law will be applied to each mass.

3

z3

2

z21

z1

k1

z3-1

c1

z3'-1

k3

z2-1

c3

z2'-1

k2

z1-1

c2

z1'-1

-K-

ms-K-

k1+k2+k3

1s

i-i

1s

i-K-

c1+c2+c3-K-

R-1-K-

R'-1 -K-

P-1-K-

P'-1

10

z33

9

z23

8

z13

7

p3

6

r3

5

z32

4

z22

3

z12

2

p2

1

r2

z2 z3

z1

Fig.4.1 simulink model for sprung mass bounce mode

Figure shows the simulink model developed for sprung mass bounce mode based on the equation,

ms z+c1 ( z1−ζ1 )+c2 ( z2−ζ 2)+c3 ( z3− ζ3 )+k1 (z1−ζ1 )+k 2( z2−ζ2 )+k3 ( z3−ζ3 )=0 ..(4.1)

In order to model the equation it can be expressed as

z=− 1ms

(c1 ( z1−ζ1 )+c2 ( z2−ζ 2)+c3 ( z3− ζ3 )+k1 (z1−ζ1 )+k 2( z2−ζ2 )+k3 ( z3−ζ3 )) ..(4.2)

These equations can be represented with gain blocks, integrator block and summation blocks

For the equation 4.2 first we will model the integrals of the accelerations of the masses

• Insert an Integrator block (from the linear block library) and draw lines to and from its

input and output terminals.

• Label the input line "z1" (for acceleration) and the output line "z2" (for velocity) by double

clicking in the empty space just above the line.

37 M V G R College of Engineering

Page 6: Matlabsimulink

Department of Mechanical Engineering Chapter 4

• Insert another Integrator block connected to the output of the first.

• Draw a line from its output and label it "z3" (for displacement).

We have taken a multi degree freedom system, in order to completely model the above

equation we need accelerations and velocities of other masses. For that five more pair of

integrators has been modeled. If we model the all of them in a single window the model will be

more confusing for that subsystems have been used. Each equation has been modeled in separate

subsystem. The variables that we are commonly exchanging among the equations are their

displacements, velocities and accelerations. The three variables are taken out of the each

subsystem by using out block. Using a bus creator the three variables can be converted to single

signal. All such signals have been added in order to generate a signal that contains all the

variables. Bus selectors are used to get the required variables from the signal. the parent diagram

for simulink vehicle model consisting of subsystems is as shown in fig 4.2

The equations can be represented with gain block (for 1/ms) and two summation blocks.

• Insert a Gain block (from the Linear block library) one attached to the input of the

integrator pairs.

• Edit the gain block corresponding to ms by double-clicking it and changing its value to

"1/ms".

There are number of forces acting on the mass all of them have to be added, for that two

summation blocks have been included all damping forces are added together and these are added

to the spring forces in another summation block. The force can be obtained by multiplying the

distances by spring constants and velocities by damping coefficients. Insert gain blocks

corresponding to each force and change the parametric value to their corresponding spring

constants or damping coefficients. Input line of these gain blocks is connected to their respective

displacements in case of spring forces and velocities incase of damping forces that have been

brought from the other subsystems. The outputs of lines of these blocks are connected to

summation blocks and signs in the parameter block are changed according to the equation above.

Remaining modes of sprung mass has been modeled similar to the sprung bounce mode as above.

38 M V G R College of Engineering

Page 7: Matlabsimulink

Department of Mechanical Engineering Chapter 4

Fig.4.2 Simulink model TWV with subsystems

Where as in the case of unsprung masses disturbance force has to be added in addition to

the spring and damping forces. In road disturbing force there are two elements one corresponding

velocity and other one is displacement. We are giving the road disturbance as longitudinal

displacement corresponding to time. Velocity component can be obtained by introducing a

derivative block in system. The simulink models for the all the modes sprung mass and bounce

modes of unsprung masses are as shown in the fallowing figures.

39 M V G R College of Engineering

Page 8: Matlabsimulink

Department of Mechanical Engineering Chapter 4

3

r32

r2

1

r1

-K-

z2-2

-K-

z2'-2

-K-

z1-2

-K-

z1'-2

-K-

r-2

-K-

p-2-K-

p'-2

1s

ii-i

1s

ii

-K-

b-2

-K-

b'-2

-K-

Gain2

-K-

Gain

Add1 Add

8

z23

7

z13

6

p3

5

z3

4

z22

3

z12

2

p2

1

z2

r3r2r1

Fig.4.3 Simulink modal for bounce mode of sprung mass

3

z3

2

z21

z1

k1

z3-1

c1

z3'-1

k3

z2-1

c3

z2'-1

k2

z1-1

c2

z1'-1

-K-

ms-K-

k1+k2+k3

1s

i-i

1s

i-K-

c1+c2+c3-K-

R-1-K-

R'-1 -K-

P-1-K-

P'-1

10

z33

9

z23

8

z13

7

p3

6

r3

5

z32

4

z22

3

z12

2

p2

1

r2

z2 z3

z1

Fig4.4 Simulink modal for sprung mass roll

40 M V G R College of Engineering

Page 9: Matlabsimulink

Department of Mechanical Engineering Chapter 4

3

p3

2

p2

1

p1

-K-

z3-3

-K-

z3'-3

-K-

z2-3

-K-

z2'-3

-K-

z1-3-K-

z1'-3

-K-

r-3-K-

r'-3

-K-

p-3

-K-

p'-3

-K-

ipy

1s

iii-i

1s

ii i

-K-

b-3-K-

b'-3

10

z33

9

z23

8

z13

7

r3

6

z3

5

z32

4

z22

3

z12

2

r2

1

z2

p3p2p1

Fig.4.5 Simulink modal for sprung mass pitch

3

z33

2

z32

1

z31

-K-

z3-6

1s

vi-i

1s

vi

du/dt

velocity

-K-

p-6

-K-

p'-6

-K-

muf

k4

k4

k1

k1

c4

c4

-K-

c1+c4k1

b-6

5

df

4

p3

3

z3

2

p2

1

z2

z33z33

z32

z32

z31

z31

Fig.4.6 Simulink model for front unsprung mass bounce

41 M V G R College of Engineering

Page 10: Matlabsimulink

Department of Mechanical Engineering Chapter 4

3

z232

z22

1

z21du/dt

velocity2

1s

v-i

1s

v

-K-

murl

k5

k5

-K-

k3+k6

-K-

k3*l4

-K-

k3*l2

k3

k3

c5

c5

-K-

c3+c6

-K-

c3*l4

-K-

c3*l1

c3

c3

7

drl

6

p3

5

r3

4

z3

3

p2

2

r2

1

z2

z22 z23z21

Fig.4.7 Simulink model for rear right unsprung mass

3

z232

z22

1

z21du/dt

velocity2

1s

v-i

1s

v

-K-

murl

k5

k5

-K-

k3+k6

-K-

k3*l4

-K-

k3*l2

k3

k3

c5

c5

-K-

c3+c6

-K-

c3*l4

-K-

c3*l1

c3

c3

7

drl

6

p3

5

r3

4

z3

3

p2

2

r2

1

z2

z22 z23z21

Fig.4.8 Simulink model for rear left unsprung mass

42 M V G R College of Engineering