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_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]¶
- 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.
- 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
- 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.
- 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.
- 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_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.
- 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.
- 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
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.
- disable(simulation)[source]¶
Disable the traffic manager, removing all managed vehicles from 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_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_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.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
- class igp2.carlasim.visualisation.HelpText(font, width, height)[source]¶
Bases:
object
Helper class to handle text output using pygame
- class igp2.carlasim.visualisation.Igp2HUD(width: int, height: int, agents: Dict[int, CarlaAgentWrapper])[source]¶
Bases:
object
- class igp2.carlasim.visualisation.KeyboardControl(world)[source]¶
Bases:
object
Class that handles keyboard input.
- 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, record: bool = False)[source]¶
Bases:
object
Create a pygame-based visualisation with HUD to show the evolution of scenarios.
- 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.