Вы находитесь на странице: 1из 10

Department of Chemical Engineering University of Texas, Austin

ChE 360 Spring, 2009

Introduction to the MATLAB SIMULINK Program


Reference: Seborg, Edgar, and Mellichamp, Process Dyamics and Control, 2nd ed., Wiley (2004). MATLAB, which stands for MATrix LABoratory, is a technical computing environment for high-performance numeric computation and visualization. SIMULINK is a part of MATLAB that can be used to simulate dynamic systems. To facilitate model definition, SIMULINK adds a new class of windows called block diagram windows. In these windows, models are created and edited primarily by mousedriven commands. Part of mastering SIMULINK is to become familiar with manipulating model components within these windows. The purpose of this tutorial is to introduce you to SIMULINK and give you experience simulating dynamic systems. In the first part of this tutorial, you will use SIMULINK to generate an open-loop set-point and disturbance response for a dynamic process. In the second part of the tutorial, you will generate the closed-loop set-point and disturbance responses. Please review Appendix C in Seborg et al. before attempting this tutorial. Log onto one of the PC computers. Click on the Microsoft Start button in the bottom corner of your screen and MATLAB will be listed under Programs. Open MATLAB. To invoke SIMULINK, type simulink at the MATLAB prompt which is indicated by >> in Figure 1 below. A new window titled simulink will open somewhere on the screen.

Figure1. Initial Matlab Screen

Figure 2. Simulink Library Browser You will have to right click on the Simulink block to make the menu on the right viewable. Once the simulink window block on the right is open, you are ready to build a SIMULINK model. This tutorial is divided into two sections. In the first section, you will build a model of the open-loop system for the second order plus time delay process 2e s G(s) = and determine the unit set-point and unit disturbance responses. (10s+ 1)(5s+ 1) In the second section, you will build a closed-loop model of the same process. After the closed-loop model is constructed, you should simulate the unit disturbance response and the unit set-point response for two different PID controller tuning methods, ITAE (setpoint) and ITAE (load), in Table 12.3 (SEM). The following steps will guide you through the discussed tasks. Construction of an Open-Loop Block Diagram (Chapters 4, 5, 6, and 7) 1. Open a new empty system window by selecting New followed by Model from the File menu in the simulink window. The new window will be titled untitled. You will build your closed loop model inside this window. Save the empty model by

choosing Save from the File menu in the untitled window. Name the model, examplesim. From this point on, the model will be referred to as examplesim. 2. Look at the list below simulink in the Simulink Library Browser window. Click on Sources and select the clock from the new list and drag the clock block from the Simulink Library Browser (Figure 2) to the examplesim window. Click on the Sinks block in the simulink window and drag the To Workspace block to examplesim. Connect the output of the clock block to the input of the To Workspace block. Double-click on the To Workspace block to open its dialog box. Change Variable name from simout to t. Set the save format shown at the bottom of the dialog box as Array. If you have followed the above steps correctly, the model will look like this:
t Clock To Workspace

Figure 3. Construction of Time Vector The simple model above will output a time vector t to the workspace which can be used with the plot command. As you have seen, double-clicking on a block will open a window filled with more blocks or open the dialog box of the block. The dialog box is used to specify parameters that govern the operation of the block. 3. Copy the Transfer Fcn and Transport Delay blocks from the Continuous block, respectively, to Examplesim. Connect the output of the Transfer Fcn block to the input of the Transport Delay block. Click on the Transfer Fcn label and rename the Transfer Fcn block "Process TF". This block represents the process. Note that in this problem, the process is G(s) = G vGpGm, not Gp. Open the dialog box of Process TF by double-clicking on it. Specify Numerator as [2] and Denominator as [50 15 1]. This indicates the transfer function 2/(50s 2 + 15s + 1). The Transfer Fcn block requires specification of vectors for the numerator and denominator. The vector elements are treated as the coefficients of descending powers of s in the polynomials representing the numerator and denominator of the transfer function. To see the denominator polynomial of s completely displayed in the block's icon, you may have to resize the blocks icon. Double-click on the Transport Delay and set Time delay to 1. Note that the Transport Delay block can be used to represent other types, such as measurement delay. Copy the Process TF and Transport Delay blocks and place the copies slightly above the originals. The copies will automatically change names to Process TF1 and Transfer Delay1. No two blocks can have the same name in on SIMULINK window. To quickly copy the original blocks, select both of them and drag them using the right mouse button. Rename the Process TF1 block Disturbance TF. In this example Gp and GL are the same, so the Numerator

4.

and Denominator parameters in the dialog box of Disturbance TF are not changed (See Figure 4). 5. Place a copy of the Sum block, located in the Math menu, to the right of the Transport Delay block. Double click above the sum block and label the block Sum. Connect the output from each Transport Delay block to the input of the Sum block. The number of inputs and their polarity can be modified from the dialog box. Later in the tutorial you will be required to do this. 6. Copy the To Workspace block to the right of the Sum block and connect the output of the Sum block to the new To Workspace block. Double-click on the new block and set Variable name to Y. The model developed to this point is a model of the open-loop system. Copy a Step Input block from the Sources menu, place the block to the left of Disturbance TF and connect it to the input of Disturbance TF. The Step Input block generates a step function. The step time (time at which the step occurs), initial value, and final value of the function can be specified. For now, open its dialog box and set the step time, initial value, and final value to zero, i.e., disabling the block. Rename the block D. Place a copy of D to the far left of Process TF and rename the new block U. Connect U to the input of Process TF. Double-click on U and set Step time to 0, Initial value to 0 and Final value 1. U will generate a unit step function in the manipulated variable at time zero. The model developed to this point is a model of the open-loop system. It should look similar to the model below.
t Clock To Workspace 0.3 15s+1 D Disturbance TF Transport Delay 1 Sum Y T o Workspace 1 2 50s2 +15s+1 U Process TF T ransport Delay1

7.

8.

Figure 4. Open-Loop Block Diagram 9. Now we are ready to simulate the open-loop response of the system. To select the integration technique and parameters to be used during simulations, pull down the Simulation menu and choose Parameters. A dialog box is opened showing all the simulation parameters that can be modified. Set the Stop Time to 50 and the
4

Max Step Size to 1. Because the system is easy to numerically integrate, SIMULINK can and will take integration step sizes equal to the default value of 10. If this occurs, the appearance of the response will not be smooth. By setting Max Step Size to 1, Y will be output to the workspace each time interval and the simulated response will be smoother. Start the simulation by selecting Start from Simulation menu. The resulting Y and t variables in the workspace will be for the open-loop unit set-point response. 10. Once a simulation has been completed, the resulting data can be manipulated and analyzed using MATLAB. Select the MATLAB command window and type plot(t,Y) to view the response. The plot command opens a MATLAB Figure window and generates a plot inside the window. To add x and y axis labels and a title type xlabel(Time) ylabel(Y)

Figure 5. Unit step response of open-loop system Figure 5 shows the resulting plot. You can add title or axes labels simply by inputting characters onto the figure window. To do this you need to first click the A button on top of the window, then double-click on the place where you want to put your words. A flashing cursor will soon appear telling you that you can type now. 11. Now simulate the open-loop unit disturbance response. Double-click on U and set Final value to 0. This eliminates the unit step in the manipulated variable. Double-click on D and set Step time to 0 and Final value to 1. This creates a unit load step. Again, select Start from the Simulation to begin the simulation. Type
5

plot(t,Y)to view the response. You can see that the old t and Y were replaced. The old x-axis label can be quickly added hitting the up arrow key to toggle through all past commands until xlabel(Time) is displayed. Hit return to execute this command. Repeat this technique for the ylabel. From the MATLAB prompt, commands can only be edited using the arrow keys; using the mouse will not work. Figure 6 shows the resulting plot.

Figure 6. Unit disturbance response of open-loop system 12. If you are not continuing to the next section, save the file examplesim so that you can use it in constructing a closed-loop block diagram. Construction of Closed-Loop Block Diagram (Chapters 11 and 12) 1. 2. Open the file examplesim if it is not already open. Click on the connection between the U block and Process TF block and delete it. Rename the U block to Ysp. This block will be used to produce a step change in the set-point. Place a copy of the Sum block to the right of Y sp. Double click above the sum block icon and label the block Sum1. Open its dialog box and change the ++ sequence to +-. Instantly, the blocks icon will reflect this change. The top input will have a + located to the right of it while the bottom input will have a located above it. Therefore, the output of Sum1 will be the top input minus the bottom input. Connect the output of Ysp to the top input of Sum1. Also, connect the output from Sum to the bottom input of Sum1. This can be done by clicking on the bottom input of Sum1 and dragging the arrow to the output of Sum. The

3.

output of Sum1 is the error between the set-point, Ysp, and the controlled variable, Y. Your model should look like Figure 7:

t Clock To Workspace 2 50s2 +15s+1 D Disturbance T F Transport Delay 1 Sum Y To Workspace 1 2 50s2 +15s+1 Ysp Process T F Transport Delay1

Sum 1

Figure 7. Partially Completed Closed Loop Diagram 4. Now close the Simulink block menu and open the Simulink Extras block by right clicking on the block labeled Simulink Extras. Click on the Additional Linear block, then select the PID Controller and drag it to the right of the newest sum block. Connect the output of the Sum1 to the input of PID controller and the output of PID controller to the input of Process TF. Double-click on the PID controller and enter the ITAE (load) controller settings given in Table 12.3 in Seborg et al. Please note that SIMULINK PID controller settings are P, I, and D where P = Kc, I = Kc/i, and D = Kc*D, so numerical values of P, I, and D should reflect these definitions. The model you have developed represents the closedloop system. Your model should now look similar to Figure 8:
t Clock To Workspace 2 50s2 +15s+1 D Disturbance TF Transport Delay 1

X1 Sum Y To Workspace 1

Sum 1

E PID

2 50s2 +15s+1 Process TF Transport Delay1 X2

Ysp

PID Controller

Figure 8. Closed-Loop Diagram

Note that some text has been added to the block diagram shown on the previous page. Simply by double-clicking on a point in examplesim and typing, text is added to the diagram at the point where you clicked. The E, P, X1, X2 text in the block diagram have no effect on its operation. 5. Now we are ready to simulate the closed-loop response of the system. We will start with the set-point response. Click on block D and set the Final value to 0 so that no step in the disturbance will occur. Create a step in the set-point by clicking on Ysp and setting the Final Value to 1. Start the simulation by selecting Start from Simulation menu. The resulting Y and t variables in the workspace will be for the unit set-point response, because D (disturbance) has been disabled. Select the MATLAB command window and type the following commands to obtain a labeled plot of the response. plot(t,Y) xlabel(Time) ylabel(Y) Figure 9 shows the resulting plot. Once a new simulation is performed, SIMULINK will write new values to t and Y. To avoid losing the old values, type t1=t; Y1=Y; to define the new variables t1 and Y1.

6.

Figure 9. Unit set-point response for ITAE (disturbance) settings. 7. Now simulate the unit disturbance response. Double-click on Y sp and set Final value to 0. Double-click on D and set Final value to 1. Again, select Start from the Simulation to begin the simulation. Type plot(t,Y)to view the response. Figure 10 shows the resulting plot.

Figure 10. Unit disturbance response for ITAE (disturbance) Before starting another simulation, type t2=t; Y2=Y; 8. Now simulate the unit disturbance response for ITAE (set-point) by entering the set-point controller settings into the PID controller block and simulating. Type t3 = t; Y3 = Y; after the simulation has ended. Next simulate the unit set-point response for ITAE (set-point) by setting Final value to 0 in D and Final value to 1 in Ysp and simulating. To reproduce Figure C.5 of the textbook, enter the following set of commands at the MATLAB prompt: subplot(211) plot(t1, Y1,-, t, Y, --) xlabel(Time) ylabel(Y) subplot(212) plot(t2, Y2, -, t3, Y3, --) xlabel(Time) ylabel(Y) The subplot(mnp) command breaks the Figure window into an m-by-n matrix of small rectangular panes and makes the p-th pane active. The plot command following subplot will place the plot in the active pane. To learn more, type help subplot. The plot(x1, y1, linetype1, x2, y2, linetype2, ...) command plots x1 vs. y1 with linetype1, x2 vs. y2 with linetype2 and, so on, on the same plot. To learn more, type help

9. 10.

plot. For the set of commands listed above, Figure 11 shows the resulting MATLAB Figure window.

Figure 11. Comparison of PID controllers with ITAE settings for SOPTD model. Solid line ITAE (disturbance); Dashed line ITAE (set-point) Adding the legend for each curve can be tedious. Two commands, which can be used to generate a legend, are text and gtext. If you are motivated, type help text and help gtext to learn how.

10