ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

I think you are calling hello before callback.

Try the following.

#!/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
    print(v.data[0]) # added


rospy.init_node("array_listener")


rospy.Subscriber("zones",Float64MultiArray, callback)

def hello():
    global v
    print(v.data[0])

# hello() # to comment
rospy.spin() # added