Jump to content

Mobile accelerometers and gyroscopes explained

+ 2
  macslocum's Photo
Posted Jul 15 2010 04:58 AM

Every once in a while I make a point to marvel at the technology now at my fingertips. Otherwise, I won't appreciate the stuff.

For example, pick up a modern mobile phone -- an iPhone or Android device will do -- and think about it for a second. It senses where it is. It knows how to calibrate based on its physical location. I'd have gone catatonic if someone had showed me that kind of handheld functionality ten years ago.

Now, before my current bout of wide-eyed wonder turns back into inevitable cynicism, I thought it would be nice to actually learn a thing or two about mobile-based accelerometers and gyroscopes. That's why I got touch with Alasdair Allan, author of "Learning iPhone Programming" and the upcoming "Programming iPhone Sensors." He digs in to my questions in the following brief Q&A.


What is an accelerometer?

Alasdair Allan: An accelerometer is a sensor that measures acceleration relative to a free-falling frame of reference. They can measure the magnitude and direction of the acceleration, and can be used to sense the orientation of the device.

The original iPhone, and first generation iPod Touch, use the LIS302DL 3-axis MEMS based accelerometer produced by STMicroelectroics. Later iPhone and iPod Touch models use a similar LIS331DL chip, also manufactured by STMicroelectronics.


What is a gyroscope?

AA: A gyroscope can be used to either measure, or maintain, the orientation of a device. Unlike an accelerometer, which measures the linear acceleration of the device, a gyroscope measures the orientation directly.

When a gyroscope is mentioned, most people immediately think of mechanical gyroscopes, essentially a spinning disc that is is mounted inside multiple gimbals allowing it to take any orientation. However, the gyroscope inside the iPhone 4 is a MEMS-based gyroscope (or more likely three independent MEMS gyroscopes).


What can these tools do on a mobile device?

AA: The iPhone's accelerometer measures the linear acceleration of the device so that it can report its roll and pitch, but not its yaw. If you are dealing with an iPhone 3GS, which has a digital compass, you can combine the accelerometer and magnetometer readings to have roll, pitch, and yaw measurements.

When dealing with acceleration measurements, you must keep in mind that the accelerometer is measuring just that: the linear acceleration of the device. When at rest (in whatever orientation), the figures represent the force of gravity acting on the device, and correspond to the roll and pitch of the device (in the X and Y directions at least). But while in motion, the figures represent the acceleration due to gravity, plus the acceleration of the device itself relative to its rest frame.

When the iPhone's accelerometer measurements are combined with the gyroscope measurements, developers can create applications that can sense motion on six-axes: up and down, left and right, forward and backwards, as well as the roll, pitch and yaw rotations.


During the iPhone 4 debut, Steve Jobs demonstrated a Jenga-like game that seemed to put the iPhone into the same domain as Nintendo's Wii and Microsoft's Kinect. Is that the case?

AA: Adding a gyroscope puts the iPhone into the same domain as the Nintendo Wii which, when paired with the Nintendo MotionPlus, has similar functionality. Microsoft's upcoming Kinect (formerly Natal) is slightly different. It's billed as "controller-free gaming" that allows users to interact with the Xbox 360 through gestures and spoken commands rather than interacting with the device through the use of a controller.


Related



Visit iphone.oreilly.com for a complete list of books and resources to successfully create, distribute, and market iPhone apps.




0 Replies