Ask Your Question

Get robot position und orientation (in degree) from TF

asked 2016-08-10 10:55:13 -0600

SeanAda gravatar image

updated 2016-08-12 07:18:47 -0600

Airuno2L gravatar image


I want to get the Position (x, y) and the orientation from my robot. The position should be relative to the map TF. Therefore I used a TransformListener:

tf::StampedTransform transform_bot;
tf::TransformListener listener;

listener.lookupTransform("/map", "/base_footprint", ros::Time(0), transform_bot);

bot_x = transform_bot.getOrigin().x();
bot_y = transform_bot.getOrigin().y();

double roll, pitch, yaw;
transform_bot.getBasis().getRPY(roll, pitch, yaw);

bot_dir = yaw * 180.0 / PI;

ROS_INFO("Bot X: %f", bot_x);
ROS_INFO("Bot Y: %f", bot_y);
ROS_INFO("Bot Z: %f", bot_dir);

So far I was not able to get good result with this solution...

Do you have any ideas, how to solve the problem?

Thank you, Sebastian

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-08-11 12:18:15 -0600

Airuno2L gravatar image

I'm not sure that getBasis does what you think, I could be wrong though. I would try using getRotation which returns a quaternion, then grabbing the yaw from that.

tf::Quaternion q = transform_bot.getRotation(); 
double yaw = tf::getYaw(q);

Here is the getYaw documentation.

If that doesn't solve things could you edit your answer and describe what results you're observing with your current code?

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools


Asked: 2016-08-10 10:55:13 -0600

Seen: 4,082 times

Last updated: Aug 11 '16