iOS: Can I get the pitch/yaw/roll from accelerometer data?

让人想犯罪 __ 提交于 2019-12-12 08:04:44

问题


I want to find out the pitch, yaw, and roll on an iPad 1. Since there is no deviceMotion facility, can I get this data from the accelerometer? I assume that I can use the vector that it returns to compare against a reference vector i.e. gravity.

Does iOS detect when the device is still and then take that as the gravity vector? Or do I have to do that? Thanks.


回答1:


It's definitely possible to calculate the Pitch and Roll from accelerometer data, but Yaw requires more information (gyroscope for sure but possibly compass could be made to work).

For an example look at Hungry Shark for iOS . Based on how their tilt calibration ui works I'm pretty sure they're using the accelerometer instead of the gyroscope.

Also, here are some formula's I found on a blog post from Taylor-Robotic a for calculating pitch and roll:

Now that we have 3 outputs expressed in g we should be able to calculate the pitch and the roll. This requires two further equations.

 pitch = atan (x / sqrt(y^2 + z^2))
 roll = atan (y / sqrt(x^2 + z^2))

This will produce the pitch and roll in radians, to convert them into friendly degrees we multiply by 180, then divide by PI.

 pitch = (pitch * 180) / PI
 roll = (roll * 180) / PI

The thing I'm still looking for is how to calibrate the pitch and roll values based on how the user is holding the device. If I can't figure it out soon, I may open up a separate question. Good Luck!



来源:https://stackoverflow.com/questions/7362417/ios-can-i-get-the-pitch-yaw-roll-from-accelerometer-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!