0
$\begingroup$

Rosanswers logo

I have an application where 2 nodes are talking to each other over a certain topic, based on where the nodes are at in the program flow they either don't care about the topic or they do. My question is something that the tutorials didn't help with, is there a command that can check a topic on demand? or check a specific piece of a topic on demand?

elevator_talk.publish(status);

works great for publishing on demand, is there something similar for subscribing?


Originally posted by Rydel on ROS Answers with karma: 600 on 2012-07-03

Post score: 1


Original comments

Comment by cagatay on 2012-07-03:
I am not sure but you may keep the track of subscribed topic by checking out the last time you received the data. For example if it was 10 seconds ago , then you would think that a problem might happen to the publishing node ? or you may use diagnostic_msgs to understand what is happening

Comment by Rydel on 2012-07-03:
yea your comment doesn't really help me. I guess what I'm asking is when a node is listening to a topic how would i have that node extract the most recent data from that topic and use it?

Comment by Thomas D on 2012-07-03:
You could just always go to your callback function when you receive a message, which will be the most recent one, and have a class variable you check at the beginning of the callback function to see if you should do anything with that data. Elsewhere in your code you can set the class variable.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

As Thomas suggested: run your callback all the time, and ignore messages (or parts of messages) you don't care about.


Originally posted by joq with karma: 25443 on 2012-07-03

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Rydel on 2012-07-06:
For anyone else who may see this in the future, I found ros::spinOnce was what I was looking for but be careful if your message isn't being published very often.

Comment by joq on 2012-07-06:
You should either run ros::spin() or call spinOnce() periodically at some appropriate rate.

Comment by Rydel on 2012-07-06:
right, or if your looking for a particular piece of the message to change like a status bit or something, put ros::spinOnce() in a while loop having the status bit break the loop

$\endgroup$

Your Answer

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