Shop OBEX P1 Docs P2 Docs Learn Events
Search for "floating ball" application — Parallax Forums

Search for "floating ball" application

ReinhardReinhard Posts: 489
edited 2012-01-21 08:05 in Propeller 1
Hi,
Do anyone know a propeller based application about "floating ball" control loop?
Means to keep a metallic object in a certain distance by a (PWM) - controlled magnetic field.
Measure the object position with hallsensor or phototransistor.
I search in the forum, but nothing found, maybe I used the wrong keyword.

Thanks for any hints,
Reinhard
«13

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-01-14 07:54
    Reinhard,

    For PWM, there is at least one PWM object in the Propeller Object Exchange (OBEX). Have a look at this:
    http://obex.parallax.com/objects/467/
    Also on the OBEX are numerous objects for various sensors and some PID controllers.
    Hope that helps get you started.
  • ReinhardReinhard Posts: 489
    edited 2012-01-14 08:40
    ElectricAye, thank you for the suggestions, they are very helpful, special the PID routines.

    I have an experimental-setup with a PWM controlled coil and use a hallsensor for measure the actual value for position.

    If I bring with my hand a metallic object into position, I can see how the puls width modulation works, but not stable enough to hold the position.

    Maybe it's better to use a light source and a LDR , I go on to try it.

    Or I improve the PI - coefficients, this is a game with try and error .

    thanks
    Reinhard

    edit: I am sure the propeller is fast enough to do this job !
  • jazzedjazzed Posts: 11,803
    edited 2012-01-14 08:48
    Reinhard wrote: »
    Hi,
    Do anyone know a propeller based application about "floating ball" control loop?
    Means to keep a metallic object in a certain distance by a (PWM) - controlled magnetic field.
    Measure the object position with hallsensor or phototransistor.

    This sounds like a great project!
    Care to share more details?
    What is your application? Magnetic levitation?
    Reinhard wrote: »
    I search in the forum, but nothing found, maybe I used the wrong keyword.
    Don't bother with the forum search facility (it worked for a few weeks once).

    Best to just use google.com.
    Enter this in the box: "site:forums.parallax.com floating ball"
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-01-14 08:49
    Reinhard,

    By "floating ball" do you mean a device like Edmund Scientific sells with a levitating globe (or space shuttle)?

    I'm pretty sure there is a permanent magnet in the object to levitate as well. The permanent magnet means the electromagnet doesn't have to be as strong as one required to lift a ferromagnetic item.

    If you're levitating an object with a permanent magnet, you can levitate it from below like this product.

    I like the video. I'm very tempted to get one myself.

    This would be very cool to be able to do with a Propeller. I don't recall seeing any sort of project like this here on the forum though.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-01-14 08:56
    Reinhard,

    Kye has an object for controlling a motor with a PID algorithm. I wonder if you could replace the encoder information with data from a hall effect sensor and use it to levitate an object.

    It might be a good starting point.
  • ReinhardReinhard Posts: 489
    edited 2012-01-14 09:08
    Yes, I mean magnetic levitation.

    first I work with an magnetic ball as floating object ( has a mass of 3 gramm)

    But now I know this is not an adequate object. His own field disturb the measure and make it too complicated.

    Now I search for a good object.

    Seems only my coil is too weak to bring up the force over a distance greater than 3 cm.
    So I have added a permanent magnet in "serial", thats allowed a little bit wider range.

    Supply it with 15 Volt and meas a maximal current of 800 mA.

    Must draw a schematic for more offers. ( programming language is propgcc )

    Be carefull if experiment with a magnetic ball, it can get a extrem high accerelation and not only in vertical direction !

    Reinhard
  • ReinhardReinhard Posts: 489
    edited 2012-01-14 09:50
    Hi,
    this is a preliminary schematic from first experimental setup.

    keep in mind this is always in flow .

    I use the DAC's to give out the position and error signal, rather than a printf.

    Reinhard
    834 x 587 - 56K
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-01-14 10:04
    Is the "PWM" connected to a Prop pin? I didn't see anything else with a "PWM" label.
    I use the DAC's to give out the position and error signal, rather than a printf.
    Are you using an analog display of some type?
  • ReinhardReinhard Posts: 489
    edited 2012-01-14 10:16
    Duane, you are right, the connection is missing in this cicuit.
    Actualy PWM is connected with P20, but it can be any free portpin (in future).

    I observe the analog out with 2 channel o-scope, so I can study the dynamic behaviour in "realtime".
    If I send out the interesst values via terminal, is not the real sample timing.
    But this isn't needed for the functionality.

    Reinhard
  • ReinhardReinhard Posts: 489
    edited 2012-01-14 10:58
    Just in time I have tested an alternative pwm driver circuit.

    seems better and smoother than the previous, has no spikes because works in linear range.

    Reinhard
    282 x 232 - 7K
  • jazzedjazzed Posts: 11,803
    edited 2012-01-14 12:08
    Fascinating thread so far. Is the A/D reading fast enough?
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-01-14 14:20
    I'm guessing you are already aware of the floating ball info in the "Process Control" booklet, but in case you're not, have a look at page 245-256, Chapter 8:

    http://www.parallax.com/Portals/0/Downloads/docs/prod/sic/Web-PC-v1.0.pdf
  • ReinhardReinhard Posts: 489
    edited 2012-01-14 15:15
    I'm guessing you are already aware of the floating ball info in the "Process Control" booklet, but in case you're not, have a look at page 245-256, Chapter 8:

    http://www.parallax.com/Portals/0/Downloads/docs/prod/sic/Web-PC-v1.0.pdf

    Thank you for this link, a very useful info !

    Reinhard
  • ReinhardReinhard Posts: 489
    edited 2012-01-14 15:18
    jazzed wrote: »
    Fascinating thread so far. Is the A/D reading fast enough?

    The AD Conversion needs 50µs, but there is place to optimize with unrolling the loops
    unsigned short 
    readMAX147(unsigned char controll)
    {
      unsigned char rb2 = 0;
      unsigned char rb3 = 0;
      unsigned char ticks;
      unsigned short result;
       
      clr_outa(nCS);        // CS:LOW
      
      for (ticks = 0; ticks < 8; ticks ++)
      {
             if(controll & (0x80 >> ticks)) 
            set_outa(DIN); 
          else 
            clr_outa(DIN);
          set_outa(SCLK);
          clr_outa(SCLK);
      }
      
      for (ticks = 0; ticks < 8; ticks ++)
      {
             clr_outa(DIN);
          set_outa(SCLK);
          clr_outa(SCLK);
          if(get_ina() & DOUT) 
            rb2 |= (0x80 >> ticks);
      }
      
      for (ticks = 0; ticks < 8; ticks ++)
      {
          clr_outa(DIN);
          set_outa(SCLK);
          clr_outa(SCLK);
          if(get_ina() & DOUT) 
            rb3 |= (0x80 >> ticks);
      }  
      
      set_outa(nCS);   // CS:H
      
      result = rb2;
      result = result << 4;
      rb3 = rb3 >> 4;
      result += rb3; 
      return (result);
    }
    
    

    Reinhard
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-01-14 15:46
    Reinhard,

    What ADC chip are you using?

    I wonder if a parallel output, high speed ADC would make this task easier? The TLC5540 (one of a hand full of ADC chips I have experience with) only has 8-bit resolution but can sample at 40 million samples per second.

    I agree with Jazzed, this is a very interesting project.
  • ReinhardReinhard Posts: 489
    edited 2012-01-15 04:07
    Duane, thank you for the tip about faster ADC.
    The reason for decision to use this kind of ADC was I have it just at hand.
    I experiment with him only as a trial to get a feeling for requirements.
    Since I have absolut no feeling about this, the setup is more a feasibility study.
    On other hand in my theoretical mind: a body in earth gravity field in idle state
    moved in 50µs a distance of 9.81m/s² * (50µs)² are round about 24 nm.
    Add the time for control algo (currently unknown) I feel there is enough time
    to calc a inverse force.
    However it is not a professionel work and I have time to deal with different rudiments.
    And in case I get no result, I have learned a lot.

    best regards
    Reinhard
  • jmgjmg Posts: 15,183
    edited 2012-01-15 12:18
    Reinhard wrote: »
    If I bring with my hand a metallic object into position, I can see how the puls width modulation works, but not stable enough to hold the position.
    Maybe it's better to use a light source and a LDR , I go on to try it.
    I'm not surprised it is not stable - there is more working against you here than you realize.
    ** the force/displacement of separated objects is highly non-linear
    Once you have above 1G (ie levitate), the force will quickly increase as your ball moves closer
    ** The Ball and your solenoid, will have magnetic build and collapse times that are non zero
    ** The inductance of your coil also works against you.
    Is this a full 3D problem ?. or is this constrained eg inside a nylon/clear tube

    If it is inside a tube, you can add viscous fluids to get your control loop working, and then drop the viscosity.
    You can also tilt a tube, so the forces needed are lower, but the control problem is similar.
    (angular momentum becomes a new variable )
  • ReinhardReinhard Posts: 489
    edited 2012-01-15 14:58
    jmg, thank you for interesst

    what you report is exactly the work I have done today afternoon.

    I have build a new mechanical setup with a plastic tube which keep the ball in 1D trajectory.

    And at first I try to determine the parameters in horizontal way.

    The idea with a fluid is very clever, what kind of fluid are you tought ?

    Reinhard
  • Heater.Heater. Posts: 21,230
    edited 2012-01-15 15:21
    I don't see how this can work with a Hall sensor. The Hall sensor detects magnetism and magnetism is what you are using to create the action. So how does the ball position come out of all of that?
  • ReinhardReinhard Posts: 489
    edited 2012-01-15 15:43
    Heater. wrote: »
    I don't see how this can work with a Hall sensor. The Hall sensor detects magnetism and magnetism is what you are using to create the action. So how does the ball position come out of all of that?

    I have found the solution with hallsensor in a schematic with analog components.
    The circuit is very simple
    the hallsensor is the input of an opamp
    the other input is a poti (reference signal)
    the output drives a power mosfet , this control the current through the solenoid.

    I think the thing is in steady state the sensor deliver a certain value which is the reference level. (+offset)

    I know this sounds too simple, but the analog solution exist, why not with a µC.

    Reinhard
  • Heater.Heater. Posts: 21,230
    edited 2012-01-15 16:10
    I can see how such a control loop can be built using an analog circuit with op amps.
    What I don't understand is the physical layout of the solenoid, floating magnet/ball and the sensor.
    It just seems to me that:
    1) Ball moves
    2) Sensor detects motion via change in magnetic field
    3) Control circuit drives solenoid
    4) That changes the magnetic field which upsets the sensor

    How is it arranged that this does not happen?
    I know this sounds too simple, but the analog solution exist, why not with a µC.

    No reason at all. Provided the whole loop of sensors-ADC-software loop-DAC-solenoid is fast enough. Of course the complete uC digital solution is a lot more complicated than an op amp or two and some R's and C's.

    Aside: I once met a semi-retired engineer working on testing aircraft flight control software. He had been involved in designing controls for the Concord and explained that it was all done in analog with op-amps. There were no uCs back then. Some times he would slap his head and ask "why are we doing all this in software it would be much simpler with an op amp?"
  • LawsonLawson Posts: 870
    edited 2012-01-15 21:23
    From the little that has been described in this thread I can see two challenges with your floating ball setup. The first challenge is that the electro-magnetic ("reluctance") actuator chosen to levitate the ball is highly non-linear. The force acting on the ball depends on the coil current and the position of the ball. (and the velocity of the ball and acceleration and even a current times velocity cross product if we want to include everything) The second challenge is your choice of a magnetic position feedback. It's highly unlikely that this feedback only measures the position of the ball without any effect from the levitation coil. (also a non-linear effect) Both of these challenges break a key assumption of PID control, i.e. PID control assumes that the system to be controlled is linear.

    I've seen two solutions to the first challenge. First is the classical approach, get a really high speed low noise position feedback signal and crank up the gain. (start with the 'D' gain (viscous damping) and progress to the 'P' (spring rate) then add a bit of 'I') This has the effect of making the controller totally dominate the motion of the system. I.e. the system is still non-linear, but those non-literariness generate forces much smaller than the magnitude of the controllers corrections, at most about 1/10th as large. While this type of approach often works, the solution is slower, more expensive, and or noisier than it could be if all the information known about the system was used.

    The second solution to the first challenge I've seen is to carefully consider the physics of the system and use the controller to modify them to suit your needs. ( a "control volume" is a useful concept here) In this case you want to be able to use the levitation coil to exert force 'commands' on the steel ball. To do that you first need to get control over the levitation coil's current. An analog servo loop or fast uC loop should do this easily as the levitation coil will mostly be an inductor. Second, you need to calculate what the relationship is between force, current, and ball position. (find an electromagnetics text and read up for this part) With this relationship you can now construct a "command transform" to transform force commands and the measured position of the ball into current commands for the levitation coil. At this point, you should be able to command the coil to exert 1 Newton of force on the ball, and have the controller exert 1N on the ball independent of it's position. At this point you've also transformed a rather nasty non-linear system into a nice simple linear system. (as long as the current control loop can keep up with your force commands anyway.) Finally, with the levitating ball system linearized, classical PID control theory applies perfectly. (wikipedia has a decent treatment )

    BTW, the proportional, derivative, and integral gains should have REAL UNITS on them. With the system linearized, proportional gain should have units of [force/length], the derivative gain should have units of [force/(length/time)] etc. These gains can also be directly measured by measuring the response to a known disturbance force. (easy to create, by adding a "disturbance" command on to the servo loop's corrections) The proportional gain of a position loop is particularly easy to measure as it's a spring.

    The second challenge of impure position sensor readings, is harder to deal with. To a certain extent, you can "map" the interactions out with a function that depends on both the position measurements and levitation coil current. This can get a small improvement in performance before the "map" function requires impractically accurate parameters. It will be much better to get a new position sensor that isn't effect by the levitation coil current.

    Lawson
  • Heater.Heater. Posts: 21,230
    edited 2012-01-16 00:24
    Another method often used to tackle those non-linear and complicated systems is to ignore the problem all together, forget about trying to analyse the system and derive a mathematical model of it. Use a fuzzy logic control loop instead.
  • ReinhardReinhard Posts: 489
    edited 2012-01-16 00:35
    Hi, because I have go to work now, I make it short.

    Here is the analog referenz design:

    http://www.bis0uhr.de/index.htm?http://www.bis0uhr.de/projekte/schwebekugel/index.html%99htt

    later more

    Reinhard
  • ReinhardReinhard Posts: 489
    edited 2012-01-16 02:28
    Heater. wrote: »
    Aside: I once met a semi-retired engineer working on testing aircraft flight control software. He had been involved in designing controls for the Concord and explained that it was all done in analog with op-amps. There were no uCs back then. Some times he would slap his head and ask "why are we doing all this in software it would be much simpler with an op amp?"

    I believe that, in aircrafts and medical products the highest requirement is absolute safeness.
    And this is easier to verify with an well proofed (analog) design.
    how knows when a bug in (large and complex) software occurs.

    back to the thread:
    using a fuzzy logic is a smart idea, exist there (spin) examples how to implement in best practise a system of rules ?

    Reinhard
  • Heater.Heater. Posts: 21,230
    edited 2012-01-16 03:00
    Have a search here on the forums. Hano has a complete working fuzy logic development system for the Propeller. He demonstrated it to great effect in his balancing bot project.
    Sadly I forget what the system or the bot are called just now.
    I think it was a comercial product so it may cost you a little.
  • RaymanRayman Posts: 14,848
    edited 2012-01-16 05:30
    Reinhard, that's a very cool web page, thanks for the link. That design is very cool looking too...
  • Heater.Heater. Posts: 21,230
    edited 2012-01-16 06:17
    One very cool looking gadget.

    So, the ball is a magnet.
    There is a magnet at the top lifting the ball.
    The sensor is sitting about midway between them.
    Could I guess that the sensor will see a zero (near zero ) magnetic field when the ball is in the desired position.
    The actuator coil only has to do a little work to maintain balance.
    A change in that field balance causes the sensor to drive the op-amp one way or another.

    Now, what goes on with the opamp circuit? Is that oscillating and having its frequency and/or pulse width adjusted by the sensor input. Or is it driving the coil linearly?
  • ReinhardReinhard Posts: 489
    edited 2012-01-16 06:33
    quote from web page above:

    The functional principle:
    An electromagnet (coil) is turned on. The magnetic sphere gravitates towards it.
    When the sphere gets near the magnet sensor (Hall sensor), the sensor reacts and turns off the electromagnet.
    In the following, the sphere descends again. The magnet sensor then turns the electromagnet on again
    and the cycle starts anew.
    This happens approx. 70 times per second (depending on the distance and the weight of the magnet).
    That's how the magnet levitates
    .

    best regards
    Reinhard

    edit: this sounds to me like a PWM over the time
  • Heater.Heater. Posts: 21,230
    edited 2012-01-16 06:55
    Ah yes, just found the "English" button.

    That sounds very a simplistic explanation but let's go with it.
    That implies that after all the talk of difficulties with physical modeling and PID control it boils down to the simplest crudest "bang-bang" controller. If "too low" turn it full on. If "too high" turn it full off.
    Sometimes it pays not to think to hard and just do it:)
Sign In or Register to comment.