Ask Your Question
1

Accessing data of different layers in Costmap2DROS

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

Luke_ROS gravatar image

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

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 imageDavid Lu ( 2014-06-13 12:11:32 -0600 )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 imageLuke_ROS ( 2014-06-17 07:09:41 -0600 )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 imageDavid Lu ( 2014-06-17 09:52:16 -0600 )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 imageDavid Lu ( 2014-06-17 09:53:46 -0600 )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 imageLuke_ROS ( 2014-06-17 10:48:05 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

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

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 imageLuke_ROS ( 2014-06-26 08:24:01 -0600 )edit

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

aswin gravatar imageaswin ( 2015-01-08 23:13:45 -0600 )edit
1

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

aswin gravatar imageaswin ( 2015-01-09 00:21:57 -0600 )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

2 followers

Stats

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

Seen: 891 times

Last updated: Jun 17 '14