EET ATOMATIC CONTROL SYSTEM LAP

profileAyn12
Lab3B-SimulinkTrainModelII.docx

Laboratory Exercise 3B

Simulink Modeling – Train System

Simulink Control

Week of 2 of this lab, we will look at the following:

· The open-loop plant model

· Implementing a PID controller in Simulink

· Running the closed-loop model

· Extracting a model into MATLAB

The open-loop plant model

In week 1 of this lab, we demonstrated how Simulink can be employed to simulate a physical system. More generally, Simulink can also simulate the complete control system, including the control algorithm in addition to the physical plant. As mentioned previously, Simulink is especially useful for generating the approximate solutions of mathematical models that may be prohibitively difficult to solve "by hand." For example, consider that you have a nonlinear plant. A common approach is to generate a linear approximation of the plant and then use the linearized model to design a controller using analytical techniques. Simulink can then be employed to simulate the performance of your controller when applied to the full nonlinear model. Simulink can be employed for generating the linearized model and MATLAB can be employed for designing the controller as described in the other Introduction pages. Various control design facilities of MATLAB can also be accessed directly from within Simulink. We will demonstrate both approaches in this page.

Recall the Simulink model of the toy train system that was built in part 1 and pictured below.

http://ctms.engin.umich.edu/CTMS/Content/Introduction/Simulink/Control/figures/inoutv.png

Assuming that the train only travels in one dimension (along the track), we want to apply control to the train engine so that it starts and comes to rest smoothly, and so that it can track a constant speed command with minimal error in steady state.

Week Two: Implementing a PID controller in Simulink

1. Open the model created last week.

2. Let us first create the structure for simulating the train system in unity feedback with a PID controller. In order to make our Simulink model more understandable, we will first save the train model into its own subsystem block. To accomplish this, delete the three scope blocks and replace each one by an Out1 block from the Sinks library.

3. Label each Out1 block with the corresponding variable name, "x1_dot", "x1", and "x2".

4. Delete the Signal Generator block and replace it with an In1 block from the Sources library.

5. Label this input "F" for the force generated between the train engine and the railroad track. Your model should now appear as follows:

6. Next select all of the blocks in your model (Ctrl A) and right click from the model to choose Create Subsystem (Ctrl G). With a little rearranging and relabeling, your model will appear as shown below.

7. Now we can add a controller to our system. We will employ a PID controller which can be implemented using a PID Controller block from the Continuous library. Placing this block in series with the train subsystem, your model will appear as follows.

8. In the following, we model the controller as generating the force "F" directly. This neglects the dynamics with which the train engine generates the torque applied to the wheels, and subsequently neglects the dynamics of how the force is generated at the wheel/track interface. This simplified approach is taken at this point since we only wish to introduce the basic functionality of Simulink for controller design and analysis.

Double-clicking on the PID Controller block, we will initially set the Integral (I) gain field equal to 0 and will leave the Proportional (P) and Derivative (D) gains as their defaults of 1 and 0, respectively.

9. Add a Sum block from the Math Operations library.

10. Double-click on this block and modify the List of signs field to "|+-".

11. Since we wish to control the velocity of the toy train engine, we will feedback the engine's velocity. This is accomplished by 4ring a line off of the "x1_dot" signal and connecting it to the negative sign of the Sum block. The output of the Sum block will be the velocity error for the train engine and should be connected to the input of the PID Controller block. Connecting the blocks as described and adding labels, your model should appear as follows.

12. Add a Signal Builder block from the Sources library to represent the velocity commanded to the train. Since we wish to design a controller to bring the train smoothly up to speed and smoothly to rest, we will test the system with a velocity command that steps up to 1 m/s followed by a step back down to 0 m/s (recall that our system is a toy train). To generate this type of command signal, double-click on the Signal Builder block. Then choose Change time range from the Axes menu at the top of the block's dialog window.

13. Set the Max time field to "300" seconds.

14. Set the step up to occur at 10 seconds and the step down to occur at 150 seconds. This is accomplished by clicking on the corresponding portions of the signal graph (left and right vertical lines) and either dragging the line to the desired position, or entering the desired time in the T field at the bottom of the window. When done, your signal should appear as follows.

http://ctms.engin.umich.edu/CTMS/Content/Introduction/Simulink/Control/figures/signal.png

15. Also add a Scope block from the Sinks library and use it to replace the Out1 block for the train's velocity. Relabeling the blocks, your model will appear as follows.

We are now ready to run the closed-loop simulation.

Running the closed-loop model

Before running the model, we need to assign numerical values to each of the variables used in the model. For the train system, we will employ the following values.

· M1 = 2 kg

· M2 = 1 kg

· k = 1 N/sec

· F = 1 N

· μ = 0.02 sec/m

· g = 9.8 m/s^2

16. Create a new m-file and enter the following commands.

M1 = 2;

M2 = 1;

k = 1;

F = 1;

mu = 0.02;

g = 9.8;

17. Execute your m-file in the MATLAB command window to define these values. Simulink will recognize these MATLAB variables for use in the model.

18. We need to set the time for which our simulation will run to match the time range of the command from the Signal Builder block. This is accomplished by selecting Model Configuration Parameters from the Simulation menu at the top of the model window and changing the Stop Time field to "300".

19. Run the simulation and open the "x1_dot" scope to examine the velocity output (hit autoscale). The result as shown below demonstrates that the closed-loop system is unstable for this controller.

(Capture this for Lab Report)

20. Since the performance achieved above is unsatisfactory, we need to redesign our controller. We will first demonstrate how to extract a model from Simulink into MATLAB for analysis and design. Then we will demonstrate how to design the control from directly within Simulink.

Extracting a model into MATLAB

The Simulink Control Design toolbox offers the functionality to extract a model from Simulink into the MATLAB workspace. This is especially useful for complicated or nonlinear simulation models. This is also useful for generating discrete-time (sampled) models. For this example, let us extract a continuous-time model of our train subsystem.

21. First we need to identify the inputs and outputs of the model we wish to extract. The input to the train system is the force F. We can designate this fact by right-clicking on the signal representing "F" (output of the PID block) and choosing Linearization Points > Input Point from the resulting menu.

22. Likewise, we can designate the output of the train system by right-clicking on the "x1_dot" signal and choosing Linearization Points > Output Point from the resulting menu. These inputs and outputs will now be indicated by small arrow symbols as shown in the following figure.

23.

Since we wish to extract a model of the train by itself, without control, we need to further delete the feedback signal, otherwise we will extract the closed-loop model from F to . Your model should now appear as follows:

Note: the figure above was likely generated in an earlier version of MATLAB. Your input and output symbols may look different.

24. We can now extract the model by opening the Linear Analysis Tool. This is accomplished by selecting Control Design > Linear Analysis from under the Analysis menu at the top of the model window. Following these steps will open the window shown below.

http://ctms.engin.umich.edu/CTMS/Content/Introduction/Simulink/Control/figures/train_lin.png

25. This tool generates an LTI object from a (possibly nonlinear) Simulink model and allows you to specify the point about which the linearization is performed. Since our Simulink model is already linear, our choice of operating point will have no effect and we can leave it as the default Model Initial Condition. In order to generate the linearized model, select the Linearize button in the above figure, which is indicated by the green triangle. The Linear Analysis Tool window should now appear as shown below.

Capture the Step Plot below for report:

26. Inspecting the above, the step response of the linearized model was automatically generated. Comparing this step response to the one generated by the simulation of the open-loop train system in the Introduction: Simulink Modeling page, you can see that the responses are identical. This makes sense since the simulation model was already linear. Additionally, the linearization process generated the object linsys1 shown in the Linear Analysis Workspace above. This LTI object can be exported for use within MATLAB by simply dragging the object into the MATLAB Workspace window immediately above the Linear Analysis Workspace window.

27. Having extracted this model, we can now employ all of the facilities that MATLAB offers for controller design. For example, let us employ the following commands to generate and analyze the closed-loop system reflecting the Simulink model created above. Report your results below:

sys_cl = feedback(linsys1,1);

pole(sys_cl)

ans =

-0.9747 + 0.0000i

0.0000 + 0.0000i

-0.2087 + 1.1332i

-0.2087 - 1.1332i

Examination of the above demonstrates that the closed-loop system in its current state has poles with positive real part and, therefore, is unstable. This agrees with the result of our closed-loop simulation from above. We can then employ MATLAB or Simulink to design a new controller.

Questions :

1. In step 19, how can you tell that system is unstable from the plot?

2. Use Simulink scope block and plot acceleration, velocity and displacement of the two individual masses in the train model. There should only be two plots.

3. Write out the mathematical relation between acceleration, velocity and displacement?

4. In the train model, we are taking into account force along the horizontal axis but why not along the vertical axis?

9