Sunday, May 15, 2011

Modification of Compass Readings

I spent a little while today reaquinting myself with some of the programming for the accelerometer and compass sensors. The programming for getting readings from these sensors was partially completed, but never finished.

The compass sensor is a digital 3-axis magnetometer. Unfortunately, its not as simple as asking which direction the sensor is pointing. I have the sensor communicating with the microcontroller, but the ouputs are just 3 numbers. The first step is to calibrate and normallize those values to a standard maximum/minimum scale. I'm doing this initially by moving the sensor around till I get two of the three axes to be as close to zero as possible and then the third axis will be at either its maximum or minium. Once I have the min and max for each axis, I can add or subract values to get the midpoint at zero and scale to get the max and min at some value. I'll aim for -1000 to +1000 for each axis. The raw min and max values I am getting for each of the axes are:
Axis 1: -675 to 660
Axis 2: -580 to 745
Axis 3: -640 to 645

Even after normalizing these values, we still need to do more work to figure out what direction the sensor is pointing. The magnetic field is not strongest when pointing north, as you might expect. Instead, the strength and direction of the magnetic field depend on your location. In two dimensions, this is called the magnetic declination. In three dimensions it is called annoying. I found a website that gives you the direction of the magnetic field for any location. After putting in my zip code, it tells me that the direction of the field is 11 deg and 38 minutes West and 69 deg and 35 min downwards. In terms of components, when you are pointing true north, the magnetic field components should be:
North: 18,486nT
West: 3804nT
Down: 50,698nT

This will all have to be accounted for in the next step, but that won't happen today.

No comments:

Post a Comment