Skip to main content

Subsection 12.5.7 Part 8: Tilt

Your driver now streams x, y, and z in milli-g, and today’s last question is how to turn those three numbers into a tilt angle. Before working out the geometry, predict what the readings do.

Activity 12.5.8. Predict the readings at 30 degrees.

The board lies flat on the table, component side up. Tilt it by 30 degrees so that the end with the +x arrow marked on your breakout board rises, and the y axis stays level. Predict what happens to each of the three readings: which move, which direction, and roughly where they end up.
This is inclination sensing, and Analog Devices’ AN-1057, Using an Accelerometer for Inclination Sensing, presents the geometry and math. From the acceleration data along one axis that is tilted (FigureĀ 12.5.22), the x reading is \(A_x = g \sin\theta\text{,}\) so \(\theta = \sin^{-1}(A_x/g)\text{:}\) one axis is enough to derive the tilt angle, for small tilts. That works, but not everywhere. The slope of \(\sin\theta\) is \(\cos\theta\text{,}\) which is close to 1 near 0° and goes to zero as \(\theta\) approaches 90°, and this slope is the measurement’s sensitivity. Near 0° a 1° tilt moves the reading by about 17 mg, and near 90° the same 1° tilt moves it by less than 1 mg, so a fixed amount of sensor noise barely disturbs the angle near 0° but can swing the computed angle by tens of degrees near 90°. And a single axis cannot distinguish all four quadrants, so there is no full-circle answer.
Figure 12.5.22. Single-axis tilt, from AN-1057 (Figure 1). The x reading is the projection of gravity: \(A_x = g \sin\theta\text{,}\) so \(\theta = \sin^{-1}(A_x/g)\text{.}\) The sine’s slope flattens toward 90°, so the angle computed this way loses sensitivity there.
Two axes fix both problems (FigureĀ 12.5.24). The two-axis formula assumes that tilt in the xz- or yz-plane is limited, so that most of the acceleration due to gravity projects into the xy-plane. With \(A_x = g \sin\theta\) and \(A_y = g \cos\theta\text{,}\) the ratio gives \(\theta = \tan^{-1}(A_x/A_y)\text{:}\) the gravity magnitude cancels, the sensitivity is good at every angle, and the signs of the two readings identify the quadrant, covering the full 360°. C’s math library handles the quadrants for you: atan2(ax, ay) takes the two readings separately and returns the angle in the correct quadrant. Lab 7 asks you to watch the axis directions marked on your own breakout board, since which axis reads which sign depends on how the board sits. In addition, AN-1057 works out the geometry and math for using all three axes to orient the accelerometer fully in space, beyond the xy-plane; the equations are in SubsectionĀ 12.6.6.
Figure 12.5.24. Two-axis tilt, from AN-1057 (Figure 7). The ratio of the two projections gives \(\theta = \tan^{-1}(A_x/A_y)\text{,}\) with constant sensitivity and, if the quadrants are handled, the full 360°. C’s atan2() handles the quadrants.