# How to determine position from gyroscope and accelerometer input?

I have a 3-axis accelerometer and a 2-axis gyroscope. I intend to measure something that only moves in the X and Z axis. I've heard of using Kalman filters to smooth out the acceleration vectors, but I can't find a good tutorial for a complete beginner to the topic. Also, I know I can double integrate acceleration to get position, but how do I do this with a finite number of sampled acceleration vectors? I would appreciate links to good tutorials for beginners on both these topics.

• Sounds kind of like this blog post I stumbled across earlier today: starlino.com/imu_kalman_arduino.html I have no connection with that site, just thought it looked relevant to what you're asking. Commented Oct 8, 2010 at 3:02
• a series of tutorials how to use and interface accelerometer sensors could be found in this article. intorobotics.com/… here are available tutorials for 2 axes measurements
– Ezu
Commented Sep 3, 2013 at 18:13

Here's a tutorial on implementing a direction cosine matrix for an IMU: http://gentlenav.googlecode.com/files/DCMDraft2.pdf

Take a look at the ArduIMU pages: http://code.google.com/p/ardu-imu/wiki/Theory

Here are a couple of open source projects which do this. Reading the code should give some clues:

Well, Kalman filter is a kind of magic that works mysteriously. :)

I started first with digital Filters. Well explained for starters. And easily understable. These simple filters work nicely for the roll and pitch of any system. Just need to adjust Accuracy vs Response ratio by experimenting. The trick is [ Accuracy = 1 - Response ].

Give it a try.

Then to understand about Kalman filter you will have to go through followings:

1. Probability
2. Bayes' law
3. Then will need to learn how to model simple scenarios for fitting those into the Kalman filter.
4. Currently I am here so finding what to do .. will surely let you know.

And must share if you come across anything like this.

... double integrate acceleration to get position

In theory (provided you have perfect sensors and measurements) you can do that, but in practice you can not. The problem is that the accelerometer will have a constant force of 1G caused by gravity when the object is lying still (zero G in case of free falling), but this is not measured as exactly 1.00000000...G. When moving the object you will have a vector as the sum of 1G gravity and the acceleration from the movement (which is typically much smaller than 1G) and your measurements will accumulate way too much noise over time to be useful if you try to integrate measured acceleration minus 1G gravity.

I started building a quad almost 6 months ago, had a lot of problems with correct angle determination :)

First of all you should try this presentation - http://web.mit.edu/scolton/www/filter.pdf It's really comprehensive and it might help you get a better idea of what you really want, it pretty much did the trick for me.

I guess it's pretty much up to you, but, implementing the Kalman filter doesn't require only pretty solid know-how in math, system theory and in this case physics but is also very demanding regarding CPU load. In case you have in mind using, let's say an Atmega328 clocked at 16Mhz you may have problems using this kind of filter. It's really effective if you are using a DSP so you can lowpass-filter you acc input.

All in all, my advice is - try using the 1st order complementary filter or maybe even 2nd order complementary filter in case you're not satisfied with the results . If your system is free of high-frequency vibrations that should work great. Other that that JustJeff's link is the perfect place to start in case you get stuck with the implementation :)

All the best, Dan

• Your link is dead. I digged a bit and found the document again: googledrive.com/host/0B0ZbiLZrqVa6Y2d3UjFVWDhNZms/filter.pdf At least it is supposed to be the same, maybe you want to doublecheck.
– John
Commented May 9, 2014 at 15:34
• Yep, it's exactly the same :)
– Dan
Commented Jun 12, 2014 at 20:26
• link is dead again :( Commented Feb 9, 2017 at 19:58
• @KyranF think I found it again :) portal.ts-muenchen.de/Dateien/filter.pdf
– Dan
Commented Feb 28, 2017 at 15:09
• @Dan nice, this is actually the exact same document I used for designing my firmware when I made a mini segway back in uni. youtu.be/zOFlJJj8pPA Commented Feb 28, 2017 at 18:14

I am also a novice and also looking some solution to my navigation work. same as you, I have a board configed with 3-axis accelerometer and 2D gyroscope. until now I have read many materials about this, likewise I decide to adopt kalman filter to my signal dealing. may be I don't have some suggestion to you, but i want to share something with you I had seen before. there are some links point to them, hope that is useful to you.

limited to my reputation, I only have authority to post less than 2 links. so the other two I want post as below:

• While this may be a useful set of links for the OP, this post would be of value if you also added summaries of the relevant content from those links, specific to the question the OP has posted. Keep in mind that when links eventually become invalid due to link rot, this post will retain no value. Thanks. Commented Sep 2, 2013 at 9:36