0
$\begingroup$

Rosanswers logo

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.


Originally posted by Luke_ROS on ROS Answers with karma: 116 on 2014-06-03

Post score: 1


Original comments

Comment by David Lu on 2014-06-13:
Can you clarify your updated question? Which name are you looking for?

Comment by Luke_ROS on 2014-06-17:
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).

Comment by David Lu on 2014-06-17:
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...

Comment by David Lu on 2014-06-17:
...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.)

Comment by Luke_ROS on 2014-06-17:
Yes. That's spot on. Sorry. I got confused by the different terminologies of the paper and the actual code.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by David Lu with karma: 10932 on 2014-06-17

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Luke_ROS on 2014-06-26:
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.

Comment by aswin on 2015-01-09:
@Luke_ROS Did you get the above to work? I dont see a getCharMap() in costmap_2d::ObstacleLayer

Comment by aswin on 2015-01-09:
Updated here. Just need to replace ObstacleLayer with costmap_2d::CostmapLayer

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.