How to understand robot orientation from quaternion yaw angle 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 close merge delete

Sort by » oldest newest most voted 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.

more

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