1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Any way to predict when to stop a moving ball in order to get it to x?

  1. Oct 11, 2013 #1
    I am working on a project for my kid. I have a question.

    Question: Is there a way to predict when to stop a moving ball in order for it to finally stop rolling at a specific position?

    Data: I know the balls x and y position, and the velocityX and velocityY float values. I think it has an accelerometer as well, but I haven't experimented with it. It has a x,y, and z value.

    Situation: I am programming a Sphero (wireless moving ball), and I know my starting location (0,0), and ending location eg:(0,300cm). Once it stops at the ending location, it needs to travel back to 150cm, (the middle between the two locations). But every time I find out the position is 150cm and send stop, it rolls past where I want it to go while its stopping. (Stopping Distance)

    I can't hard program it to stop a random SET distance (through trial and error) before the middle because its velocity won't always be the same. Sometimes it rolls on rough carpets and sometimes on smooth tile floors.
    Last edited: Oct 11, 2013
  2. jcsd
  3. Oct 11, 2013 #2


    User Avatar
    Science Advisor

    Sure. First, you can ignore the fact that it's rolling. Rolling inertia will just work as if the ball has extra mass. So you have a known x, y, Vx, and Vy, and you are trying to get the ball to come to a stop at specific position, but you don't know exactly what the acceleration is going to be. Lets talk just about x for the moment, because it's easy to generalize, and I'll just assume you want it to stop at x = 0. Naturally, you can shift the position to wherever.

    The simplest way to do this is to make an assumption about worst case acceleration. This is gives you the longest distance it's going to stop on the surface. Lets say you found (or even just guessed) the acceleration to be a. Guessing a value too high can result in errors, so start low and see if you can increase it later.

    Now you have the ball approaching zero from some distance x at velocity v. If you were to start stopping at acceleration a, you can stop in distance v²/(2a). So that's going to be your test. If x < v²/(2a), you should be trying to stop. But you keep making this test. If velocity drops too fast, and new x > v²/(2a), keep the ball rolling towards the target position.

    Even if all you can do is alternate between "stopped" and "maximum speed", because the ball has inertia, you will get smooth movement with the ball decelerating at the set rate a before reaching the target. The fact that the ball can decelerate at the rate of at least a on any surface means you won't have problems with the ball rolling past the target, and because you alternate between moving and stopped modes, the net acceleration will not exceed a even on surfaces where the ball can stop faster.

    There are a number of ways to go fancier, but I'm guessing you are looking for something pretty basic.
  4. Nov 8, 2013 #3
    thanks a lot for this! Still confused lol. I thought I would have to somehow use the sphero's internal location to learn when to stop. But you said I dont need this? Only the velocity, acceleration, and x position to stop at?

    I sent you a pm! (Confused!)

    Here is what I was thinking:
    if ((player2positioninY/2)<velocity^2/2a)
    send stop to sphero

    But I'm confused on the part where you say if velocity drops too fast.

    On my sphero, I can get: VelocityX, VelocityY, PositionX, PositionY, Accel XYZ, Gyro XYZ)
  5. Nov 8, 2013 #4


    User Avatar
    Science Advisor

    The problem is that a is just an estimate. If actual acceleration is going to be greater than a, stopping the servo too early will result in the Sphero undershooting the target.

    Ok, so lets say we have TargetY being location where we want to stop. In that case, you want to have two independent checks.

    if(|TargetY - PositionY| < VelocityY^2 / (2*a))
    send "servo-off"
    if(|TargetY-PositionY| > VelocityY^2 / (2*a))
    send "servo-on"

    Here, I'm assuming that "servo-on" will have the Sphero rolling towards TargetY. I'm sure you can figure that bit out and generalize this whole thing to movement in 2D.

    One more note, the above code will be switching servo on and off rather rapidly as it approaches target. If this causes any trouble, you can add a small threshold. Like, replace second if() with if(|TargetY-PositionY|-err > VelocityY^2 / (2*a)). Here, err is a small error you allow in the position. This will allow for a bit longer times between servo switching on and off. In ideal world this would reduce precision, but in real world a small allowance for error might actually improve it.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook