mech 412 lab 1 manual with appendix

15
MECH 412 System Dynamics and Control Laboratory 1 Manual Version 1.3 Ryan J. Caverly, Prof. M. Nahon, Prof. I. Sharf and Prof. J. R. Forbes Department of Mechanical Engineering McGill University Winter 2014

Upload: minjae-lee

Post on 19-Jul-2016

26 views

Category:

Documents


11 download

DESCRIPTION

mcgill lab

TRANSCRIPT

Page 1: MECH 412 Lab 1 Manual With Appendix

MECH 412System Dynamics and Control

Laboratory 1 Manual

Version 1.3Ryan J. Caverly, Prof. M. Nahon, Prof. I. Sharf and Prof. J. R. Forbes

Department of Mechanical EngineeringMcGill University

Winter 2014

Page 2: MECH 412 Lab 1 Manual With Appendix

1

Introduction

Preamble

This lab manual serves as a guide to the first laboratory concerning the control of a flexible-joint designed and built by Quanser Consulting Inc. The prelaboratory questions that you did inAssignments 1-3 were intended as a guide through the dynamic modelling of the flexible-joint.They are included in the Appendix of this document. This laboratory manual will guide youthrough the first lab.

Also note that this lab manual differs from a traditional lab manual in the sense that everystep includes an instruction and an explanation. The purpose of this is for you, the student, toobtain a greater understanding of the use of each step.

Page 3: MECH 412 Lab 1 Manual With Appendix

2

Laboratory 1: Experimental Open-LoopSystem Response

Problem Statement

Using the system model created in Assignment 2, experimentally find the open loop systemresponse of the actual Quanser flexible-joint system. The Simulink model created in Assignment2 will be modified to connect to the physical system in real-time using QuaRC software.

Prelaboratory: Modelling of System

The following must be completed before attending the lab:

1. Lab-related questions in Assignments 1 to 3.

2. Bring a copy of your Simulink model from Assignment 2 to the lab.

3. Download the SafetyCheck.mdl file found on MyCourses and bring it to the lab.

Laboratory Procedure

Part 1: Setup

1. Log in to your EMF account on the PC at the lab station.

2. Open up matlab2011a and set the working directory to the one that contains yourSimulink model. It is recommended to save your Simulink model to the H: drive.

Page 4: MECH 412 Lab 1 Manual With Appendix

3

3. In matlab’s Command Window type “mex -setup”. Note the space between “mex” and“-setup.” You will be asked “Would you like mex to locate installed compilers [y]/n?”;type “y”. A list of compilers will be listed. Select “Microsoft Visual C++ Studio 2010 in...”. Confirm your selection by typing “y” when prompted once more. (Note, you shouldonly have to do this once. If you have done this before, you will not have to complete thisstep again, nor the next time you run the experiment.)

4. Open your Simulink model from Assignment 2 in matlab. Ask Mario or the TA to checkyour Simulink model before continuing.

5. Open up the Simulink Library Browser and add “Add,” “Mux,” and “Gain” blocks to yourmodel.

• Use the Add block to add up the output signals θ and α.

• Connect the θ + α signal to one input of the Mux block.

• Set the Gain block to 180/pi and connect the input of the gain block to the wire leadinginto the state-space block. Connect the output of the gain block to the other input ofthe Mux block.

• Attach the output of the Mux block to a scope. This scope will now output θ + α andthe input signal.

6. Open up the Simulink Library Browser (located in the toolbar and also in the View tab)and search for “hil initialize” (this may take a long time).

• You should find a block that says QuaRC on it. If Simulink cannot find the “hilinitialize” block, save your Simulink model and have your group partner log intotheir EMF account on the computer.

• Drag this block into your model in a place that it does not interfere with anything else.

The HIL (Hardware In the Loop) Initialize block will allow you to connect to the dataacquisition card and read/write information to the Quanser flexible-joint.

7. Open the HIL Initialize block (double-click) to change the following settings:

• In Main, change the Board type to “q2 usb”.

• In Analog Inputs, add analog inputs #0 and #1 to the channels selected.

• In Analog Outputs, add analog output #0.

• In Encoder Inputs, add encoder inputs #0 and #1 and change the encoder quadratureto [4].

8. Click and drag to highlight the state-space block and to select blocks shown in Fig. 1.

Page 5: MECH 412 Lab 1 Manual With Appendix

4

• Right click and choose “create subsystem”.

• Double-click on your new subsystem and you will see the blocks that you just high-lighted.

This subsystem will allow you to add blocks to connect to the flexible-joint without crowdingyour higher level model.

Fig. 1 Blocks to select for subsystem.

9. Enlarge your subsystem window and delete everything in the subsystem except for theinput and output ports.

• Open up the SafetyCheck.mdl file and copy the SafetyCheck block into your subsys-tem.

• In the Simulink Library locate and add a “Gain”, “Saturation” and “HIL Write Ana-log” block to your subsystem and connect them all to the input port (In1→InputVoltageof SafetyCheck→Gain→Saturation→HIL Write Analog).

• Set gain to -1 and the saturation limits to -9 and 9. Verify that the HIL Write Analogblock is set to channel 0 by double-clicking it.

The gain is set to -1 so that a positive voltage turns the flexible-joint counter-clockwise.The Saturation block is added to ensure that the voltage sent to the motor is no more than90% of its maximum voltage, even if your input voltage surpasses this. The SafetyCheckblock ensures that the flexible-joint will not rotate past |θ| = 90 degrees and will neverreceive a voltage higher than 12 V.

10. Add an “HIL Read Encoder”, “Mux”, “Demux” and “Gain” block to your subsystem.

• Set the gain to 2*pi/4096.

Page 6: MECH 412 Lab 1 Manual With Appendix

5

• Set the HIL Read Encoder so that it uses channels #0 and #1. If you get an errorregarding the sample time of the HIL Read Encoder block, replace “qc get step size”in the “Sample time (seconds)” with -1.

• Connect the blocks as HIL Read Encoder→Mux→Gain→Demux→Output 1 and 2.

The gain is set to 2π/4096 in order to convert the angle measured by the encoder intoradians. The encoder quadrature is set to [4], which means that it measures 4096 countsper revolution.

11. Connect the input theta of the SafetyCheck Block to the wire that corresponds to the mea-surement of θ, as seen in Fig. 2(b).

12. You can rename our input “Vin” and your outputs “theta” and “alpha” for convenience byclicking on “In1”, “Out1” and “Out2”.

13. Return to your high level model, click on the dropdown box in the upper toolbar that says“Normal” and change it to “External”. Notice that the stop button is replaced by a “Connectto Target” button.

By switching to External mode, the model will be run through QuaRC, which will allowyou to perform the experiment in real-time.

14. Delete the “To file” blocks from your model, if you have any.

• In the Simulink Library search for the “To host file” block and add it to the Simulinkmodel. Attach it to the wire that connects to the θ + α scope.

• Double-click on the “To host file” block and change the file name to “theta plus alpha data.mat”and the variable name to “theta plus alpha data”.

15. In the QUARC menu select Options. Make sure the following settings are properly set:

• Solver menu→Type: Fixed-Step

• Solver menu→Solver: ode4 (Runge-Kutta)

• Solver menu→Fixed-step-size: 0.005

• Code Generation menu→System target file

A fixed-step solver is required to perform real-time HIL experiments, since the step sizecannot vary in real time.

Page 7: MECH 412 Lab 1 Manual With Appendix

6

Part 2: Open Loop Frequency Response

In part 2 of this lab you will operate the open loop system at various input frequencies inorder to experimentally produce a Bode diagram of the flexible-joint.

1. In Assignment 2, you had set the signal generator for a step (or square wave) input. Youshould now set it to provide a sine wave.

• Set the signal generator to a 0.05 Hz sine wave.

• Set the amplitude of the sine wave to 20 (20 degrees represents the actual angle ofmotion of the link) and enter pi/180 in the gain block to convert degrees to radians.

The magnitude of this input sine wave will remain constant at 20 degrees throughout theexperiment.

2. Set the experiment time to “inf” in the box beside “External” in the toolbar.

This will allow you to keep the experiment running until you have collected the requiredinformation.

3. Your Simulink model should now look something like Fig. 2. If there are any discrepancieswith your model, make the necessary changes.

Page 8: MECH 412 Lab 1 Manual With Appendix

7

(a) High-level Simulink model block diagram.

(b) Subsystem Simulink model block diagram.

Fig. 2 Simulink model block diagrams.

4. Make sure the matlab working directory is set to the location of your Simulink file. Thisshould be the H: drive.

5. Build the Simulink model clicking Build (or ctrl B) in the QUARC menu. The model isfinished building once the matlab Command Window says:### Model [name of your Simulink model] has been downloaded to target ‘shmem://quarc-target:1’

Page 9: MECH 412 Lab 1 Manual With Appendix

8

If you see any red text in the matlab Command Window, notify the TA or Mr. MarioIacobaccio.

The QuaRC Build command will convert your graphical block diagram code into C codefor matlab to run.

6. Now that the model is built and ready to run, turn on the VoltPAQ-X1 amplifier on the desk.The switch is on the back of the amplifier, just above the plug input. When the amplifier isswitched “on”, you will hear it “power up”. Make sure that there is nothing in the path ofthe flexible-joint. The VoltPAQ-X1 amplifier is required to regulate the voltage being sentto the motor.

7. Before continuing with the experiment, the TA or Mario should check to make sure thatyour Simulink model is correctly wired.

8. In the Simulation menu, click “Connect to Target” to connect to the data acquisition card.Once you see the blue status bar appear in the lower right of the window, the experiment isready to run.

By connecting to the target you are initializing your model to be run through QuaRC.

9. In your Simulink model, open up the scope for θ + α. Make sure you can see the entireSimulink model and the scope.

10. Manually rotate the arm of the testbed so that the arm points outward and is aligned withthe white mark for zero angle (θ=0). Now to start the experiment, click the play button.NOTE: Make sure you keep the mouse over the play button, which turns into the stopbutton, while the experiment is running. If at any point during the experiment the systembehaves in an unexpected manner (e.g., nothing happens for more than 5 s when you pressstart, there are large oscillations, the motor cuts in and out, there is a loud noise, etc.), pressthe stop button immediately. If this happens, verify your numeric values and connectionsin Simulink before rerunning the experiment. If something is wrong, ask for assistance.

11. Stop the experiment after you have obtained at least a full period of the output sine wave.During or after the experiment you can scale the scopes by right-clicking on the scopes andselecting “Autoscale”. The Simulink scopes often do not retain all the required informa-tion, so it is highly recommended to plot your results from the matlab command window.You can do this using the commands “load theta plus alpha data”,“plot(theta plus alpha data(1,:),theta plus alpha data(2,:),theta plus alpha data(1,:),theta plus alpha data(3,:))”, “grid on”.You can recall these commands later by pressing the up arrrow on the keyboard while inthe command window.

12. Using a plot of θ+α versus time, note down the peak-to-peak amplitude (Exp. Amplitude)of the flexible-joint and the phase difference between the flexible-joint and the input sine

Page 10: MECH 412 Lab 1 Manual With Appendix

9

wave. You can use the data cursor tool in the matlab figure to find the exact values. Thistool is located three icons to the right of the zoom out icon in the upper toolbar. Also notethe frequency of the input sine wave. It is recommended to use Microsoft Excel or matlabto store your readings. You should create a table that looks like the one in Table 1.

Freq. (Hz) Freq. (rad/s) tp input tp output Exp. Amplitude (deg) Gain (dB) Phase Angle (deg)0.05 0.3141590.1 0.62832...

Table 1: Suggested table for experimental results.

To calculate the phase difference between the flexible-joint response (output) and the inputsine wave, use the following.

Phase Angle (degrees) = freq · (tp input − tp output)(360 degrees), (1)

where freq is the frequency of the input sine wave in Hz, tp input is the time of a peak ofthe input wave, and tp output is the time of the corresponding peak of the output response.

13. Repeat steps 8 to 12 varying the frequency of the sine wave from 0.1 to 1 Hz in steps of0.3 Hz and then from 1 to 7 Hz in steps of 2 Hz. If you get an error while attempting toConnect to Target, try building the file again.

14. Note down the frequency of each test in rad/s by multiplying the frequency in Hz by 2*pi.

15. Find the amplitude gain of the system for each test in dB using

Gain (dB) = 20 log

(Amplitude (deg)

40 deg

)16. Now plot Gain (dB) versus frequency (rad/s) using a logarithmic scale x-axis.

If you save your data in array form within matlab, you can create your plot using thecommand “semilogx([name of your data]).”

17. Replot the first linear region of the graph using the same logarithmic scale x-axis and findthe equation of the logarithmic trendline of best fit (this will be a straight line on the semi-logarithmic plot). In Excel the logarithmic trendline of best fit is given as log base e. Youwill have to convert this to log base 10 in order to find the slope in dB/decade.

18. Plot the phase angle of the system in degrees versus frequency using a logarithmic scalex-axis.

Page 11: MECH 412 Lab 1 Manual With Appendix

10

Part 3: Shutdown Procedure

1. To shutdown, turn off the VoltPAC-X1 amplifier (using the same switch on the back of theamplifier). Close Simulink. Close matlab.

2. Please leave everything as you found it. If anything is broken, or “seems wrong”, notifythe TA or Mr. Mario Iacobaccio.

Questions

1. In Assignment 3, you obtained the transfer function G2(s). Use Matlab to draw the Bodeplot of that transfer function. How does your experimental Bode diagram match the oneobtained theoretically? Provide your experimental and theoretical Bode plots in the samediagram.

2. What is the slope of the low frequency region of the Bode diagram magnitude plot youfound experimentally (slope of logarithmic base 10 trendline of best fit)? Does it seem tomatch the slope of the Bode diagram of the theoretical transfer function?

3. How reliable are your measurements at the higher frequencies? What factors could beaffecting your high-frequency measurements?

To Submit

Submit a brief lab report (5-7 pages recommended) comprising of the following sections:

• Introduction: provide context for the lab. What were the objectives of this experiment?Write 2-3 paragraphs in your own words (do not copy the manual).

• Answers to all laboratory questions: provide one paragraph of text and supporting figuresas required. Keep the figure presentation concise.

• Conclusion: discuss your results and sources of error. What can be said about the success ofyour experiment, and the validity of your theoretical model of the system? (2-3 paragraphsrecommended length).

Page 12: MECH 412 Lab 1 Manual With Appendix

11

Appendix

Page 13: MECH 412 Lab 1 Manual With Appendix

Prelab 1. Figure 1(a) shows the Quanser flexible-link experimental testbed. It consists of an electric motor driving a square-shaped rotor. A beam is attached to the rotor with springs. Later in this course, we will be designing controllers for this system to minimize the beam’s vibration. Figure 1(b) shows a schematic of the testbed, in which are shown the rotor and the beam. We denote the rotation of the motor by θ and the rotation of the beam, relative to the rotor, by α. The rotor is considered to have a moment of inertia Jeq, and the beam has a moment of inertia JL, both about the origin shown.

Figure 1(c) shows another schematic showing the same components, but also showing the torque applied by the motor, τ, the damping internal to the rotor assembly, Beq, the aerodynamic damping acting on the arm, BL, and the stiffness of the rotational spring attaching the beam to the rotor, KS. The torque applied by the motor on the rotor can be written as , where Vm is the voltage applied to the motor.

Figure 1(c)

In our mission to design a motor controller for this system, we will start off, in this assignment, by deriving the equations of motion for this system. Derive the two coupled second-order differential equations, in θ and α, that govern the motion of this system. In these equations, the input voltage should appear on the right-hand side, and all terms containing the variables θ and α (and their derivatives) should appear on the left-hand side.

Figure 1(a) Figure 1(b)

Page 14: MECH 412 Lab 1 Manual With Appendix

Prelab 2. We now continue toward our objective of designing a controller for the Quanser flexible-link experimental testbed that we started in Assignment #1, using the following coupled equations of motion (found in Assignment #1) as a starting point.

The numerical values for the flexible-link testbed parameters are given below.

Flexible-Link Properties Motor Properties

For this assignment you must:

i. Formulate the state-space equations for the system using the provided equations of motion. Use a

state vector , an input and an output . Give the state space matrices A, B,

C and D, in numerical form. ii. Write a corresponding Simulink program to solve the system and provide a screenshot of your

block diagram. iii. Run your Simulink model with an initial condition of , and

provide a screenshot of your resulting plots of and . iv. Run your Simulink model with initial conditions of and a step input of

5V. Provide a screenshot of your resulting plots of and .

Hints • Refer to the Simulink example.mdl file which is a model of a 2 degree-of-freedom translational

system , posted in MyCourses. • In order to run the example .mdl file or your own program, click on the play button in the toolbar. • In your Simulink model of the flexible-link system, the state space equations will only work with

angles in radians. You should convert the output angles into degrees before you plot them. • To give an initial condition to the system, when you click on the State-Space Block to fill in the

A, B, C and D matrices, also give initial conditions in the state vector form.

• Simulink has a step block in its library( ). Drag blocks from the library into your model.

You can use the Simulink manual provided on MyCourses for additional information.

Page 15: MECH 412 Lab 1 Manual With Appendix

Prelab 3. This question represents the next step towards our objective of designing a motor controller for the Quanser flexible-link device that we previously started in Assignments 1 and 2. We will use the following state-space equations for the system as a starting point.

Where and .

For this assignment you must:

i. Formulate the transfer function using the above state space equation with an output

of . This represents the case where we are interested in the

angle as the output .

ii. Formulate the transfer function using the above state space equation with an output

of . This represents the case where we are interested in the

angle ( + ) as the output .

Note: You may use Matlab to solve for and , or do it by hand.