开发者

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

开发者 https://www.devze.com 2023-04-04 06:36 出处:网络
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 com

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 gravit开发者_JAVA技巧y vector? Or do I have to do that? Thanks.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消