ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

tf::Quaternion syntax question

asked 2013-02-21 10:26:54 -0500

Peter Roos gravatar image

updated 2013-02-21 10:59:33 -0500


Recently I've found out, that I must give the navigation stack a quaternion describing rotation in addition to the vector3D goal. Quaternions were new to me, so I learnt about them because I would like to use them in ROS. My question is about actual implementation.

Suppose that I would like to go from (0,0,0) to (1,1,0). Then I know, that the robot would probably face to 45°, so...

double inRadian = radian(degree);

tf::Quaternion rotateByThis(tf::Vector3(0,0,1), inRadian); // is this call okay?

goal.target_pose.pose.orientation.w = ? // tf::Quaternion has getW() method, should I use that value?

goal.target_pose.pose.orientation.x = ?

goal.target_pose.pose.orientation.y = ?

goal.target_pose.pose.orientation.z = ?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2013-02-21 22:39:10 -0500

dornhege gravatar image

tf provides some methods for the use case that you want to do (2D navigation).

In general there is: tf::createQuaternionFromYaw

Specifically for setting ROS messages, there is also: tf::createQuaternionMsgFromYaw

So, your code can be shortened to:

goal.target_pose.pose.orientation = tf::createQuaternionMsgFromYaw(inRadians)

You'll almost never have to set quaternion components manually when dealing with ROS data types. There are also conversions between tf types and messages for all common tf types.

edit flag offensive delete link more


Hello, I have the question of other way round. How to get rotations of a quaternion to RPY? I mean in my code I use a /tf listener. So after lookupTransform, now I need to call the rotations and have themin RPY. So how to call and convert them? Any wiki link is also appreciated.

Reza Ch gravatar image Reza Ch  ( 2013-03-21 02:30:51 -0500 )edit

answered 2013-02-21 11:27:28 -0500

Claudio gravatar image

A quaternion is just another way (one which doesn't have singularities) of representing angles: a quaternion, just like euler angles, signifies a rotation from one frame to another: f2 = q * f1

That said I don't know enough about the navigation stuck but I can tell you that your code doesn't look right.

tf::Quaternion rotateByThis(tf::Vector3(0,0,1), inRadian); // is this call okay?

Even if that were ok, what does it mean to turn by 1° while you said you wanted 45°? That syntax doesn't look right to me, it would probably be something like

tf::transform transform;

I suggest you check

And after you grasp the TF things then go to the navigation tutorials and look up the one regarding sending goals to the navigation stacks.

This question could also give you insight.

edit flag offensive delete link more


Why do you think the syntax is wrong? He's turning around the z-axis (0,0,1) by inRadian. That looks correct to me.

dornhege gravatar image dornhege  ( 2013-02-21 22:41:53 -0500 )edit

You're right, I didn't understand what he was doing.

Claudio gravatar image Claudio  ( 2013-03-20 01:50:29 -0500 )edit

Question Tools

1 follower


Asked: 2013-02-21 10:26:54 -0500

Seen: 4,428 times

Last updated: Feb 21 '13