Ask Your Question
0

How to subscribe to a topic?

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

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 imageMichaelDUEE ( 2019-12-12 08:14:39 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-12-12 12:35:06 -0600

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

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

Stats

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

Seen: 64 times

Last updated: Dec 12 '19