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

Is it possible to subscribe to poses computed by cartographer?

asked 2021-02-23 10:13:27 -0600

Py gravatar image

updated 2021-02-23 11:02:12 -0600

In cartographer, simultaneous localisation is happening with mapping so I assume that a cartographer node always has some estimate of robot pose. I'd like to be able to subscribe to this so I know the value of robot pose in the map generated at all times.

Could anyone tell me how to do this please?

In the documentation, it says this:

provide_odom_frame If enabled, the local, non-loop-closed, continuous pose will be published as the odom_frame in the map_frame.

But when I set this I get the following warning and no map:

[ WARN] [1614098472.740487459]: Timed out waiting for transform from base_link to map to become available before running costmap, tf error: canTransform: target_frame map does not exist.. canTransform returned after 0.10061 timeout was 0.1.
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-02-23 11:35:43 -0600

updated 2021-02-23 11:37:37 -0600

provide_odom_frame is the parameter that, if set to true, causes cartographer to not publish any poses, instead the normal odom transform of your odometry will be published.

I would set that to false.

Furthermore slam should build the transform between map and odom so i would set the following parameters:

map_frame = "map",
tracking_frame = "base_footprint", (if you have an imu this should be imu_link)
published_frame = "odom",
odom_frame = "odom",
provide_odom_frame = false, (since we want cartographer to correct any error left in the odometry)
publish_frame_projected_to_2d = true, (only if you are in 2d space)

use_odometry = true,

This will cause cartographer to publish the map->odom transform. The odom->base_footprint transform will be provided directly from your odometry or robot_localization. If you don't have any odometry source it is pretty hopeless that cartographer will generate a good odometry, but then i guess you would set the following:

map_frame = "map",
tracking_frame = "base_footprint",
published_frame = "base_footprint",
odom_frame = "odom", (doesn't matter now)
provide_odom_frame = false,
publish_frame_projected_to_2d = true,

use_odometry = false,

Now if you want to get the pose of the robot i would probably use a tf2 transform that transforms the odom message in the odom_frame to the map frame.

EDIT:

Your Error is caused by cartographer not providing the odom frame anymore hence your map is disconnected from your base-tf_tree

edit flag offensive delete link more

Comments

Thanks for the help. I've changed the .lua file as suggested and created this code to get the transform (where frame is map and required_position is odom):

def get_map_pose(frame, required_position):
    tf_buffer = tf2_ros.Buffer()
    tf2_ros.TransformListener(tf_buffer)
    while not rospy.is_shutdown():
        try:
            transform = tf_buffer.lookup_transform(frame, required_position, rospy.Time(0), rospy.Duration(5.0))
            self.pose.position = transform.transform.translation
            self.pose.orientation = transform.transform.rotation

Is this the way you are suggesting to get the robot position within the map frame?

Py gravatar image Py  ( 2021-03-11 03:04:15 -0600 )edit

This goes in the right direction but isn't really what i meant. I meant you should transform your odometry message in to the map frame not looking up the transform between the two frames.

If you want to use a transform listener, please look up the transformation between map and your base_link frame (If you get the negative position you might need to exchange the two frames in the look up transform).

If that doesn't give the wanted results i'll kindly ask you to supply a picture of your tf-tree so i know what is going on and how your system is structured. All of my answers are guesses since i don't really know anything about your system other than that you are using cartographer to build a map

Tristan9497 gravatar image Tristan9497  ( 2021-03-11 07:58:28 -0600 )edit

Btw i don't understand why my answer was flagged as offensive. I am trying to help someone and provide objective information. It is neither Spam, advertising nor malicious text.

Hope that was by mistake...

Tristan9497 gravatar image Tristan9497  ( 2021-03-11 08:45:24 -0600 )edit

Thanks for the help! No idea why anyone would flag as offensive..... it's been very helpful to me at least :)

Py gravatar image Py  ( 2021-03-15 10:41:46 -0600 )edit

No worries it disappeared fairly quickly after my comment. Probably someone clicked on it by mistake. Have you managed to get your pose yet?

Tristan9497 gravatar image Tristan9497  ( 2021-03-15 10:43:36 -0600 )edit

I have through the code I shared but it keeps giving me a TF_REPEATED_DATA warning so I'm suspicious of it and keen to understand your method. How would you go about transforming the odometry message to the map frame? Could you share a code snippet?

Py gravatar image Py  ( 2021-03-15 10:47:02 -0600 )edit

I write everything in c++ so i don't know about python, but this post seems promising.

But i'd still like to know more about your robot. Do you have an odometry source like encoders?

Tristan9497 gravatar image Tristan9497  ( 2021-03-15 12:15:53 -0600 )edit

Yes I do have an odometry source. So from the post you linked, are you suggesting that my function ought to be:

def get_map_pose(self, frame, required_position):
    tf_buffer = tf2_ros.Buffer()
    tf2_ros.TransformListener(tf_buffer)
    while not rospy.is_shutdown():
        try:
            transform = tf_buffer.lookup_transform(frame, required_position, rospy.Time(0), rospy.Duration(5))
            pose_transformed = tf2_geometry_msgs.do_transform_pose(self.pose, transform)
            return pose_transformed
        except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException) as error:
            print(error)
        continue

From this, I get the error AttributeError: 'Pose' object has no attribute 'pose'. Any ideas why?

Py gravatar image Py  ( 2021-03-16 10:43:07 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2021-02-23 10:13:27 -0600

Seen: 1,089 times

Last updated: Feb 23 '21