Jump to content
  • Advertisement
Wizumwalt

How to get RPY and plugin to Quaternion

This topic is 393 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an API that takes quaternions to set the orientation of a drone. I want to fix the roll, pitch, and yaw. I currently have the following.

    tf::Quaternion q_new, q_curr, q_rot;

    // r, p, y is current vehicle orientation
    q_curr = tf::createQuaternionFromRPY(r, p, y);

    // What to plug in here ...
    q_rot = tf::createQuaternionFromRPY(?, ?, ?);

    // I think this is how to apply the new orientation to the current
    q_new = q_curr * q_rot;

    q_new.normalize();

My problem is I don't know what values to plugin to q_rot to set the new orientation. I can think in RPY values, but not quaternions. For example, I'd like to rotate the drone around the z-axis 90 degrees, or 180 around y, or 90 degrees around the x axis, etc... How does one calculate that?

 

Share this post


Link to post
Share on other sites
Advertisement

I'm away from my computer, and I also don't remember the math off the top of my head, but you can find it with some googling.

If you're comfortable with RPY, are you also comfortable with rotation matrices? If so, then you can find the formulas to convert from matrices to quaternions, and vice versa.

But.. if you're using an API that takes in quats, does it not provide functions to help you with that?

Share this post


Link to post
Share on other sites

The code I posted shows the conversion from RPY to quaternions, so it does help with that. What I'm looking for are the values to feed into a quaternion from my current orientation. Then I can combine the two by multiplying those quats together to get the new value and feed that in. But I don't understand how to  get the value from my current orientation to the new orientation. Does that make sense? It's not a problem with the API, it's the value that I feed in to get me to my new orientation.

Share this post


Link to post
Share on other sites

Your code looks like it takes a current absolute orientation (q_curr) and a delta rotation (q_rot) which you then combine to find the new absolute orientation (q_new). So you are missing one orientation somewhere that you have available.

I can imagine that this will work something like this:

// Once
Quaternion m_Current = kQuatIdentiy; // Or any other reasonable initialization

// Every frame
Quaternion q_curr = m_Current;
Quaternion q_rot = CreateQuaternion( Y, P, R );
Quaternion q_new = Normalize( q_curr * q_rot );
m_current = q_new;

 

Edited by Dirk Gregorius

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!