0
$\begingroup$

Rosanswers logo

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.


Originally posted by haryngod on ROS Answers with karma: 30 on 2015-11-22

Post score: 0


Original comments

Comment by Dimitri Schachmann on 2015-11-23:
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?

Comment by haryngod on 2015-11-23:
I just curious about it for understanding ros system. Thanks a lot comment to me!

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by tfoote with karma: 58457 on 2018-03-21

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by JamesGiller on 2018-03-21:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.