ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

You are subscribing to sensor_msgs/LaserScan data. Below is the message definition of sensor_msgs/LaserScan:

# Single scan from a planar laser range-finder
#
# If you have another ranging device with different behavior (e.g. a sonar
# array), please find or create a different message, since applications
# will make fairly laser-specific assumptions about this data

Header header            # timestamp in the header is the acquisition time of 
                         # the first ray in the scan.
                         #
                         # in frame frame_id, angles are measured around 
                         # the positive Z axis (counterclockwise, if Z is up)
                         # with zero angle being forward along the x axis

float32 angle_min        # start angle of the scan [rad]
float32 angle_max        # end angle of the scan [rad]
float32 angle_increment  # angular distance between measurements [rad]

float32 time_increment   # time between measurements [seconds] - if your scanner
                         # is moving, this will be used in interpolating position
                         # of 3d points
float32 scan_time        # time between scans [seconds]

float32 range_min        # minimum range value [m]
float32 range_max        # maximum range value [m]

float32[] ranges         # range data [m] (Note: values < range_min or > range_max should be discarded)
float32[] intensities    # intensity data [device-specific units].  If your
                         # device does not provide intensities, please leave
                         # the array empty.

Please note that the ranges is a list. Now, please see the following snippet from your code:

    self.l_04=round(self.scan.ranges[-1],3)
    self.l_05=round(self.scan.ranges[-2],3)

    self.l_11=round(self.scan.ranges[90],3)
    self.l_12=round(self.scan.ranges[89],3)
    self.l_13=round(self.scan.ranges[91],3)

    self.l_21=round(self.scan.ranges[-90],3)
    self.l_22=round(self.scan.ranges[-89],3)
    self.l_23=round(self.scan.ranges[-91],3)

    self.m_1=round(self.scan.ranges[179-self.heading],3)
    **self.m_2=round(self.scan.ranges[359-self.heading],3)**

Please pay attention to the index of the list. The index is mentioned negatively in some places. This is why you are getting "index out of range error".

On a side note, I recommend learning/understanding the basics of Python before getting started with ROS.