24
Palestine Polytechnic University Workshop Matlab/Simulink in Drives and Power electronics – Lecture 1 18-21 May 2009 / 24 Workshop Matlab/Simulink in Drives and Power Electronics Lecture 1 : Introduction to Matlab 1 Ghislain REMY Jean DEPREZ

Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

  • Upload
    others

  • View
    48

  • Download
    6

Embed Size (px)

Citation preview

Page 1: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

WorkshopMatlab/Simulink in Drives

and Power Electronics

Lecture 1 : Introduction to Matlab

1

Ghislain REMY Jean DEPREZ

Page 2: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Workshop Program• 8 lectures will be presented based on Matlab/Simulink :

– 1 Introduction to Matlab

– 2 Introduction to Simulink

– 3 DC-Motor Control design

– 4 DC-Motor Chopper design SimPowerSystems

– 5 Introduction to Stateflow/Statechart

– 6 Induction Motor Inverter Control

– 7 Synchronous Motor Modeling

– 8 Synchronous Motor Control

• Two system applications (four quadrants electric drives of mechanical systems) will be used as "conducting lines" during the workshop.

2

Page 3: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Drives and Power Systems• Presentation of the Structure of Industrial Drives and Power

Systems– DC-Motor, Synchronous and Induction Motors

– Large applications domain

– Power Electronics (IGBT, MOSFET…)

– Classical Control Algorithm (Cascaded Control Loop, Scalar and Vector Control…)

3

Page 4: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

System applications:Four quadrants electric drives of mechanical systems

4

1- ELEVATOR

Page 5: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

F _ R O T 1 . T O R Q U

M A S S _ R O T 1 . O

0 . 3

- 0 . 3

0

- 0 . 2

- 0 . 1

0 . 1

0 . 2

- 1 5 1 50- 1 0 - 5 5 1 0

5

Page 6: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

2- ARM of ROBOT

Page 7: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Page 8: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Design of Mechatronics System• Model-based design Simulation of the system is essential• Multi-domain modeling (Mechanical, ElectroChemical, Thermal ,

Controls, Hydraulic, Electrical, Magnetic, Pneumatic…)

Matlab/Simulink is a very good tool for this kind of approach.

8

Page 9: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Matlab: General Presentation• MATLAB environment integrates numerical calculation, advanced plot

function, visualization and an advanced programming language.

• MATLAB Product Family is composed of Toolboxes:– Data-mining and Visualization ;

– Numerical and Symbolical Calculation;

– Modeling and Simulation ;

– Programming, Software and Graphical User Interface Design;

– Automatic conversion of MATLAB programs in C, C++ code.

The Toolboxes are advanced library of MATLAB functionsdesigned to bring solutions in applications.They are written in MATLAB language with accessible source, useful for develop your own algorithm.

9

Last version isR2009a

Page 10: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Presentation of the Matlab Software• Interface Presentation

10

Calculation principles Matrices

Command Window

Figures

Editor

Variables Editor

Workspace

Page 11: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Select a Current Directory for MATLAB• In the Command Window, type :

cd d:\Workshop\Ex01So the Current Directory is changed in:

D:\Workshop\Ex01

Avoid in folder and file names:

• Blank space;

• Long name;

• Special symbol.

Verify the current directory using:

cd or pwd-> MATLAB shows the folder name

11

Current Directory

Command Window

Page 12: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Variables and Workspace• MATLAB works using variables defined as :

scalar or vector or array or structure.

• The Variable names must respect the following rules: – Maximum of 31 characters;

– The 1st character must be a letter;

– MATLAB differentiate majuscule from minuscule.

• Variables are saved in the Workspace

• It is not necessary to type or define variables.– Amp = 1; adds automatically an Amp variable

• Variables are kept until explicit erase order, like: – clear deletes all variables

– clear A B deletes A and B variables only

• Control whos et who show a list of current variables

12

Page 13: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Data Manipulation• Data are managed using a vector representation, using an

Array type

• Some examples:

• A line vector is defined using: A = [1 2] or A = [1,2]a space or , are used to change of column

• A row vector is defined using: B = [3;4]; is used to change of line

• Transpose symbol: B = [3 4]’‘ is used to transpose a vector

• To include B inside C: C = [B [-1;5]]

13

A =1 2

B =34

B =34

C =3 -14 5

Page 14: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Matrix Manipulation• To multiply matrix A by a matrix B of the same size: A.*B

Examples : with A = [1 2]; B = [3 4];

A.*B 3 8 (= 1*3 2*4) term to term product

• To multiply matrix A by a constant

A.*5 5 10 (= 1*5 2*5)

• To do a scalar product of matrix A by a matrix B :

A*B’ 11 (= 1*3 + 4*2)

• To do a concatenation

[A B] 1 2 3 4

14

A = 1 2 B = 3 4

Page 15: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Data retrieval of a Matrix• To access to all columns of the x row: Matrix(x,:)

• To access to all rows of the y column: Matrix (:,y)

• To access to the x row of the y column: Matrix (x,y)Examples :

15

>> C=[ 1 2 ; 3 4]C =

1 23 4

>>C(:,1)ans =

13

>> C(2,:)ans =

3 4

>> C(2,1)ans =

3

Page 16: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Ex 1: Speed Reference Definition• Obj: Add a v_ref variable with the following profile:

• Time is a discrete signalwith a fixed step size:

• time = t_init : t_step_size : t_finalExamples: t = 0:1:10time =

Columns 1 through 11

0 1 2 3 4 5 6 7 8 9 10

16

T1=3s T2=5 s

1.4 m.s-1|v|

t

Page 17: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

The Plot function:• plot(x1,y1,’s1’,x2,y2,’s2’, …)

– x : table of the x-axis values

– y : table of the y-axis values

– s : character string: • The colors

• The line types

• The plot symbols

• The syntax is the same using the semilogx, semilogy, loglog command

17

plot(x,y,'m*:'); %plots a magenta dotted line with a star at each data pointplot(x,y,'rs'); % plots a red square at each data point, but does not draw any line because no line was selectedplot(x,y,'rs−'); % connects the data points with a solid line

Page 18: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Examples of Plot functions and options

18

Three−phases waveforms

y=sin(x); u=sin(x+2*pi/3); v=sin(x+4*pi/3);% The x−axis must be specified for each functionplot(x,y,x,u,x,v);% Turn grid and axes box ongrid on; box on;text(0.75, 0.65, 'sin(x)'); text(2.85, 0.65, 'sin(x+2*pi/3)');text(4.95, 0.65, 'sin(x+4*pi/3)')

x=linspace(0, 2*pi, 60);% pi is a built−in function in MATLAB;% we could have used x=0:0.02*pi:2*pi

or x = (0: 0.02: 2)*pi instead;

PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, disconnected line objects are created and plotted as discrete points vertically at X.

PLOT(Y) plots the columns of Y versus their index.

If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)).

In all other uses of PLOT, the imaginary part is ignored.

Page 19: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

To Plot a function: a detailled proceduret = 0 :200e-6 :50e-3 ; % definition of a time vector

w = 314 ;

plot(t,sin(w*t)) ; % show the plot of sin(wt)

hold on ; % avoid to erase previous plot

plot(t,0.8*sin(w*t-pi/3),’--’)

19

Page 20: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Modification of a figure• The figure properties can be modified using the button:

Edit Plot

Then, selection can bemade using left clicking

on the figure:

Line, Axis, Background…

And can be modified

by selecting:

Show Property Editor

20

Page 21: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

Some other Matlab commands• Previous command can be recall by using :

– the up and down arrows of the keyboard

– Type one or more characters and then use the up or down arrow to recall only the command starting with the typed characters

• Example: if a plot function have been already used

you can recall it by typing ‘pl’ then pushing the up arrow.

21

path List the known directory in MATLABhelp plot Help on the ‘plot’ functiontype fichier Show the content of an ASCII Filewhos, who List all the variables of the Workspaceclear Clear all the variables of the Workspace!, dos Give an access to the Operating System (OS)cd, dir, mkdir Command of the OS available in MATLABexit, quit End of the MATLAB session

Page 22: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

The m-file• Previous commands used in the Command Window can be re-

used in a text file : the “m-file” (due to the .m extension)

22

Page 23: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24

To create a function• To create a function toto returning a variable z calculated from

two parameters x and y:

z = toto(x,y);

• Create m-file with the name toto.m:function f=toto(u,v)

f=u+3*v^2

• Call this functionz=toto(2,3)

ans=

29

23

Page 24: Workshop Matlab/Simulink in Drives and Power Electronicslgep.geeps.centralesupelec.fr/.../Lecture_1_Introduction_to_Matlab.pdf · Workshop Matlab/Simulink in Drives and Power electronics

Palestine Polytechnic University

Workshop Matlab/Simulink in Drives and Power electronics – Lecture 118-21 May 2009 / 24