Go Down

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

Lauszus

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

batista1987

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?

Lauszus

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

batista1987

#258
Jan 28, 2012, 12:35 pmLast 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.

Lauszus

#259
Jan 28, 2012, 01:00 pmLast Edit: Jan 28, 2012, 01:05 pm by Lauszus Reason: 1
In the beginning they will be almost the same, but as the gyro drift the difference will get bigger and bigger

ok ok :-) tks

iamnarendra

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

Lauszus

#262
Feb 01, 2012, 11:20 pmLast Edit: Feb 02, 2012, 01:17 am by Lauszus Reason: 1
Are you using a programmer? That error is related to programmers.

georpo

#263
Feb 05, 2012, 07:43 pmLast Edit: Feb 05, 2012, 07:58 pm by georpo Reason: 1
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]
` x_angle=(0.993)*(x_angle+GyroRate*dt)+(0.007)*(AccAngle);`

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]
` x_angle=(0.98)*(x_angle+GyroRate*dt)+(0.02)*(AccAngle);`

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???

Lauszus

#georpo
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

georpo

complementary behaves better for me...

http://youtu.be/Youro5J2RrA

still needs some pid tuning....

Lauszus

#georpo
Awesome job!! Where did you buy the belt, gears and the shaft?

georpo

Thanks!

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

http://www.hobbyking.com/hobbyking/store/__10199__HK_500GT_Ball_Bearing_16_x_8_x_5mm_Align_part_H50067_.html
http://www.hobbyking.com/hobbyking/store/__10158__HK_500GT_Main_Shaft_Align_part_H50011_.html
http://www.hobbyking.com/hobbyking/store/__9795__HK_500GT_Metal_Main_Shaft_Holder_Align_part_H50075_.html

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....

Lauszus

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

georpo

Code: [Select]
`x_angle=(0.993)*(x_angle+GyroRate*dt)+(0.007)*(AccAngle);`

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