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

Global Costmap Updating Mysteriously

asked 2018-04-26 04:19:26 -0500

updated 2018-04-27 08:51:28 -0500

Hello everyone! I'm experiencing some weird behavior while using costmaps in move_base which I hope someone can shed some light on.

Thanks in advance to anyone who bothers with reading this wall of text and formulating a reply. Please let me know if I missed some important detail, and I'll be happy to add more information to this! :)

But first...

What I'm Trying to Achieve

I want to access costmap data directly, i.e. read the values from the map while knowing how to related them to /map coordinates. This is not complicated, and I believe I've achieved it with tf (I might have to debug it a bit, but that's beside the point). Seeing as I'm using Python, using the Costmap2D API is out of the question.

As such, I developed...

My Approach

Given that the costmap is only published once in /move_base/global_costmap/costmap, and then updated via /move_base/global_costmap/costmap_updates, I've written a small Python node that continuously listens to these, updates the main map and then serves them on a GetMap service.

This would allow me to have access to the latest costmap as an OccupancyGrid whenever I needed it, which is fine for my purposes. Furthermore, serving the map over a service only on-demand should be substantially easier on bandwidth than constantly publishing all updates.

While testing this with rviz, I stumbled upon...

The Problem

In short, it seems that the costmap that rviz shows is different than the one I'm getting on the /move_base/global_costmap/costmap topic.

I have changed my code to act as a simple passthrough (receiving the costmap on the /move_base/global_costmap/costmap topic and publishing it elsewhere) and restarting my node leads me to see, in rviz, an updated map without any messages being published in /move_base/global_costmap/costmap (which is monitored with a rostopic echo.

In other words, if I move the robot's 2D pose estimate around, leading it to "pollute" the global costmap with whatever trash it's picking up on its sensors, and then restart my node, this new data will be on the costmap published by my node, which at this point accesses only the /move_base/global_costmap/costmap topic which, according to the rostopic echo I'm starting at the beginning of the session, has only a single message being published since the beginning of the session (sequence number seq is zero).

What I'm doing is basically:

self._global_costmap = rospy.wait_for_message("/move_base/global_costmap/costmap", OccupancyGrid)

to get the first costmap, and then

rospy.Subscriber("/move_base/global_costmap/costmap_updates", OccupancyGridUpdate, self.costmap_cb)

to integrate the updates. For testing purposes, self.costmap_cb is limited to:


i.e. it publishes the "initial" map every time an update is received, without touching it at all.

My Theory

I'm thinking that rviz uses the aforementioned Costmap2D API to get updated maps. This way, when I set up a new display pointing to /move_base/global_costmap/costmap, it ... (more)

edit retag flag offensive close merge delete


it should be /map not \map.

Troski gravatar image Troski  ( 2018-04-27 01:32:53 -0500 )edit

Corrected, thanks!

Gonçalo S. Martins gravatar image Gonçalo S. Martins  ( 2018-04-27 08:51:39 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-04-30 16:44:54 -0500

David Lu gravatar image

I'm not sure I follow everything in your setup, but here's a couple of things that might help you understand what's goin on.

As you already saw, the data can be published in one of two places. costmap and costmap_updates

The data will be published in updates unless one of the following is true .

  • The always_send_full_costmap parameter is true code
  • The costmap changes size/origin code
  • There is a new subscriber. The publisher uses a variant of the traditional advertise function to ensure the full grid is published to new subscribers.
edit flag offensive delete link more


Thank you very much for your reply! I'll mark it as accepted as it answers my questions.

So new subscribers get the full map, which makes sense. But how does this happen with no new messages being delivered to rostopic echo /move_base/global_costmap/costmap?

Gonçalo S. Martins gravatar image Gonçalo S. Martins  ( 2018-05-03 02:51:58 -0500 )edit

I'm not sure. Sorry.

David Lu gravatar image David Lu  ( 2018-05-03 09:16:01 -0500 )edit

No problem, thank you very much for your answer! I'll sift through the code and (hopefully) figure it out :)

Gonçalo S. Martins gravatar image Gonçalo S. Martins  ( 2018-05-04 05:12:49 -0500 )edit

Question Tools



Asked: 2018-04-26 04:19:26 -0500

Seen: 1,560 times

Last updated: Apr 30 '18