opencda.scenario_testing.utils package

Submodules

opencda.scenario_testing.utils.customized_map_api module

Loading world from customized map

class opencda.scenario_testing.utils.customized_map_api.bcolors

Bases: object

BOLD = '\x1b[1m'
ENDC = '\x1b[0m'
FAIL = '\x1b[91m'
HEADER = '\x1b[95m'
OKBLUE = '\x1b[94m'
OKCYAN = '\x1b[96m'
OKGREEN = '\x1b[92m'
UNDERLINE = '\x1b[4m'
WARNING = '\x1b[93m'
opencda.scenario_testing.utils.customized_map_api.load_customized_world(xodr_path, client)

Load .xodr file and return the carla world object

Parameters
  • -xodr_path (string) – path to the xodr file

  • -client (carla.client) – The created CARLA simulation client.

opencda.scenario_testing.utils.customized_map_api.spawn_helper_2lanefree(carla_map, coefficient)

A helper function to locate the valid spawn point on the merge lane.

Parameters
  • -carla_map (carla.map) – the 2lanefreeway map

  • -coefficient (float) – A single scalar indicating where is the spawn point, eg. 0.5 represents the spawn position is in the middle of the merge lane.

Returns

The desired spawn points.

Return type

-transform_point (carla.transform)

opencda.scenario_testing.utils.customized_map_api.spawn_helper_2lanefree_complete(carla_map, coefficient)

A helper function to locate the valid spawn point on the merge lane.

Parameters
  • -carla_map (carla.map) – The 2lanefreeway map.

  • -coefficient (float) – A single scalar indicating where is the spawn point, eg. 0.5 represents the spawn position is in the middle of the merge lane.

Returns

The desired spawn points.

Return type

-transform_point (carla.transform)

opencda.scenario_testing.utils.sim_api module

Utilize scenario manager to manage simulation construction.

class opencda.scenario_testing.utils.sim_api.ScenarioManager(scenario_params, apply_ml, xodr_path=None, town=None, cav_world=None)

Bases: object

The manager that controls simulation construction, backgound traffic generation and CAVs spawning.

Parameters
  • scenario_params (dict) – The dictionary contains all simulation configurations.

  • xodr_path (str) – The xodr file to the customized map, default: None.

  • town (str) – Town name if not using customized map, eg. ‘Town06’.

  • apply_ml (bool) – Whether need to load dl/ml model(pytorch required) in this simulation.

client

The client that connects to carla server.

Type

carla.client

world

Carla simulation server.

Type

carla.world

origin_settings

The origin setting of the simulation server.

Type

dict

cav_world

CAV World that contains the information of all CAVs.

Type

opencda object

carla_map

Car;a HD Map.

Type

carla.map

create_platoon_manager(map_helper=None, data_dump=False)

Create a list of platoons.

Parameters
  • map_helper (function) – A function to help spawn vehicle on a specific position in a specific map.

  • data_dump (bool) – Whether to dump sensor data.

Returns

single_cav_list – A list contains all single CAVs’ vehicle manager.

Return type

list

create_traffic_carla()

Create traffic flow.

Returns

  • tm (carla.traffic_manager) – Carla traffic manager.

  • bg_list (list) – The list that contains all the background traffic vehicles.

create_vehicle_manager(application, map_helper=None, data_dump=False)

Create a list of single CAVs.

Parameters
  • application (list) – The application purpose, a list, eg. [‘single’], [‘platoon’].

  • map_helper (function) – A function to help spawn vehicle on a specific position in a specific map.

  • data_dump (bool) – Whether to dump sensor data.

Returns

single_cav_list – A list contains all single CAVs’ vehicle manager.

Return type

list

destroyActors()

Destroy all actors in the world.

spawn_vehicle_by_range(tm, traffic_config, bg_list)

Spawn the traffic vehicles by the given range.

Parameters
  • tm (carla.TrafficManager) – Traffic manager.

  • traffic_config (dict) – Background traffic configuration.

  • bg_list (list) – The list contains all background traffic.

Returns

bg_list – Update traffic list.

Return type

list

spawn_vehicles_by_list(tm, traffic_config, bg_list)

Spawn the traffic vehicles by the given list.

Parameters
  • tm (carla.TrafficManager) – Traffic manager.

  • traffic_config (dict) – Background traffic configuration.

  • bg_list (list) – The list contains all background traffic.

Returns

bg_list – Update traffic list.

Return type

list

opencda.scenario_testing.utils.sim_api.car_blueprint_filter(blueprint_library)

Exclude the uncommon vehicles from the default CARLA blueprint library (i.e., isetta, carlacola, cybertruck, t2).

Parameters

blueprint_library (carla.blueprint_library) – The blueprint library that contains all models.

Returns

blueprints – The list of suitable blueprints for vehicles.

Return type

list

opencda.scenario_testing.utils.yaml_utils module

Used to load and write yaml files

opencda.scenario_testing.utils.yaml_utils.load_yaml(file)

Load yaml file and return a dictionary. :param file: yaml file path. :type file: string

Returns

param – A dictionary that contains defined parameters.

Return type

dict

opencda.scenario_testing.utils.yaml_utils.save_yaml(data, save_name)

Save the dictionary into a yaml file.

Parameters
  • data (dict) – The dictionary contains all data.

  • save_name (string) – Full path of the output yaml file.

Module contents