Levitating ping-pong ball

Discussion in 'Embedded Systems and Microcontrollers' started by Xkyve, Nov 30, 2012.

  1. Xkyve

    Thread Starter Member

    Nov 30, 2012
    32
    2
    Hey,

    This project I'm working on is about making a ping-pong ball float in a transparent plastic tube at a specified distance relative to the proximity sensor (infrared). The ball should float with minimum oscillations. A small ventilator at the base of the tube is used to push the ball up.

    The fan has a brushless motor controlled through a driver that accepts a PWM signal from a microcontroller. The driver is basically a low-pass filter and a bipolar transistor that works in the active region. The fan datasheet specifically said that it can't be controlled directly with a PWM signal.

    The infrared sensor outputs an analog signal that is read by the ADC of the microcontroller. Serial communication with the PC allows a user to specify the floating distance and view the distance read from sensor for debugging purposes.

    I have reached the point where I have to implement an algorithm to make the ball float steadily at a given distance. I have very limited experience with digital control and I want to ask your help to guide me through this process. Any ideas, suggestions are welcome. Remember it's ok for the ball to oscillate a little and it's also ok if the stabilizing time is not very low.

    The tube is about 35 cm long, 4.6 cm in diameter. The ball has 4 cm in diameter. The sensor is placed at the top of the tube, right on the top hole of the tube, letting the air to pass by. The sensor can measure distances from 4 cm to 30 cm. I have placed a thin wire in the tube to limit the ball from ever reaching distances below 4 cm relative to the sensor.

    I have to mention that I don't have a linear characteristic in the output voltage of the fan driver in comparison with the PWM duty cycle. So 50% duty cycle doesn't mean half the supply voltage of the fan driver. The characteristic looks more like a capacitor charge curve. I don't know if this has a major impact in the design of the control algorithm.

    I'm looking forward on reading your suggestions on the control algorithm
    Thank you
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,362
    This is an exercise in control systems. Search for PID control.
     
  3. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,347
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,605
    Gee, the pertebations on the ball height are pretty minimal if they exist at all, since the only force I can see acting on the ball is the wind blowing up and gravity pulling down. So you should be able to input a fixed set of drives and measure where the ball goes. Then use that data to create a fixed open loop control expression.
     
  5. Xkyve

    Thread Starter Member

    Nov 30, 2012
    32
    2
    It doesn't work like that. The ball either stays down or goes up to the limit for a fixed duty cycle PWM signal.

    For example at 50% the ball is down, if I increase to 51% it slowly goes up and stays at the upper limit. There is no middle ground, only if I play with the duty cycle and continually change it.

    Anyways, I know what a PID is and where to find info about it. I was just curious if someone has practical experience and can tell me some details like: do I need to consider the speed, not just the position of the ball; how fast should I change the PWM duty cycle, and so on.

    Is the PI or PID method the best way to go? Will there be a problem if I have a buffer to compute the average of the readings (digital filter). How will this buffer impact my control algorithm?
     
    Last edited: Nov 30, 2012
  6. GetDeviceInfo

    Senior Member

    Jun 7, 2009
    1,571
    230
    PID considers all that you query. It would be the way to go. It will require tuning however, which makes for better understanding of the functions that contribute to the loop process.
     
  7. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675

    Most likely, you'd need to monitor velocity and acceleration too, as the control parameter(wind speed) takes a while to act on the ball(relatively). Actually, I think this project would be best suited toward a fuzzy logic controller, though a PID should be able to do this also...

    You'd probably need to use a PID at least, though a PI may work, though I wouldn't count on it....
    Computing the average will slow your processor, though can be used to help your response... a moving average could help you to predict the next position of the ball and preempt the positional changes...Really, it depends on how you use it...
     
    Xkyve likes this.
  8. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    I don't think you will much chance of success. The mechanical instabilities or the ball anbd tube are too large and unpredictable, and the lag from controlling the fan speed to affecting the ball is too great compared to the frequency of the instability.

    PID or any good control system would keep the ball at an average height, but there's no way you can stop it bobbing around.
     
  9. Xkyve

    Thread Starter Member

    Nov 30, 2012
    32
    2
    I was able to complete this project using a fuzzy controller that has as inputs the position and the speed of the ball.

    I saw similar projects done with a PID controller based only on position, but the plastic tubes were longer. The longer the tubes were, the better the open-loop control was. In consequence, building a closed loop control using PID with modest performance wasn't hard.

    Thanks to everybody for the help and suggestions.
     
    tshuck likes this.
  10. SPQR

    Member

    Nov 4, 2011
    379
    48
    I wonder if adding a little hysteresis to the system might make it easier to control.
    Could you put a cap on the top of the tube, and change the size of a hole in the cap?
     
  11. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Do you have a video of your project in action?

    I've seen the magnetic levitation version from MIT, never heard of this one, though it sounds similar.
     
  12. Xkyve

    Thread Starter Member

    Nov 30, 2012
    32
    2
    I don't think I understand what you are saying. Obstruct somehow the air escaping at the top of the tube?

    Problem is the sensor is mounted at the top. The only way would be to obstruct the air intake from the bottom of the tube. I already tried that manually, with my hand or a piece of paper :p

    Also I placed a piece of plastic foil in the tube between the ball and the ventilator to direct air flow. Otherwise the ball would behave badly, oscillating left and right, hitting the walls of the tube.

    I think limiting somehow the airflow would improve stability, maybe you are right.

    Anyway, the project is done and i don't have it anymore to modify it.


    You are right, the control principles involved are the same.
    I will upload the video and the code as soon as possible and announce it here.
     
    Last edited: Dec 18, 2012
    tshuck likes this.
  13. Xkyve

    Thread Starter Member

    Nov 30, 2012
    32
    2
  14. Xkyve

    Thread Starter Member

    Nov 30, 2012
    32
    2
  15. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Nicely done!

    I'm curious, what hardware did you use?
     
  16. Xkyve

    Thread Starter Member

    Nov 30, 2012
    32
    2
    Infrared sensor: SHARP GP2Y0A41SK0F
    Microcontroller Dev Board: MSP430_LaunchPad_(MSP-EXP430G2)
    Ventilator: SUNON ME50151V1-000U-A99

    A driver for the ventilator was used that accepts a PWM input from the microcontroller and outputs a DC voltage for the ventilator using a bipolar transistor that works in the active region.

    The fan datasheet specifically said that the fan can not accept PWM signal directly (we tried), that's why we didn't use a MOSFET, only a bipolar transistor.

    If someone is interested in the schematic of the driver I will try to upload it here.
     
  17. juriskg

    New Member

    Mar 4, 2012
    1
    0
    Hi, i'm interested in schematic of the driver, and if you can send mi your hardware model, schematic of electronics, etc. I'm working with similar model, with PLC.
    Thanks in advance
     
  18. alex54321

    New Member

    Jun 27, 2014
    1
    0
    Hi. Did you post the hardward details at all? I'd be really interested in the details, BOM and spec/part number of the fan please
     
Loading...