#!/usr/bin/env python # license removed for brevity # # Example program that # wanders avoid obstacles # T3 version # dml 2020 # # import math import random import rospy # needed for ROS from geometry_msgs.msg import Twist # ROS Twist message from sensor_msgs.msg import LaserScan # ROS laser msg motionTopic='/cmd_vel' # turtlebot vel topic laserTopic = '/scan' # laser scan topic #global variable to hold the closest front distance gBumpLeft,gBumpRight = False,False # virtual bumper set if laser shows obstacle close # callback for the laser range data # calculates only if something too close # def callback_laser(msg): '''Call back function for laser range data''' global gBumpLeft, gBumpRight tooClose = 0.5 #meters center = 0 # laser reading directly in front of robot width = 30 # bumper zone cone half angle gBumpLeft,gBumpRight=False,False for i in range(center-width,center+width): if not math.isnan( msg.ranges[i] ) and not math.isinf( msg.ranges[i] ): if msg.ranges[i]