my subscriber cannot connect to the topic
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
Asked by ShehabAldeen on 2018-10-16 13:37:55 UTC
Comments
I guess it's because you are waiting for a message on topic "\signal" when it should be "/signal"
Asked by lucascoelho on 2018-10-16 13:53:02 UTC
no this is not the situation as appeared to me
Asked by ShehabAldeen on 2018-10-16 18:19:02 UTC
Did already try to use relative names to the topics you are using?
Asked by matheusns on 2018-10-16 18:25:31 UTC
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?
Asked by Reamees on 2018-10-17 01:27:58 UTC