creating a simple modelghz.elec.uow.edu.au/controllab/ecte344version2015... · web viewyou can use...

21
Experiment 1: Introduction to the control laboratory. Before starting the experiment write down the number of your experimental motor rig in your lab logbook. You should keep using the same rig for all the 5 experiments because each motor has its own unique transfer function. Task 1 - Learning how to use the Simulink software. You can use Simulink ® to model a system and then simulate the dynamic behaviour of that system such as those studied in ECTE344. The basic techniques you use to create a simple model in this tutorial are the same techniques that you use for more complex models in the following experiments. I. Creating a simple model From the Simulink Library Browser, you can create a new model (block diagram) and search for blocks that you want to use in your model. You need MATLAB ® running before you can open the Simulink Library Browser. Perform the following steps. a) From the MATLAB Toolstrip, click the Simulink Library icon . b) You should view a window similar to the one in Figure 1. The left hand window shows the navigation pane of Simulink libraries. Most of the blocks required for ECTE344 can be found under the “Simulink” library, and the subset categories are highlighted in red.

Upload: nguyenkhanh

Post on 21-Apr-2018

217 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Experiment 1: Introduction to the control laboratory.

     Before starting the experiment write down the number of your experimental motor rig in your lab logbook.   You should keep using the same rig for all the 5 experiments because each motor has its own unique transfer function.

  Task 1 - Learning how to use the Simulink software.

        You can use Simulink® to model a system and then simulate the dynamic behaviour of that system such as those studied in ECTE344. The basic techniques you use to create a simple model in this tutorial are the same techniques that you use for more complex models in the following experiments.

I. Creating a simple model

From the Simulink Library Browser, you can create a new model (block diagram) and search for blocks that you want to use in your model. You need MATLAB® running before you can open the Simulink Library Browser. Perform the following steps.

a) From the MATLAB Toolstrip, click the Simulink Library icon .b) You should view a window similar to the one in Figure 1. The left hand window

shows the navigation pane of Simulink libraries. Most of the blocks required for ECTE344 can be found under the “Simulink” library, and the subset categories are highlighted in red.

Page 2: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Figure 1 block categories that are used in ECTE344

c) From the Simulink Library Browser toolbar (Figure 1), click the New Model icon

. A Simulink Editor window opens with a new block diagram. You should see a blank model in a separate window like the one in Figure 2. The commonly used toolstrip shortcut icons are highlighted and labelled in red.

Figure 2 a blank Simulink model

d) Go to the library window. From Figure 1 the “sources” category contains all sources of signals that will be used as inputs to the systems in ECTE344 which could include sine, square wave, and step functions. They can be thought of as our emulated function generator.

Page 3: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

e) Double click on the Sources icon and find the “Sine wave” block, then drag the Sine block onto your blank Simulink model

Figure 3 simulink model with a block

f) By browsing through the library window categories Figure 1, add the following blocks to your model, “Slider Gain”, “Sum”, “Transfer Fcn”, “Scope” and “clock”. You should have an arrangement of blocks like that shown in Figure 4 system blocks.

g) Before connecting the blocks in your model it is best practice to align them, so the lines will be neat and easy to follow. In order to do this, click and drag all the blocks so that they are arranged similar to Figure 4.

Figure 4 system blocks

h) The next step is to connect the signal lines; this can be done by clicking on the arrows on each block then dragging to the desired node. From Figure 5 you can observe that the “>” symbol pointing into a block is an input port and the “>” symbol pointing out of a block is an output port. The black bar is a multiplexer which can be used to combine a scalar signal with another scale signal outputting a vector with the inputs as multiple rows. To add extra inputs double click on the multiplexer as shown in figure 8 and type in the number 3 into the text box.

Page 4: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Figure 5 input/output of a block

Connect the signal lines in your model so that it is configured the same as in Figure 6. Run the model with the default parameters and observe the output waveforms on the scope.

Figure 6 system with signal lines

Figure 7 slider gain

Tip: The Sliding gain block is useful for emulating a continuous scaling of a variable in a Simulink model. Especially in the following labs when the model is connected to external hardware.

Page 5: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Figure 8 adding extra inputs to a multiplexer

II. Running a Simulation

After you have all the model nodes connected we can run the model.

1. From the Simulink Editor menu bar, select Simulation > Run. Tip   Alternatively, you can control a simulation by clicking the Run simulation button ( the green right facing arrow button as shown in figure 2)

III. Observe Simulation Results

After simulating a model you can view the simulation results in a Scope window.

1. Double-click the Scope block.

The Scope window opens and displays the simulation results. The plot shows a sine wave signal with the resulting cosine wave signal.

During the following experiments you will need to take measurements from signals in the Simulink scope. This can be performed in two ways:

1. Zooming in on a point of interest in the Simulink scope2. Exporting the signals to the MATLAB workspace and plotting the results using a

matlab script.

Perform both of these methods on the model you have created in the preceding task. If you do not know how to do this follow the instructions listed as follows:

1) Run the simulation. Open the Simulink scope by double clicking on it. Pick a point of interest on the signal, click and hold on an area around this point by dragging the mouse across the point of interest. This will zoom in the scope over the area you highlighted. You may need to do this a few times to increase the accuracy of your

Page 6: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

measurements.

2) Open the Simulink scope before running the simulation. Click on the scope parameters button, navigate to the History tab and check the "Save data to workspace" box and make sure the variable name is "ScopeData". Also make sure that the "limit data points to last" option is sufficiently high. Approx. 10000. Run the simulation and navigate to the MATLAB command window and type plot(ScopeData.time,ScopeData.signals.values). Open the MATLAB figure. To measure specific values you may want to use the Data Cursor by clicking the data cursor button . Once the data cursor icon is selected a point on the signal can be selected and the data points will be displayed.

Assess the advantages and disadvantages of both of these methods with regards to both signal visualization and taking measurements at specific points.

Tip: If the signals on the scope appear to be under sampled you can unjust the simulation step size in the simulation configuration parameters. That is you could reduce it to be a number much smaller than the period of the input signal. Like 0.001 in this case. However this applicable for offline simulations only. (see figure 9 and figure 10)

Figure 9 seting the number of data points

Page 7: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Figure 10 Model configuration parameters setting the step size, change auto to the desired sample step if your model appears to have a low sampling rate

Question 1.1: What is the gain (output amplitude/input aplitude) of the system in figure 6 (including the slider block) when the input sine block has an amplitude of 1 and a frequency of 0.1Hz (express answer in units of dB )?

Question 1.2: What is the phase shift between the wire labeled1 and the wire labelled 2 in figure 6 in units of degrees?

Question 1.3: Write a description of the functions for the following simulink blocks, Mux, Gain, Slider Gain, Sum and Transfer Function.

Page 8: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Question 1.4: Build a Simulink model that simulates the following differential equation in:

y=∫ x dx+5 xWhere y is the output sink signal signal and x is the input signal. Plot the system outputs when the input is in the form of a step and a sinusoidal signal with a frequency of 0.2Hz. Describe the differences in the dimensions of the input and output signals.

Task 2 – Testing the Hilink motor control

In every lab in ECTE344 you will be required to experiment on a Hilink real time motor. Figure 13 shows an image of the board. This board can be interfaced through matlab so you transmit an input control signal to the motor and receive a signal from a rotary encoder. The key features of the board are shown in Figure 13, A is the reset button which will be needed when the simulation crashes, B is the RS232 serial communications port which is to be connected to the PC. C is the connection to mains AC power. If the board is powered on the green status light will be on.

The Simulink model can run in a similar fashion to the model simulated in the previous tasks. The apparent difference that you will need to take note of is that the model will have a Connect button as shown in figure 11.

Page 9: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Figure 11 hilink motor control board

Figure 12 Simulink hilink real time hardware model

For this task you will be required to test the motor position and speed control systems are working correctly.

1) Navigate the directory to C:\Program Files(x86)\Hilink. Copy and paste all of the files in this folder to another folder that is secure and accessible to you, preferably on your

Page 10: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

USB drive. Then change the MATLAB working directory to your new directory where all the files were pasted.

2) Download the Simulink files needed for this laboratory here3) Open the model from the downloaded content named "Experiment1part1".4) Ensure that the Hilink board is connected correctly to the desktop computer and is

powered on5) In the model window, go to File->model properties, then click the callbacks tab, then

select InitFcn. Define the constants shown in the following figure. Then click apply then click OK once done. Every Simulink model you make for interfacing with hilink will need to have this definition in the callbacks tab (Here STOP_T is stop time deined to be infinite and T defines the sampling period of the Simulink model which is the sampling period of the hilink board.)

6) With the model opened press ctrl+b (or click this button ) to build the model. Note: Every time there is a change in the model (excluding block parameters such as frequency or amplitude) you will need to build the model again.

7) Click on the Connect to Target button on the Simulink tool bar and run the simulation.8) Record your observations, ensure that the model is operating correctly, i.e. on the

scope the output red line roughly follows the input blue line.9) Repeat the process for the file "Experiment1part2"

Page 11: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

IMPORTANT: The source files and library files will always need to be in the same folder (not in subfolders). Like that shown in the following figure.

Figure 13 hilink source code

Task 3 - Developing Subsystems

Open the model "Experiment1part1" from the downloaded files and copy it into your matlab path.

Identify the blocks in the Simulink model that could be combined into one Simulink block that represents the motor where the input is the input voltage and the output is the position of the shaft as shown in the figure below:

This is a PID controlled system which will be studied later in the session.

To create this custom block

Page 12: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Once all relevant blocks are highlighted press "ctrl+g" to create a subsystem. After creating your subsystem delete everything from your model except the subsystem. Double click the gain block at the output of the block E0 and change the gain from 180/pi to 1 for output in radians. Change the label from "Subsystem" to "MPradians" signifying that it is motor position (radians) and save your model as "MPradians.mdl".Now create a subsystem Double click the gain block at the output of the block E0 and change the gain from 180/pi to 1 for output in radians. Change the label from "Subsystem" to "MPradians" signifying that it is motor position (radians) and save your model as "MPradians.mdl".

1) Highlight the blocks you think need to be included in the motor position block by holding "Shift" and clicking each block that needs to be included.

2) Once all relevant blocks are highlighted press "ctrl+g" to create a subsystem. After creating your subsystem delete everything from your model except the subsystem.

3) Double click the gain block at the output of the block E0 and change the gain from 180/pi to 1 for output in radians. Change the label from "Subsystem" to "MPradians" signifying that it is motor position (radians) and save your model as "MPradians.mdl".

4) Follow the same procedure to find a motor speed block. This can be done using the model "Experiment1part2" downloaded at the start of the experiment. Find the block for speed output in radians/sec. Save this subsystems and "MSradians".

Note: The shaft is always subject to a sinusoidal dithering signal for position control. This is to reduce the non-linear effects of static friction. Hence the high frequency sinusoid being fed into H0 must be included in the motor position subsystem.

Note: The model "Experiment1part2" is already in rad/sec so no need to convert. Also since the speed block is typically already constantly moving there is no need for a dithering signal.

Page 13: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Figure 14 example of creating a subsystem

IMPORTANT: Save these subsystem blocks in an accessible and secure location such as a USB drive or a network drive, you will need both MPradians.mdl MSradians.mdl in the later experiments

Question 1.5: Draw a sketch on the contents of the subsystem you have created MPradians.mdl. Write annotations explaining what the purpose of each block is.

Question 1.6: When you changed the output units of the subsystem MPradians.mdl did the output response of the system change? Suggest a reason for this. (Hint: the answer has something to do with the units of the PID gains but try to explain in terms of what changing the units has on other signals in the model)

Page 14: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Question 1.7: Draw a sketch of the MSradians subsystem. Write annotations explaining what the purpose of each block is.

For the next task we are going to create subsystems that can be used to emulate a real time function generator you will be required to construct the following model. The block between points A and B represent some sort of dynamic system and the mux and scope represent an output measurement device. The rest of the blocks are an input excitation source.

Figure 15 phase and gain measurement

Tip: You can add extra input and outputs to a subsystem by from the library browser under sinks-> output and soucres-> input

Page 15: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Note: this task may be quite challenging and you might not finish it this lab, however you should make an attempt and aim to have a result by week 6.

Challenge Question 1.8: Describe the relationship between the signals at the output of each sine block in figure 14.

Challenge Question 1.9: Construct the model shown in figure 14. Set the stop time to inf and run the model. What is the frequency in Hz in the diagram? Set the frequency to 5Hz and then determine the phase shift between points A and B on the block Diagram using the slider gain that is set to‘?’.

Challenge Question 1.10: Create a subsystem from the model used in question 1.9, with two outputs labelled reference and a input signal that can be used to measure the phase shift between two signals in real time. Save this subsystem to a safe location you will need it in the later experiments.

Challenge Question 1.11: Similarly to the previous task, create a subsystem, which will generate two output signals labelled reference and input that can be used to measure the ain between two signals in real time. Save this subsystem to a safe location you will need it in the later experiments.

HINT: An example of a correct solution could look like this…

Page 16: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

Task 4 - DC motor speed: Simulink modelling

Download the following Simulink file: (Right Click -> save as)

http://ctms.engin.umich.edu/CTMS/Content/MotorSpeed/Simulink/Modeling/Motor_Model.mdl

Modify the model by following these steps:

1) Delete the input and output terminals by right click on it and select delete.

2) Connect a step block from the Source section of the Simulink Library Browser to the voltage input of the DC motor.

3) Connect a scope from the Sink section of the Library to the speed output of the DC motor block.

4) Simulate the speed of the motor to a step voltage. This is the step response of the DC motor.

5) Change the motor parameters to the following displayed in Code 1. By executing them in the main Matlab command terminal:

R = 5.22;

L = 0.00295;

b = 0.0000109;

J = 0.00000208;

Ke= 0.0234;

Kt = 0.0234;

6) Simulate the step response of the DC motor for the step inputs with the following final values: 1, 4, 7, 10, 13 and 16 (set by double clicking the step block).

Question 1.12: Comment on the similarity and difference of these step responses when the final step value is set to a different final values.

Page 17: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

7) Obtain a Saturation block in the Discontinuities section from the Simulink Library Browser. Insert it between the step block and the DC motor in order to simulate the saturation of the Hilink board.

8) Set the upper and lower limit of the block to 8 and -8, by double clicking on the saturation block and entering the limits.  Repeat the simulation using the same step inputs and make comments on similarity and difference of the step responses.

Question 1.13: Compare the simulation results with and without the saturation and comment on the effects of the saturation.

Question 1.14: If the saturation is unknown how can you determine the saturation in terms of its upper and lower limit using step responses based on experience gained in the above simulation?

Further Reading

[1] Mathworks. (2015). Creating and Simulating a Simple Model. Available: http://au.mathworks.com/help/physmod/simscape/ug/creating-and-simulating-a-simple-model.html

[2] R. C. Dorf, R. H. Bishop, Modern Control Systems: Prentice Hall, 2010.

[3] K. Ogata, Modern Control Engineering: International Version, 5th ed.: Pearson Education, 2008.

Page 18: Creating a simple modelghz.elec.uow.edu.au/controllab/ECTE344version2015... · Web viewYou can use Simulink® to model a system and then simulate the dynamic behaviour of that system

[4] B. M. D. Tilbury. (2015). Control Tutorials for MATLAB and Simulink (CTMS). Available: http://ctms.engin.umich.edu/CTMS/index.php?aux=Home