Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
world,
debug_mode,
criteria_enable=criteria_enable)
self._traffic_light = CarlaDataProvider.get_next_traffic_light(self.ego_vehicles[0], False)
if self._traffic_light is None:
print("No traffic light for the given location of the ego vehicle found")
sys.exit(-1)
self._traffic_light.set_state(carla.TrafficLightState.Red)
self._traffic_light.set_red_time(self.timeout)
# other vehicle's traffic light
traffic_light_other = CarlaDataProvider.get_next_traffic_light(self.other_actors[0], False)
if traffic_light_other is None:
print("No traffic light for the given location of the other vehicle found")
sys.exit(-1)
traffic_light_other.set_state(carla.TrafficLightState.Green)
traffic_light_other.set_green_time(self.timeout)
if self._traffic_light is None:
print("No traffic light for the given location of the ego vehicle found")
sys.exit(-1)
self._traffic_light.set_state(carla.TrafficLightState.Green)
self._traffic_light.set_green_time(self.timeout)
# other vehicle's traffic light
traffic_light_other = CarlaDataProvider.get_next_traffic_light(self.other_actors[0], False)
if traffic_light_other is None:
print("No traffic light for the given location of the other vehicle found")
sys.exit(-1)
traffic_light_other.set_state(carla.TrafficLightState.Green)
traffic_light_other.set_green_time(self.timeout)
def make_surface(tl):
w = 40
surface = pygame.Surface((w, 3 * w), pygame.SRCALPHA)
surface.fill(COLOR_ALUMINIUM_5 if tl != 'h' else COLOR_ORANGE_2)
if tl != 'h':
hw = int(w / 2)
off = COLOR_ALUMINIUM_4
red = COLOR_SCARLET_RED_0
yellow = COLOR_BUTTER_0
green = COLOR_CHAMELEON_0
pygame.draw.circle(surface, red if tl == tls.Red else off, (hw, hw), int(0.4 * w))
pygame.draw.circle(surface, yellow if tl == tls.Yellow else off, (hw, w + hw), int(0.4 * w))
pygame.draw.circle(surface, green if tl == tls.Green else off, (hw, 2 * w + hw), int(0.4 * w))
return pygame.transform.smoothscale(surface, (15, 45) if tl != 'h' else (19, 49))
self._original_surfaces = {
surface.fill(COLOR_ALUMINIUM_5 if tl != 'h' else COLOR_ORANGE_2)
if tl != 'h':
hw = int(w / 2)
off = COLOR_ALUMINIUM_4
red = COLOR_SCARLET_RED_0
yellow = COLOR_BUTTER_0
green = COLOR_CHAMELEON_0
pygame.draw.circle(surface, red if tl == tls.Red else off, (hw, hw), int(0.4 * w))
pygame.draw.circle(surface, yellow if tl == tls.Yellow else off, (hw, w + hw), int(0.4 * w))
pygame.draw.circle(surface, green if tl == tls.Green else off, (hw, 2 * w + hw), int(0.4 * w))
return pygame.transform.smoothscale(surface, (15, 45) if tl != 'h' else (19, 49))
self._original_surfaces = {
'h': make_surface('h'),
tls.Red: make_surface(tls.Red),
tls.Yellow: make_surface(tls.Yellow),
tls.Green: make_surface(tls.Green),
tls.Off: make_surface(tls.Off),
tls.Unknown: make_surface(tls.Unknown)
}
self.surfaces = dict(self._original_surfaces)
def set_traffic_lights_green(world: carla.World):
set_world_asynchronous(world)
for tl in world.get_actors().filter('traffic.*'):
if isinstance(tl, carla.TrafficLight):
tl.set_state(carla.TrafficLightState.Green)
tl.freeze(True)
surface.fill(COLOR_ALUMINIUM_5 if tl != 'h' else COLOR_ORANGE_2)
if tl != 'h':
hw = int(w / 2)
off = COLOR_ALUMINIUM_4
red = COLOR_SCARLET_RED_0
yellow = COLOR_BUTTER_0
green = COLOR_CHAMELEON_0
pygame.draw.circle(surface, red if tl == tls.Red else off, (hw, hw), int(0.4 * w))
pygame.draw.circle(surface, yellow if tl == tls.Yellow else off, (hw, w + hw), int(0.4 * w))
pygame.draw.circle(surface, green if tl == tls.Green else off, (hw, 2 * w + hw), int(0.4 * w))
return pygame.transform.smoothscale(surface, (15, 45) if tl != 'h' else (19, 49))
self._original_surfaces = {
'h': make_surface('h'),
tls.Red: make_surface(tls.Red),
tls.Yellow: make_surface(tls.Yellow),
tls.Green: make_surface(tls.Green),
tls.Off: make_surface(tls.Off),
tls.Unknown: make_surface(tls.Unknown)
}
self.surfaces = dict(self._original_surfaces)
self._other_actor_transform = None
self._blackboard_queue_name = 'SignalizedJunctionLeftTurn/actor_flow_queue'
self._queue = py_trees.blackboard.Blackboard().set(self._blackboard_queue_name, Queue())
self._initialized = True
super(SignalizedJunctionLeftTurn, self).__init__("TurnLeftAtSignalizedJunction",
ego_vehicles,
config,
world,
debug_mode,
criteria_enable=criteria_enable)
self._traffic_light = CarlaDataProvider.get_next_traffic_light(self.ego_vehicles[0], False)
traffic_light_other = CarlaDataProvider.get_next_traffic_light(self.other_actors[0], False)
if self._traffic_light is None or traffic_light_other is None:
raise RuntimeError("No traffic light for the given location found")
self._traffic_light.set_state(carla.TrafficLightState.Green)
self._traffic_light.set_green_time(self.timeout)
# other vehicle's traffic light
traffic_light_other.set_state(carla.TrafficLightState.Green)
traffic_light_other.set_green_time(self.timeout)
def __init__(self, traffic_light_id, state, name="TrafficLightStateSetter"):
"""
Init
"""
super(TrafficLightStateSetter, self).__init__(name)
self._actor = None
actor_list = CarlaDataProvider.get_world().get_actors()
for actor in actor_list:
if actor.id == int(traffic_light_id):
self._actor = actor
break
new_state = carla.TrafficLightState.Unknown
if state.upper() == "GREEN":
new_state = carla.TrafficLightState.Green
elif state.upper() == "RED":
new_state = carla.TrafficLightState.Red
elif state.upper() == "YELLOW":
new_state = carla.TrafficLightState.Yellow
elif state.upper() == "OFF":
new_state = carla.TrafficLightState.Off
self._new_traffic_light_state = new_state
self.logger.debug("%s.__init__()" % (self.__class__.__name__))
def make_surface(tl):
w = 40
surface = pygame.Surface((w, 3 * w), pygame.SRCALPHA)
surface.fill(COLOR_ALUMINIUM_5 if tl != 'h' else COLOR_ORANGE_2)
if tl != 'h':
hw = int(w / 2)
off = COLOR_ALUMINIUM_4
red = COLOR_SCARLET_RED_0
yellow = COLOR_BUTTER_0
green = COLOR_CHAMELEON_0
pygame.draw.circle(surface, red if tl == tls.Red else off, (hw, hw), int(0.4 * w))
pygame.draw.circle(surface, yellow if tl == tls.Yellow else off, (hw, w + hw), int(0.4 * w))
pygame.draw.circle(surface, green if tl == tls.Green else off, (hw, 2 * w + hw), int(0.4 * w))
return pygame.transform.smoothscale(surface, (15, 45) if tl != 'h' else (19, 49))
self._original_surfaces = {