LaserScan can not go out from callback function

asked 2021-01-24 08:34:05 -0500

UchihaMadara gravatar image

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()
edit retag flag offensive close merge delete

Comments

Is the callback function being called? If not, it is recommended to print in the callback function to check.

miura gravatar image miura  ( 2021-01-25 09:05:46 -0500 )edit