Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elif event.key == K_m:
self._control.manual_gear_shift = not self._control.manual_gear_shift
self._control.gear = world.player.get_control().gear
world.hud.notification('%s Transmission' %
('Manual' if self._control.manual_gear_shift else 'Automatic'))
elif self._control.manual_gear_shift and event.key == K_COMMA:
self._control.gear = max(-1, self._control.gear - 1)
elif self._control.manual_gear_shift and event.key == K_PERIOD:
self._control.gear = self._control.gear + 1
elif event.key == K_p and not pygame.key.get_mods() & KMOD_CTRL:
self._autopilot_enabled = not self._autopilot_enabled
# world.player.set_autopilot(self._autopilot_enabled)
world.hud.notification(
'Autopilot %s' % ('On' if self._autopilot_enabled else 'Off'))
elif event.key == K_l and pygame.key.get_mods() & KMOD_CTRL:
current_lights ^= carla.VehicleLightState.Special1
elif event.key == K_l and pygame.key.get_mods() & KMOD_SHIFT:
current_lights ^= carla.VehicleLightState.HighBeam
elif event.key == K_l:
# Use 'L' key to switch between lights:
# closed -> position -> low beam -> fog
if not self._lights & carla.VehicleLightState.Position:
world.hud.notification("Position lights")
current_lights |= carla.VehicleLightState.Position
else:
world.hud.notification("Low beam lights")
current_lights |= carla.VehicleLightState.LowBeam
if self._lights & carla.VehicleLightState.LowBeam:
world.hud.notification("Fog lights")
current_lights |= carla.VehicleLightState.Fog
if self._lights & carla.VehicleLightState.Fog:
world.hud.notification("Lights off")
world.hud.notification("Low beam lights")
current_lights |= carla.VehicleLightState.LowBeam
if self._lights & carla.VehicleLightState.LowBeam:
world.hud.notification("Fog lights")
current_lights |= carla.VehicleLightState.Fog
if self._lights & carla.VehicleLightState.Fog:
world.hud.notification("Lights off")
current_lights ^= carla.VehicleLightState.Position
current_lights ^= carla.VehicleLightState.LowBeam
current_lights ^= carla.VehicleLightState.Fog
elif event.key == K_i:
current_lights ^= carla.VehicleLightState.Interior
elif event.key == K_z:
current_lights ^= carla.VehicleLightState.LeftBlinker
elif event.key == K_x:
current_lights ^= carla.VehicleLightState.RightBlinker
if not self._autopilot_enabled:
if isinstance(self._control, carla.VehicleControl):
self._parse_vehicle_keys(pygame.key.get_pressed(), clock.get_time())
self._control.reverse = self._control.gear < 0
# Set automatic control-related vehicle lights
if self._control.brake:
current_lights |= carla.VehicleLightState.Brake
else: # Remove the Brake flag
current_lights &= carla.VehicleLightState.All ^ carla.VehicleLightState.Brake
if self._control.reverse:
current_lights |= carla.VehicleLightState.Reverse
else: # Remove the Reverse flag
current_lights &= carla.VehicleLightState.All ^ carla.VehicleLightState.Reverse
def parse_vehicle_lights(info):
"""
Parses a list into a carla.VehicleLightState
Args:
info (list): list corresponding to a row of the recorder
"""
srt_to_vlight = {
"None": carla.VehicleLightState.NONE,
"Position": carla.VehicleLightState.Position,
"LowBeam": carla.VehicleLightState.LowBeam,
"HighBeam": carla.VehicleLightState.HighBeam,
"Brake": carla.VehicleLightState.Brake,
"RightBlinker": carla.VehicleLightState.RightBlinker,
"LeftBlinker": carla.VehicleLightState.LeftBlinker,
"Reverse": carla.VehicleLightState.Reverse,
"Fog": carla.VehicleLightState.Fog,
"Interior": carla.VehicleLightState.Interior,
"Special1": carla.VehicleLightState.Special1,
"Special2": carla.VehicleLightState.Special2,
}
lights = []
for i in range(2, len(info)):
lights.append(srt_to_vlight[info[i]])
return lights
elif event.key == K_i:
current_lights ^= carla.VehicleLightState.Interior
elif event.key == K_z:
current_lights ^= carla.VehicleLightState.LeftBlinker
elif event.key == K_x:
current_lights ^= carla.VehicleLightState.RightBlinker
if not self._autopilot_enabled:
if isinstance(self._control, carla.VehicleControl):
self._parse_vehicle_keys(pygame.key.get_pressed(), clock.get_time())
self._control.reverse = self._control.gear < 0
# Set automatic control-related vehicle lights
if self._control.brake:
current_lights |= carla.VehicleLightState.Brake
else: # Remove the Brake flag
current_lights &= carla.VehicleLightState.All ^ carla.VehicleLightState.Brake
if self._control.reverse:
current_lights |= carla.VehicleLightState.Reverse
else: # Remove the Reverse flag
current_lights &= carla.VehicleLightState.All ^ carla.VehicleLightState.Reverse
if current_lights != self._lights: # Change the light state only if necessary
self._lights = current_lights
world.player.set_light_state(carla.VehicleLightState(self._lights))
elif isinstance(self._control, carla.WalkerControl):
self._parse_walker_keys(pygame.key.get_pressed(), clock.get_time(), world)
world.player.apply_control(self._control)
Parses a list into a carla.VehicleLightState
Args:
info (list): list corresponding to a row of the recorder
"""
srt_to_vlight = {
"None": carla.VehicleLightState.NONE,
"Position": carla.VehicleLightState.Position,
"LowBeam": carla.VehicleLightState.LowBeam,
"HighBeam": carla.VehicleLightState.HighBeam,
"Brake": carla.VehicleLightState.Brake,
"RightBlinker": carla.VehicleLightState.RightBlinker,
"LeftBlinker": carla.VehicleLightState.LeftBlinker,
"Reverse": carla.VehicleLightState.Reverse,
"Fog": carla.VehicleLightState.Fog,
"Interior": carla.VehicleLightState.Interior,
"Special1": carla.VehicleLightState.Special1,
"Special2": carla.VehicleLightState.Special2,
}
lights = []
for i in range(2, len(info)):
lights.append(srt_to_vlight[info[i]])
return lights
"""
Parses a list into a carla.VehicleLightState
Args:
info (list): list corresponding to a row of the recorder
"""
srt_to_vlight = {
"None": carla.VehicleLightState.NONE,
"Position": carla.VehicleLightState.Position,
"LowBeam": carla.VehicleLightState.LowBeam,
"HighBeam": carla.VehicleLightState.HighBeam,
"Brake": carla.VehicleLightState.Brake,
"RightBlinker": carla.VehicleLightState.RightBlinker,
"LeftBlinker": carla.VehicleLightState.LeftBlinker,
"Reverse": carla.VehicleLightState.Reverse,
"Fog": carla.VehicleLightState.Fog,
"Interior": carla.VehicleLightState.Interior,
"Special1": carla.VehicleLightState.Special1,
"Special2": carla.VehicleLightState.Special2,
}
lights = []
for i in range(2, len(info)):
lights.append(srt_to_vlight[info[i]])
return lights
def parse_vehicle_lights(info):
"""
Parses a list into a carla.VehicleLightState
Args:
info (list): list corresponding to a row of the recorder
"""
srt_to_vlight = {
"None": carla.VehicleLightState.NONE,
"Position": carla.VehicleLightState.Position,
"LowBeam": carla.VehicleLightState.LowBeam,
"HighBeam": carla.VehicleLightState.HighBeam,
"Brake": carla.VehicleLightState.Brake,
"RightBlinker": carla.VehicleLightState.RightBlinker,
"LeftBlinker": carla.VehicleLightState.LeftBlinker,
"Reverse": carla.VehicleLightState.Reverse,
"Fog": carla.VehicleLightState.Fog,
"Interior": carla.VehicleLightState.Interior,
"Special1": carla.VehicleLightState.Special1,
"Special2": carla.VehicleLightState.Special2,
}
lights = []
for i in range(2, len(info)):
lights.append(srt_to_vlight[info[i]])
def parse_vehicle_lights(info):
"""
Parses a list into a carla.VehicleLightState
Args:
info (list): list corresponding to a row of the recorder
"""
srt_to_vlight = {
"None": carla.VehicleLightState.NONE,
"Position": carla.VehicleLightState.Position,
"LowBeam": carla.VehicleLightState.LowBeam,
"HighBeam": carla.VehicleLightState.HighBeam,
"Brake": carla.VehicleLightState.Brake,
"RightBlinker": carla.VehicleLightState.RightBlinker,
"LeftBlinker": carla.VehicleLightState.LeftBlinker,
"Reverse": carla.VehicleLightState.Reverse,
"Fog": carla.VehicleLightState.Fog,
"Interior": carla.VehicleLightState.Interior,
"Special1": carla.VehicleLightState.Special1,
"Special2": carla.VehicleLightState.Special2,
}
lights = []
for i in range(2, len(info)):
lights.append(srt_to_vlight[info[i]])
return lights
Args:
info (list): list corresponding to a row of the recorder
"""
srt_to_vlight = {
"None": carla.VehicleLightState.NONE,
"Position": carla.VehicleLightState.Position,
"LowBeam": carla.VehicleLightState.LowBeam,
"HighBeam": carla.VehicleLightState.HighBeam,
"Brake": carla.VehicleLightState.Brake,
"RightBlinker": carla.VehicleLightState.RightBlinker,
"LeftBlinker": carla.VehicleLightState.LeftBlinker,
"Reverse": carla.VehicleLightState.Reverse,
"Fog": carla.VehicleLightState.Fog,
"Interior": carla.VehicleLightState.Interior,
"Special1": carla.VehicleLightState.Special1,
"Special2": carla.VehicleLightState.Special2,
}
lights = []
for i in range(2, len(info)):
lights.append(srt_to_vlight[info[i]])
return lights
def __init__(self, world, start_in_autopilot):
self._autopilot_enabled = start_in_autopilot
if isinstance(world.player, carla.Vehicle):
self._control = carla.VehicleControl()
self._lights = carla.VehicleLightState.NONE
# world.player.set_autopilot(self._autopilot_enabled)
world.player.set_light_state(self._lights)
elif isinstance(world.player, carla.Walker):
self._control = carla.WalkerControl()
self._autopilot_enabled = False
self._rotation = world.player.get_transform().rotation
else:
raise NotImplementedError("Actor type not supported")
self._steer_cache = 0.0
world.hud.notification("Press 'H' or '?' for help.", seconds=4.0)