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

JaimeGJ's profile - activity

2018-11-01 06:21:08 -0500 received badge  Famous Question (source)
2018-06-19 10:29:08 -0500 received badge  Famous Question (source)
2018-06-04 07:52:34 -0500 received badge  Notable Question (source)
2018-06-04 07:52:34 -0500 received badge  Popular Question (source)
2018-04-30 04:23:14 -0500 received badge  Enthusiast
2018-04-27 06:41:09 -0500 asked a question 'OSError: [Errno 13] Permission denied' when launching a node

'OSError: [Errno 13] Permission denied' when launching a node Hello everyone, I'm having troubles launching the control

2018-04-09 09:38:13 -0500 received badge  Notable Question (source)
2018-04-08 15:03:00 -0500 marked best answer 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.

2018-04-08 15:03:00 -0500 received badge  Scholar (source)
2018-04-07 13:54:11 -0500 received badge  Popular Question (source)
2018-04-07 11:33:25 -0500 received badge  Supporter (source)
2018-04-07 11:31:53 -0500 commented answer Is it possible to read data from /map?

Thank you, Jasmin. The code I posted was based on that one that you said. What I want to do with the data from /map is t

2018-04-06 06:57:28 -0500 asked a question Is it possible to read data from /map?

Is it possible to read data from /map? Hello weveryone, I'm trying to read the data from the topic /map (in ROS Kinetic)