Android : Device yaw on Android

on Monday, October 6, 2014


I want my app to work on both iOS and Android devices.


I need it to act like a compass when device lies on table, but without magnetometer - relative yaw is enough for me. I don't care about cases when device isn't placed flat.


In iOS I store reference attitude first:



motionManager = [[CMMotionManager alloc] init];
[motionManager startDeviceMotionUpdates];


...



referenceAttitude = [specific->motionManager.deviceMotion.attitude retain];


And when I need relative yaw, I take it this way:



attitude = specific->motionManager.deviceMotion.attitude;
[attitude multiplyByInverseOfAttitude:specific->referenceAttitude];
return attitude.yaw;


How to make this in Android? In NDK there is file named android/sensor.h, but I am only able to get ASensorEvent::vector.roll which is rather rotation speed than angle, from queue and then calculate yaw this way:



yaw = 0;


...



yaw += ASensorEvent::vector.roll * dt;


This works okay on low rotation speeds, but it is very unaccurate. How can I get relative attitude on Android?


0 comments:

Post a Comment