Ask Your Question

obtain a copy of the global_costmap

asked 2015-07-23 18:16:18 -0600

Naman gravatar image

updated 2015-07-24 10:43:01 -0600

Hi all,

I am planning to write my own node in ROS and I need to access the global_costmap which is being published. I have the following piece of code:

int main(int argc, char** argv){

    ros::NodeHandle n;

    tf::TransformListener tf_(ros::Duration(10));

    costmap_ros_ = new costmap_2d::Costmap2DROS("global_costmap", tf_);

    costmap_ = costmap_ros_->getCostmap();

    unsigned int sizeX = costmap_->getSizeInCellsX();
    unsigned int sizeY = costmap_->getSizeInCellsY();

    std::cout << "SX: " << sizeX << " SY: " << sizeY << std::endl;

    return 0;

Now the problem is I don't think I am getting the global_costmap because the size getting printed is (200,200) (Its the default I guess). The correct size of the global_costmap is (280,457). Can anyone tell me what is wrong here? Or If there is any other way to obtain a copy of the global_costmap, please let me know. Let me know if you need more information from my side.

Yeah, I was able to subscribe to /move_base_node/global_costmap/costmap and obtain nav_msgs/OccupancyGrid message but I was wondering how can I have a new Costmap object which is an exact copy of the global_costmap being published my move_base instead of just getting the OccupancyGrid data or how can I create a costmap object once I have this Occupancy Grid data? I would like to have this so that I can use all the costmap functions.

Thanks in advance.
Naman Kumar

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-23 20:17:12 -0600

David Lu gravatar image

You're just creating a new costmap object. It does not subscribe to the costmap that is published.

edit flag offensive delete link more


Thanks for the reply @David! Yeah that is true.I can subscribe to the costmap that is being published but in that case I will only get the nav_msgs/OccupancyGrid message which I can use. But, how can I get the exact copy of the costmap as is so that I can use all its functionalities? TIA

Naman gravatar image Naman  ( 2015-07-24 10:01:10 -0600 )edit

You should be able to subscribe to the global_costmap/costmap in a static layer

David Lu gravatar image David Lu  ( 2015-07-24 10:18:06 -0600 )edit

Thanks @David! I have updated my original question. Can you please have a look. TIA

Naman gravatar image Naman  ( 2015-07-24 10:43:34 -0600 )edit

I have a similar problem. But subscribing to global_costmap/costmap will give the original map and not the occupancy grid that is obtained after updating it with sensor data. Is there any way to access the updated costmap in a node?

sonali gravatar image sonali  ( 2015-07-24 12:39:44 -0600 )edit

You need to also subscribe to the updates.

David Lu gravatar image David Lu  ( 2015-07-24 12:55:27 -0600 )edit

Thanks @David! Is there any way to get this data as a costmap_2d::Costmap2D_ROS object so that I can take advantage of its functions like @Naman asked?

sonali gravatar image sonali  ( 2015-07-24 13:35:36 -0600 )edit

Like I said, you can create a Costmap2DROS with a single static layer, and instead of /map have it subscribe to global_costmap/costmap

David Lu gravatar image David Lu  ( 2015-07-24 13:54:20 -0600 )edit

@Naman@sonali Do you mind explaining how you solved this issue?

bochen87 gravatar image bochen87  ( 2017-08-21 07:41:31 -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



Asked: 2015-07-23 18:16:18 -0600

Seen: 558 times

Last updated: Jul 24 '15