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

Quaternion rotation

asked 2017-05-24 10:24:42 -0600

tonio gravatar image

Hi guys, i'm having some problems with the rotation through quaternions. I have two quaternions coming one from a nav_msgs::odometry and the other one from a geometry_msgs::pose. I want to rotate the robot until the quaternion of the nav_msgs is equal, or almost equal, to the geometry_msgs one. How is it possible to solve my problem? Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2017-05-24 10:39:44 -0600

Chaos gravatar image

You can obtain the radians value for the yaw through tf::getYaw and then compute the angular speed command for the robot.

edit flag offensive delete link more


I obtain this warning: MSG to TF: Quaternion Not Properly Normalized, what's that? By the way, surfing the web, I found some mathematical formulas that state: yaw = atan2(2(wz+xy),1-2(y^2+z^2)). I compared the result from this formula and the result from tf::getYaw and they are different, which use?

tonio gravatar image tonio  ( 2017-05-24 11:04:13 -0600 )edit

If you got that error, it means that the quaternion was not properly computed. How do you obtain the two quaternions? The norm of the quaternions should always be 1. In order to compute the yaw, first, you should know how the rotation was built (x-y-z or z-y-x, etc...)

Chaos gravatar image Chaos  ( 2017-05-25 02:49:56 -0600 )edit

If I set an orientation goal (a geometry_msgs::Pose) equal to (0,0,1,1), it should rotate of 180° but the warning shows up, so what's wrong with this?

tonio gravatar image tonio  ( 2017-05-25 04:30:34 -0600 )edit

(0,0,1,1) is not a unitary quaternion. Its norm is 2. You can create quaternion with tf::createQuaternionFromYaw or tf::createQuaternionFromRPY. Check this

Chaos gravatar image Chaos  ( 2017-05-25 04:43:19 -0600 )edit

Question Tools

1 follower


Asked: 2017-05-24 10:24:42 -0600

Seen: 2,098 times

Last updated: May 24 '17