ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How to subscribe to a topic?

asked 2019-12-12 07:28:55 -0500

Parth2851 gravatar image

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 '???'.

edit retag flag offensive close merge delete


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.

MichaelDUEE gravatar image MichaelDUEE  ( 2019-12-12 08:14:39 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-12-12 12:35:06 -0500

Try this tutorial on for size:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-12-12 07:28:55 -0500

Seen: 352 times

Last updated: Dec 12 '19