#!/usr/bin/env python
'''
last editted on 16/09/2019
by Phillip Luu
'''
import rospy
from sensor_msgs.msg import LaserScan
import math

rospy.init_node('scan_read')

ns_pub = rospy.Publisher("/new_scan", LaserScan, queue_size = 1)

def read_cb(data):
    # reset feature variables
    angle = []
    rmin = 0.025
    rmax = 3
    ang_range = 1.75

    # new data that is shortened
    newdata = data

    # ensure laser variables are up to date
    ang_min = data.angle_min
    ang_max = data.angle_max
    a_inc = data.angle_increment

    new_scan = list(data.ranges)
    # reject invalid data and initialise new data to be processed
    for d, data_l in enumerate(data.ranges):
        angle.append(ang_min + d*a_inc)
        if data_l < rmin or data_l > rmax or math.isnan(data_l) or abs(angle[d]) > ang_range:
            new_scan[d] = float('nan')

    #print(len(angle))
    #print('angle = ' + str(angle))
    newdata.ranges = list(new_scan)
    ns_pub.publish(newdata)

def listener():
    rospy.Subscriber("/scan", LaserScan, read_cb, queue_size = 1)

    #spin forever
    rospy.spin()

listener()

4a2f58e2248fcaa0acf4fb05351cf1ea8a90b77a
<mask token>


def read_cb(data):
    angle = []
    rmin = 0.025
    rmax = 3
    ang_range = 1.75
    newdata = data
    ang_min = data.angle_min
    ang_max = data.angle_max
    a_inc = data.angle_increment
    new_scan = list(data.ranges)
    for d, data_l in enumerate(data.ranges):
        angle.append(ang_min + d * a_inc)
        if data_l < rmin or data_l > rmax or math.isnan(data_l) or abs(angle[d]
            ) > ang_range:
            new_scan[d] = float('nan')
    newdata.ranges = list(new_scan)
    ns_pub.publish(newdata)


def listener():
    rospy.Subscriber('/scan', LaserScan, read_cb, queue_size=1)
    rospy.spin()


<mask token>

<mask token>
rospy.init_node('scan_read')
<mask token>


def read_cb(data):
    angle = []
    rmin = 0.025
    rmax = 3
    ang_range = 1.75
    newdata = data
    ang_min = data.angle_min
    ang_max = data.angle_max
    a_inc = data.angle_increment
    new_scan = list(data.ranges)
    for d, data_l in enumerate(data.ranges):
        angle.append(ang_min + d * a_inc)
        if data_l < rmin or data_l > rmax or math.isnan(data_l) or abs(angle[d]
            ) > ang_range:
            new_scan[d] = float('nan')
    newdata.ranges = list(new_scan)
    ns_pub.publish(newdata)


def listener():
    rospy.Subscriber('/scan', LaserScan, read_cb, queue_size=1)
    rospy.spin()


listener()

<mask token>
rospy.init_node('scan_read')
ns_pub = rospy.Publisher('/new_scan', LaserScan, queue_size=1)


def read_cb(data):
    angle = []
    rmin = 0.025
    rmax = 3
    ang_range = 1.75
    newdata = data
    ang_min = data.angle_min
    ang_max = data.angle_max
    a_inc = data.angle_increment
    new_scan = list(data.ranges)
    for d, data_l in enumerate(data.ranges):
        angle.append(ang_min + d * a_inc)
        if data_l < rmin or data_l > rmax or math.isnan(data_l) or abs(angle[d]
            ) > ang_range:
            new_scan[d] = float('nan')
    newdata.ranges = list(new_scan)
    ns_pub.publish(newdata)


def listener():
    rospy.Subscriber('/scan', LaserScan, read_cb, queue_size=1)
    rospy.spin()


listener()

<mask token>
import rospy
from sensor_msgs.msg import LaserScan
import math
rospy.init_node('scan_read')
ns_pub = rospy.Publisher('/new_scan', LaserScan, queue_size=1)


def read_cb(data):
    angle = []
    rmin = 0.025
    rmax = 3
    ang_range = 1.75
    newdata = data
    ang_min = data.angle_min
    ang_max = data.angle_max
    a_inc = data.angle_increment
    new_scan = list(data.ranges)
    for d, data_l in enumerate(data.ranges):
        angle.append(ang_min + d * a_inc)
        if data_l < rmin or data_l > rmax or math.isnan(data_l) or abs(angle[d]
            ) > ang_range:
            new_scan[d] = float('nan')
    newdata.ranges = list(new_scan)
    ns_pub.publish(newdata)


def listener():
    rospy.Subscriber('/scan', LaserScan, read_cb, queue_size=1)
    rospy.spin()


listener()

#!/usr/bin/env python
'''
last editted on 16/09/2019
by Phillip Luu
'''
import rospy
from sensor_msgs.msg import LaserScan
import math

rospy.init_node('scan_read')

ns_pub = rospy.Publisher("/new_scan", LaserScan, queue_size = 1)

def read_cb(data):
    # reset feature variables
    angle = []
    rmin = 0.025
    rmax = 3
    ang_range = 1.75

    # new data that is shortened
    newdata = data

    # ensure laser variables are up to date
    ang_min = data.angle_min
    ang_max = data.angle_max
    a_inc = data.angle_increment

    new_scan = list(data.ranges)
    # reject invalid data and initialise new data to be processed
    for d, data_l in enumerate(data.ranges):
        angle.append(ang_min + d*a_inc)
        if data_l < rmin or data_l > rmax or math.isnan(data_l) or abs(angle[d]) > ang_range:
            new_scan[d] = float('nan')

    #print(len(angle))
    #print('angle = ' + str(angle))
    newdata.ranges = list(new_scan)
    ns_pub.publish(newdata)

def listener():
    rospy.Subscriber("/scan", LaserScan, read_cb, queue_size = 1)

    #spin forever
    rospy.spin()

listener()
