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)
            float: predicted score of the traffic light state. Higher score means higher prediction confidence.
        """
        closest_light = None
        light_wp_idx = None

        # List of positions that correspond to the line to stop in front of for a given intersection
        stop_line_positions = self.config['stop_line_positions']
        if(self.pose):
            car_wp_idx = self.get_closest_waypoint(self.pose.pose.position.x, self.pose.pose.position.y)
            rospy.loginfo("Car waypoint idx: " + str(car_wp_idx))
            # find the closest visible traffic light (if one exists)
            diff = len(self.waypoints.waypoints)
            for i, light in enumerate(self.lights):
                #get stopline waypoint index
                line = stop_line_positions[i]
                temp_wp_idx = self.get_closest_waypoint(line[0], line[1])
                d = temp_wp_idx - car_wp_idx
                if d >= 0 and d < diff:
                    diff = d
                    closest_light = light
                    light_wp_idx = temp_wp_idx

        do_detection = self.is_within_detection_distance(self.waypoints.waypoints, car_wp_idx, light_wp_idx)

        if closest_light and do_detection:
            state, score = self.get_light_state(closest_light)
            return light_wp_idx, state, score
        else:
            if closest_light:
                rospy.loginfo("Did not run detector. Next light is too far away.")
            return -1, TrafficLight.UNKNOWN, 0
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)
            float: predicted score of the traffic light state. Higher score means higher prediction confidence.
        
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):
        closest_light = None
        light_wp_idx = None
        stop_line_positions = self.config['stop_line_positions']
        if(self.pose):
            car_wp_idx = self.get_closest_waypoint(self.pose.pose.position.x, self.pose.pose.position.y)
            rospy.loginfo("Car waypoint idx: " + str(car_wp_idx))
            diff = len(self.waypoints.waypoints)
            for i, light in enumerate(self.lights):
                line = stop_line_positions[i]
                temp_wp_idx = self.get_closest_waypoint(line[0], line[1])
                d = temp_wp_idx - car_wp_idx
                if d >= 0 and d < diff:
                    diff = d
                    closest_light = light
                    light_wp_idx = temp_wp_idx
        do_detection = self.is_within_detection_distance(self.waypoints.waypoints, car_wp_idx, light_wp_idx)
        if closest_light and do_detection:
            state, score = self.get_light_state(closest_light)
            return light_wp_idx, state, score
        else:
            if closest_light:
                rospy.loginfo("Did not run detector. Next light is too far away.")
            return -1, TrafficLight.UNKNOWN, 0
def process_traffic_lights ( self ) : closest_light = None light_wp_idx = None stop_line_positions = self . config [ 'stop_line_positions' ] if ( self . pose ) : car_wp_idx = self . get_closest_waypoint ( self . pose . pose . position . x , self . pose . pose . position . y ) rospy . loginfo ( "Car waypoint idx: " + str ( car_wp_idx ) ) diff = len ( self . waypoints . waypoints ) for i , light in enumerate ( self . lights ) : line = stop_line_positions [ i ] temp_wp_idx = self . get_closest_waypoint ( line [ 0 ] , line [ 1 ] ) d = temp_wp_idx - car_wp_idx if d >= 0 and d < diff : diff = d closest_light = light light_wp_idx = temp_wp_idx do_detection = self . is_within_detection_distance ( self . waypoints . waypoints , car_wp_idx , light_wp_idx ) if closest_light and do_detection : state , score = self . get_light_state ( closest_light ) return light_wp_idx , state , score else : if closest_light : rospy . loginfo ( "Did not run detector. Next light is too far away." ) return - 1 , TrafficLight . UNKNOWN , 0
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)
            float: predicted score of the traffic light state. Higher score means higher prediction confidence.
        """ # List of positions that correspond to the line to stop in front of for a given intersection # find the closest visible traffic light (if one exists) #get stopline waypoint index
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)
float: predicted score of the traffic light state. Higher score means higher prediction confidence.
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 ) float : predicted score of the traffic light state . Higher score means higher prediction confidence .
int
self