Occupancy grid map being only partially loaded
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.