Thursday, March 1, 2012

Compensating accelerometer with the compass - the limitations

In the previous parts of our sensor processing series, we have seen how to use the gyroscope to separate the motion and the gravity acceleration components measured by the accelerometer. But gyroscope-equipped phones are rare. Can we have a "poor man's gyroscope" that is more widely deployed in today's devices?

Let's reiterate the problem. We have an accelerometer that is exposed to two main kinds of accelerations: gravity and motion acceleration. Gravity acceleration is always present. Sadly, its direction is not constant but changes with the direction of the device. If the device is subject to motion acceleration (e.g. the user is walking), motion acceleration is added to the gravity component. Motion acceleration vector changes dynamically due to the movement phases. If we have to assume that motion acceleration is present but we don't know the gravity acceleration vector, separating the gravity and motion acceleration components is impossible. We need another sensor therefore and we made a good use of the gyroscope so far.

The other evident sensor that can be used to determine the Earth's coordinate system relative to the device coordinate system is the compass or magnetic sensor. Compass is attractive because it is widely available in today's devices. Unfortunately it has certain drawbacks that make it more inconvenient to support the accelerometer than gyroscope. In this part I will go through the characteristics of the compass to set the expectations before we start to discuss, how to use it together with the accelerometer.

First the basics. The compass measures the magnetic field the device is exposed to. This magnetic field has many components. We are most interested in the Earth's magnetic field but obviously there are other disturbances, e.g. metal objects, magnets, magnetic fields generated by electric devices. The Earth's magnetic field is not trivial either. Contrary to a belief I hear often, the Earth's magnetic field points mostly downward, toward the center of the Earth. The effect is called magnetic inclination and it means that the Earth's magnetic field has a varying degree relative to the Earth's surface. Where I live, the inclination is  about 70 degrees. The component that compasses measure to find the "North" (more exactly: magnetic North) is just the x and y components of the magnetic field which are smaller than the z component.

External magnetic fields can make measuring the Earth's magnetic field virtually impossible. The graph below shows an extreme case when I started compass sampling and walked into an underground train that eventually left the station.
Click here to read the post further.

No comments: