Prescott, Arizona Campus Department of Electrical and Computer Engineering EE 402 Control Systems Laboratory Spring Semester 2016 Lab Section 51PC Thursday 1:25 – 4:05 pm King Eng. Bldg. Rm 122 Lab Instructor: Dr. Stephen Bruder Lab 02 Introduction to the Quanser QUBE Servo Date Experiment Performed: Thursday, Jan 28, 2016 Instructor’s Comments: Comment #1 Comment #2 Lab Report Due: Monday, Feb 1 Group Members: Student # 1 Name & Email Student # 2 Name & Email Grade: ?? / 100 EE 402 Control Systems Lab TABLE OF CONTENTS Spring 2016 PAGE 1. Lab Overview........................................................................................................................................ 3 2. Background and Introduction................................................................................................................ 3 2.i. The QUARC Real-Time Control Software ................................................................................... 3 2.ii. The Hardware................................................................................................................................ 3 3. Theory and Experimental Methods ....................................................................................................... 5 4. Equipment and Procedures.................................................................................................................... 6 4.i. Initializing the Simulink Model .................................................................................................... 6 4.ii. Reading the Motor Shaft Angle .................................................................................................... 6 4.iii. Driving the DC Motor ............................................................................................................... 7 4.iv. Adding Stall Detection .............................................................................................................. 8 5. Results and Discussion ......................................................................................................................... 8 6. Conclusion ............................................................................................................................................ 9 7. References ............................................................................................................................................. 9 LIST OF TABLES PAGE Table 1 Encoder angle vs physical angle (in deg)........................................................................................ 7 LIST OF F IGURES PAGE Figure 1 An optical incremental quadrature encoder. ................................................................................... 4 Figure 2 Inside the Quanser QUBE. ............................................................................................................. 5 Figure 3 A real-time Simulink-QUARC model ............................................................................................ 5 Figure 4 A Screen capture of your finalized Simulink model ...................................................................... 9 LIST OF SYMBOLS Names of Students in the Group PAGE Page 2 of 9 EE 402 Control Systems Lab Spring 2016 1. LAB OVERVIEW In this lab, we will realize the following learning objectives: Initial exposure to the Quanser QUBE-Servo hardware. Develop familiarity with the QUARC® Real-Time Control Software that will be used to interface with the QUBE-Servo. Interface to a DC motor: Read the motor’s shaft angle from the quadrature encoder and drive the motor with a fixed voltage. 2. BACKGROUND AND INTRODUCTION 2.i. The QUARC Real-Time Control Software The QUARC real-time control software will be used to interact with the hardware of the QUBE-Servo system. In particular, the QUARC software will allow us to run Simulink models in real-time in order to read sensors (e.g., encoder) and generate PWM signals to realize desired motor drive voltages. This process generally proceeds in three steps: 1. First, develop a Simulink model that contains QUARC blocks to interact with your QUBEServo and other optional blocks, which typically perform user defined signal conditioning or implement a control algorithm. 2. Build your model and resolve any compile-time errors to produce real-time code. 3. Link this code to your real-time target, and then execute the code. In MATLAB, type “doc quarc” at the command prompt to see QUARC documentation. Also, in the Simulink Library Browser (type “simulink” in the MATLAB command window) expand “QUARC Targets” to see a list of the supported blocksets. 2.ii. The Hardware The Quanser QUBE contains a quadrature encoder, a pwm motor driver, and a brushed DC motor (user manual). 2.ii.a. The Quadrature Encoder The quadrature encoder in the QUBE is a US Digital E8P OEM Optical Kit Encoder. Similar to rotary potentiometers, optical encoders can also be used to measure angular position. There are many types of encoders, but one of the most common is the rotary incremental optical encoder, as shown in Figure 1. Names of Students in the Group Page 3 of 9 EE 402 Control Systems Lab Spring 2016 Figure 1 An optical incremental quadrature encoder. Despite having a 1-pulse per revolution index signal (Channel I – see Figure 1), the relative encoder does not measure an absolute angle, hence, when first powered up it resets its angle to zero. Absolute optical encoders do exist, however, they are typically more sophisticated. The encoder has a coded disk that is marked with a radial pattern (see Figure 1). As the disk rotates (with the shaft), the light from an LED shines through the pattern and is picked up by a photo sensor. This effectively generates the A and B signals shown in Figure 1 (left). An index pulse is generated once every full rotation of the disk, which can be used for calibration or as a homing system. The A and B signals that are generated as the shaft rotates are used in a quadrature decoder algorithm to generate a count. The resolution of the encoder depends on the coding of the disk and the decoder. For example, our encoder with 512 lines on the disk can generate a total of 512 pulses for every rotation of the encoder shaft. However, in a quadrature decoder as depicted in Figure 1, the number of counts (and thus its resolution) quadruples for the same line patterns and generates 2048 (= 4512) counts per revolution. This can be explained by the 90 phase shift between the A and B channels. Instead of Channel A (or B) being either high (=1) or low (=0), now there are now four patterns (AB = 00, 01, 10, or 11). This A/B phase shift changes from +90 (clockwise) to -90 (counter-clockwise), which allows the encoder to also detect the direction of the rotation. 2.ii.b. The DC Motor The QUBE also contains an 18 volt, 7 watt Allied Motion CL40 Series Coreless DC Motor (model 9904 120). This motor is driven by a pulse width modulation (pwm) amplifier. Names of Students in the Group Page 4 of 9 EE 402 Control Systems Lab Motor driver Spring 2016 DC motor encoder Figure 2 Inside the Quanser QUBE. 3. THEORY AND EXPERIMENTAL METHODS In this lab, we will develop a Simulink model using QUARC blocks to drive the DC motor and measure its corresponding relative shaft angle as shown in Figure 3. Figure 3 A real-time Simulink-QUARC model The QUARC block that reads the encoder outputs the motor’s shaft angle as the number of quadrature counts. Question 1. What is the constant conversion factor to convert from counts to degrees? K ??? (deg/count) Question 2. What is the maximum voltage that should be applied to the DC motor (via the QUARC write Analog block)? Vmax ??? Volts Question 3. For this motor, what is the starting current at nominal voltage (also known as the stall current – see motor datasheet in Section 2.ii.b)? istall ??? Names of Students in the Group amps Page 5 of 9 EE 402 Control Systems Lab Spring 2016 4. EQUIPMENT AND PROCEDURES In this section, we will create a Simulink model to read and display the motor’s shaft angle and drive the motor with a constant voltage. 4.i. Initializing the Simulink Model Start MATLAB and then create a new Simulink model. Save the model as LastName_FirstName_Lab02.slx (use your LastName and FirstName and save on your P-drive). Enter >> simulink in the MATLAB Command Window to display the Simulink Library Browser. In the Library Browser, expand QUARC Targets Data Acquisition Generic and select Configuration. Drag a copy of the HIL Initialize icon into your new Simulink model. In your model-double click on the HIL Initialize icon, and from the pull-down list under “Board type”, select “qube_servo_usb”. Be sure to save your Simulink model. From the pull-down menu, select “External.” Then, click on the Build icon (wait a few secs), next connect to target, and then Run. This process should complete without generating any errors (look at the MATLAB command window). You will need to resolve any errors before proceeding. Click on the stop button (icon to the right of the Run icon) Connect to target Build Run before continuing. 4.ii. Reading the Motor Shaft Angle In this section, you will add the necessary blocks to your Simulink model to read the motor’s shaft angle and display the angle in degrees. Return to the Simulink Library Browser, expand QUARC Targets Data Acquisition Generic, and select Timebases. Names of Students in the Group Page 6 of 9 EE 402 Control Systems Lab Spring 2016 Add a copy of the HIL Read Encoder Timebase icon to your Simulink model. Add a gain block (Simulink Commonly Used Blocks) to the output of your HIL Read Encoder icon, and then enter the constant conversion factor you calculated in Question 1 therein. Add a display (Simulink Sinks) to the output of the gain block. Physically adjust the Red disk on the QUBE-Servo to point to 0, and then Build, Connect to Target, and Run the model. Manually, rotate the disk counterclockwise (positive angle) to align with the 45 mark and record the value Displayed in your Simulink model. o If you found any issues/problems resolve them. Record the values displayed for the physical angles selected in the table below. Table 1 Encoder angle vs physical angle (in deg) Physical Angle +90 +45 0 -45 -90 Displayed Angle Stop your Simulink model before continuing. Manually, rotate the disk to physical angle other than 0. What was the physical angle you chose? ___???____ deg Now, Connect to Target and then Run the model. Move the disk around and stop with the disk pointing to an angle of 0 deg (see image below). Record the final angle displayed in your Simulink model: ___???____ deg Question 4. What can you conclude from this test? -90 +90 4.iii. Driving the DC Motor Now, we will apply a voltage (actually PWM) to the DC motor to drive it. -45 +45 Return to the Simulink Library Browser, expand QUARC Names of Students in the Group Page 7 of 9 EE 402 Control Systems Lab Spring 2016 Targets Data Acquisition Generic, and select Immediate I/O. Add a copy of the HIL Write Analog icon to your Simulink model. Drive this block with a constant voltage (Simulink Sources then add Constant icon). Enter a value of +0.5 in the Constant Block and then Build, Connect, and Run the model. The motor should rotate in a positive (i.e., counterclockwise) direction. o Question 5. If you found any issues/problems resolve them. What is the minimum voltage required to cause the disk to begin rotating? ________V HINT: Start from 0 Volts and incrementally increase the value slowly while running!!! Question 6. Why does the motor not begin rotating at a much lower voltage? 4.iv. Adding Stall Detection As a safeguard against damaging the DC motor, we will add “stall detection” to our model. This block will monitor the applied voltage and speed of the DC motor to ensure that if the motor is motionless for more than 2 seconds with an applied voltage of over 5V, the model execution is halted to prevent damage to the motor. Open the provided Simulink model stall_detect.slx and copy the “Stall Detection” block to your model. Be sure to connect it as shown in Figure 3. Test your stall detection. Apply 5.5 V and hold the disk stationary with your hand for more than 2 seconds (first you must: Save, Build, Connect, and Run the model). Demonstrate this functionality to the instructor or lab TA. 5. RESULTS AND DISCUSSION Include a screen capture of your final Simulink model in Figure 4. Be sure to add text with your name(s) and date to the Simulink diagram. Names of Students in the Group Page 8 of 9 EE 402 Control Systems Lab Spring 2016 Figure 4 A Screen capture of your finalized Simulink model 6. CONCLUSION What can you say (qualitatively) about the main difference(s) that you have observed between this physical DC motor and an idealistic theoretical model of a DC motor? 7. REFERENCES [1] www.quanser.com Names of Students in the Group Page 9 of 9