Receiving information from magnetic sensors

I listen to the values ​​of the sensors and get them in my handler with

if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { for (i=0;i<3; i++) mag[i] = event.values[i]; 

Developer documents say that for Sensor.TYPE_MAGNETIC_FIELD you get: "All values ​​are in micro Tesla (uT) and measure the surrounding magnetic field along the X, Y and Z axis."

How can I turn this information into azimuth, step and roll? How to turn it into a magnetic compass heading?

Does it provide only the same information that you can get from the ORIENTATION sensor and from the ACCELEROMETER sensor after performing matrix transformations?

+4
source share
1 answer

If you have access to the accelerometer, you can use the getOrientation () method, which returns the azimuth, step and roll, as determined from the two sensors, and is calculated using the getRotationMatrix () method.

edits

Reply to comments ... I see your question now. I'm sorry. Using only a 3-axis magnetometer, you cannot accurately obtain the azimuth, pitch and roll, unless the device is parallel to the surface of the earth. Remember, when using a compass, the needle compass and one having it: a) on the spindle so you can see and manually compensate for the tilt, or b) sealed in liquid so you can get the bubble level in the center? To get the azimuth:

 azimuth = arctan(y/x) 

Now, if you tilt the phone, the errors in the perception of the x / y plane can become large. Now you need to figure out the slope (using the accelerometer), then measure the magnetic force of the Z axis, and then use three to compensate. This is what you know as getRotationMatrix () and getOrientation ().

In part, I think Sensor.TYPE_ORIENTATION is deprecated in API 8 because there is no separate orientation sensor per se . This is a combination of magnetic field and acceleration sensitivity.

The good paper I dug up that covers it all:

http://www.ssec.honeywell.com/position-sensors/datasheets/sae.pdf

+3
source

All Articles