Very slow update of global variables - python
Hi
I have made a node which takes input from several different sensors. I want to proces the sensor data and publish a on a new topic.
However when I move the data from the callback functions to my processing algorithm the using global variables, the variables are updated very slowly.
I have a very simplified node of what I have done...
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import LaserScan
from std_msgs.msg import Float64
ranges = []
def callback(data):
global ranges
rospy.loginfo(data)
ranges = data.ranges[200]
def listener():
rospy.init_node('listener', anonymous=True)
rospy.Subscriber("scan", LaserScan, callback)
if __name__ == '__main__':
while not rospy.is_shutdown():
listener()
rospy.Publisher('talk', Float64, queue_size=5).publish(ranges)
rospy.sleep(0.01)