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

Accessing data of different layers in Costmap2DROS

asked 2014-06-03 08:34:48 -0500

Luke_ROS gravatar image

updated 2014-06-04 01:07:07 -0500

I would like to access the data of the internal master_grid of the obstacle_layer. I am working in another layer and right now I am reading the values out of the layered_costmap_, which works fine like that:

  costmap_2d::Costmap2D* costmap = layered_costmap_->getCostmap();

Also, if I would be within the obstacle_layer, I would access the data of its own master_grid like that:

  unsigned char* master_array = master_grid.getCharMap();

But how would I access the master_grid of the obstacle_layer from another layer? Thanks!


UPDATE:

I think I found a working piece of code which answers like 95 % of my question. So the code searches through all the layers of the COSTMAP (actually it is a layered costmap of type costmap_2d::Costmap2DROS) and operates on the one which matches a predefined string (layer_sear_string_). But can somebody help me how to find the name of the layered costmap global_planner when running move_base?

std::vector<boost::shared_ptr<costmap_2d::Layer> >* plugins = COSTMAP->getLayeredCostmap()->getPlugins();

for (std::vector<boost::shared_ptr<costmap_2d::Layer> >::iterator pluginp = plugins->begin(); pluginp != plugins->end(); ++pluginp) {

    boost::shared_ptr<costmap_2d::Layer> plugin = *pluginp;

    if(plugin->getName().find(layer_search_string_)!=std::string::npos) {
        boost::shared_ptr<costmap_2d::ObstacleLayer> costmap;
        costmap = boost::static_pointer_cast<costmap_2d::ObstacleLayer>(plugin);
        unsigned char* grid = costmap->getCharMap();

        // do sth with it

    }
}

Code found here.

edit retag flag offensive close merge delete

Comments

Can you clarify your updated question? Which name are you looking for?

David Lu gravatar image David Lu  ( 2014-06-13 12:11:32 -0500 )edit

When running move_base you get a global_planner and a local_planner. Both of them should be of type costmap_2d::Costmap2DROS, right? So I am looking for a way to access the top layered costmap of the global_planner from within a layer. (In order to finally access the master_grid of another layer).

Luke_ROS gravatar image Luke_ROS  ( 2014-06-17 07:09:41 -0500 )edit
1

To clarify terminology: In move_base, there is a global planner and a local planner, which operate on the global costmap and local costmap respectively (both of which are Costmap2DROS). I believe you are looking for a way to access the layered costmap object of the global costmap...

David Lu gravatar image David Lu  ( 2014-06-17 09:52:16 -0500 )edit
1

...so that you can access an individual layer's private costmap. (There is no such thing as a "top layered costmap" and the layered costmap has a master costmap, but the individual layers aren't referred to as master costmaps.)

David Lu gravatar image David Lu  ( 2014-06-17 09:53:46 -0500 )edit
1

Yes. That's spot on. Sorry. I got confused by the different terminologies of the paper and the actual code.

Luke_ROS gravatar image Luke_ROS  ( 2014-06-17 10:48:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-06-17 11:29:23 -0500

David Lu gravatar image

Within any layer, you can access the layered costmap object via

protected:
    LayeredCostmap* layered_costmap_;

You can use that object to get a particular layer with the code you linked above.

edit flag offensive delete link more

Comments

1

Thanks a lot. Your answer led me on the right path again. I simply needed to replace COSTMAP->getLayeredCostmap() with the layered_costmap_ since we still operate within the same Costmap2DROS structure. Problem solved. Many things learned.

Luke_ROS gravatar image Luke_ROS  ( 2014-06-26 08:24:01 -0500 )edit

@Luke_ROS Did you get the above to work? I dont see a getCharMap() in costmap_2d::ObstacleLayer

aswin gravatar image aswin  ( 2015-01-08 23:13:45 -0500 )edit
1

Updated here. Just need to replace ObstacleLayer with costmap_2d::CostmapLayer

aswin gravatar image aswin  ( 2015-01-09 00:21:57 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2014-06-03 08:34:48 -0500

Seen: 1,560 times

Last updated: Jun 17 '14