Better filtering makes all the difference on self-balancing robot

I programmed a simple moving average filter. This will remove the rapid changes and make the robot calmer and with less overshoots.

It also handles pushes much better than before.

Posted in Self-balancing robot
16 Comments »Better filtering makes all the difference on self-balancing robot
  1. geejay says:

    Hi, can you give a psuedocode or a block diagram on how you made a reading on the wheel encoders and used them on the cascaded PID's... and also on how you implemented the cascaded PID's. Thanks.

  2. geejay says:


    are these files to be loaded into one arduino only? thanks.

  3. geejay says:

    i think I'll just add the files under sketch before compiling..

  4. Nice project and impressive robot!

  5. Mark says:

    Hi, great project. I'm am starting to try and build one myself.
    Do you think it is possible to build one without using wheel encoders?

  6. Aubrey Remington says:

    i am bulding a robot or rather its built already but its not balancing on the two wheels,i had to put two more wheels across just to get it to stay upright for now but i still want to balance it on just to,what can i do,any ideas please?

    • sebnil says:

      Sorry I do not have an simple answer. Read some literature about control systems and especially PID controllers. Then start experimenting.

  7. Kim says:

    Hi,your robot can balanced on a inclined surface?

    • sebnil says:

      Sure that's no problem. Since the outer loop will have a zero wheel speed as setpoint it will stand still and balance around the tilted equilibrium. I have tested and confirmed it.

  8. Kim says:

    Thank for your answer!
    I know in your code, you use 2 PID controller from Arduino PID library.But i wonder about that 2 PID for wheel speed and angle must be different because:
    +output of PID for speed += pTerm + iTerm + dTerm (sign "+" mean when motor reach the desire speed,it must remain PID value to drive motor at that speed.Otherwise,output for PID for angle = pTerm + iTerm + dTerm (doesn't need sign "+" ).
    Any opinion about that problem.

  9. sebnil says:

    Output from the speedPID (outer loop) is an angle. This angle is the setpoint for the anglePID (inner loop).
    speed setpoint 0 -> SpeedPID -> angle setpoint -> AnglePID -> motor voltage

  10. Jawad Hashmi says:

    hey friend, i am an electronic engineering student and interested in making this self balancing robot. can i have your contact email? my email is
    waiting for your reply :)

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>