NameError: global name 'NAME' is not defined <SOLVED>
Hi people! :) i am listening GPS's data and i want use them in another part of my code, for do Path Planing, but when I try to use them, it give me back this error
I defined variable global (global Lon, Lat) in many places like inside of def listener(), def backlatitud(): and def backlongitud() and it give back the same error.
Traceback (most recent call last):
File "/home/pi/ros_catkin_ws/src/ceres_pkg/src/Controlador.py", line 25, in <module>
listener()
File "/home/pi/ros_catkin_ws/src/ceres_pkg/src/Controlador.py", line 20, in listener
print Lat
NameError: global name 'Lat' is not defined
This is my code:
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
global Lon, Lat
def backlatitud(data1):
Lat = float(data1.data)
#rospy.loginfo('Latitud %s', data1.data)
return;
def backlongitud(data):
Lon = float(data.data)
#rospy.loginfo('longitud %s', Lon)
return;
def listener():
rospy.init_node('listener', anonymous=True)
rospy.Subscriber("/latitud", String, backlatitud)
rospy.Subscriber("/longitud", String, backlongitud)
print Lat
print Lon
rospy.spin()
if __name__ == '__main__':
listener()
Please format code & console copy/pastes using the Preformatted Text button (the one with
101010
on it) in the future. That makes things much easier to read. Thanks.Also: how is this related to NameError: global name 'NAME' is not defined?