Publisher and Subscriber nodes don't seem to be communicating [closed]
I made a publisher node that publishes Float64MultiArray
message type to a topic zones
. The script that contains this node constantly changes the .data portion of the message type. So for example, when it runs and I rostopic echo /zones
, the .data portion of the message type looks like this [1.234,0.345]
(the floating point numbers constantly change). Int he terminal. So the publisher node obviously works. I'm testing to make a subscriber node to this topic zone
.As seen here below
#!/usr/bin/python3
import rospy
from std_msgs.msg import Float64MultiArray
from rospy.numpy_msg import numpy_msg
import numpy as np
v=Float64MultiArray()
def callback(msg):
global v
v=msg
rospy.init_node("array_listener")
rospy.Subscriber("zones",Float64MultiArray, callback)
def hello():
global v
print(v.data[0])
hello()
when I run this script, v.data[0]
is empty and gives and as a result the script gives back an index error on the terminal. v.data[0] is not supposed to be empty, it should have the first element in .data
. I dont know why the subscriber does not seem to get information from the topic. I really need help on this.
Could you also post your publisher here?
@Akhil Kurup If you would please take a look, I updated the question here