Accessing data of different layers in Costmap2DROS
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.
Can you clarify your updated question? Which name are you looking for?
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).
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...
...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.)
Yes. That's spot on. Sorry. I got confused by the different terminologies of the paper and the actual code.