Subscriber not receiving messages even though publisher is continuously publishing on the given same topic

asked 2018-09-05 01:01:11 -0500

Aruco gravatar image

updated 2018-09-05 09:59:06 -0500

Hey! Had a question I needed your clarification with! I have a publisher that continuously publishes onto a topic, and I have a subscriber node that is defined as a part of the class. For some reason, the subscriber is not receiving any messages, but when I do rostopic echo for the topic I am publishing my data on, I can see the proper data over there. I understand that this is the simple ROS setup, but for some reason, I am not able to debug this..Would you have any particular places that I can look for bugs ?

EDIT -

I ran the rqt_graph, and I have found something interesting. When I do a rostopic echo, I get a list of all the topics that I have created (as expected). But when I run the rqt_graph, I dont see any of these topics. If required, I can provide screenshots of the same.

One implementation detail that I'd like to explain - I have a .h file (headers file) where I define a class, and have declared the Publishers and Subscribers in the public variables space.

In my .cpp file, I have a constructor to which I am passing the nodehandle from my main function. I am initializing my Publishers and Suscribers.

Would this kind of an implementation be an issue???

P.S. - I am not hiding any of the below in my rqt_graph:

Dead sinks (ie: subscriptions that have no publisher) Leaf topics (ie: publishers with no subscriptions) Debug (ie: all topics used for logging msgs and related infra)

edit retag flag offensive close merge delete

Comments

4

Would you have any particular places that I can look for bugs ?

Well .. the first place would be your code.

But if you want our help with that you'll need to to show that code to us.

gvdhoorn gravatar image gvdhoorn  ( 2018-09-05 01:16:59 -0500 )edit
1

Also, rostopic info <your topic> will tell you what nodes are publishing/subscribing to it. rosnode info <node> is also useful. This might give you some hints as to where the node fails. Add debug statements to your code, printing out variables etc, to see where it fails.

Reamees gravatar image Reamees  ( 2018-09-05 02:12:34 -0500 )edit

And rqt_graph will show you if perhaps you have a typo in your topic name, or a namespace problem or similar.

KenYN gravatar image KenYN  ( 2018-09-05 02:39:43 -0500 )edit

Have edited the question with some extra implementation details.

Aruco gravatar image Aruco  ( 2018-09-05 09:56:31 -0500 )edit
1

Are you using C++ or Python for your subscriber code? If C++, do you have a ros::spinOnce(); that is called periodically or a ros::spin();?

Gary Servin gravatar image Gary Servin  ( 2018-09-06 09:37:25 -0500 )edit

I am having this exact same problem, no solution.

db gravatar image db  ( 2020-08-14 06:29:37 -0500 )edit

Ok, in my case the problem was that I was doing nh.subscribe("topic", 1, &cla::mehtod, this), without assigning the result anywhere. You need to assign like ros::Subscriber sub = nh.subscribe(..."

db gravatar image db  ( 2020-08-14 06:57:32 -0500 )edit