0
$\begingroup$

Rosanswers logo

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::init(argc,argv,"publish_multiple_goals");
    ros::NodeHandle n;

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

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

    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.

Update:
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


Originally posted by Naman on ROS Answers with karma: 1464 on 2015-07-23

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by David Lu with karma: 10932 on 2015-07-23

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Naman on 2015-07-24:
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

Comment by David Lu on 2015-07-24:
You should be able to subscribe to the global_costmap/costmap in a static layer

Comment by Naman on 2015-07-24:
Thanks @David! I have updated my original question. Can you please have a look. TIA

Comment by sonali on 2015-07-24:
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?

Comment by David Lu on 2015-07-24:
You need to also subscribe to the updates.

Comment by sonali on 2015-07-24:
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?

Comment by David Lu on 2015-07-24:
Like I said, you can create a Costmap2DROS with a single static layer, and instead of /map have it subscribe to global_costmap/costmap

Comment by bochen87 on 2017-08-21:
@Naman @sonali Do you mind explaining how you solved this issue?

$\endgroup$

Your Answer

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