What is an accelerometer? Measuring acceleration and estimating tilt
Atlasbot · 18/8/2026 · 11 min read
Accelerometer (accelerometer) is one of the two main sensors inside IMUs (learned at What is IMU? ), which measures acceleration in the 3 axes X, Y, and Z. It sounds abstract, but the most common application in robotics is intuitive: using gravity to see how far the robot is tilting.
Key concepts
Even at full stillness, the accelerometer measures a value of about 9.8 m/s² (1g) on the vertical axis — which is the same as the gravitational acceleration. When the robot tilts, this component of gravity "distributes" between the axes in a tilt - dependent ratio, allowing trigonometric back calculation of the tilt angle.
How it works
When upright: Z axis ≈ 9.8 m/s², X and Y axes ≈ 0
When tilted by θ: gravity is split between Z and the tilt axis according to cos(θ)/sin(θ)
This calculation of the inclination angle is accurate only when the robot is stationary or moving uniformly— principle relies on the assumption that the measured acceleration comes only from gravity. When the robot accelerates/decelerates, vibrations from rough floors, or slight collisions, the accelerometer measures both the real-motion acceleration and the mutual gravitational force — causing the calculated angle of inclination to be distorted, oscillating continuously even though the robot is not tilting further.
This is why accelerometers are rarely used alone to calculate angular inclination in the real-world — often combined with gyroscopes (measurement of angular velocity, unaffected by linear vibration, learn next lesson) via filters such as Complementary Filter or Kalman Filter to derive the advantages of both: gyroscopes are instantaneous accurate but drifted over time (drift), the accelerometer does not drift but noise upon vibration — in combination suppresses each other's disadvantages.
Technical details
Formulas
The pitch/roll angle, calculated from the three acceleration components, uses the atan2 function to properly treat all four quadrants:
roll = atan2(acceleration_Y, acceleration_Z)
pitch = atan2(-acceleration_X, √(acceleration_Y² + acceleration_Z²))
Example: robot tilts forward, measuring ax=-3.4, ay=0.1, az=9.2 (m/s²)
pitch = atan2(3.4, √(0.1² + 9.2²)) = atan2(3.4, 9.2) ≈ 0.353 rad ≈ 20.2°
Use atan2 instead of atan simply because atan2 properly handles sign and avoids dividing by 0 when one of the components equals 0 — common errors when writing code calculating angles from acceleration.
Parameters
| Metric range (full scale) | Respective sensitivity (MPU6050) | Matching |
|---|---|---|
| ±2g | 16384 LSB/g | Slow motion, high precision. |
| ±8g | 4096 LSB/g | Robot moving normally |
| ±16g | 2048 LSB/g | Strong impact/vibration |
Practical applications
In the real-world AMR architecture (learned at the IMU paper in AMR), accelerometer data are not used independently to calculate the continuous inclination angle — Its main role in EKF is to provide a "drift-free" reference source to compensate for gyroscope drift (next paper), and to detect unusual collisions/vibration (using a mutation acceleration threshold to trigger an alert or emergency stop). Another application of little interest: setting a threshold above the composite magnitude √(ax²+ay²+az²) to detect the robot being lifted or struck hard — that deviates far from 9.8 m/s²(1g) in the presence of anomalous external forces, distinct from slight fluctuations due to normal floor vibrations.
Practical example
import math
def tinh_goc_nghieng(ax, ay, az):
roll = math.atan2(ay, az)
pitch = math.atan2(-ax, math.sqrt(ay**2 + az**2))
return math.degrees(roll), math.degrees(pitch)
# Robot dung yen, hoi nghieng nhe ve mot ben
roll, pitch = tinh_goc_nghieng(ax=1.2, ay=2.1, az=9.5)
print(f"Roll: {roll:.1f}°, Pitch: {pitch:.1f}°")
Output:
Roll: 12.4°, Pitch: -7.2°
In real-world operation, if this value is measured while the robot is accelerating abruptly, the result will fluctuate sharply even though the robot is not tilted further — which directly demonstrates the limitation stated in the Operating Principles section, the reason for incorporating gyroscopes through filters.
Common mistakes
- Using
ataninstead ofatan2— as in Formula section, causes division by 0 errors or wrong angle sign when a component accelerates by 0 or negative. - Exploring the angle of inclination calculated from the accelerometer when the robot is accelerating/decelerating— as the above example, the results are perturbed by the real motion acceleration, not just gravity.
- Full scale measurement range selection is not suitable for application— the ±2g range is too narrow for robotics with strong collision/rung (cut/saturated band crossing values), the ±16g range is too rough for applications requiring high sensitivity at slow motion.
- Using the accelerometer alone for the application that requires the correct continuous inclination— bypasses incorporating gyroscopes through the filter, resulting in unstable noisy data while moving.
Conclusion
Accelerometers give the direction of gravity, which in turn infer the inclination angle by the formula atan2— but are reliable only when the robot is at rest or in very uniform motion. The next lecture on gyroscopes will explain the compensating sensor for this drawback.
Get new articles and lessons by email
When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.
Unsubscribe any time with the link in each email. See our Privacy policy.