10 · Estimate attitude
Open this interactive lesson and device downloads
Goal
Fuse gyroscope integration and gravity angles with a complementary filter to obtain Roll and Pitch. The basic lesson does not enable the heater or wait for a temperature threshold.
Model
Each update combines alpha × integrated gyro angle + (1-alpha) × gravity angle, with alpha=0.95 by default. Elapsed time is measured using esp_timer_get_time() and includes I²C reads and averaging; it is not assumed to be exactly 5 ms.
Linear acceleration disturbs the gravity estimate. Gravity alone cannot provide absolute heading.
Procedure
Keep the board still during startup bias calibration, then tilt it slowly. Compare different alpha values. Browser angles are simulated inputs; hardware reads the onboard QMI8658 over GPIO10/11.
Source: 10_ahrs/main/main.c. Historical Madgwick and heater files remain as advanced references but are not built in this lesson.
Parameter scope
Alpha closer to one emphasizes gyro integration per update. Reassess the weight if sample frequency changes.
Verification
Test flat, slow side-to-side tilt, and slow forward/back tilt. Errors during rapid translation are a model limitation.