USING THE GYROSCOPE AND ACCELEROMETER

The gyroscope in an iOS device enables you to measure the device's angular acceleration around the x, y, and z axes. Figure 15-1 shows how this enables you to accurately measure the yaw, pitch, and roll of the device.

The accelerometer in iOS devices measures the acceleration of the device relative to freefall. A value of 1 indicates that the device is experiencing 1 g of force exerted on it (1 g of force being the gravitational pull of the earth, which your device experiences when it is stationary). The accelerometer measures the acceleration of the device in three different axes: x, y, and z. Figure 15-2 shows the different axes measured by the accelerometer.

image

FIGURE 15-2

Table 15-1 shows example readings of the three axes when the device is in the various positions. Bear in mind that you won't see the exact same values as these, because they are always fluctuating due to the accelerometer's sensitivity.

TABLE 15-1: Example Readings of the X, Y, and Z Axes

image

image

If the iPhone is held upright and moved to the right quickly, the value of the x-axis will increase from 0 to a positive value. If it is moved to the left quickly, the value of the x-axis will ...

Get Beginning iOS 5 Application Development 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.