igp2.carlasim package

Submodules

igp2.carlasim.carla_agent_wrapper module

class igp2.carlasim.carla_agent_wrapper.CarlaAgentWrapper(agent: Agent, actor: Actor)[source]

Bases: object

Wrapper class that provides a simple way to retrieve control for the attached actor.

property actor: Actor
property actor_id: int
property agent: Agent
property agent_id: int
done(observation: Observation) bool[source]

Returns whether the wrapped agent is done.

property name

The role name of the wrapped Actor.

next_control(observation: Observation) VehicleControl | None[source]
reset_waypoints()[source]
property state: AgentState

igp2.carlasim.carla_client module

class igp2.carlasim.carla_client.CarlaSim(fps: int = 20, xodr: str | Map | None = None, map_name: str | None = None, server: str = 'localhost', port: int = 2000, launch_process: bool = False, carla_path: str | None = None, record: bool = False, rendering: bool = True)[source]

Bases: object

An interface to the CARLA simulator

TIMEOUT = 20.0
add_agent(agent: Agent, rolename: str | None = None, blueprint: ActorBlueprint | None = None)[source]

Add a vehicle to the simulation. Defaults to an Audi A2 for blueprints if not explicitly given.

Parameters:
  • agent – Agent to add.

  • rolename – Unique name for the actor to spawn.

  • blueprint – Optional blueprint defining the properties of the actor.

Returns:

The newly added actor.

property agents: Dict[int, CarlaAgentWrapper]

All IGP2 agents that are present or were present during the simulation.

attach_camera(actor: ~carla.libcarla.Actor, transform: ~carla.libcarla.Transform = <carla.libcarla.Transform object>)[source]

Attach a camera to the back of the given actor in third-person view.

Parameters:
  • actor – The actor to follow

  • transform – Optional transform to set the position of the camera

property client: Client

The CARLA client to the server.

property dead_ids: List[int]

List of Agent IDs that have been used previously during the simulation

property fps: int

Execution frequency of the simulation.

get_ego(ego_name: str = 'ego') CarlaAgentWrapper | None[source]

Returns the ego agent if it exists.

get_traffic_manager() TrafficManager[source]

Enables and returns the internal traffic manager of the simulation.

load_opendrive_world(xodr: str)[source]
property map: Map

The CARLA map.

property recording: bool

Whether we are recording the simulation.

property recording_path: str

The save path of the recording.

remove_agent(agent_id: int)[source]

Remove the given agent from the simulation.

Parameters:

agent_id – The ID of the agent to remove

run(steps=400)[source]

Run the simulation for a number of time steps

property scenario_map: Map

The current road layout.

property spectator: Actor

The spectator camera of the world.

step(tick: bool = True)[source]

Advance the simulation by one time step.

Returns:

Current observation of the environment before taking actions this step, and the actions that will be taken.

property timestep: int

Current timestep of the simulation

property world: World

The current CARLA world

igp2.carlasim.controller module

class igp2.carlasim.controller.PIDLateralController(vehicle, offset=0, K_P=1.0, K_I=0.0, K_D=0.0, dt=0.03)[source]

Bases: object

PIDLateralController implements lateral control using a PID.

change_parameters(K_P, K_I, K_D, dt)[source]

Changes the PID parameters

run_step(waypoint)[source]

Execute one step of lateral control to steer the vehicle towards a certain waypoin.

param waypoint:

target waypoint

return:

steering control in the range [-1, 1] where:

-1 maximum steering to left +1 maximum steering to right

class igp2.carlasim.controller.PIDLongitudinalController(vehicle, K_P=1.0, K_I=0.0, K_D=0.0, dt=0.03)[source]

Bases: object

PIDLongitudinalController implements longitudinal control using a PID.

change_parameters(K_P, K_I, K_D, dt)[source]

Changes the PID parameters

run_step(target_speed, debug=False)[source]

Execute one step of longitudinal control to reach a given target speed.

param target_speed:

target speed in Km/h

param debug:

boolean for debugging

return:

throttle control

class igp2.carlasim.controller.VehiclePIDController(vehicle, args_lateral, args_longitudinal, offset=0, max_throttle=0.75, max_brake=0.3, max_steering=0.8)[source]

Bases: object

VehiclePIDController is the combination of two PID controllers (lateral and longitudinal) to perform the low level control a vehicle from client side

change_lateral_PID(args_lateral)[source]

Changes the parameters of the PIDLongitudinalController

change_longitudinal_PID(args_longitudinal)[source]

Changes the parameters of the PIDLongitudinalController

run_step(target_speed, waypoint)[source]

Execute one step of control invoking both lateral and longitudinal PID controllers to reach a target waypoint at a given target_speed.

param target_speed:

desired vehicle speed

param waypoint:

target location encoded as a waypoint

return:

distance (in meters) to the waypoint

igp2.carlasim.local_planner module

This module contains a local planner to perform low-level waypoint following based on PID controllers.

class igp2.carlasim.local_planner.LocalPlanner(vehicle: Actor, world: World, map: Map, dt: float = 0.05, **kwargs)[source]

Bases: object

LocalPlanner implements the basic behavior of following a trajectory of waypoints that is generated on-the-fly.

The low-level motion of the vehicle is computed by using two PID controllers, one is used for the lateral control and the other for the longitudinal control (cruise speed).

When multiple paths are available (intersections) this local planner makes a random choice, unless a given global plan has already been specified.

done()[source]

Returns whether or not the planner has finished

Returns:

boolean

follow_speed_limits(value: bool = True)[source]

Activates a flag that makes the max speed dynamically vary according to the spped limits

Parameters:

value – Whether to follow speed limit or not.

get_incoming_waypoint_and_direction(steps=3)[source]

Returns direction and waypoint at a distance ahead defined by the user.

param steps:

number of steps to get the incoming waypoint.

reset_vehicle()[source]

Reset the ego-vehicle

run_step(debug=False)[source]

Execute one step of local planning which involves running the longitudinal and lateral PID controllers to follow the waypoints trajectory.

Parameters:

debug – boolean flag to activate waypoints debugging

Returns:

The control to be applied

set_global_plan(current_plan, stop_waypoint_creation=True, clean_queue=True)[source]

Adds a new plan to the local planner. A plan must be a list of [carla.Waypoint, RoadOption] pairs If ‘clean_queue`, erases the previous plan, and if not, it is added to the old one The ‘stop_waypoint_creation’ flag avoids creating more random waypoints

Parameters:
  • current_plan – list of (carla.Waypoint, RoadOption)

  • stop_waypoint_creation – bool

  • clean_queue – bool

set_speed(speed)[source]

Changes the target speed

Parameters:

speed – new target speed in Km/h

class igp2.carlasim.local_planner.RoadOption(value)[source]

Bases: Enum

RoadOption represents the possible topological configurations when moving from a segment of lane to other.

CHANGELANELEFT = 5
CHANGELANERIGHT = 6
LANEFOLLOW = 4
LEFT = 1
RIGHT = 2
STRAIGHT = 3
VOID = -1

igp2.carlasim.traffic_manager module

class igp2.carlasim.traffic_manager.TrafficManager(scenario_map: Map, n_agents: int = 5, ego: Agent | None = None, spawn_tries: int = 10)[source]

Bases: object

Class that manages non-ego CARLA agents in a synchronous way. The traffic manager manages its own list of agents that it synchronises with the CarlaSim object.

property agents: Dict[int, Agent]

The agents managed by the manager

disable(simulation)[source]

Disable the traffic manager, removing all managed vehicles from the simulation.

property ego: Agent

The ID of the ego vehicle in the simulation.

property enabled: bool

Whether the traffic manager is turned on.

property n_agents: int

Number of agents to maintain as traffic in the simulation

set_agents_count(value: int)[source]

Set the number of agents to spawn as traffic.

set_ego_agent(agent: Agent)[source]

Set an ego agent used for spawn radius calculations in vehicle spawning based on the agent’s view radius

set_spawn_filter(actor_filter: str)[source]

Set what types of actors to spawn.

set_spawn_generation(actor_generation: str)[source]

Set which version of actor blueprint generation to use. This is usually set to 2. Must be either ‘1’, ‘2’, or ‘All’.

property spawns: List[Transform]

List of all possible spawn points

update(simulation, observation: Observation | None = None)[source]

This method updates the list of managed agents based on their state. All vehicles outside the spawn radius are de-spawned.

Parameters:
  • simulation – The currently running simulation object

  • observation – The last observation of the environment

igp2.carlasim.util module

igp2.carlasim.util.draw_waypoints(world, waypoints, z=0.5)[source]

Draw a list of waypoints at a certain height given in z.

param world:

carla.world object

param waypoints:

list or iterable container with the waypoints to draw

param z:

height in meters

igp2.carlasim.util.find_weather_presets()[source]
igp2.carlasim.util.get_actor_blueprints(world, filter, generation)[source]
igp2.carlasim.util.get_actor_display_name(actor, truncate=250)[source]
igp2.carlasim.util.get_speed(vehicle: Actor, ignore_z: bool = True)[source]

Compute speed of a vehicle in Km/h.

Parameters:
  • vehicle – the vehicle for which speed is calculated

  • ignore_z – Whether to ignore the velocity component in the z-axis.

Returns:

speed as a float in Km/h

igp2.carlasim.visualisation module

Welcome to CARLA manual control.

L : toggle next light type SHIFT + L : toggle high beam Z/X : toggle right/left blinker I : toggle interior light

TAB : change sensor position ` or N : next sensor [1-9] : change to sensor [1-9] G : toggle radar visualization C : change weather (Shift+C reverse) Backspace : change vehicle

V : Select next map layer (Shift+V reverse) B : Load current selected map layer (Shift+B to unload)

R : toggle recording images to disk T : toggle vehicle’s telemetry

CTRL + R : toggle recording of simulation (replacing any previous) CTRL + P : start replaying last recorded simulation 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

class igp2.carlasim.visualisation.CameraManager(parent_actor, hud, gamma_correction)[source]

Bases: object

next_sensor()[source]
render(display)[source]
set_sensor(index, notify=True, force_respawn=False)[source]
toggle_camera()[source]
toggle_recording()[source]
class igp2.carlasim.visualisation.CollisionSensor(parent_actor, hud)[source]

Bases: object

get_collision_history()[source]
class igp2.carlasim.visualisation.FadingText(font, dim, pos)[source]

Bases: object

render(display)[source]
set_text(text, color=(255, 255, 255), seconds=2.0)[source]
tick(_, clock)[source]
class igp2.carlasim.visualisation.GnssSensor(parent_actor)[source]

Bases: object

class igp2.carlasim.visualisation.HUD(width, height)[source]

Bases: object

error(text)[source]
notification(text, seconds=2.0)[source]
on_world_tick(timestamp)[source]
render(display)[source]
tick(world, clock)[source]
toggle_info()[source]
class igp2.carlasim.visualisation.HelpText(font, width, height)[source]

Bases: object

Helper class to handle text output using pygame

render(display)[source]
toggle()[source]
class igp2.carlasim.visualisation.IMUSensor(parent_actor)[source]

Bases: object

class igp2.carlasim.visualisation.Igp2HUD(width: int, height: int, agents: Dict[int, CarlaAgentWrapper])[source]

Bases: object

on_world_tick(timestamp)[source]
render(display)[source]
tick(world, clock)[source]
toggle_info()[source]
class igp2.carlasim.visualisation.KeyboardControl(world)[source]

Bases: object

Class that handles keyboard input.

parse_events(client, world)[source]
class igp2.carlasim.visualisation.LaneInvasionSensor(parent_actor, hud)[source]

Bases: object

class igp2.carlasim.visualisation.RadarSensor(parent_actor)[source]

Bases: object

class igp2.carlasim.visualisation.Visualiser(carla_simulation: CarlaSim, ego_role_name: str = 'ego', res_width: int = 1920, res_height: int = 1080, gamma: float = 2.2)[source]

Bases: object

Create a pygame-based visualisation with HUD to show the evolution of scenarios.

initialize()[source]

Start pygame window and create subcomponents for running simulation.

run(steps: int | None = None)[source]

This method will initiate the simulation and begin its visualisation.

Parameters:

steps – The number of execution steps. If None, then execute indefinitely.

step(clock: Clock, world: World, display: Surface, controller: KeyboardControl) bool[source]

Take one step of the simulation. Internally calls the step method of the corresponding CarlaSim.

class igp2.carlasim.visualisation.World(carla_world: World, ego: CarlaAgentWrapper, hud: HUD, igp2_hud: Igp2HUD, gamma: float)[source]

Bases: object

Wrapper to manage the CARLA world and its rendering to pygame.

destroy()[source]
destroy_sensors()[source]
load_map_layer(unload=False)[source]
next_map_layer(reverse=False)[source]
next_weather(reverse=False)[source]
render(display)[source]
restart()[source]
tick(clock)[source]
toggle_radar()[source]

Module contents