Python Script global variable
Hello,
I am facing an error with this script :
class testAvoidance:
def __init__(self):
self.sub = rospy.Subscriber('/RosAria/lms1xx_1_laserscan', LaserScan, self.laser_callback)
rospy.loginfo('LaserScan Subscribed')
def laser_callback(self, scan):
global laser_array
laser_array = scan.ranges
def update(self):
global laser_array
laser_array_we = laser_array[80:460]
...
And I get the following error :
File "/home/seekurjr/catkin_ws/src/perso_package/src/obstacle_avoidance.py", line 112, in <module>
node.update()
File "/home/seekurjr/catkin_ws/src/perso_package/src/obstacle_avoidance.py", line 32, in update
laser_array_we = laser_array[80:460]
NameError: global name 'laser_array' is not defined
I don't understand why 'laserarray' is not considered as global variable as defined in lasercallback. If someone could help me, It would be nice
Regards,
Matthieu
Asked by mattMGN on 2017-03-30 11:33:08 UTC
Comments
http://answers.ros.org/question/258269/global-variable-python/
Asked by jarvisschultz on 2017-03-30 14:13:54 UTC