How to get user location using accelerometer, gryoscope, and magnetometer in iPhone?
Asked Answered
S

0

6

The simple equation for user location using inbuilt inertial measurement unit (IMU) which is also called pedestrian dead reckoning (PDR) is given as:

x= x(previous)+step length * sin(heading direction)
y= y(previous)+step length *cos(heading direction )

We can use the motionManager property of CMMotionManager class to access raw values from accelerometer, gyroscope, and magnetometer. Also, we can get attitudes values as roll, pitch, and yaw. The step length can be calculated as the double square root of acceleration. However, I'm confused with the heading direction. Some of the published literature has used a combination of magnetometer and gyroscope data to estimate the heading direction. I can see that CLHeading also gives heading information. There are some online tutorials especially for an android platform like this to estimate user location. However, it does not give any proper mathematical explanation.

I've followed many online resources like this, this,this, and this to make a PDR app. My app can detect the steps and gives the step length properly however its output is full of errors. I think the error is due to the lack of proper heading direction. I've used the following relation to get heading direction from the magnetometer.

magnetometerHeading = atan2(-self.motionManager.magnetometerData.magneticField.y, self.motionManager.magnetometerData.magneticField.x);

Similarly, from gyroscope:

grysocopeHeading +=-self.motionManager.gyroData.rotationRate.z*180/M_PI;

Finally, I give proportional weight to the previous heading driection, gryoscopeheading, and magnetometerHeading as follows:

headingDriection = (2*headingDirection/5)+(magnetometerHeading/5)+(2*gryospoceHeading/5);

I followed this method from a published journal paper. However, I'm getting lots of error in my work. Is my approach wrong? What exactly should I do to get a proper heading direction such that the localization estimation error would be minimum?

Any help would be appreciated.

Thank you.

EDIT

I noticed that while calculating heading direction using gyroscope data, I didn't multiply the rotation rate (which is in radian/sec) with the delta time. For this, I added following code:

CMDeviceMotion *motion = self.motionManager.deviceMotion; [_motionManager startDeviceMotionUpdates]; if(!previousTime) previousTime = motion.timestamp; double deltaTime = motion.timestamp - previousTime; previousTime = motion.timestamp;

Then I updated the gyroscope heading with :

gyroscopeHeading+= -self.motionManager.gryoData.rotationRate.z*deltaTime*180/M_PI;

The localization result is still not close to the real location. Is my approach correct?

Scevor answered 6/10, 2017 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.