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

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

Comments

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
0

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

Try this tutorial on for size: http://wiki.ros.org/ROS/Tutorials/Wri...

edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 541 times

Last updated: Dec 12 '19