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

How to get the current position of a robot (C++) ?

asked 2016-05-26 09:56:38 -0600

lfr gravatar image

updated 2016-05-27 04:05:41 -0600

Hello !

I try to get the situation of my robot using the following code:

tf::TransformListener listener;
tf::StampedTransform transform;
listener.lookupTransform("/move_base/local_costmap/global_frame", "/move_base/local_costmap/robot_base_frame", ros::Time::now(), transform);

and use it using the following methods:

transform.getOrigin().x()
transform.getOrigin().y()
//...

My problem is when I run this code, I get the the following error:

[ERROR] [..., ...]: "move_base/local_costmap/global_frame" passed to lookupTransform argument target_frame does not exist.

But when I check the "move_base/local_costmap/global_frame" parameter existence (the same with the "move_base/local_costmap/robot_base_frame" parameter), I find that it exists well and is settled to 'odom' value (respectively 'base_link').

I also tried to write directly "odom" and "base_link" instead of "move_base/local_costmap/global_frame" and "move_base/local_costmap/robot_base_frame" but I have the same error:

[ERROR] [..., ...]: "odom" passed to lookupTransform argument target_frame does not exist.

However, when I do:

rosrun tf view_frames

I have the following tree: image description
The first and the third frames are those which interest me.

Moreover, when I use the command:

rosrun tf tf_monitor odom base_link

I have this:

RESULTS: for odom to base_link
Chain is: odom -> base_footprint -> base_link
Net delay     avg = 0.00599856: max = 0.016

Frames:
Frame: base_footprint published by unknown_publisher Average Delay: 0.000963 Max Delay: 0.005
Frame: base_link published by unknown_publisher Average Delay: -0.500052 Max Delay: 0

All Broadcasters:
Node: unknown_publisher 146.156 Hz, Average Delay: -0.102412 Max Delay: 0.005

If someone can help me, I will be very grateful,
lfr

edit retag flag offensive close merge delete

Comments

Check my update with waitforTransform

NEngelhard gravatar image NEngelhard  ( 2016-05-27 05:25:47 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-05-26 11:18:01 -0600

NEngelhard gravatar image

updated 2016-05-27 06:04:25 -0600

You have to pass the frame name directly to lookupTransform and not the name of a parameter that contains the frame name. You can't expect such a function to decide if you passed the name of a frame or of a parameter.

Next, you should add a listener.waitForTransform before you try to look up. You just created the listener so it had no time to collect any transformations on the /tf-topic.

BTW: You should have a look at TF2. It reduces the used bandwidth and gets rid of the republishing of static transformations.

edit flag offensive delete link more

Comments

Thank you for answering me.
I already tried to use 'odom' instead of "move_base/local_costmap/global_frame" and 'base_link' instead of "move_base/local_costmap/robot_base_frame" but it generates the same error with 'odom'.

lfr gravatar image lfr  ( 2016-05-27 01:55:44 -0600 )edit

What is published on /tf and /tf_static?

NEngelhard gravatar image NEngelhard  ( 2016-05-27 02:46:27 -0600 )edit

On /tf, a lot of things are published non-stop but nothing is published on /tf_static.
This is a sample of data published on /tf:

transforms:

header: 
  seq: 0
  stamp: 
    secs: 77
    nsecs: 129000000
  frame_id: odom
child_frame_id: base_footprint
lfr gravatar image lfr  ( 2016-05-27 02:55:00 -0600 )edit

...

transform: 
  translation: 
    x: 0.000368870873302
    y: 0.000194895575539
    z: 0.0839691068639
  rotation: 
    x: -3.22346543618e-07
    y: 4.25625394189e-07
    z: 0.000436463216874
    w: 0.99999990475
lfr gravatar image lfr  ( 2016-05-27 02:57:46 -0600 )edit
1

Thank you, it works successfully !!
Really thank you.

lfr gravatar image lfr  ( 2016-05-27 05:35:09 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-05-26 09:56:38 -0600

Seen: 3,846 times

Last updated: May 27 '16