LaserScan can not go out from callback function
I have callback function and it checks distance between obstacle. But I want to do other things after robot stops. I can not kill callback function after 'else' condition. I've tried break,quit,exit,return and even working with threads but I can not solve it. Can someone help me please thanks. Here is the function:
def Moveuntilobstacle():
move = Twist()
move.linear.x=2
move.angular.z= 0.0
def callback(msg):
if msg.ranges[135] > 0.5:
move.linear.x = 2
move.angular.z = 0.0
else:
move.linear.x = 0.0
move.angular.z = 0.0
pub. publish(move)
rospy.init_node('walker1', anonymous= True)
rospy.Subscriber(nodename+' /base_scan', LaserScan, callback)
rospy.Publisher(nodename+'/cmd_vel', Twist, queue size = 10)
rospy.spin()
Is the callback function being called? If not, it is recommended to
print
in the callback function to check.