Ask Your Question

How to understand robot orientation from quaternion yaw angle

asked 2012-08-12 19:34:29 -0600

searchrescue gravatar image

I have this line of code

geometry_msgs::Quaternion odom_quat = tf::createQuaternionMsgFromYaw(currentth);

Where currentth is the angle in radian to represent the pose of the robot. Then i am making the assignment

odom_trans.transform.rotation = odom_quat;

where i do the propagation. In another node i have a callback as follows

void odometryCallback (const nav_msgs::Odometry::ConstPtr &odom)
// ROS_INFO("ODOMETRY RETRIEVED FROM ODOMETRY NODE and orientation is %f",robotCurrentTheta );
  currentX = odom->pose.pose.position.x;
  currentY = odom->pose.pose.position.y;
  robotCurrentTheta= odom->pose.pose.orientation.w; // not sure here
  ROS_INFO("ODOMETRY RETRIEVED FROM ODOMETRY NODE and orientation is %f %f %f %f",
  odom->pose.pose.orientation.x,odom->pose.pose.orientation.y,odom->pose.pose.orientation.z,odom->pose.pose.orientation.w );

Now how i can obtain robot's orientation in radian? am i missing something.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-08-12 23:04:27 -0600

You can do it like this:

  tf::Pose pose;
  tf::poseMsgToTF(odom->pose.pose, pose);
  double yaw_angle = tf::getYaw(pose.getRotation());

Haven't tested this actual snippet, but should work. It's also advisable to get a basic idea what quaternions are.

edit flag offensive delete link more


And if anyone wants to know how to do the same thing in python, check out this question here

M@t gravatar image M@t  ( 2016-07-18 22:29:31 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2012-08-12 19:34:29 -0600

Seen: 15,341 times

Last updated: Aug 12 '12