Jump to content

How the iPhone sensors work in concert to determine orientation

0
  blackbear's Photo
Posted Nov 17 2009 08:11 PM

In a recent interview with Alasdair Allan regarding the iPhone sensor suite, he talked a bit about how the various sensors have to be used together to figure out how the phone is oriented.


"Basically the magnetometer in the iPhone is exactly that. It measures the magnetic field. And it is very susceptible to local changing magnetic field monitors, CPUs, TVs, anything like that will affect it quite badly. By default, what you're measuring, of course, is the ambient magnetic field of the Earth. And that's how you can use it as a digital compass because there are tables that will draw up and show you how to do deviations from magnetic north to true north, depending on your latitude and longitude. Which is why to do augmented reality apps, you need both the accelerometer and the magnetometer, so it can get your pitch and roll to the device and the GPS to get the latitude and longitude so you know the deviation from true north."

"I think it's misleading to talk about precision. I mean basically, it reports three figures: X, Y, and Z. And this is the linear acceleration values reported by the hardware's G force values. So value one represents a load of approximately one gravity. But, of course, the problem is what you're dealing with is you're measuring the acceleration. So if your iPhone is sitting face-up on the table, you'll be measuring an acceleration of one gravity straight down, thereabouts. So if you're using it as a detection of movement, you also have to take into account the fact that you're in a gravitational field and, of course, just spinning the iPhone left and right if it's sitting flat on the table isn't going to give you the roll. I mean that's one of the big gotchas of the accelerometer. And it's a mistake quite a lot of people make is that you're not going to get your pitch and roll out of the accelerometer. You need the magnetometer in addition to that."



Tags:
0 Subscribe


2 Replies

 : Nov 19 2009 11:16 PM

Quote

And it's a mistake quite a lot of people make is that you're not going to get your pitch and roll out of the accelerometer. You need the magnetometer in addition to that.


Whatever your naming convention, you'll get two of the three pitch, yaw, and roll values from the 3-axis accelerometer, and the final one from a 3 axis magnetometer. If the phone is flat on the table, and spinning is given as yaw (magnetometer bearing), both pitch about the length, and roll about the width will come from the accelerometer.
 : Nov 20 2009 09:59 AM
+1 for content, -1 for readability.

The acceleromter on the iPhone measures acceleration (usually due to gravity.) If you want to see the raw data represented by the accelerometer, check out the "Sensor Data" app. It shows you the raw sensor data (including GPS lat/lon) and the orienatation the phone thinks it's in.

You'll see that the accelerometer values usually range from -1 to 1. When an axis is perfectly horizontal, the value is 0. When the axis is perfectly vertical, the value is 1 or -1. To figure out the exact angle, you need to do some geometry: a value of .70 is roughly 45º, and a value of .5 is roughly 30º off of level. (This is the Sin-1 function on your iPhone's calculator. Go ahead: try entering any number between 0 and 1, then pressing 2nd, then sin-1. The resulting value is the angle, with horizontal being 0.)

The X value is the phone's left/right sensor. -1 means it's the left side.
The Y value is the phone's top/bottom sensor. -1 means it's standing upright. (The bottom is where the sync cable plugs in.)
The Z value is the phone's front/back sensor. -1 means it's sitting with the screen facing up.

So by taking the x, y, and z accelerations, you can get the phone's bank and pitch values. To get the heading, your direction relative to magnetic North), you need a compass. Since magnetic North and true North don't quite coincide, the software needs to compensate for this. Fortunately, that's an easy task, since you have the phone's location in space from the GPS.

Speaking of the GPS, fire up Sensor Data again and look at the GPS data. notice the Position Accuracy and Altitude Accuracy. After sitting still for a few minutes, my position accuracy is down to 17.1 meters, or roughly 56 feet. That's simply not good enough for augmented reality. This is where, in the long run, algorithms will be needed to sample the data from the phone's camera, compare that picture to a known 3D mesh of the area, and guess exactly where the device is based on that data. At that point, the software should have enough data to overlay the virtual imagery.