Software for the self balancing robot

Obs! This software is based on having a control-panel on it, to load parameters from. Have that in mind when trying to understand the code.

Note that i share my code, and therefore Im not obliged to do any support. So do your best with the code and hopefully it will help you.


Main Code — > samwind/Self balancing robot

43 reaktion på “Software

  1. Would appreciate your code. Which accelerometer/gyro did you use?
    I just purchased the MCU6050. I hope I can use it. I built the following, but it is very unstable and erratic.


    Thank you!

  2. Hi Librav! Im using an IMU (Internal Measurement Unit). Arduino has libraries for some of the IMU cards and it simplifies the coding. One just need to add the library and the IMU ”spits” out the angle, very simple and nice! When using Gyro and Accelerometer, in order to combine these to get an angle one must use complementary-filter or Kalman-filter.

    So my suggestion is to use a 6DOF or 9DOF IMU. I bought one on e-bay search for ”9DOF sensor stick” I will upload the sensor-card on ”hardware” and the code as soon as i can!

  3. I measure the angle with a IMU-card. And I use the I2C-bus to read the sensor values. The controller that I use is an Cascade connected PID controller. And also a PID-controller for wheel-speed. I will update the software-side soon. But you can read about the sensor in ”About the sensor and hoe to connect it”. There is also some test code that one can test the sensor with :)

  4. can you explain for me about ”Cascade connected PID controller”?
    thank you,samir! :)

  5. Yes, my intention is to share the code. I need to clean it up first, lots of old cod in it :) But I will upload the code.

  6. Hi there, I’m building a similar robot for my school project and was wondering if you would mind sharing the code and also explaining the steps taken? I’m going to be using a different microcontroller so i’m trying to understand how the program works on the Arduino first. Thank you, hope to hear from you soon!


  7. Hi Samir,

    Great job on the robot. I am building the same and am pretty close. I think I just need to fine tune my PID and would love to see your code to see how you did it. I know my kp, kd, ki will be different but I would still like to see how you did it if you do not mind.


  8. Hello!

    I see that you have used a PID Control for this system. Do you mind sharing the method and need for cascading it?

  9. Hi Samir!
    Great work on the robot! Would it be possible to share your code? I am having difficulty implementing the PID controller, So if you could send me the PID snippet, or the whol code, irrespective of messy it is, I would be very appreciative!
    Thanks in advance,

  10. Hello!

    Have you cleaned the code yet? Could you share it with us? I’m very interesting in doing this project myself.

    Thank you!
    Best regards.

  11. sir i am trying to do a balancing bot but there is too much of oscillation.i want it to be like the 1 in your balancing bot video.its awesome.. could you please share your code so that it would be helpful for my project

  12. hey there, i am kind of stuck on the coding. so is it alright that you can provide the codes of this project? that will be great help. thanks mate

  13. I have used almost same components as u did. Its 2014 now and I can see you haven’t uploaded the code so Do you mind sharing your code?? its kind of urgent.

  14. Pau, is it so that you can’t program yourself? Why don’t you try to do that, maybe you learn something from it… Im not obliged to help you in any way, the code is free and the knowledge i give is free.

  15. Hi. I was wondering if your robot is able to move (remote control). I’ve seen some functions for it in your code, but I am curious how would it look like in reality. I’m doing similar robot and I have a problem with PID setup. I implemented cascade PIDs for wheels velocity and for angle. Just like you. To be honest I didn’t use your code because I found it just today.
    My problem is that when I try to make it move forward, backward, turn etc it oscillates too much. When steady everything is cool, even when I push it, the reaction is quite decent. The problem is movement. You can see it on this video:
    It cannot keep the constant speed, it just accelerates and deccelerates. It looks like the PID loop which is controlling the speed tries to keep required speed and when it is overshoted, it brakes, but it does it too strong. Unfortunately I tried many different configurations of PID values and I’ve lost many hours without any positive effect.
    Today I’ve read in one of your comments that you recommend using motors with RPM > 300. In fact now I use motors from pololu which have 50:1 gearbox. It means that the speed in RPM is only 200. I wonder if you tested motors of similar parameters and they were giving bad results and that’s why you recommend different motors. I saw several balancing robots, some of them worked very well and they all had 29:1 gearmotors. Do you think the replacement of the motors will improve performance of my robot? And it would be great to see your robotin movement. Do you have such video?

  16. Hmmm… Sounds like you get a windup-problem. If you want to make a remote controller. There are tow ways. 1. Set an ofset on the angle. Force it to move to ceep steady.
    2. Increase motor position… Add or remove steps. Then you need a PID that has setpoint=0. The PID will then move the robot so that it furfills the stated setpoint. I dont think that your motors has anyting to do with this part… You might not be able to get fast reactions from it… So that can mess up some things. But try and see. Else change the motors. //sam

  17. Your link… ”/home/myvideos” you need to logout then copy the public link for others to see your video :)

  18. Of course. I have noticed that. Silly me. Here is proper link.

    On this video you can see that robot accelerates and slows down repeaedly. As I said I control it with cascade PID loops for motors speed and tilt angle.The speed PID setpoint was set on constant value but it cannot keep constant speed.

  19. Hmmm… How about the position of the wheels, can du add (++) on the motor/wheel position instead? And don’t mind the motor speed… Try and see, I’m gonna try the same for my robot.

  20. You mean that I should try to replace the pid loop that regulates speed with loop that regulates position (remove position integrating process) and then give a desired position as a setpoint? I think I tried this solution in the past and the robot was moving even worse. There were much more oscillations regardless of PIDs settings. But maybe I shuld indeed try to make it one more time. In few days I will replace the motors’ gearboxes for 29:1 and check dynamic parameters. Maybe they are just too slow to achieve desired speed fluently…. If motors fail I will try to regulate position..

  21. Sounds like a plan. Yepp, maby the RPM is to slow.. I notice that if you just replace one hardware with just a small amount of change to another, the total outcome can change a lot. Keep me updated!


E-postadressen publiceras inte. Obligatoriska fält är märkta *

Följande HTML-taggar och attribut är tillåtna: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>