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

Is it necessary to using Callback function when I subscribe?

asked 2015-11-22 19:14:10 -0500

haryngod gravatar image

Hi guys! I'm begginer studying ros at this moment. When I do tutorials that make talker and listener (Publisher & Subscriber), I really wonder weather it is necessary to using callback function in subscriber. If I dosen't use callback function, I could get the message? Or If I can use it, How to I get the message?

Thanks guys! Have a good day also.

edit retag flag offensive close merge delete

Comments

Never seen such a possibility and I think the fact that ros works heavily with callbacks is one of the good things about ros. Why would you avoid callbacks?

Dimitri Schachmann gravatar image Dimitri Schachmann  ( 2015-11-23 04:50:04 -0500 )edit

I just curious about it for understanding ros system. Thanks a lot comment to me!

haryngod gravatar image haryngod  ( 2015-11-23 18:57:00 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-03-21 16:37:48 -0500

tfoote gravatar image

The short answer is yes they are necessary. Callbacks are triggered when messages are received. They are required to be able to do something useful with new data.

There are other approaches which would require the user to poll for new messages that could be implemented, but that's generally a completely different programming model.

edit flag offensive delete link more

Comments

1

Also, to answer "How to I get the message?": The function you supply as a callback is provided with the message as an argument, so that is how you access it.

JamesGiller gravatar image JamesGiller  ( 2018-03-21 20:57:58 -0500 )edit

Question Tools

Stats

Asked: 2015-11-22 19:14:10 -0500

Seen: 586 times

Last updated: Mar 21 '18