Go Down

Topic: Balancing robot for dummies (Read 91178 times) previous topic - next topic


I'm going to try this code on a ChipKIT Uno32 because of the incredibly fast processing speed in comparison to the Arduino. (80Mhz) I think that should take the loop time down significantly, thus potentially leading to better balance.

One thing I really don't understand is the Kalman filter.

Patrik, or Kas, could one of you offer any insight into being able to further tune balance by changing the Kalman parameters?


Mar 04, 2012, 11:53 pm Last Edit: Apr 15, 2012, 11:19 pm by Lauszus Reason: 1
Hi guys,

Just want to show you a robot I made. It uses the motors, brackets and motorcontroller as Kas original used:

See my blog post for more details: http://blog.tkjelectronics.dk/2012/03/the-balancing-robot/.

I have now ported the code to Arduino.
The code can be found at github: The Arduino version, can now be found at github: https://github.com/TKJElectronics/BalancingRobotArduino

Kristian Lauszus



In wich sector ( industry, army ) it will be able to be use ?


Unbelievable work Lauszus!!

I am also in the middle of getting my robot to balance.. Tried to implement the original coding from KASbot but I haven't yet managed to change the PID values etc.

It's only when you try to do this yourself that you realise how challenging it is! Hopefully I will get my balancing program working soon... RC control is a long way off!



I'm not totally sure what you mean? :)

Thank you, see my reply at my blog: http://blog.tkjelectronics.dk/2012/03/the-balancing-robot/#comment-20483


In wich sector ( industry, army ) it will be able to be use ?

only for play and self-satisfaction =)


Lauszus make screenshot of your "Processing application" pls


why the IMU (red small board) placed on the middle platform, not near the wheel axis (middle of bottom platform)?



I know what you mean that it is deemed most effective to place the IMU as close to the wheel axle as possible. However my thinking was that because the gyroscope measures the angular velocity, I thought it would be most effective if the gyroscope was as close to the top of the structure ie. where the battery is so it would measure any slight variations in angular velocity...

I could be wrong in the this... Let me know your thoughts!


See my github, here a link for the compiled versions of the processing application:

You should put the IMU as close to the axis as possible, as I wrote in my email.


Mar 24, 2012, 01:22 am Last Edit: Mar 24, 2012, 01:25 am by AlphaZeta Reason: 1
I just built a balancing robot using ATmega328 and Arduino libraries myself. I built it using a toy truck as a base, while not as stable as some other builds it is easy on the wallet. Here is a short video:

You can find more information on the theory and the build on my blog (three parts):



Thanks Eugene and Lauszus for the advice, I fully understand now why the IMU should be as close as possible to the axis of rotation.

However, I am quite close to achieving balance with the current setup, I am kinda short on time to move the IMU to the lower deck as the project deadline is fast approaching... Or am I just wasting my time trying to achieve balance with the IMU located where it currently is?? (about 50mm above the axis of rotation in the vertical direction)

My current stumbling block is finding the correct PID parameters.. I am using the original coding as posted by Kas in the initial thread on this topic

Am I correct in thinking that I should tune the terms in this manner. Tune Kp value first then Ki value then the Kd value and finally the "outside"  K value? The coding I am referring to shown here:

Code: [Select]
float K = 1.4;
int   Kp = 3;                     
int   Ki = 1;                   
int   Kd = 6; 
int last_error = 0;
int integrated_error = 0;
int pTerm = 0, iTerm = 0, dTerm = 0;

int updatePid(int targetPosition, int currentPosition)   {
  error = targetPosition - currentPosition;
  pTerm = Kp * error;
  integrated_error += error;                                       
  iTerm = Ki * constrain(integrated_error, -GUARD_GAIN, GUARD_GAIN);
  dTerm = Kd * (error - last_error);                           
  last_error = error;
  return -constrain(K*(pTerm + iTerm + dTerm), -255, 255);

I will try to post a video today to show the stage of balancing that I am at! :)

Any advice appreciated! Thanks guys!


Hey guys I am thinking about trying to build one of these self balancing robots.  I have an arduino r3 motor shield.  Im curious if I can find good enough motors that I can control with my shield and not push the 2 amp limit.

Go Up