ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Occupancy grid map being only partially loaded

asked 2020-11-27 15:32:45 -0500

JeffR1992 gravatar image

I'm trying to load a map that is being published by a map_server node, but it seems like the map is not being properly loaded when running the localization node that uses the map. In the terminal a map_server is used to publish a map as follows:

rosrun map_server map_server /path/to/map_file.yaml

In the code for the localization node, the map is loaded as follows:

nav_msgs::OccupancyGridConstPtr occupancy_grid_map_ptr_ = ros::topic::waitForMessage<nav_msgs::OccupancyGrid>("/map", node_handle_);

From there various map data and info is assigned to private class variables as follows:

std::vector<int8_t> occupancy_grid_map_data_ = occupancy_grid_map_ptr_->data;
double resolution_ = occupancy_grid_map_ptr_->info.resolution;
uint num_rows_ = occupancy_grid_map_ptr_->info.height;
uint num_cols_ = occupancy_grid_map_ptr_->info.width;

When printing out the values stored in resolution_, num_rows_ and num_cols_ everything looks good. However, when printing out the data that is stored inside occupancy_grid_map_data_, as follows:

for(std::size_t i = 0; i < occupancy_grid_map_ptr_->data.size(); ++i) {
    std::cout << occupancy_grid_map_data_[i] << std::endl;

the data looks incorrect, where instead of seeing int values being printed, I instead see diamonds with question marks in them.

As such, I was wondering what I could be doing wrong. If all of the data looked incorrect (i.e. in resolution_, num_rows_ and num_cols_ as well), then this would have made things a bit less confusing. But since only occupancy_grid_map_data_ seems to have incorrect data it's left me a little confused. Any help would be appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-11-28 01:06:57 -0500

miura gravatar image

This is probably because occupancy_grid_map_ptr_->data is not a vector<int8_t> but int8[] data.

for(std::size_t i = 0; i < occupancy_grid_map_ptr_->data.size(); ++i) {
    std::cout << occupancy_grid_map_ptr_->data[i] << std::endl;

Or do the following

std::vector<int8_t> occupancy_grid_map_data_(std::begin(occupancy_grid_map_ptr_->data), std::end(occupancy_grid_map_ptr_->data));
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-11-27 15:32:45 -0500

Seen: 251 times

Last updated: Nov 28 '20