Go Down

Topic: Guide to gyro and accelerometer with Arduino including Kalman filtering (Read 346787 times) previous topic - next topic

You should have a look in the code, it's pretty simply. To convert from radians to degrees you multiply it by 180/PI (approximately 57.2957795), normally the gyro output will already be in deg/s, so you don't have to change that. What IMU are you using? Post the datasheet and I will have a look at it :)
You should the feed the Kalman filter with the accelerometer angle in degrees and the gyro rate in degrees per seconds as mentioned in the orignal post.
To see if your gyro data is correct try multiplying with the delta time and see if the accelerometer angle and gyro angle are close - it's only close in the beginning, as the gyro will drift over time.

- Lauszus

I've a questions.

In this code i think  the angle measured dependent  from the initial instant. That is, depending on how it is at the beginning. If I wanted to know the absolute angle instead of (or an angle that does not depend from the initial instant ) how should I do? Why kalman angles are scaled with respect to real angles?

I'm not totally sure that I understand your question.
You should just use the zerovoltage constant in the datasheet, instead of "calibrating" the device at startup.

What do you mean by scaled angles? :)

- Lauszus

Jan 28, 2012, 12:35 pm Last Edit: Jan 28, 2012, 12:47 pm by batista1987 Reason: 1
tks for the first solutions, i will try this solution and will update.

For "scaled angles" i mean that  betwen x_angle (kalmanCalculateX output) and gyroXangle there is a big difference, and this difference i think is costant.

In the beginning they will be almost the same, but as the gyro drift the difference will get bigger and bigger :)

m gettin error like this while running the program.....
wat does it mean..... pls help me......

avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

Are you using a programmer? :) That error is related to programmers.


Hello Everybody!

Lauszus, I was stuck on page 17 and thought you never replied! I am so silly!

Anyway, thanks for the support. Look at what I have till now : http://www.youtube.com/watch?v=3rn2kOoLw6E

I am using complementary filter.

Code: [Select]


I modified the values to take more of the gyro output because if I use the defaults
the robot gets lazy and needs big tilt before trying to react.

Code: [Select]


How can I also modify the kalman filter to take more out of the gyro?

I think the secret is here... Right?

Code: [Select]

   float Q_angle  =  0.001; //0.001
    float Q_gyro   =  0.003; //0.003
    float R_angle  =  0.03;  //0.03

But which is which???

Q_angle is the process noise covariance for the accelerometer, Q_gyro is the process noise covariance for the gyro and R_angle is the measurment noise covariance.
You should try to lower the Q_gyro value and raise the Q_angle value :)


complementary behaves better for me...


still needs some pid tuning....

Awesome job!! Where did you buy the belt, gears and the shaft? :)



Belts and pulleys are from http://www.econobelt.com/e-store/Pulleys.htm
They are the cheapest I could find after much searching...

Shafts, bearings and bearing housing are all from class 500 RC helicopter ( I also fly RC models helicopters, airplanes etc)
You can find many things at hobbyking


Motor base is made of FR4 (the material we use to make printed circuit boards )  cut with a CNC router that I have at where I work.

Of course the shaft needs cutting and you also need a 8mm adapter for the wheels.

Until now complementary filter works better for me. Do you think that kalman will make a big difference?
Is it worth to spend some more time for it?

For now it seems to balance well enough but it needs more clever way to control the attitude, for example if I push it hard enough
it will start chasing itself and finally fall.. I think that I should add another K for the gyro rate. If we are falling too fast, go faster!

This robot is just a lesson for me because I need all the balance knowledge to make a self flying quadcopter. I hope....

Thanks for the links, might need it some day :) Or useful to others.

I don't think you will need a Kalman filter, for instance these guys: http://web.mit.edu/first/segway/ used a complimentary filter just like you.

You can prevent it from falling when pushed, if you add encoders or add body velocity (read gyro) into the PID loop.
What constants did you end up with for the IMU for the complementary filter? I haven't really experimented on that, as I just used some I found on the web.

Nice. A loot of people are trying to do just that, so there's a ton of info out there :)


Code: [Select]

My gyro is IDG500 and my accelerometer is MMA6271 both soldered on a custom made pcb.
I am using only 1 axis of the accelerometer and calculate the angle with asin as you suggested.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131