ros/src/tl_detector/tl_detector.py
def process_traffic_lights(self):
        """Finds closest visible traffic light, if one exists, and determines its
            location and color

        Returns:
            int: index of waypoint closes to the upcoming stop line for a traffic light (-1 if none exists)
            int: ID of traffic light color (specified in styx_msgs/TrafficLight)

        """

        light = None

        if hasattr(self, 'waypoints') and hasattr(self, 'pose'):

            min_dist = float('inf')

            car_wp = self.get_closest_waypoint(self.pose.pose)

            light_positions = self.light_positions

            i = 0

            for light_pos in light_positions:

                light_wp, tl_candid, tl_dist = self.calclulate_distance_to_traffic_light(car_wp, light_pos)

                if (tl_dist < min_dist) \
                        and (car_wp % len(self.waypoints.waypoints)) < (light_wp % len(self.waypoints.waypoints)) \
                        and (tl_dist < OBSERV_DIST) :
                    closest_light_wp = light_wp
                    min_dist = tl_dist
                    light = tl_candid

                i += 1

            state = TrafficLight.UNKNOWN
            light_wp = -1

            if light:
                state = self.get_light_state()
                light_wp = closest_light_wp

        else:
            light_wp = -1
            state = TrafficLight.RED

        return light_wp, state
Finds closest visible traffic light, if one exists, and determines its
            location and color

        Returns:
            int: index of waypoint closes to the upcoming stop line for a traffic light (-1 if none exists)
            int: ID of traffic light color (specified in styx_msgs/TrafficLight)

        
Finds closest visible traffic light, if one exists, and determines its
location and color
Finds closest visible traffic light if one exists and determines its location and color
def process_traffic_lights(self):
        light = None
        if hasattr(self, 'waypoints') and hasattr(self, 'pose'):
            min_dist = float('inf')
            car_wp = self.get_closest_waypoint(self.pose.pose)
            light_positions = self.light_positions
            i = 0
            for light_pos in light_positions:
                light_wp, tl_candid, tl_dist = self.calclulate_distance_to_traffic_light(car_wp, light_pos)
                if (tl_dist < min_dist) \
                        and (car_wp % len(self.waypoints.waypoints)) < (light_wp % len(self.waypoints.waypoints)) \
                        and (tl_dist < OBSERV_DIST) :
                    closest_light_wp = light_wp
                    min_dist = tl_dist
                    light = tl_candid
                i += 1
            state = TrafficLight.UNKNOWN
            light_wp = -1
            if light:
                state = self.get_light_state()
                light_wp = closest_light_wp
        else:
            light_wp = -1
            state = TrafficLight.RED
        return light_wp, state
def process_traffic_lights ( self ) : light = None if hasattr ( self , 'waypoints' ) and hasattr ( self , 'pose' ) : min_dist = float ( 'inf' ) car_wp = self . get_closest_waypoint ( self . pose . pose ) light_positions = self . light_positions i = 0 for light_pos in light_positions : light_wp , tl_candid , tl_dist = self . calclulate_distance_to_traffic_light ( car_wp , light_pos ) if ( tl_dist < min_dist ) and ( car_wp % len ( self . waypoints . waypoints ) ) < ( light_wp % len ( self . waypoints . waypoints ) ) and ( tl_dist < OBSERV_DIST ) : closest_light_wp = light_wp min_dist = tl_dist light = tl_candid i += 1 state = TrafficLight . UNKNOWN light_wp = - 1 if light : state = self . get_light_state ( ) light_wp = closest_light_wp else : light_wp = - 1 state = TrafficLight . RED return light_wp , state
Finds closest visible traffic light, if one exists, and determines its
location and color
Finds closest visible traffic light if one exists and determines its location and color
"""Finds closest visible traffic light, if one exists, and determines its
            location and color

        Returns:
            int: index of waypoint closes to the upcoming stop line for a traffic light (-1 if none exists)
            int: ID of traffic light color (specified in styx_msgs/TrafficLight)

        """
index of waypoint closes to the upcoming stop line for a traffic light (-1 if none exists)
int: ID of traffic light color (specified in styx_msgs/TrafficLight)
index of waypoint closes to the upcoming stop line for a traffic light ( - 1 if none exists ) int : ID of traffic light color ( specified in styx_msgs / TrafficLight )
int
self