Feedback Control Systems Lab #3 Assignment The

0 downloads 0 Views 1MB Size Report
In order to be able to download your Simulink block diagram to Arduino, you need to ... Obtain the bode plot by applying sinusoidal inputs and compare with ...
EEE 342 – Feedback Control Systems Lab #3 Assignment The goal of the third lab is to perform system identification studies on a physical DC motor in frequency domain. You will first repeat the model based system identification procedure you performed in the first lab, then you will perform a frequency domain system identification by using sinusoidal signals on hardware. Finally, effect of time delay will be investigated on the frequency response. NOTE: Please save all the result figures you obtained during the lab, since you will not be able to repeat the experiments and there will be too many figures to deal with. Put all the figures and results to your lab report including necessary explanations. Q.1. Our first job is to perform a system identification strategy for our physical DC motor platform. The steps are as follows •

Apply 9 V step input to the DC motor and obtain the step response.

Step 0. Please close Matlab 2012b and plug your USB cable for Arduino and wait until COM port assigned. Then, you can open Matlab 2012b. Step 1. Create a workspace folder in desktop and download lab1_velocity_step_response.slx file from Moodle into this folder. Step 2. Set your Matlab current workspace directory to your own workspace directory. Step 3. Open lab1_velocity_step_response.slx file and configure voltage source to give 9 V step input at time 0. Please see the below figure.

1

Step 4. In order to be able to download your Simulink block diagram to Arduino, you need to configure your Simulink file lab1_velocity_step_response.slx to run on target hardware as seen below. (Click Prepare to Run)

Step 5. In the pop-up menu, select Arduino Uno as target hardware and click apply.

2

Step 6. Make sure that in the new pop-up menu target hardware is Arduino Uno and configure Serial 0 baud rate as 115200.

Step 7. If everything is correct, your menu should look like below.

3

Step 7.5. Enter the configuration settings of Simulink diagram, open the solver tab and change Solver option type to Fixed-Step and fixed step size to 0.01.

Step 8. Click and open “DC Motor Plant” block and make sure that your Matlab directory is same with your workspace directory. Then, click and open Encoder block.

4

Step 9. Click Build button in order to compile encoder c-function.

Step 10. Your compilation result should look like this.

5

Step 11. Close c-function-builder and you should see that compiled files should be seen on your workspace folder like below.

Step 12. Click Build Model button to download your design to Arduino. This process can take 10-20 seconds.

Note that you programmed your block diagram in order to transmit the velocity data via serial communication. In order to receive and process this data, you need to use another Simulink file, whose details will be given below.

6

Step 13. Download and open velocity_read.slx file from Moodle into your workspace folder. Note that this file will work on the computer side, so you do not need to configure it to work in Arduino Target.

Step 14. Open Receive from Arduino block and choose the newly assigned COM port. Then, open Serial Configuration block and repeat the same procedure.

Step 15. Now click run button to start simulation. Please hold the DC motor to stabilize.

Step 16. Plot and save the response in order to visualize the step response of the DC motor.

7

Q.2. Fit a first order transfer function to the received DC motor step response data. Then, implement this transfer function in a new Simulink file and obtain the step response for 9 V input. Note that you are working in simulation environment, not in Arduino. - Compare the step response of estimated transfer function and DC motor in the same graph. Q.3. Use the following code sample to generate the bode plot of the estimated transfer function. Please do not forget to update A and B parameters of the transfer function, G, in the following code sample with the one you estimated in the previous question. w = logspace(-1,2,100); for k = 1:100 s = 1i * w(k); G(k) = A / (s+B); end subplot(2,1,1) semilogx(w,20*log10(abs(G))); grid on subplot(2,1,2) semilogx(w,angle(G)*180/pi) grid on Q.4. Obtain the bode plot by applying sinusoidal inputs and compare with theoretical Computations. Step 1. Download lab3_sinusoidal_input.slx and lab3_velocity_read.slx files to your working directory. Please don’t forget to repeat Step 4 to Step 16 of Q.1. by doing necessary modifications in order to configure the following files for hardware experiments. • •

lab3_sinusoidal_input.slx file can be used to give sinusoidal inputs to the DC motor plant. This file requires an input angular frequency of the desired sinusoidal. lab3_velocity_read.slx file can be used to read the velocity output of the DC motor. Please DO NOT use the lab1_velocity_read.slx file in this part.

SYSTEM ID PROCEDURE: Repeat the following Step 2 to Step 7 for each of the angular frequency inputs in the following table for the corresponding time durations. Angular Frequency (rad/s) 0.1 0.6 3 10 30 60

Simulation Duration (s) 70 70 25 10 10 10

8

Step 2. Open lab3_sinusoidal_input.slx and open Angular Frequency input block

Step 3. Set the angular frequency to your desired angular frequency value from the table

Step 4. Build lab3_sinusoidal_input.slx file to embed the software into Arduino. Note that Angular frequency block shows the given angular frequency value.

9

Step 5. Open lab3_velocity_read.slx file and set the communication ports as you did in Q.1. Step 14. Then set the simulation time duration corresponding to your given angular frequency in the table. Then press run button to read data from the Arduino.

Step 6. Plot both input sinusoid and the output sinusoid coming from the Arduino on the same graph. Note that the following script generates the input sinusoid. You need to plot input generated by the following code and the output velocity coming from Arduino on the same graph with different colors. Your result should look like below. angular_frequency = 0.1; duration = 70; t = 0:0.01:duration; input = 10*sin(angular_frequency * t);

10

Step 7. Take Fast Fourier Transform (FFT) of both input and output signals by using Matlab’s ‘fft’ command. Note that the resulting values are complex numbers. •

Magnitude: Find magnitude of the signals found in Step 7 by using Matlab’s ‘abs’ command. The index of the maximum value of the absolute fft signal corresponds to the frequency value you are working on. Therefore, you can find the gain of the DC motor plant at this specific frequency by dividing the maximum value of the output to the maximum value of the input. [maxVel, maxVelIndex] = max(abs(fft(velocity.signals.values))) 𝐾=



max⁡(𝑎𝑏𝑠(𝑓𝑓𝑡(velocity. signals. values))) max⁡(𝑎𝑏𝑠(𝑓𝑓𝑡(𝑖𝑛𝑝𝑢𝑡)))

Note that maxVelIndex represents the index of the maximum value in the absolute velocity signal. Phase: Find the phase of the both fft signals and find the phase difference by subtracting the phase of the input signal in maxVelIndex from the phase of the velocity signal in the same index as shown below. 𝜙𝑣𝑒𝑙𝑜𝑐𝑖𝑡𝑦 = 𝑎𝑛𝑔𝑙𝑒(𝑓𝑓𝑡(velocity. signals. values)) 𝜙𝑖𝑛𝑝𝑢𝑡 = 𝑎𝑛𝑔𝑙𝑒(𝑓𝑓𝑡(𝑖𝑛𝑝𝑢𝑡)) 𝜙 = 𝜙𝑣𝑒𝑙𝑜𝑐𝑖𝑡𝑦 (𝑚𝑎𝑥𝑉𝑒𝑙𝐼𝑛𝑑𝑒𝑥) − 𝜙𝑖𝑛𝑝𝑢𝑡 (𝑚𝑎𝑥𝑉𝑒𝑙𝐼𝑛𝑑𝑒𝑥)

• Save both 20*log10(K) and ∅ values in an array to use them later for bode plot generation Step 8. Plot both the magnitude and phase graphs using 20*log10(K) and ∅ values on the figures you generated in Q.3 for comparison.

Q.5. The hardware system has a time delay of 10 ms due to the processing requirements. Therefore you may observe a phase difference in the high frequencies. The main reason for this problem is that you did not consider the effect of time delay in your estimated transfer function. Step 1. Make a first order Pade approximation for the 10 ms time delay and update your transfer function as 𝐺𝑑𝑒𝑙𝑎𝑦𝑒𝑑 (𝑠) = 𝐺(𝑠)

1 − 0.005𝑠 1 + 0.005𝑠

Step 2. Please draw the bode plot of the new estimated transfer function on the Bode plot comparison you obtained in Step 8 of Q.4. Note that you will have three Bode plots on the same graph; estimated transfer function in Q.2., estimated transfer function in Q.5 and experimental Bode obtained in Q.4. for both magnitude and phase.

11