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.

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, CustomSensorInterface

Class for camera management

Parameters:
__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 set sensor and index to a valid value.

Parameters:
sensor: carla.Sensor | None
toggle_camera() None[source]

Activate a camera

Return type:

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

next_sensor() None[source]

Get the next sensor

Return type:

None

destroy() None[source]

Stops and destroys the actor of the sensor

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]

TypeGuard check if a variable is a duck-typed dummy object.

Objects might be dummy objects that have no function if LaunchConfig.pygame is set to False.

Parameters:

obj (Any)

Return type:

TypeGuard[MockDummy]

is_dummy_: bool = False
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

static stop_following_actor() None[source]
Return type:

None

stop() None[source]

Stop the sensor if its in listening mode. If it is a carla.Sensor, calls the simulator.

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:
class classes.ui.hud.HUD(width: int, height: int, world: carla.World, help_text: str | None = RSSKeyboardControl.__doc__)[source]

Bases: CanBeDummy

Class to display text and other information on the pygame screen.

If LaunchConfig.pygame is set to False the HUD is not available.

Parameters:
default_font: ClassVar[str] = 'ubuntumono'
__init__(width: int, height: int, world: carla.World, help_text: str | None = RSSKeyboardControl.__doc__)[source]

Constructor method

Parameters:
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:
toggle_info()[source]

Toggle info on or off

notification(text: str, seconds: float = 2.0)[source]

Display a notification

Parameters:
error(text: str)[source]

Display an error notification

Parameters:

text (str)

render(display: pygame.Surface)[source]

Render for HUD class

Parameters:

display (pygame.Surface)

classmethod is_dummy(obj: Any) TypeGuard[MockDummy]

TypeGuard check if a variable is a duck-typed dummy object.

Objects might be dummy objects that have no function if LaunchConfig.pygame is set to False.

Parameters:

obj (Any)

Return type:

TypeGuard[MockDummy]

is_dummy_: bool = False

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: object

Primitive base for keyboard control classes.

H/? : toggle help

Parameters:
__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.

enable(value: bool = True)[source]
Parameters:

value (bool)

classmethod get_docstring()[source]

Return the docstring of the class

parse_events(events=None) Literal[True] | Any[source]

Parse the input events and return True if the loop should end.

Return type:

Literal[True] | ~typing.Any

class classes.ui.keyboard_controls.PassiveKeyboardControl(world_model: WorldModel, *, show_help_notice=True, clock: pygame.time.Clock | None = None)[source]

Bases: KeyboardControl

Does not allow to control the vehicle. Only allows to quit the simulation.

ESC : quit
H/? : toggle help
Parameters:
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.

enable(value: bool = True)
Parameters:

value (bool)

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, KeyboardControl

Use ARROWS, WASD keys or mouse click and drag for control.

W : throttle
S : brake
AD : steer
Q : toggle reverse
Space : hand-brake
P : toggle autopilot (depends on setup)
TAB : change view
Backspace : change vehicle (will unset externalActor; experimental)
R : toggle recording images to disk
F2 : toggle RSS visualization mode
F3 : increase log level
F4 : decrease log level
F5 : increase map log level
F6 : decrease map log level
B : toggle RSS Road Boundaries Mode
G : RSS check drop current route (experimental)
S : toggle RSS (NotImplemented)
T : toggle vehicle’s telemetry visualization
O : open/close vehicle’s doors
N : 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 HUD
H/? : toggle help
ESC : quit
Parameters:
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.controller to this instance.

Parameters:
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

enable(value: bool = True)
Parameters:

value (bool)

classmethod get_docstring()

Return the docstring of the class

classmethod is_dummy(obj: Any) TypeGuard[MockDummy]

TypeGuard check if a variable is a duck-typed dummy object.

Objects might be dummy objects that have no function if LaunchConfig.pygame is set to False.

Parameters:

obj (Any)

Return type:

TypeGuard[MockDummy]

is_dummy_: bool = False
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