Ask Your Question
0

Detect when costmap2DROS is updated

asked 2015-08-07 13:30:40 -0500

Sebastian gravatar image

I am using a Costmap2DROS object to access a occupancy grid created with gmapping.

I want to execute some algorithm on the map whenever it gets updated. I figured the easiest way to do this is to have a subscriber to the "/map" topic with a callback that executes the algorithm.

I am worried about the overhead associated with the subscriber. I don't want the "/map" data to be cached in some queue somewhere, since it is being cached by Costmap2DROS.

I guess I would want a queue_size = zero.

I don't want ROS to send the occupancyGrid message to my callback function because I don't need it. I can get the data from Costmap2DROS.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-08-07 15:46:51 -0500

paulbovbel gravatar image

updated 2015-08-07 15:49:31 -0500

That's an interesting case.

You could subscribe to the topic_tools::ShapeShifter msg on the map topic, which would AFAIK not deserialize the message automatically.

Another simple solution would to boost::bind to your subscription callback but discard the _1 argument. Something like:

class Node
{
    init(){
        nh.subscribe(boost::bind(&Node::mapCb, this))
    }

    void mapCb(){
        //do stuff
    }
};

I'm not 100% if this would skip the (de)serialization, or merely prevent the shared object from being created.

edit flag offensive delete link more

Comments

Am I supposed to be subscribing to the /map topic directly if I want to do something like this? It really seems like costmap2DROS should provide some way of achieving this behavior. Isn't updating after new map data common design decision?

Sebastian gravatar image Sebastian  ( 2015-08-07 16:17:16 -0500 )edit

FYI the costmap's publish and update frequencies are actually separate parameters. If you're looking to insert something into the costmap's update loop, writing a costmap_2d plugin may be the way to go.

paulbovbel gravatar image paulbovbel  ( 2015-08-12 00:48:25 -0500 )edit

This is the route I went down with frontier_exploration, and I can tell you that it was the wrong approach. Just read the map data from the costmap object periodically, and run your algorithm as needed. If your frequencies are synced, you may OCCASIONALLY get a stale or dropped frame.

paulbovbel gravatar image paulbovbel  ( 2015-08-12 00:50:17 -0500 )edit

Ok, I think I will go with the periodic route, for now at least. Thanks.

Sebastian gravatar image Sebastian  ( 2015-08-14 15:51:07 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-08-07 13:30:40 -0500

Seen: 99 times

Last updated: Aug 07 '15