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

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
9

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

Comments

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

#include <tf/tf.h>

CroCo gravatar image CroCo  ( 2022-09-08 13:16:17 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 16,852 times

Last updated: Aug 12 '12