my subscriber cannot connect to the topic

asked 2018-10-16 13:37:55 -0500

ShehabAldeen gravatar image

Hello,

I am trying to connect to a topic as shown in the following code

#!/usr/bin/env python
import rospy
from std_msgs.msg import Float64

class signal_tools(object):

    def __init__(self):
        self.init_signal()
        self.sig_subscriber = rospy.Subscriber("/signal", Float64, self.callback)
        rospy.loginfo("initiated tools")

    def init_signal(self):
        self._signal = None
        while self._signal is None:
            try:
                self._signal = rospy.wait_for_message("\signal",
                                                   Float64, timeout=1)
            except:
                rospy.loginfo("/signal topic is not ready yet, retrying")

        rospy.loginfo("/signal topic READY")

    def callback(self, data):
        self.signal = data

    def get_signal (self):
        return self.signal.data


if __name__ == '__main__':
    rospy.init_node("test")
    signal = signal_tools()
    rospy.loginfo("%f",signal.get_signal())

    rospy.spin()

but whenever I am trying I cannot connect to it I am using ubuntu 18.04 with ROS melodic

I used the same code on Ubuntu 16.04 with ROS kinetic and was working fine, can anyone spot the problem

edit retag flag offensive close merge delete

Comments

4

I guess it's because you are waiting for a message on topic "\signal" when it should be "/signal"

lucascoelho gravatar image lucascoelho  ( 2018-10-16 13:53:02 -0500 )edit

no this is not the situation as appeared to me

ShehabAldeen gravatar image ShehabAldeen  ( 2018-10-16 18:19:02 -0500 )edit

Did already try to use relative names to the topics you are using?

matheusns gravatar image matheusns  ( 2018-10-16 18:25:31 -0500 )edit

have you tried the usual? I.e rosnode info ('node that is publising /signal' and 'node that is subscribing') to see what they actually subscribe/publish to. rostopic info /signal to see what is using it. Are you sure there are messages being published on /signal? Are you using bags or live data?

Reamees gravatar image Reamees  ( 2018-10-17 01:27:58 -0500 )edit