How to subscribe to a topic?
So I have used Map_server to get an occupancy grid of the map. So, this publishes two topics - /map and /map_metadata.
I have another node where I need to subscribe to these topics but I'm a bit confused with what to write. Here's what I have done till now.
ros::init(argc, argv, "driver");
ros::NodeHandle n("~");
ros::Subscriber sub = n.subscribe("/map", 1000, ???);
???
I am confused with what to write where I've put '???'.
In your '???' you must write a callback function. A callback function is function that activates when your subscriber reads data from the topic ( /map for your situation). In this tutorial it has the chatterCallback that only prints the data.