1

I have seen many questions and articles mentioning that Quaternions can be used to derive better,accurate and stable yaw, pitch and roll readings from the iPhone rather than reading it's direct yaw, pitch and roll readings. But at the same time, I haven't seen any proper methods of implementing Quaternions in iPhone platform. As a beginner, It's really hard to know, How these Quaternions works and implementing them in a piece of code? (Sorry for not providing any code as i have no idea of how it works in xcode platform of apple)

So please be kind enough to provide an answer to my question that most of the users will benefit from it!

Thanks in advance!

sam
  • 259
  • 1
  • 6
  • 22

1 Answers1

0

You don't have to implement anything, the API provides the quaternion for you:

CMAttitude Class Reference, quaternion propery

I personally like rotation matrices better because I find them easier to understand and to work with.

As I am reading your question, I still have the impression that you somehow want yaw, pitch and roll. You have to use quaternions everywhere in your code to get rid of the problems yaw, pitch and roll cause.

Ali
  • 56,466
  • 29
  • 168
  • 265
  • But how to access them continuously in a piece of code to compute yaw, pitch and roll ? – sam Sep 07 '12 at 18:07
  • 1
    The minute you compute yaw, pitch and roll from a quaternion you will have the same problem as if you were using just yaw, pitch and roll. You have to use quaternions **EVERYWHERE** in your code and forget about yaw, pitch and roll. – Ali Sep 07 '12 at 18:11
  • @Ali- Actually what is the best method of obtaining rate of change of angel from the device accurately? As we all know integrating gyroscope data is subjected to the problem of drift and accumulation of integration error, So what is the best practice to get a stable reading? :) – sam Sep 07 '12 at 18:16
  • @sam I am confused at this point. What would you like to do? You would like to use these values for something, what is it? – Ali Sep 07 '12 at 18:21
  • I want to track the continuous change of angel of the device to the greatest accuracy possible along y axis. Think like this, If you have a pendulum resting vertically to gravity. And when you move your device up, pendulum should move exactly the same angel it's moved by the user, But at the same time, if user move continuously for 10 seconds, It should log the exact angel variation with respect to the reference vertical position both in positive and negative directions! – sam Sep 07 '12 at 18:31
  • I am sorry, I failed to understand your application. – Ali Sep 07 '12 at 22:15
  • I am also trying to extract an angle of movement along the y axis but only using accelerometers (comparing a current reading of acceleration to that of gravity). Have you had any luck solving this problem? – ravemir Apr 03 '13 at 15:01
  • Sorry, I don't understand a question. Please post it as a question. – Ali Apr 03 '13 at 16:13
  • @Ali I had no idea that computing roll, pitch and yaw from quaternion had the same problem as using just roll, pitch and yaw until I noticed the issue a while back, searched and saw the comment here... So looks like i need to change the whole code. I really need a solution for this. Please could you be so kind to point me to a sample code for using Quaternion for this purpose? – iSeeker Oct 07 '13 at 11:18
  • @iSeeker Could you be more specific, please? What is it you are trying to solve? What do you do with quaternions? I would gladly help but it is not clear to me what you need. – Ali Oct 07 '13 at 11:28
  • @Ali Thank you for quick response. What i am trying to do is, save the attitude(roll pitch and yaw) when a camera picture is taken and then save them to nsuserdefaults then change the orientation and then try to bring the phone to the same attitude the picture was taken by constantly comparing the attitude values. For this purpose there are 3 dots (one for each attitude parameter)on screen which guide to the correct orientation the picture was taken. – iSeeker Oct 07 '13 at 11:57
  • @iSeeker OK, please post this comment as a new, separate question. I believe I have an idea how to do it which is easy to implement (but may require testing and adjustments). Posting it as a new question is also useful for you: I am not an expert in this area and others can have better ideas / more experience with these kind of stuff so you may get better answers. – Ali Oct 07 '13 at 12:32
  • @Ali As per your advice I have posted this as a new question, :). Please go through it [here](http://stackoverflow.com/questions/19239482/using-quaternion-instead-of-roll-pitch-and-yaw-to-track-device-motion) – iSeeker Oct 08 '13 at 05:07