Connect with us

PID Problem

Discussion in 'Electronic Design' started by mglazer, Sep 29, 2006.

Scroll to continue with content
  1. mglazer

    mglazer Guest


    I have been building a 2 wheel balancing robot and have it pretty much
    balancing. I say "Pretty much" because it tends to run away on me and
    not balance in a single spot. Please see link to video.
    Maybe I just need a break to figure it out but thought I would post a
    message here as someone here may have solved this problem before.

    Below is the code:

    //robotvelocity is cm/sec
    //angle and q_bias(Gyro rate) are converted to deg and deg/sec

    kalman_update(asin(AccZ), asin(AccY));
    state_update(GyroY * PI / 180);

    torque = (((angle * 180 / PI) + Offset) * K1) + ((q_bias * 180 / PI) *
    K2) + (robotvelocity * K3);

    if(torque >= 500)
    torque = 500;
    if(torque =< -500)
    torque = -500;

    OCR1A = 1500 + (torque);
    OCR1B = 1500 + (torque);

    Any help would be very much appreciated.

    Kind Regards,
  2. Boris Mohar

    Boris Mohar Guest

    Maybe bit more Integral? It could also be that the forward/reverse gains
    (losses) are not the same. How does it behave on a slope?


    Boris Mohar

    Got Knock? - see:
    Viatrack Printed Circuit Designs (among other things)

    void _-void-_ in the obvious place
  3. Tim Wescott

    Tim Wescott Guest

    Do you have any absolute position measurement? If not then it's going
    to be hard to keep it in one spot. I don't see a variable that
    indicates a robot position, not even one that's done by integrating the
    robot velocity -- this would at least keep your robot down to a crawl,
    and probably better than that if you're using position encoders to get

    You're probably beyond it, but check out my book, anyway:


    Tim Wescott
    Wescott Design Services

    Posting from Google? See

    "Applied Control Theory for Embedded Systems" came out in April.
    See details at
  4. mglazer

    mglazer Guest

    Thanks for the replys, I have no position measurement which is what I
    need. Thanks for that, It's amazing how much something makes sense
    after you give it a break for a while.

    Your book looks good, ill see if I can get hold of it in Australia
    otherwise I might get a copy from overseas.

  5. colin

    colin Guest

    You need to keep track of how many steps it has taken in trying to balance
    itself then try to undo those steps by adjusting the setpoint for the center
    of gravity/angle whatever untill eventualy it should move back to the
    original position then keep still.

    Colin =^.^=
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day