This is an implementation of estimating and trackiing the tilt angle of a moving or static IOS phone with the data from gyroscope and accelerometer (IMU on phone). The code is adapted from github repository from Justin Chan
This project leverages the gyroscope and accelerometer already embedded in most commodity phone devices to estimate the tilt angle of phone when it is moving. The tilt angle is defined as the angle ρ between the gravitational vector measured by the accelerometer and the initial orientation with the gravitational field pointing downwards along the
To do this, three ways of usiing differeng sensors were implemented here.
If the accelerometer reading is
First calculate the accumulated rotation angle on
angle
To test this program, use Xcode, connect your phone to laptop -> choose your phone as device at the top -> select your project in the left 'buildtime' window -> select project in 'target' -> 'singning and capabilities', sign in your account and change the bundle identifier (add one number at the end is fine) -> build and run the project.
Note that all the code changes are in the file './imu_test/ViewController.swift'
We test put phone on table and make it static. The tilt estimation results for a long time are shown in below figure, where the red color represents the estimation results for accelerometer, the blue color represents the results for gyroscope, and the blue color represents the results for complementary filter with parameter 0.98, 0.02
Demo of running code on iphone in real time: