ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
This really isn't a ROS question at all, this is a Python question. You'd have better luck looking on generic programming support sites (like stack overflow). The issue is that the first time the testAvoidance.update
method gets called, the variable has never actually been defined. The only place in the code you posted that the variable gets defined is in the testAvoidance.laser_callback
method, but almost certainly, the update
method will get called first. You could easily solve this by adding a definition to main
:
rospy.init_node('obstacle_avoidance_node')
global laser_array
laser_array = [0]*460
node = testAvoidance()
Other notes:
ranges
in it? This is why I defined the variable to be 460 zeros in the above snippet.update
function as fast as you can. Is this really necessary?while(1):
line with while not rospy.is_shutdown():
to help the node shutdown more reliably.