Guide to gyro and accelerometer with Arduino including Kalman filtering

Thanks for posting this guide. I will give it a go!

Justin

I have updated the code, so it now measures 3600 instead of 1800. Just add this after you calculate the angle measured by the accelerometers:

if(accZval < 0)//360 degrees
  {
    if(accXangle < 0)
    {
      accXangle = -180-accXangle;
    }else
    {
      accXangle = 180-accXangle;
    }
    if(accYangle < 0)
    {
      accYangle = -180-accYangle;
    }else
    {
      accYangle = 180-accYangle;
    }
  }

Awesome work

I am making a 3 axis rate table to measure how accurate the imu is.
I want to answer the following questions
1)For a given set of sensors, how can i get the best possible performance from my Kalman filter in estimating angles.
2)Now that the "optimal" Kalman filter code is identified, can i achieve better performance by choosing better gyros and accelerometers.

Thank you. Are you using the same IMU as me or a different one?
If so will you please tell me what you come up as the best values for Q_angleX, Q_gyroX, and R_angleX?

I am using the Ardu-Imu

R is the co-variance matrix. It should typically be the square of the standard deviation of the Gyro.
I think it should be there in the datasheet, or you could just keep things stationary and log the data for about 5 mins.
Calculate the mean and std deviation.
R=std_deviation^2

Hello,

This is a great post about IMU's. Lots of good information. I am also working with Gyro's and accelerometers in my Quadrotor project. I needed a simple tool to visualize data and ended up writing one. Although there are ways to plot data using Processing, I wanted a stand alone tool.

Here is link to relevant thread. Hope you guys find the tool useful.

http://arduino.cc/forum/index.php/topic,58911.0.html

I will probably change the tools to accept float data in the next version.

Cheers

Aerosam:
What unit do you measure the standard deviation and mean in? For example is it %/C or what?

  • Lauszus

This is a great for IMU-starters like me. I will give it a try.
Thank you very much.

Fons

This isn't working for me. My angle is still drifting at a degree per second.

Are u using the same IMU as me or a different one?
If not, try to change the value of R_angleX and R_angleY and see if it helps.

  • Lauszus

I'm using a different one, the digital combo board. SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 - SEN-10121 - SparkFun Electronics. I had to mod the code to suit the digital version, but i'm confident it works.
I've tried changing the values but they don't seem to have any benificial effects :frowning:
Sometimes the result jump about 20 degrees, quite rarely. Does this ever occur for you?

Okay.
It sounds like you are getting data from the accelerometer. I you sure you are using both sensors? :slight_smile:

  • Lauszus

Haha, yeh definitely getting all the data :stuck_out_tongue: For some reason i get more accurate data from the non filtering. The calculated accelerometer angle doesn't go through 360degrees. Gets about a max of 50. Is this supposed to happen?

Try to use the complementary filter instead and see what happens.

Post your code and I will have a look at it - you must have done something wrong :slight_smile:

  • Lauszus

I modded the code into java, as i'm doing the postprocessing on the PC.
the only thing i think i modded is this...
xAngle += kalmanCalculateX(accXangle, gyroXrate, dtime);
I made the xAngle += so I just print total xAngle directly. Is that wrong?
Apart from that, using nano seconds and slightly different calibration position it is the same.

Yes that it totally wrong. If you do like that, it will plus the angle with the last one. It should be:

Angle = kalmanCalculateX(accXangle, gyroXrate, dtime);

It is only when you calculate the gyros angle that you have to plus the last angle with the new one!

  • Lauszus

ok fixed that. But it only works for about 50 degrees +-. Similar to the other kalman filter i tried :frowning:

Maybe you forgot that gyroXrate should be in degrees per second and not degrees in this line:

Angle = kalmanCalculateX(accXangle, gyroXrate, dtime);
  • Lauszus

Hi Lauszus, I bought the same gyro(Gyro Breakout Board - LY530AL - 300°/s - SEN-09165 - SparkFun Electronics) used by IMU on your project. I just want to read angle from the gyro but having a little confuse about the HP, PD and ST pin. Should I just left them all unconnect or do you have any suggestion?

~Thanks :slight_smile:
~Fino

You can just leave them all unconnected :slight_smile:

  • Lauszus