I am trying to return an array that contains a latitude and a longitude from a subscriber that I wrote. What I am trying to do is have some type of global variable and when infoGetter() is called, go to the callback function, run once, set new values from the /novatel/fix topic to my latitude and longitude variables and return them in an array once we are back in the infoGetter function. The array is sent to another program so I made my subscriber into a function. It is only supposed to run once in my other program and return those values. Is it possible to do what I am trying to do? What am I missing? Here's my subscriber function:
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import NavSatFix
#from RetreiveFiles import whatTheHell
latitude = 0
longitude = 0
ra = [0,0]
def callback(data):
rospy.loginfo("Longitude: %f, Latitude %f" % (data.longitude, data.latitude))
global latitude
global longitude
latitude = data.latitude
longitude = data.longitude
#whatTheHell(latitude, longitude)
def infoGetter():
rospy.init_node('infoGetter', anonymous=True)
rospy.Subscriber("/novatel/fix", NavSatFix, callback)
#rospy.spin()
global latitude
global longitude
global ra
pritn ra
ra[0] = latitude
ra[1] = longitude
return ra
"""if __name__ == '__main__':
infoGetter() """
Originally posted by negotiator14 on ROS Answers with karma: 35 on 2015-08-13
Post score: 1