Chapter 21. Accelerometers

Accelerometers are a good introduction to a class of electronic components called microelectromechanical systems (MEMS). An accelerometer can either be one-axis, two-axis, or three-axis. This designates how many different directions it can simultaneously measure acceleration. Most gaming devices have three-axis accelerometers.

As far as game development is concerned, acceleration values are typically delivered to your program via an API with units in multiples of g. One g is equal to the acceleration caused by gravity on the Earth, or 9.8 m/s2. Let’s pretend that we have a one-axis accelerometer and we orient it such that the axis is pointing toward the center of the earth. It would register 1g. Now, if we travel far away from any mass, such that there is no gravity, the accelerometer will read 0. If we then accelerate it such that in one second it goes from 0 m/s to 9.8 m/s, the accelerometer will read a steady 1g during that one-second interval. Indeed, it is impossible to tell the difference between acceleration due to gravity and acceleration due to changing velocity.

Real-life motion is generally nonsteady. Depending on your application’s goals, you might have to apply different smoothing functions such as high-pass or low-pass filters. This amounts to digital signal processing, a topic that has consumed entire texts. One example we can recommend is Digital Signal Processing: A Computer Science Perspective by Jonathan Y. Stein (Wiley).

Also, many accelerometers ...

Get Physics for Game Developers, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.