Control With Matlab Part 1

28
Overheads and Flash lectures for Introduction to MATLAB for engineers Anthony Rossiter Department of Automatic Control and Systems Engineering University of Sheffield www.shef.ac.uk/acse © University of Sheffield 2009 This work is licensed under a Creative Commons Attribution 2.0 License .

description

part of a series of flash resources on using matlab for engineers. For whole series see: http://controleducation.group.shef.ac.uk/OER_index.htm

Transcript of Control With Matlab Part 1

Page 1: Control With Matlab Part 1

Overheads and Flash lectures for Introduction to MATLAB for engineers

Anthony RossiterDepartment of Automatic Control and

Systems EngineeringUniversity of Sheffield

www.shef.ac.uk/acse

© University of Sheffield 2009 This work is licensed under a Creative Commons Attribution 2.0 License.

Page 2: Control With Matlab Part 1

Control with MATLAB

Anthony RossiterACS108 (and ACS211)

Department of Automatic Control and Systems

Engineering

Page 3: Control With Matlab Part 1

Overview

1. Representation of Laplace transforms2. Inverse Laplace3. Block diagrams4. Time responses

These slides assume you have the control toolbox.

Page 4: Control With Matlab Part 1

Laplace transforms

Basic tool is tf.m

Consider

Numerator coefficients are[1 3 2]Denominator coefficients are[1 9 27 27]tf.m takes vectors of these

coefficients.The final result is clear

27279

2323

2

sss

ssG

Page 5: Control With Matlab Part 1

TASK

Use MATLAB to define the following transfer functions.

Answers are on the next slide.

ss

sM

s

sK

sH

sss

sG

4

)1(2

6

53

4

3

644812

23

2

223

Page 6: Control With Matlab Part 1

AnswersG=tf([3,2],[1,12,48,64])H=tf(3,[1, 0,4])K=3*tf([1 5],[1 6])M=tf([2 2],[1 4 0])

Note it sometimes better to use commas rather than spaces to separate coefficients as this is clearer.

You should try these if you did not enter them yet.

See week6_laplace.m

Also has other examples to look at.

Page 7: Control With Matlab Part 1

Extracting dataHow do I get the numerator coefficients out of a transfer function?

Use tfdata.m as shown here. [The ‘v’ is important]

Two output arguments are vector of numerator coef. and vector denominator coef.

Page 8: Control With Matlab Part 1

TASK

Try extracting numerator and denominator coefficients for all the transfer functions defined in the earlier slides.

Page 9: Control With Matlab Part 1

Forming polynomials quickly

If you are given roots of a polynomial rather than coefficients, use poly.m to find the coefficients.

If you are given the coefficients and want the roots, use roots.m

ssssss

ssss

43)1)(4(

23)2)(1(23

2

Page 10: Control With Matlab Part 1

TASK

1. What does the following command do?H=tf(poly(-2),poly([0,-3 -5]))2. Enter the transfer function with the following

poles and zeros.Poles at {0,-1,-2+j,-2-j}Zeros at {1,-2}

3. Find the roots of ssss 466 234

Page 11: Control With Matlab Part 1

Inverse LaplaceThe control toolbox does this numerically, not analytically.

Two options exist:• impulse response •step response

The latter is more common in control scenarios.

See ilaplace.m for analytic inverse

])(

[

)]([

1

1

s

sGL

sGL

Page 12: Control With Matlab Part 1

Inverse Laplace

0 0.5 1 1.50

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

2Impulse Response

Time (sec)

Am

plitu

de

0 1 2 3 4 5 6 70

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5Impulse Response

Time (sec)

Am

plitu

de

Page 13: Control With Matlab Part 1

Extracting the numerical answers

If you want the numbers, not the plots use.

To specify the final time of the data computed.

Specify time points where you want the inverse Laplace computed.

Produce a plot afterwards.

0 0.5 1 1.50

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

2

Page 14: Control With Matlab Part 1

What about step responses

Same syntax as impulse.mJust write step instead, e.g.

[y,t]=step(G,tfinal)

Page 15: Control With Matlab Part 1

TASKS

1. Compute and plot the impulse and step responses for all the transfer functions given earlier.

2. Validate your answers by doing some computations on pen and paper.

3. Take some examples from the ACS114 notes/lectures and form the impulse/step responses with MATLAB.

4. Look at week6_laplace.m, week6_laplace1.m, week6_laplace2.m

Page 16: Control With Matlab Part 1

Non-simple input sequences

1. In some cases the input is neither an impulse or a step but some more complicated shape.

2. To simulate the response of a transfer function in this case use lsim.m

3. This function needs enough information to define the input precisely, that is pairs of values (input magnitude, time).

4. It will interpolate between the values given, so ensure the time gaps are small to minimise any errors from this interpolation.

Page 17: Control With Matlab Part 1

Illustration of lsim.m

1. Define input values.2. Define corresponding

times.3. Give three

arguments, G(s), inputs and times.

4. Plotting:Note the input values in green circles and output is plotted with a line

0 0.5 1 1.5 2 2.5 3 3.5 40

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

Output response

Input values

Page 18: Control With Matlab Part 1

Block diagramsHow do I form the closed-loop

transfer functions with unity negative feedback?

Set point to output.Set point to input/error.

Use the command feedback.mFirst argument is forward path, 2nd

argument is feedback path

rGrG

u

rGrG

Gy

cu

c

1

11

Page 19: Control With Matlab Part 1

Block diagrams with controller

What happens when I add a compensator ?

Set point to output.Set point to input.

For output, forward path is GK, feedback path is 1.

For input, forward path is K, feedback path is G.

rGrGK

Ku

rGrGK

GKy

cu

c

1

1

Page 20: Control With Matlab Part 1

TASK

Use MATLAB for find the closed-loop transfer functions (setpoint to error, input and output) for the following arrangements.

Use pen and paper to validate your programming.

04.0

1.0;)3)(2(

21;

)2)(1(

2

2;)2)(1(

21;

4

3

s

sK

sssGK

ssG

sK

ssGK

sG

Page 21: Control With Matlab Part 1

Extra task

1. How would you use feedback if there is a compensator H(s) in the feedback path as indicated in this figure ? Try it!

2. How would you compute the closed-loop poles/zeros for the systems on the previous slide ?

[Hint look at the slide on tfdata.m and roots.m, or look up pzmap.m (i.e. [p,z]=pzmap(G) )]

Page 22: Control With Matlab Part 1

Closed-loop responses

Now you know how to:1. Enter transfer functions.2. Build closed-loop transfer functions.3. Compute step and impulse responses.

Next job is to look at the impact of feedback on closed-loop responses.

Page 23: Control With Matlab Part 1

Closed-loop response

Open the file compare_open_closed.mNote how it overlays open

and closed-loopTASKcompare_open_closed(G,K)

0 0.2 0.4 0.6 0.8 1 1.2-0.2

0

0.2

0.4

0.6

Output step response

Time (sec)

Am

plitu

de

Closed-loop

Open-loop

-0.2 0 0.2 0.4 0.6 0.8 1 1.2

0

1

2

3

Input step response

Time (sec)

Am

plitu

de

Closed-loop

Open-loop

Page 24: Control With Matlab Part 1

TASK

• Look at the file overlaymany.mThis allows you to compare the closed-loop responses of

a single G(s) with various alternative compensators.• For example try:G=tf(1,[1 2 1 0]); K1=1;K2=0.2;K3=0.2*tf([1 0.1],[1 0.02])overlaymany(G,K1,K2,K3)• Try some more examples of your choice.

NOTE: Please make sure all the closed-loops are stable or the figure will be dominated by the divergent plots.

Page 25: Control With Matlab Part 1

TASK for ACS108Set up a function file that allows the user to tune a

suspension system (constants B and k) , iteratively (use a while loop), to give the best behaviour in response to a range of road surfaces, e.g. small steps and sinusoidal surfaces of various periods (ie. Equivalent to changing frequency). You could use subplots to display responses to different surfaces in a single figure.

You can assume that the response is given from X(s) where:

orws

wor

ws

wor

ssRsR

kBsMssX

22

22

21

21

2

1)();(

1)(

Page 26: Control With Matlab Part 1

TASK for ACS108A summary of the MATLAB code for ACS108 (and

ACS114) is covered in week6_overview_control.mIn module ACS114 you will have been introduced to

some main control concepts such as feedback loops, block diagrams and time responses. MATLAB facilitates your computation of all these things. You should read the introduction to the control system toolbox in the help and become familiar with standard operations.

Put extra emphasis on the commands such as series, parallel, feedback, connect and append to see how to construct the transfer function of a block diagram.

Page 27: Control With Matlab Part 1

TASK for ACS108

1. Create a file that overlays the open-loop and closed-loop step responses of a system G(s) when connected with unity negative feedback.

– Modify the file it allows a controller to be included in the closed-loop.

– Modify the file so that it also produces the closed-loop input responses (input is output of controller or input to plant).

2. Write a file that illustrates resonance. 3. Try right-click on a step response and observe the

characteristics available (e.g. rise time, peak, settling time, etc.)

Page 28: Control With Matlab Part 1

This resource was created by the University of Sheffield and released as an open educational resource through the Open Engineering Resources project of the HE Academy Engineering Subject Centre. The Open Engineering Resources project was funded by HEFCE and part of the JISC/HE Academy UKOER programme.

© 2009 University of Sheffield

This work is licensed under a Creative Commons Attribution 2.0 License.

The JISC logo is licensed under the terms of the Creative Commons Attribution-Non-Commercial-No Derivative Works 2.0 UK: England & Wales Licence. All reproductions must comply with the terms of that licence.

The HEA logo is owned by the Higher Education Academy Limited may be freely distributed and copied for educational purposes only, provided that appropriate acknowledgement is given to the Higher Education Academy as the copyright holder and original publisher.

The name and logo of University of Sheffield is a trade mark and all rights in it are reserved. The name and logo should not be reproduced without the express authorisation of the University.

Where Matlab® screenshots are included, they appear courtesy of The MathWorks , Inc.