Question

I've created an app that used the Gyrosope Native Extension really well in Android, and runs perfectly.

However now I've tested on an iPhone 4 (iOS7) using AIR 4.0 and the gyrosope performance seems to be totally different, where tilt doesn't seem to do anything but rotating the phone does.

Does anyone know if there's a major difference to how this data works on iOS and Android?

I have seem this http://www.ketzler.de/2011/11/adobe-air-gyroscope-native-extension-with-euler-angles-roll-pitch-yaw-for-ios/ which I'm considering attempting to use.

Would this be a replacement or an addition to the existing native extension?

Was it helpful?

Solution

You're going to get much better results out of using multiple sensors to calculate the device position. The extension you've referred to does this through the builtin functions in the iOS SDK. Using a fusion of the available sensors you get quick response from the gyroscope but account for the drift using the accelerometer and magnetometer.

On iOS this uses the CMAttitude class (which is what the ane link you have provided uses):

https://developer.apple.com/library/ios/documentation/CoreMotion/Reference/CMAttitude_Class/Reference/Reference.html

Using this technique on both platforms definitely brings the readings closer together, however there are a few different ways to do it on Android as you have access to a lot more information. The biggest problem on Android is, of course, all the different hardware used so the sensors all report slightly different ranges and values. The best method I've found is using the TYPE_ROTATION_VECTOR sensor and then the SensorManager.getOrientation function if you're after Euler angles. I've also tried a custom fusion algorithm with mixed results.

http://developer.android.com/reference/android/hardware/Sensor.html#TYPE_ROTATION_VECTOR

I also recommend you look into quaternion's. These provide a much better result for device positioning and avoid the associated gimbal lock.

I've spent a lot of time going through all this for distriqt's extension package and am just about to release a new DeviceMotion extension that does all this if you're interested in that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top