Is it possible to read data from /map?
Hello weveryone, I'm trying to read the data from the topic /map (in ROS Kinetic) but I don't know if I'm subscribing correctly.
I'm using the following code to count the number of gray pixels (unexplored pixels):
#include <ros/ros.h>
#include <nav_msgs/MapMetaData.h>
#include <nav_msgs/OccupancyGrid.h>
#include "std_msgs/Header.h"
#include "nav_msgs/MapMetaData.h"
double Ngray = 0;
void mapCallback(const nav_msgs::OccupancyGrid::ConstPtr& msg){
std_msgs::Header header = msg->header;
nav_msgs::MapMetaData info = msg->info;
nav_msgs::OccupancyGrid data = msg->data;
ROS_INFO("Got map %d %d", info.width, info.height);
for (unsigned int x = 0; x < info.width; x++)
for (unsigned int y = 0; y < info.height; y++)
if (data(x,y) == -1)
Ngray++;
ROS_INFO("Number of gray cells is: %e", Ngray);
//map.Insert(Cell(x,y,info.width,msg->data[x+ info.width * y]));
//nav_msgs::OccupancyGrid* newGrid = map.Grid();
//newGrid->header = header;
//newGrid->info = info;
//map_pub.publish(*newGrid);
}
int main(int argc, char **argv){
ros::init(argc, argv, "map_reader");
ros::NodeHandle n;
ros::Subscriber map_sub = n.subscribe("map",2000,mapCallback);
ros::spin();
return 0;
}
I'm having troubles with line 12. I'm sure I'm not writing it good, but I don't know how to.
Can anybody help me?
Thank you very much.