# How to use an IMU to hover at a fixed location in a quadcopter in the presence of gravity?

There's an accelerometer in the IMU. The output can then be integrated to estimate the position, at least in theory.

But in practice, there's a huge acceleration from gravity, which varies rather randomly across locations. Vibrations etc can be filtered out with low-pass filters, but how do you filter out gravity? Is it simply the case that the vertical vector is ignored when doing any calculations?

My application is, I want to build a quadcopter that could hover in one place even in the presence of (reasonable) winds: the quadcopter ideally would tilt towards random gusts to maintain a certain position. Every single tutorial I could find on the Internet only uses the accelerometer to estimate where down is when stationary, and simply assumes that using the gyroscope to hold the quadcopter level is enough.

I also want to use the IMU to estimate altitude if possible, of course as an input to something like a Kalman filter in conjunction with a sonar system.

Obviously, for my application GPS is far too slow.

• Not try to be rude, but what exactly is your question? Are you asking how to filter the noise out of accelerometer readings?
– Chuck
Jun 9, 2015 at 1:25
• I will rephrase my question. My biggest question is how to filter out gravity actually. Jun 9, 2015 at 1:30
• Why you want to filter out the gravity? The gravity vector can be used for attitude estimation by vector projection. With the gravity vector alone you can easily estimate the pitch and roll. If you even take the magnetic field vector you can apply the so-called "bi-vector" method. In general a vector projection to estimate the attitude of the quadrocopter. Jun 9, 2015 at 5:53
• didn't read all your questions. But for filter out the gravity: use a high-pass filter on accelerometer. As what Android does: developer.android.com/reference/android/hardware/… Jun 9, 2015 at 12:24
• another maybe better idea is the step detection algorithem, but can only detect there happened a movement/vertical instead of finding its direction. To do it, calculate the total magnitude of acceleration on three axis, then minus 9.8, and set a threshold to detect whether there is a movement or not. Jun 9, 2015 at 12:28