systems & control lab.-manual (3)

17
German University in Cairo - GUC Information Engineering and Technology Electronics, Communications, & Networks Systems & Control Lab. Systems & Control Lab. Systems & Control Lab. Systems & Control Lab.-Manual Manual Manual Manual ( ( ( (3) A brief overview of: By: Eng. Moustafa Adly

Upload: others

Post on 12-Jun-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Systems & Control Lab.-Manual (3)

German University in Cairo - GUC Information Engineering and Technology Electronics, Communications, & Networks

Systems & Control Lab.Systems & Control Lab.Systems & Control Lab.Systems & Control Lab.----ManualManualManualManual ( ( ( (3333))))

A brief overview of:

By: Eng. Moustafa Adly

Page 2: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

2

ON-OFF control simulation

Thermostatic control of temperature is quite common in domestic appliances and in simple industrial processes. A thermostat is just a relay that switches a heater ON when the temperature is below the set point and OFF when it rises above the set point. Simulate an electrically heated water tank (for 200 seconds) if:

� At steady state, the water temperature rises by 8°C for every amp of heater current, and the dynamic response of the heater can be modeled by a dominant lag (�1) of 9 seconds and a secondary lag (�2) of 1 second, plus a delay time (�d) of 0.1 second. The initial temperature is 20°C. The set point is 50°C. The heater current is 10 amps when the thermostat is energized.

� Re-simulate the problem if the thermostat has a differential gap of 2°C.

Give your comments.

Page 3: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

3

PID controller Design A unity feed back system has a feed forward transfer unction: It’s required to:

� Simulate this system and hence find the rise time, peak time, settling time, maximum peak and steady state error if the input is 5u(t), where u(t) is the unit step function.

� Design a series controller in order to get a specific response such as getting a

maximum peak of 20% or a settling time of 2 seconds while keeping the steady state error to a minimum. Your design simulation should have the flexibility of switching between different types of controllers.

� Now, repeat for )4(

2)(

+=

SSsG .

42

)(+

=S

sG

Page 4: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

4

Introduction: Simulink is a wonderful program that simplifies the matter for you, you can

easy put the building blocks of your system like filters, generators, integrators, transfer functions, nonlinear elements like quantizers, and others to build your system, and then simply put scope in the part of the system you want to see how the waveform change with time, you can put frequency analyzers to see your signal in the frequency domain, and you can also send all these data to MATLAB, so you can integrate the Simulink as a powerful tool for simulation and MATLAB as a powerful tool in data analysis.

So, we will try to go step by step to discover what Simulink is and how we can integrate between Simulink and MATLAB.

Quick start:

You will have the following window, now press on the icon seen in the circle, this is the button that will help you to have the following window, and it is called the Library browser.

Page 5: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

5

This window is an important window; you will make everything from here.

Example (1): We will make here a simulation for an adder of 3 inputs of different

frequencies (1,2 and 3 Hz), and we want it to output the summation of them.

1. Start by creating new model. This can be done from the main menu of

MATLAB file -> new -> model, or from Simulink file ->new ->model, or

by simply pressing this button . You will have now the following window.

Page 6: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

6

2. Now start by inserting 3 sin wave generators, this comes from a library called Simulink > sources >sine wave

Page 7: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

7

Drag the sine wave from the Library browser and put it into the model, do this

job 3 times to have 3 sine wave generators, and you will have the following figure:

3. Now from the Simulink>Math operators>Sum, drag and drop a summation node.

4. Finally drag and drop a scope in your model, you can find it in Simulink >Sinks library, this is the monitoring element in our simulation.

Now, you should have the following figure.

Page 8: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

8

By the way, you can search to find these blocks in the (find) edit box in the library browser; for example, you want to search for scope, and you forgot where to find this scope, and in which library, then you write “scope” in the find box, and you will get it. To have the properties of any block, double click this block, so please:

5. Double click the summation element, you will have the Parameters window

of the summation element, in this window change List of signs to (+++) this means that you want 3 inputs, all summation “no subtraction”.

6. Now click on the top sin wave and press CTRL key and hold it, and then press on the sum node, you will find that you connected them together.

7. Make this with all the other sine wave generators, after this make this

between the sum node and the scope, you should now have the following figure:

8. Now, double click the first Sine wave generator, you will have its

parameters window, change it to be as the follows:

Page 9: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

9

All the details in the parameter window will be clear soon. 9. Make the same with the other 2 generators, only change the frequency from

(2* � *1) to (2*�*2) and (2* � *3) “the frequency in rad/sec”.

Page 10: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

10

10. Now double click the scope and see its

parameter window, and then inside it press the button, change the properties to be as follows:

The result of the above configurations will lead to 3 sine wave generators with

frequencies 1,2,3 Hz and a summer for them, and we will have a scope having 4 display windows and 4 input ports, now, we want to connect the signals required to be monitored to the scope.

11. Connect the output of the summer to the first input of the scope (it should

be already connected. And then click on the line output from the first sine wave generator, and press CTRL and connect the new line to the 2nd input of the scope, make this also with the 2 other inputs, as shown:

Page 11: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

11

Now all what you want to do is to press button, and now double click the

scope to see the scope output, you will see the following:

By now, it is assumed that you became familiar with the Simulink environment, of course you can save your work from file >save, and you can open an existing model from file>open, and you can copy, paste and cut from a model, these are the basic things you want to know to begin working with Simulink.

Now, we will describe in brief some things that we did in the Example (1), I

think you can answer the following questions to discover them yourself.

The result consists of 3 harmonics

Page 12: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

12

1- What will be the change in the summation element if we changed (+++) by

(++++)?

2- What will happen if you change the number of axis in the scope parameter window to 5?

3- What will be the change if we checked the check box of “limit data points to

last:” in the scope parameter window number 2? Please try it yourself, you can catch it, put the number=5000 and run the simulation to see the output then change it to 3000 then 2000 and test the output, what’s the obvious observation? What’s the relation between the output of the scope and the SAMPLING TIME “the last parameter” of the sine wave?? To discover it, keep one element fixed, say the (limit data points to last 5000) and double

4- the value of the sampling time, what will be the effect, then put it into half

of its value, do you understand now what happens? I think you can get it.

5- Try to click on the word “Sine Wave 1”, now you can edit the name.

6- Double click on any place in the empty parts of the model, and write your comments there. Just double click in an empty region and start to write.

Page 13: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

13

Subsystems:

No one can deny the importance of functions in any programming language, it has two main advantages, the first is to decrease the size of the written code, and therefore save the memory required to carry the program, the second objective is much more important than the first, it is the readability and the reliability of the program, so you develop a clear module that makes clear task, and you test it several times, then you start using it in your system, the code becomes clear and readable. The subsystem also makes your model easy to trace and read. The subsystem is a black box that has a lot of Simulink components, and has inputs and outputs. You put these components into your model, you can mask for better interface with the system designer. The masked system can have parameters from the designer.

Example (2):

1- Open the model of the last example, save it with different name “like exp.mdl”.

2- Select the 3 sine wave generator by the mouse or by clicking on them while keeping SHIFT key pressed.

3- Right click and choose “create subsystem”, you should have the following figure:

Page 14: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

14

4- Change the name of subsystem to “3_sines”.

5- From the toolbar, press on the button.

6- Now, you will see the model browser, you can switch between the main system and the 3_sines subsystem, I think if what is inside the subsystem is a lot of things, this method will be a nice help for us.

7- Now switch to 3_sines subsystem and change the name of the output ports to f1, f2, f3 I hope that you reach the following figure:

8- Go to the parameters window of the sine wave generators and make the frequencies 2*pi*f1, 2*pi*f2 and 2*pi*f3 “note f1, f2, f3 will be specified soon”.

9- Go to the main model, and right click the subsystem and choose Edit

mask. You will have the following window:

Page 15: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

15

Now click on parameters tab.

10- Now change the input data to be as follows:

We think what happens now should be clarified, all what we did is that we

decided to input the three frequencies of our small subsystem by an Edit box, this is similar to send the arguments of a function in any programming language, if you double click now on the subsystem, you will have the following dialog box:

Page 16: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

16

We think things now became clear, we have now 3 Edit boxes, the input for

them are sent to f1, f2, f3 respectively and the prompt of them are shown as determined bythe mask designer.

Now we want to write short note on the block and we want to call it something,

this is done by right click on the subsystem->edit mask-> documentation tab, then write the name in the “mask type” part, and the description which will appear when double clicking the block in the Mask description part, and the help that you want the user to see in the Mask help part as shown in the following 2 figures:

Page 17: Systems & Control Lab.-Manual (3)

Systems & Control Lab.-Manual(3) Simulink

17

Press on the help button also to find the help written by us now.