First time here? Check out the FAQ!


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 Jun 3 '14

Luke_ROS gravatar image

updated Jun 4 '14

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.

Preview: (hide)

Comments

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

David Lu gravatar image David Lu  ( Jun 13 '14 )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  ( Jun 17 '14 )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  ( Jun 17 '14 )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  ( Jun 17 '14 )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  ( Jun 17 '14 )edit

1 Answer

Sort by » oldest newest most voted
2

answered Jun 17 '14

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.

Preview: (hide)

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  ( Jun 26 '14 )edit

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

aswin gravatar image aswin  ( Jan 9 '15 )edit
1

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

aswin gravatar image aswin  ( Jan 9 '15 )edit

Question Tools

2 followers

Stats

Asked: Jun 3 '14

Seen: 1,845 times

Last updated: Jun 17 '14