Project 12 Ev al ua tio n co py PID Ping-Pong® Ball Levitation Levitation is a process in which an object is suspended against gravity by a physical force. Many methods can be used as the levitating medium, including magnetic repulsion, viscous liquids, sound waves, and air currents. In this Project, we will use an air stream provided by a fan to provide the levitating force on a Ping-Pong ball. Controlling the Ping-Pong ball is not easy, but you can build a good controls system using LabVIEW that can work well. The photo above shows the setup for the Challenge. Engineering Projects with NI LabVIEW and Vernier © Vernier Software & Technology P12 - 1 Project 12 PROJECT DESIGN REQUIREMENTS In this Project, you will build a device to levitate a Ping-Pong ball in a long vertical tube using the force of air. You will use a small DC fan to provide the lift force for the Ping-Pong ball. The fan should be secured to the bottom of the tube in such a way that there is an air-tight seal between the sides of the fan and the tube, but that the top and bottom of the fan are open to provide air intake and exhaust. Your LabVIEW program should allow the user to control the speed of the fan (the lift force on the ball) from the front panel via a voltage control to the fan motor. When program execution ends, the fan should automatically turn off. Note: There are two methods for powering the fan motor depending upon the interface you are using. All LabQuest interfaces have two DIG ports, so the fan motor can be powered with the Vernier Digital Control Unit (DCU). Since the SensorDAQ only has one DIG port, it will be much simpler to power the fan motor using an analog voltage control and the Vernier Power Amplifier. MATERIALS SensorDAQ or LabQuest interface LabVIEW computer USB cable small DC fan Ping-Pong ball ring stand 3-finger clamp Styrofoam block long hollow plastic tube ADDITIONAL MATERIALS (SENSORDAQ ONLY) Vernier Power Amplifier Vernier Analog Proto Board Connector breadboard jumper wires ADDITIONAL MATERIALS (LABQUEST INTERFACE ONLY) Vernier Digital Control Unit (DCU) LabQuest or LabPro power supply PROJECT SETUP Build a levitation chamber 1. Cut a hole through the Styrofoam block that is the same diameter as the long plastic tube. Insert the tube into one end of the block (it should fit snugly with no air leaks). 2. Insert or mount the DC fan to the other end of the Styrofoam block. The lead wires of the fan should extend away from the tube and block. 3. Use a ring stand and 3-finger clamp to support the tube and block so that the tube is oriented vertically, and the Styrofoam block is positioned 2–5 cm (1–3 in) above the ground to allow air flow to the fan. Connect the fan to the Power Amplifier (SensorDAQ) 1. Connect the positive (red) lead of the fan to the ±10V (red) terminal on the Power Amplifier. Connect the negative (black) lead of the fan to the GND (black) terminal. P12 - 2 Engineering Projects with NI LabVIEW and Vernier PID Ping-Pong Ball Levitation 2. Insert a Vernier Analog Proto Board Connector into a breadboard. 3. Connect one end of a BTA cable to the port marked Audio Input on the Power Amplifier and the other end into the Analog Proto Board Connector. 4. Use jumper wires to connect the SensorDAQ screw terminal to the Analog Proto Board Connector, as shown in the figure below. Figure 1 Analog Proto Board Connector pin-out to the SensorDAQ screw terminal 5. Connect the Power Amplifier to its external power source and flip the power switch to the On position. 6. Connect the SensorDAQ to the computer. Connect the fan to the DCU (LabQuest interface) 1. Plug the 9-pin cable into the socket on the side of the DCU. 2. Wire the motor to the DCU line 4 as shown in the figure below. You can find the color-coded pin-out for the DCU cable on the label attached to the cord. Figure 2 Wiring diagram for DCU-controlled circuit 3. Connect a power supply to the DCU. 4. Connect the DCU to channel DIG1 on the side of the LabQuest interface. Note: Simply turning the voltage on or off can be done from either DIG channel, but sending a PWM signal must be done from the first DIG port, line 4. 5. Connect the interface to the computer. If you are using a LabQuest interface with a power button, make sure it is turned on. Engineering Projects with NI LabVIEW and Vernier P12 - 3 Project 12 PROJECT BACKGROUND INFORMATION SensorDAQ In this Project, the user will be controlling the rate at which the air moves past the Ping-Pong ball, with a variable voltage control on the fan. The Vernier Power Amplifier should be used for this Project, because it has the ability to output an analog signal unlike a digital device (such as the Vernier Digital Control Unit). The Power Amplifier also allows you to drive loads that typically draw more power than the signal source can deliver. The Power Amp Express VI (found on the Vernier functions palette) should be used when writing your LabVIEW program. This Express VI sends a DC voltage signal by default that can be regulated with a front-panel control. LabQuest interface In this Project, you are asked to levitate a Ping-Pong ball using the force of air. LabQuest interface users should use the Vernier Digital Control Unit (DCU) to provide power to the fan. The DCU is an electronic device that allows you to control up to six digital output lines for on/off control of motors and other DC electrical components. The DCU plugs into one of the digital connections on the interface and is powered by a separate DC power supply. A 9-pin, Dsub socket cable with bare wires on one end is supplied with the DCU for use in building projects. There are connections for all six digital lines, plus a power connection and two ground connections. The color code of the wires is identified on a label attached to the cable. Always keep the power limitations of the DCU and your DCU power supply in mind. You should not exceed 1000 mA total. The user will be controlling the rate at which the air moves past the Ping-Pong ball with a technique called pulse-width modulation (PWM). In PWM, a short pulse, typically 1–2 millisecond, is sent from the controller such that the voltage is on for a portion of the pulse and then off for the remainder of the pulse. When these pulses are sent to the motor at a high frequency, the average voltage to the motor is reduced and it operates at a slower speed. The ratio of “on” time to total time is called the duty cycle. In the example shown below, the pulse is “on” for 60% of the time. If the supply voltage is 10 volts, this results in an effective voltage of 6 volts. The option for sending a PWM signal to the DCU, through line 4, is found in the Digital Express VI. The duty cycle is designated as a decimal value between 0 and 1. Both the duty cycle and frequency can be regulated through front-panel controls. However, in most cases, only the duty cycle should be modified as your LabVIEW program is running. Figure 3 Pulse-width modulated signal PROJECT TIPS 1. One method of cutting the hole in the Styrofoam block is to push and twist the plastic tube through it. P12 - 4 Engineering Projects with NI LabVIEW and Vernier PID Ping-Pong Ball Levitation 2. The long tube should be vertically aligned when viewed from all directions to minimize friction between the ball and the tube. 3. Provide 2–5 cm (1–3 in) of air space underneath the fan for air intake. 4. Avoid using the Abort Execution button to stop your VI or the fan may continue spinning. 5. Refer to Appendix C for additional information on programming the DCU, and the Digital and Power Amp Express VIs. 6. Refer to Appendix E for additional information on the Vernier Power Amplifier, DCU, and Analog Proto Board Connector. PROJECT TROUBLESHOOTING 1. You can test-run your fan motor from the configuration window of the Power Amp or Digital Express VIs to ensure that all of your electrical connections are working properly. 2. Check the direction of air flow from the fan. It should be blowing air up into the tube, not exhausting air out the bottom of the tube. 3. Check for air leaks between the fan and the Styrofoam block. CHALLENGE DESIGN REQUIREMENTS Note: Do not attempt the Challenge until you have completed the Project Design Requirements. Add a Vernier Motion Detector to the top of the tube. Then, modify your VI created in the Project to levitate the Ping-Pong ball at an exact distance of 30 cm away from the Motion Detector using Proportional-Integral-Derivative (PID) control. Your device should raise the ball to this position as quickly as possible with a minimum of oscillation. Create a Waveform Chart on the front panel to display a plot of the desired position of the ball and a second plot to display the actual position of the ball. Place a second Waveform Chart on the front panel to display the motor voltage (SensorDAQ) or the duty cycle (LabQuest interface). ADDITIONAL MATERIALS Vernier Motion Detector rod clamp CHALLENGE SETUP Connect a Motion Detector to the levitation device 1. Position the Motion Detector about 5 cm above the top of the tube using a rod clamp. The gold circular sensor should be centered exactly above the tube opening and pointing downward. Tip: The Motion Detector has a pivoting head to aid in positioning the sensor. Simply rotate the detector head away from the detector body. Engineering Projects with NI LabVIEW and Vernier P12 - 5 Project 12 2. If your Motion Detector has a sensitivity switch on the Motion Detector , set it to the Cart setting. The sensitivity switch is located under the pivoting detector head. 3. Connect the Motion Detector to the unused DIG port on the interface. CHALLENGE BACKGROUND INFORMATION In the Challenge, you are asked to levitate the Ping-Pong ball at an exact position away from the Motion Detector. You can use the Digital Express VI (found in the Vernier functions palette) to monitor position readings with the Motion Detector. When using a front panel control, as in the Project, the user can raise the ball to the desired position fairly quickly by increasing the voltage to the fan for more lift and then decreasing the voltage to maintain that lift. However, in this Challenge, the program needs a method of control in the absence of a human operator. A Proportional-Integral-Derivative (PID) controller uses the weighted sum of three error terms to quickly and smoothly adjust the ball to the desired position. The proportional term takes into consideration how far away the Ping-Pong ball is from the desired position. As the difference grows or shrinks, the influence of the proportional term grows or shrinks. The main problem with proportional control alone is that the ball tends to oscillate up and down. You could increase the voltage to the fan at a very slow rate to avoid oscillating the ball, but keep in mind that your goal is to get the ball to its desired position as quickly as possible. Addition of the integral term will accelerate the ball towards the desired position. However, since the integral term is accelerating the process, it can cause the ball to overshoot and even fly out of the tube. A derivative term is added to reduce the amount of overshoot. This equation can be shown as: de dt where Kp is the proportional constant, e(t) is the error, Ki is the integral constant, V t K p et K i et dt K d et dt is the de is the time dt rate of change of the error. For SensorDAQ users, V(t) is the output voltage to the fan motor. For LabQuest interface users, V(t) represents the duty cycle. summation of the error and the previous error, Kd is the derivative constant, and This equation may appear intimidating, but you do not need an extensive background in differential equations to use it in your LabVIEW program. All of the terms can be simplified to basic arithmetic. Let’s start with the error since it is used three times in the equation. The error in this exercise is simply the difference (positive or negative) in centimeters between the actual position of the ball in relation to the Motion Detector and the desired position. Remember, the detector is above the ball, so you should not think of the ball’s position in terms of its height above the floor. e(t) = error = measured position – desired position If the ball is too low, the measured distance from the Motion Detector will be too large and the error will be positive. P12 - 6 Engineering Projects with NI LabVIEW and Vernier PID Ping-Pong Ball Levitation Using one Shift Register in your LabVIEW program to store the current error value (and use it in the next iteration as the previous error), and a second Shift Register to store the sum of the errors, will allow you to compute ( et dt ) (error + sum of errors) and de (error – previous error). To get the rate of change in the error, we should really use the change in the error value divided by the time between readings (dt). By default the Digital Express VI reads the Motion Detector 20 times a second, and therefore, dt = 0.05 seconds/sample. The simplified result for the PID portion of the equation can now be written as: Kp error Ki error sum of error Kd error previous error / 0.05 Figure 4 Calculating the Error, Change in Error, and Sum of Errors using LabVIEW Tuning the PID equation Tuning the PID equation is a matter of finding the optimal K coefficients that will yield a responsive system with minimal overshoot or oscillation. The best approach is trial and error. Make sure your equipment is in an isolated location so that if the Ping-Pong ball happens to fly out of the tube, it will not hit other people or equipment. When you write your LabVIEW program, place a Waveform Chart on the front panel to monitor the ball’s position in relation to the desired position. You can use a Bundle function (found in the Programming ► Cluster, Class, & Variant palette) to plot both the desired and the actual ball positions on the same chart. Engineering Projects with NI LabVIEW and Vernier P12 - 7 Project 12 Figure 5 Plotting two values on a Waveform Chart with a Bundle function 1. Set all three K coefficients to zero. 2. As you run the program, increase the proportional coefficient (Kp) until the ball begins to oscillate a little bit up and down, but not wildly. Note that you are not trying to match the position of the ball to the desired position at this stage. Tip: From the Properties window, set the Data Entry Increment for the K constants to help you in tuning your PID system. The value of the increment will depend on your system, but we found the Ki increment, in some cases, needed to be as small as 0.00001. 3. Next, cut Kp in half and increase Ki to accelerate the process. Note that the system will probably continue to oscillate, but Ki will quickly make the system unstable 4. Next increase Kd until the system stabilizes to the desired position. 5. At this point, you should stop and restart your program taking note of the amount of overshoot at the beginning of your system. Adjust the Ki value and notice how it affects how quickly the system reaches the desired position, and how much it overshoots. Adjust the Kd value and note the overshoot and the ability to hold the desired position. 6. Continue stopping and restarting your system until the overshoot is as small as possible (an adjustment in Kd) and the system reaches the desired angle very quickly (an adjustment in Ki). CHALLENGE TIPS 1. You may want to look up articles on PID control on the internet or in engineering books. 2. Make sure that you define the error as the difference between the measured position and the desired position, so that the error comes out positive when the ball is too low. 3. Make sure that you have programmed the mathematics correctly or your system will be unstable and impossible to tune properly. 4. Make sure that the Motion Detector is sensing the entire length of the tube. If the detector is positioned too far above the tube, it will detect the lip of the tube and not the Ping-Pong ball. P12 - 8 Engineering Projects with NI LabVIEW and Vernier PID Ping-Pong Ball Levitation 5. (LabQuest interface users) If you are having trouble getting the ball to the required position while performing pwm output from the LabQuest, then consider trying a more powerful power supply for the DCU. The DCU can accept external power supplies up to 12V. 6. Refer to Appendix E for additional information about the Vernier Motion Detector. CHALLENGE TROUBLESHOOTING A common mistake when tuning the PID system is to try to match the position of the ball to the desired position when adjusting the Kp coefficient. You may think you have “tuned” the system, but in actuality you will notice a significant amount of overshoot or delay in reaching the desired position. When adjusting the Kp coefficient, the ball should exhibit a uniform oscillation about the desired position. The addition of the Ki and Kd coefficients should be used to level out the ball. Engineering Projects with NI LabVIEW and Vernier P12 - 9 Vernier Lab Safety Instructions Disclaimer THIS IS AN EVALUATION COPY OF THE VERNIER STUDENT LAB. This copy does not include: z Safety information z Essential instructor background information z Directions for preparing solutions z Important tips for successfully doing these labs The complete Engineering Projects with NI LabVIEW™ and Vernier manual includes 12 projects as well as essential teacher information. The full lab book is available for purchase at: http://www.vernier.com/cmat/epv.html Vernier Software & Technology 13979 S.W. Millikan Way • Beaverton, OR 97005-2886 Toll Free (888) 837-6437 • (503) 277-2299 • FAX (503) 277-2440 info@vernier.com • www.vernier.com