Exemple #1
0
 def _must_obey_european_traffic_light(self, ego_transform: Transform,
                                       tl_locations,
                                       tl_max_dist_thresh: float) -> bool:
     ego_waypoint = self._get_waypoint(ego_transform.location)
     # We're not on a road, or we're already in the intersection. Carry on.
     if ego_waypoint is None or self.__is_intersection(ego_waypoint):
         return (False, None)
     # Iterate through traffic lights.
     for tl_loc in tl_locations:
         tl_waypoint = self._get_waypoint(tl_loc)
         if (tl_waypoint.road_id != ego_waypoint.road_id
                 or tl_waypoint.lane_id != ego_waypoint.lane_id):
             continue
         if ego_transform.is_within_distance_ahead(tl_loc,
                                                   tl_max_dist_thresh):
             return (True, tl_loc)
     return (False, None)
Exemple #2
0
    def _must_obey_american_traffic_light(self, ego_transform: Transform,
                                          tl_locations,
                                          tl_max_dist_thresh: float) -> bool:
        ego_waypoint = self._get_waypoint(ego_transform.location)
        # We're not on a road, or we're already in the intersection. Carry on.
        if ego_waypoint is None or self.__is_intersection(ego_waypoint):
            return (False, None)

        min_angle = 25.0
        selected_tl_loc = None
        for tl_loc in tl_locations:
            if ego_transform.is_within_distance_ahead(tl_loc,
                                                      tl_max_dist_thresh):
                angle, distance = ego_transform.get_angle_and_magnitude(tl_loc)
                if distance < 60.0 and angle < min(25.0, min_angle):
                    min_angle = angle
                    selected_tl_loc = tl_loc
        if selected_tl_loc is not None:
            return (True, selected_tl_loc)
        else:
            return (False, None)