Self Balancing Robot

Hi,

I have build a balancing robot based on Sparkfun 5DOF acc/gyro combo, Arduino and Parallax continuous servo.
I had sofar mixed results and suspect the servos have to much backslash

I want to test the AX12 route.
Can you point me to some Arduino code to run these specific servos ::slight_smile:

TIA
Yves


The "looseness" you describe is a real problem with balancers. I used motors similar to yours at first, but was able to achieve much tighter and more responsive balancing by switching to zero-backlash servos (Dynamixel AX-12).

Here's a little sample movie of what a difference reduced backlash makes: ....

That demo is using the "encoder" (continuous rotation pot) integrated into the AX-12.

A friend of mine worked on a commercial balancing toy. He mentioned that it used cheap high-backlash motors, and they had to use sophisticated filtering and modeling to accommodate the backlash. It took an experienced control expert quite a while to get it working.

So I'll just stick with tighter motors.

  • Nathan

Hi,
This is really nice work!!
How did you design the control law? Do you have or used any white paper on (LQR) controller design?

:slight_smile:

Thanks :slight_smile:
uhm no, I implemented a PID controller to control the motors.

I implemented a PID controller to control the motors.
Well, did you publish your implementation steps somewhere? Is it possible to know and repeat your steps? :slight_smile:

I have a background in mathematics of PID, LQR and so on, but no practical experience. It could be very helpful to just repeat your steps for the first time, if it is allowed.

:slight_smile:

It is sure possible :slight_smile: It just require some understanding and patience.

Well first off i did a quick test of the hardware, making a simple arduino program to read some raw values from the IMU, just to check that it was working properly.

Then i studied/implemented/adapted the Kalman filter to obtain the correct angle, which was the thing that was scaring me off the most (it would be a waste to have a complete robot and then be unable to read the value :P). I proceeded by strapping the Arduino and the Imu on a wood stick. Then i did a simple pc program (with Delphi, but you can use whatever :P) that reads the angle data from the serial line, and show a simple line that is (should be) oriented as the robot. That gave the best "feeling" of how precise the measuring was. At that point i spent quite some time debuggin the filter to obtain a stable and responsitive reading, mostly a work of trial and error that is unluckly very coupled with the specific hardware and setup (read: you have to adjust your own parameters :P)
After i was satisfied with it, i designed the robot (well most of it was already on my mind), i used pen and paper and rulers and also did some 3d sketches with blender. Then went on building it. I can say: keep the design as simple as you can, becouse then just the slightest error drilling a hole or gluing something can make everything displaced and ultimately a great pain :slight_smile:

Then i did some test, simply running the motors proportionally to the current angle. At the time i didn't know what a PID controller was :slight_smile:
That gave some results but of course it wasn't stable at all. I learned the PID controller and implemented it (which is easy) and tuned it (which is hard, as you probably already know :stuck_out_tongue: ). The best thing you can do is to find some generic values to determine the order of magnitude and then attach three potentiometers to dinamically change the P,I and D parameters while the robot is running. Wikipedia has a good practical article on the PID that explained a couple of tecniques to find the parameters.
At the end the results was the one on the videos: the robot can actually stand without fall for indefinite time, but it's not completely stable and swings back and forth quite a lot.
That's possibly a combination of bad hardware, bad robot structure, and me not being an engineer :slight_smile:

Btw i'm now planning a second version with different hardware, i'll post on this forum as soon as i've something :slight_smile:

That was it, feel free to ask any question. :slight_smile:
The complete source is avaiable on this thread.

Thank you very much for sharing your experience, it gives insight! I am following you :wink:

great :slight_smile:
if you are planning on hardware, i'll suggest making it smaller than mine. It was too heavy and the structure was barely strong enought not to break apart when falling. In my new version i'm keeping the Arduino and the IMU, and using instead a simple motor driver (an L293something), two small pololu motors and 4 AA cells.

Thank you for information!
Actually I'm late for using this information, as I've already purchased the hardware.

By the way, why didn't you use a driving system based on incremental quadrature encoders? Well they have their own specially adapted Kalman filter, and I think that (at least theoretically) using them together with their KF, gives a cheaper/better/lighter/more sophisticated driving system. May be you have already tested them?

Hi my friend, this is really great, congratulations ;). I found in an other forum than you "burn" the MD23. I am worried, because I followed your steps and I do not want to burn my md23, do you found what was the problem?, thanks a lot.

Cuauh

Thanks :slight_smile:
Yes i did burnt an MD23. That was a very sad experience, my first "expensive" hardware lost.
Anyway, i did it just connecting the MD23 to an unregulated power supply. Yes that's a stupid mistake, but i'm learning electronics on the go, and i was not aware.. basically the power supply shoot 15V or more to the board and a chip released its magic smoke.

If you're unaware of the issue (but you probably are :P), i suggest learning it the soft way reading this:
http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=103

ironbot: uhm no, i didn't used the encoders.. I can't see how to take advantage of them. how would you use them ?

Well, as you know I still did not implement them so I'm not sure how much it is practically effective.

Give me a month and I bring some experimental results.

For now, all I have to share is the theory:
http://www.mindspring.com/~tom2000/Delphi/Codewheel.html

I have the math of KF for optical encoders in a pdf file. If you would like, I send it to you.

I have a question:

On the IMU board which I purchased exactly as you recommended I have:

X Accel
Y Accel
ST3
ST1
ST2
TEMP
2.5v
RATE
GND
5v

well what are these and how did you connect them to your Arduino board, can you explain some words please? :slight_smile:

Hello, pins are as follow (the datasheet includes all the info anyway):
ST1, ST2, ST3 are "self test" pins, basically you can just ignore them
5V, GND: here you connect the power, they can go directly to 5V and GND on the Arduino
RATE: is the gyroscope reading: an analog output that you can connect to any analog input on arduino
X,Y accel: two analog output that give the accelerometers reading, they go to analog inputs on arduino
TEMP: another analog output, it's the temperature. The IMU has a "termometer" to read ambient temperature and use it to "linearize" the data. Since it's there, they give it to the user too.

So you only need to connect X,Y and RATE to three arduino analog input (leave 4 and 5 free, they're used by I2C bus) and 5, GND to arduino power output

Hello, I'm one step further by your help!

Can you please explain about pot more? I read all posts here, your description on PID is very clear and helpful but I just can't understand completely, the role of pots in the PID you developed:

  1. where you installed them
  2. how you get use of them there?

thank you!! :wink:

The PID algorithm require three parameters to work: these are called Kp, Ki and Kd. They have to be found empirically, in a process called Tuning.

There are methods to find some working parameters, but mainly you have to make many many tests, andjusting them a little and checking the result.
Doing this by modifying the program and reflashing it on the arduino is much impractical, you really want to be able to do it "on the fly" while the robot is in function. This is where the potentiometers come in: to make you able to dinamically change the three parameters. Just read them in the code and use them as "multiplicators" for the basic values. You probalby have to work out which order of magnitude assign them to "close in" on a valid range.

The bad news is that you probably have just 1 free analog input on arduino :stuck_out_tongue: This means you need some extra hardware, either some multiplexer to connect three pots on the same input, some ADC to use digital ports, or something else. You could also try to find one parameter at a time but it's not good.

I ended up using a chip for data acquisition with I2C interface (just like the MD23) and 8 input channels. The chip is called MAX127.
You can see my circuit (design and pictures) here and here.
That's where i asked for help too, so don't take my work as perfect in any way! It was my very first circuit
Well anyway that worked, i hooked up the potentiometers and could read them in the program :slight_smile:
Here's a picture of the beast:

well by this your post I'm clear about how to expand inputs of arduino. About the pots I'm still confused. Well the idea that you use them to get values needed for PID was also clear in your other posts. The question is how you do it, I mean, where are they exactly placed in your circuit (behind your ADC IC) and how do they perform their job? how they obtain those values? Which mechanism of the robot changes them, so that they signal the value you need?

thank you for guiding a novice toward a new balancing robot :wink:

uhm.. i don't really understand your question.. potentiometers are turn knob thingies that you turn by hand, just like the volume of your stereo. The robot just read them, there's no automatic adjustment.

Here's where they're placed in the robot:

uhm...I just begin to understand...I first thought that you have some control mechanism, like neural-kalman or fuzzy-kalman that (learn and) always change the parameters of PID automatically, based on some calculations (using their knowledge base). then this means that you yourself may change them by your hand as you decide "on the fly", and the software read the new values in when running, right?

nice photo, recalls: "one picture worth 1000 words" :wink:

Exacly :slight_smile:
What you were thinking is some kind of PID auto-tuning, which i think is very hard to implement.
Anyway, i thought about it. If you're going to implement it, i think the best way is to monitor the controller and trying to extract some basic characteristic of how the controller behave, like the oscillation frequency (around the desired value) and width, how much it overshoot, etc etc, then applying the table on this page to adjust the parameters.

Good luck :slight_smile:

Hi again :slight_smile:
could you please tell me exactly what kind of pots do you use, or possibly a link to them? I'm going to buy right what you've got (as it is like that excluding motors and their controller). :wink: