Balancing robot for dummies

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?

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: TKJ Electronics » The Balancing Robot.

Update
I have now ported the code to Arduino.
The code can be found at github: The Arduino version, can now be found at github: GitHub - TKJElectronics/BalancingRobotArduino: This is the Arduino version of the code for my balancing robot/segway

Regards
Kristian Lauszus

Good job, 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!

Robot Pic.png

#ericlausanne
I'm not totally sure what you mean? :slight_smile:

#rob4white
Thank you, see my reply at my blog: TKJ Electronics » The Balancing Robot

ericlausanne:
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

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

@Eugene

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!

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

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

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):

http://www.kerrywong.com/2012/03/08/a-self-balancing-robot-i/
http://www.kerrywong.com/2012/03/14/a-self-balancing-robot-ii/
http://www.kerrywong.com/2012/03/21/a-self-balancing-robot-iii/

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:

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! :slight_smile:

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.

Also what do you guys think of this IMU. The goal is to use this on a balancing robot first and if I have success I will move onto a quad copter.

#rob4white
I followed this guide to find the P, I, and D constants:
http://robotics.ee.uwa.edu.au/theses/2003-Balance-Ooi.pdf see page 42:

  1. Select typical operating setting for desired speed, turn off integral and derivative part, and then increase Kp to max or until oscillation occurs.
  2. If system oscillates, divide Kp by 2.
  3. Increase Kd and observe behaviour when changing desired speed by about 5% and choose a value of Kd that gives a fast damped response.
  4. Slowly increase Ki until oscillation starts. Then divide Ki by 2 or 3.
    I more or less followed that, but I then fine tuned it myself. I recommend using a wireless application, so you can set them wirelessly, as mentioned in the video, as you have to spend a lot of time finding those values.

#Wmgatorfan08
Yes I think it is possible to make a very low cost segway using those parts, but I don't think the performance will be as good, but I will still be a great learning experience and a fun project. Just take a look at AlphaZeta robot: Balancing robot for dummies - #43 by AlphaZeta - Robotics - Arduino Forum
That only cost approximately 20$ excluding the motors!!

I think your forgot to insert the link for your IMU :slight_smile:

Sorry here is the link SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 - SEN-10121 - SparkFun Electronics

I feel pretty comfortable with this IMU. I have been reading a lot about it and have already found several examples of code to get the data that I need. I have been using arduino for about a year now so I feel pretty confident with my ability to get the board working. I am not as familiar with I^2C as I should be but I am reading and working on it now.

My main concern is the motors. I know that selecting the proper motors and wheels will make or break the project. Ultimately I am thinking I need something with a lot of torque that can respond quickly. I don't think I need high rpm, but it must spin fast enough to catch up with itself when falling.

Possibly this type of motor with the encoders. http://www.robotshop.com/12v-gear-motor-encoder.html

Also correct me if I am wrong, but I am thinking something around a foot to foot and a half tall with the center of mass being around the motors. From what I am reading the IMU needs to be near the top?

For best results, the IMU needs to be placed near the center of the gravity of your build, wherever that is. Typically, the higher the center of gravity is, the easier it is to balance as the timing becomes less critical.

Yeah I guess that would be true because of the moment of inertia. So ill move the battery toward the top and mount the IMU close to it.