Arduino Forum

Topics => Robotics => Topic started by: lukagabric on Mar 23, 2014, 07:02 pm

Title: Self balancing robot issue
Post by: lukagabric on Mar 23, 2014, 07:02 pm
Hi all,

I've been working on a self balancing robot (http://goo.gl/D4Sl61) using Arduino UNO, IMU is 6 DOF MPU6050 (GY521) Accel + Gyro, L298N Motor Driver, 2 x 12V 122rpm DC motors with 80mm wheels.

To get correct angle, I'm using Kalman filter which is providing results with little noise, here is the Processing video: http://youtu.be/JN4TPRrLeRc.

I've posted the source code (sketch + libraries) on my GitHub repo:

https://github.com/lukagabric/Franko

The robot oscillates a couple of times before it falls over (up to 3 seconds max). I have 3 potentiometers for PID tunings. I've spent quite some time trying to tune the system but with no success. Any help would be much appreciated.

Thanks,
Luka.
Title: Re: Self balancing robot issue
Post by: johnwasser on Mar 24, 2014, 12:02 am
This project might provide some hints:
http://students.iitk.ac.in/eclub/assets/documentations/summer12/self-balancing-bot.pdf

Check out the PID Tuning section.
Title: Re: Self balancing robot issue
Post by: Nishant_Sood on Mar 24, 2014, 03:00 pm
This is a very good source that I'm reading too! >> http://blog.tkjelectronics.dk/2012/09/a-practical-approach-to-kalman-filter-and-how-to-implement-it/
Title: Re: Self balancing robot issue
Post by: lukagabric on Mar 24, 2014, 05:22 pm

This is a very good source that I'm reading too! >> http://blog.tkjelectronics.dk/2012/09/a-practical-approach-to-kalman-filter-and-how-to-implement-it/


I don't think Kalman is the issue... The values are without noticeable noise, you can check the video. I recorded the graph from Processing.
Title: Re: Self balancing robot issue
Post by: lukagabric on Mar 24, 2014, 05:31 pm

This project might provide some hints:
http://students.iitk.ac.in/eclub/assets/documentations/summer12/self-balancing-bot.pdf

Check out the PID Tuning section.


I've seen this method mentioned on a number of self balancing robot projects. I've already tried tuning the robot like that quite a few times but with no success. I'm not sure if the issue is in code or maybe the design itself. I tried to replicate the design from other self balancing robot projects I found online...
Title: Re: Self balancing robot issue
Post by: charliesixpack on Mar 24, 2014, 06:58 pm
You are correct that you do not need a Kalman filter.  You also do not need an accelerometer.  Check out the attached document for some of the myths concerning balancing robots.
Title: Re: Self balancing robot issue
Post by: johnwasser on Mar 24, 2014, 08:05 pm
Perhaps your tuning knobs don't cover the stable region.  Try changing the range on your various tuning knobs (one at a time) to allow for finer tuning as you approach usable settings.
Title: Re: Self balancing robot issue
Post by: lukagabric on Mar 24, 2014, 08:40 pm

Perhaps your tuning knobs don't cover the stable region.  Try changing the range on your various tuning knobs (one at a time) to allow for finer tuning as you approach usable settings.


For kp i tried ranges from 0 to max output, for ki i tried ranges from 0 to 4 times max output and for ki very small values... everything as advertised on other projects but no luck.
Title: Re: Self balancing robot issue
Post by: lukagabric on Mar 25, 2014, 01:59 pm
Just to follow up.

I was suggested to try out this implementation for MPU6050 (instead of reading and combining data using Kalman filter): http://goo.gl/A1W2uP

After I implemented that I got far better results than before, still not balancing but I haven't had the time to play with PID tuning yet. I plan to add a running average filter and place the MPU a little closer to the base of the robot. I hope that it will improve stability and the robot would finally balance. Here is a clip of current progress, even though the robot is still not balancing: http://goo.gl/2LbvGN
Title: Re: Self balancing robot issue
Post by: polyglot on Mar 27, 2014, 10:58 am
Using a Kalman or any other form of filter introduces latency into your control loop, which will make it much harder to keep the loop stable.   Think of it this way: more delay means less phase margin.
Title: Re: Self balancing robot issue
Post by: lukagabric on Mar 27, 2014, 11:01 am
I'm not using Kalman, just reading the MPU6050 values I get. After some PID tuning and adjusting the wheel speeds this is the result I get. Hope to improve stability a bit more:

https://www.youtube.com/watch?v=mW9SlK1hiZA
Title: Re: Self balancing robot issue
Post by: thw777 on Mar 29, 2014, 03:16 pm
Hello,

I think you might need a feedback from your motors. DC motors have a dead zone and do not start to move until the applied voltage overcomes it's friction/robot weight. It will usually overshoot right after its first move. In other words, the voltage-speed control is non linear. You might also notice that the motor will operate at different speed when different load is used at the same voltage. When there is a load, your motor driver's input speed differs from the actual motor's output speed.

Perhaps you might want to attach a tachometer or use motors with encoders. Either of these device will be able to feedback the motor's actual speed. Then you can use PID to tune the motor's speed.

Try to tune your motor's speed response first, making sure that it's speed can be controlled linearly before tuning the balancing PID.

Hope that helps;)

-thw777
Title: Re: Self balancing robot issue
Post by: lukagabric on Mar 30, 2014, 12:23 pm

Try to tune your motor's speed response first, making sure that it's speed can be controlled linearly before tuning the balancing PID.


I have noticed a lag when the robot gets an offset from the vertical position. It takes a split of a second for motors to start moving. Is that a dead zone? I feel like the motors should have started to move slowly, but they lag and then they start to move fast right away. The robot is balancing, but I think the robot would balance much better if the wheels would turn a bit more responsively from the vertical position. How to compensate for that dead zone? Currently I output the speed from 0->255. Should I map the speed of 0->255 to something like 30(or so)->255 to compensate for the wheels not moving due to the friction of the wheels and the weight of the robot? Is there a way to get the linear speed control (or close to that) of the wheels with current motors without adding additional components like encoders?
Title: Re: Self balancing robot issue
Post by: wildbill on Mar 30, 2014, 01:23 pm
When the PID responds to a small error, the resulting output will be small. It sounds as though, as suggested, your motors don't do anything for low values of PWM.

Quote
Should I map the speed of 0->255 to something like 30(or so)->255 to compensate


Sounds like it would be worth a try.
Title: Re: Self balancing robot issue
Post by: lukagabric on Apr 08, 2014, 08:11 pm
Here are two more videos after I added motor dead zone compensation:

https://www.youtube.com/watch?v=i-PIlF5rdAA
https://www.youtube.com/watch?v=anxJNQCpQuA
Title: Re: Self balancing robot issue
Post by: charliesixpack on Apr 11, 2014, 12:48 am
The dead zone problem is common for DC motors.  Using the Lego NXT I was able to record the motor input and the wheel position while my robot was balancing to get an accurate fit for my model of input vs output.  You could see that for small values of motor input the wheel position was not moving even though the motor input was small  but non-zero.  I have a plot of this phenomenon but can't manage to post it here.
Title: Re: Self balancing robot issue
Post by: grasshopper on May 14, 2014, 04:22 pm

Here are two more videos after I added motor dead zone compensation:

https://www.youtube.com/watch?v=i-PIlF5rdAA
https://www.youtube.com/watch?v=anxJNQCpQuA


Hi! How did you add the dead zone compensation? Only by adding an offset to the PWM signal?

Thanks!

PS: I'm working on a balancing robot too, but I don't get full stability. It gets perturbations from it's own start-stop acceleration that makes it drift a little bit too much
Title: Re: Self balancing robot issue
Post by: lukagabric on May 14, 2014, 04:55 pm
Yes, just by adding an offset to the PWM signal.

Also, adding weight on top of the robot improves stability. And be sure to check the standard PID tuning techniques, that is the most important part.
Title: Re: Self balancing robot issue
Post by: caymanguy on Jun 11, 2014, 01:49 pm
hi

where I connect the gyro and the :
3 .....  10 k resistance !!!!
from where I get I2Cdev.h

Title: Re: Self balancing robot issue
Post by: randomvibe on Jun 12, 2014, 12:51 am
Here's my self-balancer without gyros or accelerometers:

http://www.youtube.com/watch?v=bxx14Xe2iNg

It uses one IR range sensor to measure pitch angle, then differentiate that to get pitch rate.  These feed a PID controller for stability.

I'm working on a new version without the IR range sensor because that system only works on smooth flat surfaces.  I built and IMU with a Kalman filter on the Arduino Due using the Eigen C++ library for the matrix math.  Next step is to integrate it all.
Title: Re: Self balancing robot issue
Post by: caymanguy on Jun 14, 2014, 07:36 am
plz can u answer me where to put the 3 10 k ohm variable resistance and the gyro sensor


:smiley-eek: :smiley-eek: :smiley-eek: :smiley-eek: =( =( =( =( =(
Title: Re: Self balancing robot issue
Post by: caymanguy on Jun 28, 2014, 09:23 am
i did it

i will upgrade later

http://youtu.be/kIss1mZJWPs
Title: Re: Self balancing robot issue
Post by: caymanguy on Jun 28, 2014, 09:29 am
https://www.youtube.com/watch?v=kIss1mZJWPs
Title: Re: Self balancing robot issue
Post by: caymanguy on Jun 29, 2014, 11:13 pm
no active post why
Title: Re: Self balancing robot issue
Post by: ranrettig on Jul 26, 2014, 08:45 pm
hi
is it possible for you to post the code so we can all enjoy? :)
thanks!
Title: Re: Self balancing robot issue
Post by: cagiva on Nov 06, 2014, 08:35 am
We decided to install an Android device on the robot to control its balance instead of using an IMU. Here you can see the result:

http://youtu.be/xtMCmuR8uNU
Title: Re: Self balancing robot issue
Post by: Southpark on Mar 20, 2016, 09:20 am
You are correct that you do not need a Kalman filter.  You also do not need an accelerometer.  Check out the attached document for some of the myths concerning balancing robots.
It's pretty odd how they mention things like :

http://forum.arduino.cc/index.php?action=dlattach;topic=228028.0;attach=74470 (http://forum.arduino.cc/index.php?action=dlattach;topic=228028.0;attach=74470)

"You can balance with just PID control but if you give the robot a push or have an offset in the gyro output you will cause the robot to fall."

And "In order to balance you need PID control plus positive feedback."

And "Positive feedback seems to be necessary. If you are balancing with a 'complementary filter' you are introducing positive feedback. If you are balancing with a gyro and an accelerometer you are introducing positive feedback. If you are balancing with a gyro and wheel encoders you are introducing positive feedback."

I disagree with most of his/her comments. Maybe even all of their comments.

I agree that you don't need a Kalman filter or an accelerometer, or wheel encoders for balancing a bot though. On the other hand, some of these features could enhance performance if you have a fast enough processor to handle things. But a number of things in that 'myth' pdf is quite misleading.

Their equation that comes after their sentence "PID control with positive feedback looks like this..." is erroneous.

I've recently been tinkering with a balance bot, and looking for information in the Arduino forums. Getting ideas about what others are doing to get their bots to balance really well, and dealing with noisy data and practical effects. Stumbled on this myth pdf, and thought some of the teachings in there are kind of misleading.