ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

check for active state of topic

asked 2013-12-05 23:35:15 -0500

hvn gravatar image


I have 2 nodes, 1 publishing the topic, 1 subscribing to that topic. Current situation is that when I start the subscribing node, the values that will be read from the topic are initialized to 0. After reading from the topic, they get the correct values, but when the topic stops publishing they keep that value which may no longer be correct. In that case I want the values set to 0 again. How can I (from within the subscribing node, i.e. not using the rostopic command) check if the publishing topic is still active ?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-12-06 00:06:07 -0500

dornhege gravatar image

The values "on the topic" will not be 0 when the topic is not active and will not stay at the last value when de-activated again. When a topic is not active (this is also the way to check) it will not send any data.

So the very likely explanation for the values being 0 and staying at their value is that this is a logic that you do in you subscriber node. Here, you can change everything to your intended behavior.

edit flag offensive delete link more


From your answer it seems I didn't describe it good enough. After reading from the topic, the values are not 0 anymore but have a value such as 0.60. After the topic stops, no more data is received. Shouldn't the value change to something else then, instead of staying 0.60 ? Or is this up to my own code ?

hvn gravatar image hvn  ( 2013-12-06 02:08:35 -0500 )edit

If there are no more publishers to a topic, there is no more value. How you interpret that is up to you. Keep the latest value, set it to a default or handle explicitly that there is no more data. This depends on what you need.

dornhege gravatar image dornhege  ( 2013-12-06 03:03:41 -0500 )edit

What I've tried is setting the default in the callback with a boolean, but that is no use since without the topic, the callback isn't called. Doing it in the constructor doesn't work either and doing it inside run() the values change so quickly that the default situation is kept. Any suggestions ?

hvn gravatar image hvn  ( 2013-12-06 03:21:58 -0500 )edit

This is you code logic after the ROS calls. You'll need to implement your desired behavior. I don't know what your want and nothing about your code.

dornhege gravatar image dornhege  ( 2013-12-06 03:24:57 -0500 )edit

Point taken. Thanks for replying.

hvn gravatar image hvn  ( 2013-12-06 03:33:14 -0500 )edit

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


Asked: 2013-12-05 23:35:15 -0500

Seen: 2,084 times

Last updated: Dec 06 '13