MCPcopy Create free account
hub / github.com/OpenDriveLab/DriveAdapter / _is_light_red

Method _is_light_red

agents/navigation/agent.py:73–108  ·  view source on GitHub ↗

Method to check if there is a red light affecting us. This version of the method is compatible with both European and US style traffic lights. :param lights_list: list containing TrafficLight objects :return: a tuple given by (bool_flag, traffic_light), where

(self, lights_list)

Source from the content-addressed store, hash-verified

71 return control
72
73 def _is_light_red(self, lights_list):
74 """
75 Method to check if there is a red light affecting us. This version of
76 the method is compatible with both European and US style traffic lights.
77
78 :param lights_list: list containing TrafficLight objects
79 :return: a tuple given by (bool_flag, traffic_light), where
80 - bool_flag is True if there is a traffic light in RED
81 affecting us and False otherwise
82 - traffic_light is the object itself or None if there is no
83 red traffic light affecting us
84 """
85 ego_vehicle_location = self._vehicle.get_location()
86 ego_vehicle_waypoint = self._map.get_waypoint(ego_vehicle_location)
87
88 for traffic_light in lights_list:
89 object_location = self._get_trafficlight_trigger_location(traffic_light)
90 object_waypoint = self._map.get_waypoint(object_location)
91
92 if object_waypoint.road_id != ego_vehicle_waypoint.road_id:
93 continue
94
95 ve_dir = ego_vehicle_waypoint.transform.get_forward_vector()
96 wp_dir = object_waypoint.transform.get_forward_vector()
97 dot_ve_wp = ve_dir.x * wp_dir.x + ve_dir.y * wp_dir.y + ve_dir.z * wp_dir.z
98
99 if dot_ve_wp < 0:
100 continue
101
102 if is_within_distance_ahead(object_waypoint.transform,
103 self._vehicle.get_transform(),
104 self._proximity_tlight_threshold):
105 if traffic_light.state == carla.TrafficLightState.Red:
106 return (True, traffic_light)
107
108 return (False, None)
109
110 def _get_trafficlight_trigger_location(self, traffic_light): # pylint: disable=no-self-use
111 """

Callers 2

run_stepMethod · 0.45
run_stepMethod · 0.45

Calls 5

is_within_distance_aheadFunction · 0.90
get_locationMethod · 0.80
get_waypointMethod · 0.80
get_transformMethod · 0.80

Tested by

no test coverage detected