Go Down

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


After some request I decided to start up a new topic to continue the two previous topics made by @Kas. Where the discussion and support of building balancing robots can continue..

Heres the previous topics that now are read only:

All information and some source code are hosted here: http://www.x-firm.com/?page_id=145

Robots built using the guide or parts of it: http://www.x-firm.com/?page_id=284

All initially information of the Balancing robot for dummies was provided by @Kas and I half to tank him to inspired me to finally start building a balancing robot that I had planed to do for so long.
The balancing robot for dummies guide


Thanks to Patrik for getting this subject going again. I am in dire need of help......

Ok, so I've built a couple of balancing robots but have yet to achieve 'balance'. I'll post photos and video clips later (am at work), but for now I'd like to fish for advice given I get the same problem irrespective of code/hardware changes.

I've used code from a few sources, but am currently testing KbotV1.1 which I've managed to adapt to my setup.
I've used sparkfun IMU's, but am currently using the one from gadgetgangster.
I've used Pololu 300rpm motors, but have just switched to a couple of 300rpm planetary gear motors I sourced locally in the UK (E192.12.13
- http://www.dcgearedmotors.co.uk/E192.html).

So, my problem seems to be that when I have the gain high enough so that it can pick itself up to the point of low freq oscillations (overshoot) I seem to get an additional high freq oscillation which I _think_ seems to be caused by motor/gearbox backlash. It's like the robot is bouncing off the backlash points.
I have fitted an LED on my robot which basically will be on when driving forward and off when driving backwards......this LED will flash rapidly. I also scoped the PWM output and you can see the 'chatter' in the output.

It's almost as though the gyro/accel signal is noisy.

So, I raised the robot off the ground and have it sitting perfectly vertical and very stable/fixed. If I leave the main loop scan at 9mS then the chatter is noticeable, but the more I reduce it the better it gets.

So believe it or not I overclocked my Arduino to 28mHz and got the main loop down to less than 2mS and it's better but still there.

No matter what code I use (i've tried a good few from various sources and including writing my own) the problem is always the same. I've played with the PID settings, I've replaced the PID code with others I've found.

I've written my own interrupt routines to fix the scan time of all the subroutines not just the main loop.

I've tried different sized wheels, weighted the robot differently, moved the IMU central to the axle.....everything.

I guess a video will speak a million words, so I'll upload one tonight.....for now here's where my test code lives:-




May 03, 2011, 10:22 pm Last Edit: May 03, 2011, 11:22 pm by IanJohnston Reason: 1

Here's some pictures and video clips of my Bot.

PID settings used to demonstrate 'chattering' problem:-

#define   GUARD_GAIN   5.0
float K = 1.4;
int   Kp = 6;                      
int   Ki = 1;                  
int   Kd = 1;  

These motors are real quiet, so the chattering you are hearing is the problem.....and you can see the chattering is in sync with the LED on my bot that signifies motor direction. You can also see/hear that when I pick the bot up and move it back and forth and also completely still that there is no chattering, it's only when the bot is on the ground and the control loop is complete that it starts, and obviously the higher Kp the bigger the chattering.
I've tried other PID loops as well as all sorts of settings to no avail. It's also worse on a hard surface hence the large soft tyres and carpet test.

Any ideas?

PS. I haven't tried the encoders on the motors yet.

Update:.......Have been playing with the code and I'm beginning to think my Bot is too heavy for motors that don't like low voltages. Even without any load my motors, which have a range of 0 - 255 (127 is stop), need to see 122 or 123 before they really start to move and even then any load at all and they won't move. So, the net result is the oscillation I have been seeing.










I haven't had the time to look at your code yet but it sounds like your having the same problems that I have..

I have no problem getting my robot to balance but it's shaking a lot and I think it's manly to the backlash.
You can see it in the video blow if you look closely you will see the shaking..

I have recently seen that I may have a problem with my IMU which the zero point is moving after a will and that I also think is do to the shaking and mess up the kalman filter..

My next step is to change the motors to the stepper motors below:
#1200 Stepper Motor: Unipolar/Bipolar, 200 Steps/Rev, 42x48mm, 4V, 1200mA
#1182 A4988 Stepper Motor Driver Carrier

The balancing robot for dummies guide


Word of caution on stepper motors, they are significant power drains, essentially drawing peak current at all times (unless completely unpowered, in which case they have effectively zero holding torque).  In a more stable rover-like platform where you could completely cut power when not moving, they may not be too bad, but in a balancing bot where the motors have to be driven constantly, battery life will be significantly diminished with stepper motors.


I agree that it will significantly lower the battery life but It would be nice to see the bot perform without the backlash that I currently have with my DC-motors.. 
The balancing robot for dummies guide


May 06, 2011, 01:44 pm Last Edit: May 06, 2011, 02:02 pm by markB Reason: 1
Great to see another balancing project.
Mine is still a collection of pieces waiting for a useless Australian supplier of driver boards to even reply to an email....anyway.
Yes i know there are lots of other suppliers, but not for motor currents above 2 Amps, which if theu don't work out will be suitable for a second purpose.

If I recall correctly, I read somewhere (it might be from Kaz original postings, or a sedgway application) that someone had backlash issues, and it turned out to be the motor controller.
Not sure what the exact problem was (or if my memory is right), but my guess would be the amount of zero time, so that the driver devices didn't get fried when going from forward to reverse.
It could be that they went to faster motors (less gearing) with a better controller as well, and found the controller was the problem.  :~

You should be able to measure the backlash by shorting the motor, and seeing how much rotation there is before you meet resistance.

I would agree with the stepper drain issue. A DC motor with a short across it, applies significant braking force, with no power drain.

Good luck and keep up the great topic.



May 08, 2011, 01:33 pm Last Edit: May 08, 2011, 04:13 pm by IanJohnston Reason: 1
Hi all,

Having played with it again, I think there is 1 significant issue which cause chatter and a failure to balance properly with my bot. Please also bear in mind I have 2off completely different software designs but which both give the same problems at the end of the day.

It seems to me that these DC motors don't have much torque at the very low voltages being applied around the balance point. This means it takes a good few counts to get the motor going, and when it does get going it flies off. Thats why when I pick my bot up and move it back and forth there is ZERO chatter......but give it even the slightest load and the low torque suppresses the motor movement.

To compound this, I remember my first bot used RC servos, and I had no chatter and it balanced much better.

So, I think I'll need to hook up the encoders on the motors, but in some intelligent kind of way, i.e. in some kind of feedback loop so that the Arduino applies motor power and will be able to tell when and if the correct speed/movement has been applied.
I have seen encoders used in some balancing robot PID loops, but I'm not sure that's good enough.......I need to get a better understanding..........

My ultimate goal is a home-built Segway.......and I'm always wondering whether the wheelchair motors etc that I plan to use will have the same low torque problem around the balance point.....or whether this problem is limited to my small bot only......hmmmmm!



May 08, 2011, 06:20 pm Last Edit: May 09, 2011, 02:51 pm by prof_jazz Reason: 1
Hi all,

this is my bot...made using as a "trace" the Kas guide.. and spending a lot of time (more ore less 6 months).

on the third month the bot was running, then an inverse current from the motor driver burned Imu, Arduino and the sonar..

I am now using the 5dof Sparkfun analog Imu..anyway I also tried the Fabio Varesano digital FreeImu.


The last version uses a sonar that make the bot turn when an obstacle is <=25 cm close....

Motors are the Pololu 29:1 Metal Gearmotor 37Dx52L mm with 64 CPR Encoder (http://www.pololu.com/catalog/product/1443);

It works because:

1) the new wheel ( http://www.robot-italy.com/product_info.php?cPath=7_158&products_id=1525) are much more heavvy than the previous (http://www.pololu.com/catalog/product/1435);

2) the bot is much smoller than previous version (now 25 cm).

With our motors the bot has to be small and "not high" other wise you'll never correct a tilt with a K*velocity of motors, velocity of motors will only generate a translation of the bot that will compensate only partially the tilt.

With heavy wheel and a toll bot K*velocity will compensate the tilt.

My way:

1) I did find (making 10 tries and then evaluating an average) the "zero" values of the 2 Acc and the Gyro. Then You have to use always this 3 zero values..your tuning will not depend any more on the starting position.

2) I manually found the "real" setPoint (the one that makes the mass center cross the motor line).

3) I used a potentiometer to find the right set of PID values;

4)You'll find Kp working with the  potentiometer as the values that make the bot oscillating (it will jitter because of backslash...)

5) Then I used a low Pi and found Kd using the  potentiometer as the values that make the stop oscillating...be careful if you use a bigger Kd the bot will be "nervous"..

6) Kpwheel will be set as enough to make to bot turn back, but it will create again oscillation (non on the tilt but on the position);

7) Kdwheel will be set as  the values that make the stop oscillating on the position.. be careful if you use a bigger value the bot will be "nervous"..




Great info......looks like I need to play with Kasbot V2 and the encoders.



I'm interested in the wheelchair motors bit, as that's exactly what I had planned.
Only problem is the speed.
Mine are about 60rpm, but bigger wheel dia (not normal chair size)

I read here http://tlb.org/scooter.htmlthe he had issues until he went to a new controller, and bigger wheel.

Now that yours balances, any chance you could give the wheel rotation, and diameter, so we can check the speed.?



May 08, 2011, 10:41 pm Last Edit: May 08, 2011, 10:43 pm by IanJohnston Reason: 1
My motors are Jazzy 1121 wheelchair motors (rated at 5mph with 14" wheels which I work out at 120rpm).

Probably gonna use a Sabertooth 25A Dual Motor Driver.......once I can get the proper spec for my motors.



May 08, 2011, 11:48 pm Last Edit: May 08, 2011, 11:52 pm by markB Reason: 1
Thanks Ian
I have ordered one of these controllers to try http://secure.oatleyelectronics.com//product_info.php?cPath=94&products_id=206, however getting across the water has been an exercise in frustration.

If they ever get here, It wil be interesting to see how they go, as they should be capable of 40Amps at 24v.

I've just checked mine again and the motor are english and the sticker says 113rpm 7.5 Amps 24v.
The wheels are 12.5 inches, so if my maths is right at 100% it should be 4.19mph.

in reality the segway and all balancers only drive at 80% full speed, so its more like 3.3mph for mine.
Since its a balancer, not a rideon, it should be okay.

I have riden one of the newer segeways. it had the offroad tyres, and you moved the handlebar sideways to steer left or right. It was very natural, and even the wife had the hang of it within a couple of minutes.




Nice progress I will also try with the bigger and heavier tiers. I'm currently rebuilding the frame to get It a little higher and get space for a 4x20 LCD and some potentiometers. Then I will remove all the the jumper cables and the breadboard..

I don't know if you had any musics in your youtube clip but it's blocked in Sweden do to Sony Music Entertainment (SME). If you have music in the clip could you post another without music?
The balancing robot for dummies guide


May 09, 2011, 09:40 am Last Edit: May 09, 2011, 09:37 pm by prof_jazz Reason: 1
@ MarkB:

i posted the links of my motors and my wheels, you should read all the tech. specifications...please tell me if you need something else..

Here is a link without music:


Go Up