classes.ui package
This package implements tools to allow the user to interact with the simulation. This includes cameras, keyboard inputs, and the HUD.
Most features are only available from the pygame when using LaunchConfig.pygame.
- classes.ui.spectator_follow_actor(actor: carla.Actor)[source]
Continuously follow the ego vehicle with the spectator view.
Attention
Needs to be run in a separate thread.
Does not allow for thread.join() to stop the thread, before calling
stop().
- Parameters:
actor (carla.Actor)
- classes.ui.stop()
Stop following the actor.
See also
Submodules
classes.ui.camera_manager module
- classes.ui.camera_manager.CameraBlueprints: Final = {'Camera Depth (Gray Scale)': ('sensor.camera.depth', carla.ColorConverter.Depth, 'Camera Depth (Gray Scale)', None), 'Camera Depth (Logarithmic Gray Scale)': ('sensor.camera.depth', carla.ColorConverter.LogarithmicDepth, 'Camera Depth (Logarithmic Gray Scale)', None), 'Camera Depth (Raw)': ('sensor.camera.depth', carla.ColorConverter.Raw, 'Camera Depth (Raw)', None), 'Camera RGB': ('sensor.camera.rgb', carla.ColorConverter.Raw, 'Camera RGB', None), 'Camera Semantic Segmentation (CityScapes Palette)': ('sensor.camera.semantic_segmentation', carla.ColorConverter.CityScapesPalette, 'Camera Semantic Segmentation (CityScapes Palette)', None), 'Camera Semantic Segmentation (Raw)': ('sensor.camera.semantic_segmentation', carla.ColorConverter.Raw, 'Camera Semantic Segmentation (Raw)', None), 'Lidar (Ray-Cast)': ('sensor.lidar.ray_cast', carla.ColorConverter.Raw, 'Lidar (Ray-Cast)', None)}
Camera blueprints used by the CARLA examples.
Todo
Should be replaced by
CameraConfig.camera_blueprints
- classes.ui.camera_manager.CameraBlueprintsSimple: List[CameraBlueprint] = [('sensor.camera.rgb', carla.ColorConverter.Raw, 'Camera RGB', None)]
Just a single RGB camera. Default for
CameraManager.sensors()
- class classes.ui.camera_manager.CameraManager(parent_actor: carla.Actor, hud: HUD, args: LaunchConfig, sensors: List[CameraBlueprint] | None = CameraBlueprintsSimple)[source]
Bases:
CanBeDummy,CustomSensorInterfaceClass for camera management
- Parameters:
parent_actor (carla.Actor)
hud (HUD)
args (LaunchConfig)
sensors (List[CameraBlueprint] | None)
- __init__(parent_actor: carla.Actor, hud: HUD, args: LaunchConfig, sensors: List[CameraBlueprint] | None = CameraBlueprintsSimple)[source]
Constructor method.
set_sensor()should be called after init to setsensorandindexto a valid value.- Parameters:
parent_actor (carla.Actor) – The actor to which the camera is attached.
sensors (List[CameraBlueprint] | None) – The sensors for the user interface to be used with the
HUD. Defaults to one RGB camera.hud (HUD)
args (LaunchConfig)
- sensor: carla.Sensor | None
- set_sensor(index: int | None, notify=True, force_respawn=False) None[source]
Set the sensor that should be used for the camera output
- Parameters:
index (int | None)
- Return type:
None
- render(display: pygame.surface.Surface) None[source]
Renders method the current camera image
- Parameters:
display (pygame.surface.Surface)
- Return type:
None
- classmethod is_dummy(obj: Any) TypeGuard[MockDummy]
TypeGuardcheck if a variable is a duck-typed dummy object.Objects might be dummy objects that have no function if
LaunchConfig.pygameis set toFalse.
- classmethod follow_actor(actor: carla.Actor | None = None, updater=spectator_follow_actor) None[source]
Follows the actor with the spectator view.
- Parameters:
actor (carla.Actor | None) – The actor to follow. Defaults to the parent_actor.
updater – The function to update the camera view. Defaults to
camera_follow_actor().
- Return type:
None
classes.ui.hud module
Example of automatic vehicle control from client side
Based on original CARLA example by German Ros
- classes.ui.hud.get_actor_display_name(actor: carla.Actor, truncate: int = 250)[source]
Method to get actor display name
- Parameters:
actor (carla.Actor)
truncate (int)
- class classes.ui.hud.HUD(width: int, height: int, world: carla.World, help_text: str | None = RSSKeyboardControl.__doc__)[source]
Bases:
CanBeDummyClass to display text and other information on the
pygamescreen.If
LaunchConfig.pygameis set to False the HUD is not available.- Parameters:
width (int)
height (int)
world (carla.World)
help_text (str | None)
- __init__(width: int, height: int, world: carla.World, help_text: str | None = RSSKeyboardControl.__doc__)[source]
Constructor method
- Parameters:
width (int)
height (int)
world (carla.World)
help_text (str | None)
- on_world_tick(timestamp: carla.WorldSnapshot)[source]
Callback to get information from the world at every tick
- Parameters:
timestamp (carla.WorldSnapshot)
- tick(world: WorldModel, clock: pygame.time.Clock, obstacles: Iterable[carla.Actor] | None = None)[source]
HUD method for every tick
- Parameters:
obstacles (Iterable[carla.Actor] | None) – If obstacles is passed these actors will be displayed on the HUD,
displayed. (if not the closest vehicles will be)
world (WorldModel)
clock (pygame.time.Clock)
- render(display: pygame.Surface)[source]
Render for HUD class
- Parameters:
display (pygame.Surface)
- classmethod is_dummy(obj: Any) TypeGuard[MockDummy]
TypeGuardcheck if a variable is a duck-typed dummy object.Objects might be dummy objects that have no function if
LaunchConfig.pygameis set toFalse.
classes.ui.keyboard_controls module
- class classes.ui.keyboard_controls.KeyboardControl(world_model: WorldModel, *, show_help_notice=True, clock: pygame.time.Clock | None = None)[source]
Bases:
objectPrimitive base for keyboard control classes.
H/? : toggle help
- Parameters:
world_model (WorldModel)
clock (pygame.time.Clock | None)
- __init__(world_model: WorldModel, *, show_help_notice=True, clock: pygame.time.Clock | None = None)[source]
- Parameters:
world_model (WorldModel) – WorldModel
show_help_notice – bool Show a notice about the help keys.
clock (pygame.time.Clock | None) – To track the game time.
- class classes.ui.keyboard_controls.PassiveKeyboardControl(world_model: WorldModel, *, show_help_notice=True, clock: pygame.time.Clock | None = None)[source]
Bases:
KeyboardControlDoes not allow to control the vehicle. Only allows to quit the simulation.
ESC : quitH/? : toggle help- Parameters:
world_model (WorldModel)
clock (pygame.time.Clock | None)
- parse_events() Literal[True] | None[source]
Parse the input events and return True if the loop should end.
- Return type:
Literal[True] | None
- __init__(world_model: WorldModel, *, show_help_notice=True, clock: pygame.time.Clock | None = None)
- Parameters:
world_model (WorldModel) – WorldModel
show_help_notice – bool Show a notice about the help keys.
clock (pygame.time.Clock | None) – To track the game time.
- classmethod get_docstring()
Return the docstring of the class
- class classes.ui.keyboard_controls.RSSKeyboardControl(world_model: WorldModel, *, clock: pygame.time.Clock, start_in_autopilot: bool = False, agent_controlled: bool = True, config=None)[source]
Bases:
CanBeDummy,KeyboardControlUse ARROWS, WASD keys or mouse click and drag for control.
W : throttleS : brakeAD : steerQ : toggle reverseSpace : hand-brakeP : toggle autopilot (depends on setup)TAB : change viewBackspace : change vehicle (will unset externalActor; experimental)R : toggle recording images to diskF2 : toggle RSS visualization modeF3 : increase log levelF4 : decrease log levelF5 : increase map log levelF6 : decrease map log levelB : toggle RSS Road Boundaries ModeG : RSS check drop current route (experimental)S : toggle RSS (NotImplemented)T : toggle vehicle’s telemetry visualizationO : open/close vehicle’s doorsN : pause simulation (not in sync mode)– Experimental, recording –CTRL + R : toggle recording of simulation (replacing any previous)CTRL + P : start replaying last recorded simulation (untested)CTRL + + : increments the start time of the replay by 1 second (+SHIFT = 10 seconds)CTRL + - : decrements the start time of the replay by 1 second (+SHIFT = 10 seconds)F1 : toggle HUDH/? : toggle helpESC : quit- Parameters:
world_model (WorldModel)
clock (pygame.time.Clock)
start_in_autopilot (bool)
agent_controlled (bool)
- MOUSE_STEERING_RANGE = 150
Controls the size of steering area when using the mouse.
- __init__(world_model: WorldModel, *, clock: pygame.time.Clock, start_in_autopilot: bool = False, agent_controlled: bool = True, config=None)[source]
- Parameters:
- world_modelWorldModel
The world model that controls the interface.
- clockpygame.time.Clock
The clock to get the time from.
- start_in_autopilotbool
If CARLA’s autopilot is used; or some other system. May not be True if agent_controlled is True. Defaults to
False.- agent_controlledbool
May not be True if start_in_autopilot is True. Defaults to
True.- configAny
Configuration data. Currently unused.
Note
Creating a controller registers
WorldModel.controllerto this instance.- Parameters:
world_model (WorldModel)
clock (pygame.time.Clock)
start_in_autopilot (bool)
agent_controlled (bool)
- property controlled_externally: bool
Returns True if the vehicle is controlled by some system, i.e not manually by the user.
- render(display: pygame.Surface) None[source]
- Parameters:
display (pygame.Surface)
- Return type:
None
- classmethod get_docstring()
Return the docstring of the class
- classmethod is_dummy(obj: Any) TypeGuard[MockDummy]
TypeGuardcheck if a variable is a duck-typed dummy object.Objects might be dummy objects that have no function if
LaunchConfig.pygameis set toFalse.
- parse_events(control: carla.VehicleControl | None = None) Literal[True] | None[source]
Parse the input events and return True if the loop should end.
- Parameters:
control (Optional[carla.VehicleControl])
- Return type:
Literal[True] | None