top of page

EML4313 Dynamics and Controls System Design Lab

University of Florida

March 2020 - April 2020

Executive Summary/

What Was Accomplished

  • Using LabVIEW, a closed loop PID controller was developed that tracks the positional error of a desired vertical position and regulates the amount of voltage sent to a variable speed fan which controls the magnitude of the thrust force provided to lift a ping pong ball against gravity within a vertical tube. A machine vision and bilinear mapping technique was implemented that thresholds the captured image and accounts for the distortion in the camera in order to track the centroid of the ping pong ball and calculate the error.

​Biggest Takeaways/

Lessons Learned

  • PID is a simple controls scheme and works well for many mechanical systems; more often than not, keeping control schemes simple proves to be a successful and a time effective solution.
     

  • Machine vision is a powerful tool when used properly; much of the procedure went into ensuring the camera would properly see (dark contrast, no glare) and interpret the results properly (bilinear mapping) in order to properly command the motor. Without such measures, the controller would have a lot of difficulty achieving sufficient control of the system.

Transferrable

Skills

  • Programming and manually tuning a PID controller in LabVIEW

  • Implementing a machine vison system using RGB thresholding and bilinear mapping

  • General MATLAB programming

  • General software and hardware troubleshooting

  • Display and analysis of engineering data

Introduction

 

During the Spring of 2020, the final project ​in my EML4313 Dynamics and Controls System Design Lab class was to control the position of a floating pin pong ball inside a clear tube using a 12V DC fan, a camera, and a control scheme of our choice. This project was generally open ended and conducted in our homes due to the Covid-19 lockdown. Below is a brief summary of the engineering process and results. A final report PDF is also linked here, which includes much more detail.

I choose to develop a PID controller to regulate the desired position of the ping pong ball using feedback error and evaluate its performance using metrics such as rise time and percent overshoot.

Experimental Setup

The major components of the experimental set-up included: a 12 V DC power supply, a 40mm 4 wire 12 V DC brushless cooling fan, a 20 inch long polycarbonate fluorescent light tube protector, an orange ping pong ball, a Sony PlayStation 3 USB camera, a breadboard and other electrical components, a laptop with LabVIEW (controller), an Out of the Box Data Acquisition Device (DAQ) and SADI motor controller, blue paper for a contrasting background, and a source of light. 


Capture3.PNG
IMG_9925.jpg

The LabVIEW VI (Virtual Instrument) uses a machine vision technique to capture the image from the camera and implements a thresholding procedure on the RGB range of colors in the image that produces a final image of only the ping pong ball in black and the remaining background in white. The VI then calculates the centroid of the remaining black pixels and reports this as the centroid (position) of the ping pong ball.

Capture1.PNG
Picture1.png

Next, a free body diagram was created of the ping ping ball inside the tube to determine the fan velocity (and subsequent fan voltage) that balances the forces acting on the ping pong ball in the vertical direction. Taking a force balance in static equilibrium in the vertical direction, the force due to gravity on the ping pong ball can be set equal to the force of drag from the fan, ignoring the friction between the ball and the tube walls. With known parameters and the linear relationship between the fan speed and input voltage, a feed forward term can be developed into the controller that keeps the ball suspended in air. Any input voltage above this value with raise the ball, and any input voltage below this value will lower the ball. Approximately 1.39 volts held the ball in place in the tube at a fan speed of 8.35 m/s.

2.PNG
Capture23.PNG
33.PNG
444.PNG

Although the "pixel space" of the image from the camera and the blue "paper space" of the background are both cartesian coordinate systems, it cannot be assumed that they are identical, or map one to one, due to the distortion in the camera’s lens. In order to accurately track the ping pong ball using the camera, a method called bilinear mapping is used that accounts for this distortion.  For this process, a transformation is created in the VI that allows the centroid pixel coordinates obtained from the thresholding precedure to be converted into blue paper space coordinates using the equation, where (wx, wy) are the blue paper space coordinates and (px, py) are the pixel coordinates.

3343.PNG
Capture44.PNG

To be able to use this transformation, a set of bilinear calibration coefficients (c1 through c8) must be determined by using four known points in blue paper space. The ping pong ball is placed at four known points and the camera captures the pixel coordinates for each of the known points. Using MATLAB, a program is created to input the known blue paper space coordinates and VI pixel coordinates and then solves for the calibration coefficients using matrix inverse and multiplication. The four known points that were used for the calibration are (0, 0), (0, 60), (60, 0), and (60, 60), which are the four corners of the blue space square in centimeters.

12.PNG

PID Controller in LabVIEW

The VI was programmed to use the bilinear mapping constants and transformation to convert the centroid pixel coordinates from the thresholding into blue paper space coordinates in real time. A desired vertical position of the ping pong ball in centimeters is input into the system by toggling a case structure that either allows the VI to generate a time varying desired vertical position by using a square wave or by using a sub-VI called trajectory that produced a repeating pattern of desired positions and switches to the next desired input when the error is within 0.5 cm of the desired value.

 

The camera monitors the ping pong ball’s position, which is then used to calculate the error between the actual position and the desired position. The VI computes the derivative and integral of the error as well, where the integration points value is set to 30 and the derivative points value is set to 3. The error, integral error, and derivative error is then used with a set of PID gains that were manually tuned to generate an appropriate and optimal output signal. 

 

The output of the PID controller is a magnitude to increase or decrease the feed forward voltage term described earlier. This additive term of the feed forward voltage and the PID output is then sent through a command and coerce structure so that the voltage remains in a range of 0 to 5 volts. The final command signal is then sent to the DAQ’s AO0 pin, which controls the amount of voltage delivered to the fan which determines the fan speed and subsequent drag force on the ping pong ball. The system continuously tracks the position and error, updating the output of the controller appropriately.


Capture2.PNG

Results

Following a manual tuning process, the most optimal proportional gain, integral gain, and derivative gain to track the square wave signal was determined to be 0.085, 0.06, and 0.045, respectively. The system response is shown below in the graph, were the light gray line is the desired input, and the dark gray line is the position of the ping pong ball. The system response exhibits some overshoot and oscillations but does settle to within 2.5% of the final value in a reasonable time. Table I outlines the mean, standard deviation, and Root Mean Square (RMS) for the error and command effort using one full cycle of data from the PID controller’s response to the square wave input.

 

The RMS error is a metric of how well the task is performed, and the RMS command effort is a measure of how much effort it took to achieve the level of control.  All rise times are reported as the time it took for the response to go from 10% to 90% of the desired value. Percent overshoots are reported as the percent the response exceeds the desired value. All settling times are reported as the time it took for the response to stay within 2.5% of the desired value.

The most optimal proportional gain, integral gain, and derivative gain to track the trajectory sub-VI is determined to be 0.0555, 0.075, and 0.0375, respectively. The response of the system does overshoot for some positions; however, it completes the trajectory consistently and quickly in 9.84 seconds which meets the target goal of under 10 seconds. The graph is tarred to start at a time of zero to easily see the completion time, and two cycles of completion are included to show the consistency at which is the controller performs the tracking.


done2.PNG
done.PNG
done3.PNG

Analysis/Discussion

There were challenges to arriving at the gain values for the trajectory test. If the gains were tuned too small, the response would sometimes come within 1 cm of the desired value and no longer change in position because the small error multiplied by the small gain would produce too small of a voltage command to raise or lower the ball; moreover, the 1 cm of error was not within the trajectory’s acceptable margin of error of 0.5 cm, so the ping pong ball would stall in one location and the next signal would never be sent out. Other challenges included getting the ping pong ball to stop oscillating outside the range of 0.5 cm fast enough to get the response time under 10 seconds, which was improved by increasing the integral term to be the highest gain in the system.

For both the square wave and trajectory input, both controllers can be tuned to be able to sufficiently track and meet the desired performance metrics. In early iterations of the experimental setup and VI, the feedforward term was not utilized, which caused early problems. Without the term, the system would stop sending any voltage at all to the motor once the tracking error was low and the desired output was met, which resulted in the ball beginning to free fall because the lifting force was eliminated. This effect is most noticeable during the square wave tuning, and the controller would stay in a constant state of turning on and off around the desired value, which led to a high RMS command and high oscillations, especially when given a high desired distance in the tube to achieve such as 40 cm. The feedforward term significantly improved performance and tracking, allowing for the simple PID controller to be effective in adjusting the voltage that holds the ball in equilibrium.

While completing the project, it did not occur to me to capture what the ping pong ball looked like successfully completing the tests; I only recorded the front panel of the VI capturing the position in real time of one successful test; however, I did record one of the many troubleshooting moments during the project. This goes directly against the saying "no one will remember you for your failures," as all I have documented for you to look at is one of my temporary failures...enjoy!

bottom of page