From 3a40b4e3ebb19f3d414fee6b301d6f93430787d6 Mon Sep 17 00:00:00 2001 From: Hanchu Zhou Date: Fri, 12 May 2023 14:53:13 -0700 Subject: [PATCH 1/2] Add 3 OpenScenarios to the develop branch --- .../config_yaml/openscenario_1.yaml | 64 ++++++++ .../config_yaml/openscenario_2.yaml | 63 ++++++++ .../config_yaml/openscenario_3.yaml | 65 +++++++++ opencda/scenario_testing/openscenario_1.py | 117 +++++++++++++++ opencda/scenario_testing/openscenario_2.py | 118 +++++++++++++++ opencda/scenario_testing/openscenario_3.py | 118 +++++++++++++++ .../scenario_testing/scenarios/scenario_1.py | 132 +++++++++++++++++ .../scenario_testing/scenarios/scenario_1.xml | 11 ++ .../scenario_testing/scenarios/scenario_2.py | 135 +++++++++++++++++ .../scenario_testing/scenarios/scenario_2.xml | 14 ++ .../scenario_testing/scenarios/scenario_3.py | 138 ++++++++++++++++++ .../scenario_testing/scenarios/scenario_3.xml | 13 ++ 12 files changed, 988 insertions(+) create mode 100644 opencda/scenario_testing/config_yaml/openscenario_1.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_2.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_3.yaml create mode 100644 opencda/scenario_testing/openscenario_1.py create mode 100644 opencda/scenario_testing/openscenario_2.py create mode 100644 opencda/scenario_testing/openscenario_3.py create mode 100644 opencda/scenario_testing/scenarios/scenario_1.py create mode 100644 opencda/scenario_testing/scenarios/scenario_1.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_2.py create mode 100644 opencda/scenario_testing/scenarios/scenario_2.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_3.py create mode 100644 opencda/scenario_testing/scenarios/scenario_3.xml diff --git a/opencda/scenario_testing/config_yaml/openscenario_1.yaml b/opencda/scenario_testing/config_yaml/openscenario_1.yaml new file mode 100644 index 00000000..94b8f3e7 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_1.yaml @@ -0,0 +1,64 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town01 + + # E.g., for the Overtake scenario + scenario: Scenario_1 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_1.xml' + additionalScenario: '/home/ucdavis/OpenCDA/opencda/scenario_testing/scenarios/scenario_1.py' + + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [200.2, 195.4, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_2.yaml b/opencda/scenario_testing/config_yaml/openscenario_2.yaml new file mode 100644 index 00000000..169982a9 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_2.yaml @@ -0,0 +1,63 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town03 + + # E.g., for the Overtake scenario + scenario: Scenario_2 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_2.xml' + additionalScenario: '/home/ucdavis/OpenCDA/opencda/scenario_testing/scenarios/scenario_2.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [-28.8, 134.7, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_3.yaml b/opencda/scenario_testing/config_yaml/openscenario_3.yaml new file mode 100644 index 00000000..2e441cd2 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_3.yaml @@ -0,0 +1,65 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town03 + + # E.g., for the Overtake scenario + scenario: Scenario_3 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_3.xml' + additionalScenario: '/home/ucdavis/OpenCDA/opencda/scenario_testing/scenarios/scenario_3.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [-28.8, 134.7, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 18 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/openscenario_1.py b/opencda/scenario_testing/openscenario_1.py new file mode 100644 index 00000000..063fb1fb --- /dev/null +++ b/opencda/scenario_testing/openscenario_1.py @@ -0,0 +1,117 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params, )) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") diff --git a/opencda/scenario_testing/openscenario_2.py b/opencda/scenario_testing/openscenario_2.py new file mode 100644 index 00000000..c3e3bcf3 --- /dev/null +++ b/opencda/scenario_testing/openscenario_2.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_3.py b/opencda/scenario_testing/openscenario_3.py new file mode 100644 index 00000000..c3e3bcf3 --- /dev/null +++ b/opencda/scenario_testing/openscenario_3.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/scenarios/scenario_1.py b/opencda/scenario_testing/scenarios/scenario_1.py new file mode 100644 index 00000000..0ac9ffef --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_1.py @@ -0,0 +1,132 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_1(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Overtake Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 4 + self.vehicle_01_velocity = 0 + self.vehicle_02_velocity = 8 + self.vehicle_03_velocity = 8 + self.vehicle_04_velocity = 8 + self._trigger_distance = 150 + + super(Scenario_1, self).__init__("Scenario_1", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_1.xml b/opencda/scenario_testing/scenarios/scenario_1.xml new file mode 100644 index 00000000..37e52e73 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_2.py b/opencda/scenario_testing/scenarios/scenario_2.py new file mode 100644 index 00000000..1bb511e0 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_2.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_2(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Left Turn Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 7 + self.vehicle_01_velocity = 0 # Stopped large vehicle + self.vehicle_02_velocity = 5 # Vehicle blocked by large vehicle + self.vehicle_03_velocity = 5 # Vehicle in front of ego vehicle + self.vehicle_04_velocity = 5 # Vehicle behind ego vehicle + self.vehicle_05_velocity = 7 # Vehicle in front of block vehicle + self.vehicle_06_velocity = 5 # Vehicle on the right side of ego vehicle + self.vehicle_07_velocity = 5 + self._trigger_distance = 150 + + super(Scenario_2, self).__init__("Scenario_2", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_2.xml b/opencda/scenario_testing/scenarios/scenario_2.xml new file mode 100644 index 00000000..282c7195 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_2.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_3.py b/opencda/scenario_testing/scenarios/scenario_3.py new file mode 100644 index 00000000..d3ba58b5 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_3.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_3(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Red-light Violation Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 6 + self.vehicle_01_velocity = 7 # Violated vehicle + self.vehicle_02_velocity = 0 # Large vehicles from 02 to 06 + self.vehicle_03_velocity = 0 + self.vehicle_04_velocity = 0 + self.vehicle_05_velocity = 0 + self.vehicle_06_velocity = 0 + self._trigger_distance = 150 + + super(Scenario_3, self).__init__("Scenario_3", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + if i == 0: + waypoint = [carla.Location(x=-108.6, y=129.5, z=0.5), carla.Location(x=-120.6, y=129.5, z=0.5), carla.Location(x=-140.6, y=115.2, z=0.5), carla.Location(x=-142.0, y=87.6, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + else: + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_3.xml b/opencda/scenario_testing/scenarios/scenario_3.xml new file mode 100644 index 00000000..0e0a83af --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + From 6083de4341fb27db7223a73b6a0de152f70f55b3 Mon Sep 17 00:00:00 2001 From: Hanchu Zhou Date: Mon, 22 May 2023 14:50:32 -0700 Subject: [PATCH 2/2] Add all 17 OpenScenarios to the develop branch --- .../config_yaml/openscenario_1.yaml | 2 +- .../config_yaml/openscenario_11.yaml | 74 +++++++++ .../config_yaml/openscenario_12.yaml | 74 +++++++++ .../config_yaml/openscenario_13.yaml | 74 +++++++++ .../config_yaml/openscenario_14.yaml | 74 +++++++++ .../config_yaml/openscenario_15.yaml | 74 +++++++++ .../config_yaml/openscenario_16.yaml | 74 +++++++++ .../config_yaml/openscenario_17.yaml | 74 +++++++++ .../config_yaml/openscenario_18.yaml | 74 +++++++++ .../config_yaml/openscenario_2.yaml | 2 +- .../config_yaml/openscenario_3.yaml | 2 +- .../config_yaml/openscenario_4.yaml | 74 +++++++++ .../config_yaml/openscenario_5.yaml | 74 +++++++++ .../config_yaml/openscenario_6.yaml | 74 +++++++++ .../config_yaml/openscenario_7.yaml | 74 +++++++++ .../config_yaml/openscenario_8.yaml | 74 +++++++++ .../config_yaml/openscenario_9.yaml | 74 +++++++++ opencda/scenario_testing/openscenario_11.py | 120 +++++++++++++++ opencda/scenario_testing/openscenario_12.py | 120 +++++++++++++++ opencda/scenario_testing/openscenario_13.py | 120 +++++++++++++++ opencda/scenario_testing/openscenario_14.py | 120 +++++++++++++++ opencda/scenario_testing/openscenario_15.py | 120 +++++++++++++++ opencda/scenario_testing/openscenario_16.py | 118 +++++++++++++++ opencda/scenario_testing/openscenario_17.py | 118 +++++++++++++++ opencda/scenario_testing/openscenario_18.py | 118 +++++++++++++++ opencda/scenario_testing/openscenario_4.py | 118 +++++++++++++++ opencda/scenario_testing/openscenario_5.py | 118 +++++++++++++++ opencda/scenario_testing/openscenario_6.py | 118 +++++++++++++++ opencda/scenario_testing/openscenario_7.py | 118 +++++++++++++++ opencda/scenario_testing/openscenario_8.py | 118 +++++++++++++++ opencda/scenario_testing/openscenario_9.py | 119 +++++++++++++++ .../scenario_testing/scenarios/scenario_11.py | 136 +++++++++++++++++ .../scenarios/scenario_11.xml | 10 ++ .../scenario_testing/scenarios/scenario_12.py | 135 +++++++++++++++++ .../scenarios/scenario_12.xml | 10 ++ .../scenario_testing/scenarios/scenario_13.py | 134 ++++++++++++++++ .../scenarios/scenario_13.xml | 13 ++ .../scenario_testing/scenarios/scenario_14.py | 133 ++++++++++++++++ .../scenarios/scenario_14.xml | 12 ++ .../scenario_testing/scenarios/scenario_15.py | 135 +++++++++++++++++ .../scenarios/scenario_15.xml | 9 ++ .../scenario_testing/scenarios/scenario_16.py | 139 +++++++++++++++++ .../scenarios/scenario_16.xml | 9 ++ .../scenario_testing/scenarios/scenario_17.py | 130 ++++++++++++++++ .../scenarios/scenario_17.xml | 9 ++ .../scenario_testing/scenarios/scenario_18.py | 130 ++++++++++++++++ .../scenarios/scenario_18.xml | 9 ++ .../scenario_testing/scenarios/scenario_4.py | 131 ++++++++++++++++ .../scenario_testing/scenarios/scenario_4.xml | 10 ++ .../scenario_testing/scenarios/scenario_5.py | 143 ++++++++++++++++++ .../scenario_testing/scenarios/scenario_5.xml | 14 ++ .../scenario_testing/scenarios/scenario_6.py | 143 ++++++++++++++++++ .../scenario_testing/scenarios/scenario_6.xml | 14 ++ .../scenario_testing/scenarios/scenario_7.py | 139 +++++++++++++++++ .../scenario_testing/scenarios/scenario_7.xml | 9 ++ .../scenario_testing/scenarios/scenario_8.py | 138 +++++++++++++++++ .../scenario_testing/scenarios/scenario_8.xml | 10 ++ .../scenario_testing/scenarios/scenario_9.py | 131 ++++++++++++++++ .../scenario_testing/scenarios/scenario_9.xml | 10 ++ 59 files changed, 4747 insertions(+), 3 deletions(-) create mode 100644 opencda/scenario_testing/config_yaml/openscenario_11.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_12.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_13.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_14.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_15.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_16.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_17.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_18.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_4.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_5.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_6.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_7.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_8.yaml create mode 100644 opencda/scenario_testing/config_yaml/openscenario_9.yaml create mode 100644 opencda/scenario_testing/openscenario_11.py create mode 100644 opencda/scenario_testing/openscenario_12.py create mode 100644 opencda/scenario_testing/openscenario_13.py create mode 100644 opencda/scenario_testing/openscenario_14.py create mode 100644 opencda/scenario_testing/openscenario_15.py create mode 100644 opencda/scenario_testing/openscenario_16.py create mode 100644 opencda/scenario_testing/openscenario_17.py create mode 100644 opencda/scenario_testing/openscenario_18.py create mode 100644 opencda/scenario_testing/openscenario_4.py create mode 100644 opencda/scenario_testing/openscenario_5.py create mode 100644 opencda/scenario_testing/openscenario_6.py create mode 100644 opencda/scenario_testing/openscenario_7.py create mode 100644 opencda/scenario_testing/openscenario_8.py create mode 100644 opencda/scenario_testing/openscenario_9.py create mode 100644 opencda/scenario_testing/scenarios/scenario_11.py create mode 100644 opencda/scenario_testing/scenarios/scenario_11.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_12.py create mode 100644 opencda/scenario_testing/scenarios/scenario_12.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_13.py create mode 100644 opencda/scenario_testing/scenarios/scenario_13.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_14.py create mode 100644 opencda/scenario_testing/scenarios/scenario_14.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_15.py create mode 100644 opencda/scenario_testing/scenarios/scenario_15.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_16.py create mode 100644 opencda/scenario_testing/scenarios/scenario_16.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_17.py create mode 100644 opencda/scenario_testing/scenarios/scenario_17.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_18.py create mode 100644 opencda/scenario_testing/scenarios/scenario_18.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_4.py create mode 100644 opencda/scenario_testing/scenarios/scenario_4.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_5.py create mode 100644 opencda/scenario_testing/scenarios/scenario_5.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_6.py create mode 100644 opencda/scenario_testing/scenarios/scenario_6.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_7.py create mode 100644 opencda/scenario_testing/scenarios/scenario_7.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_8.py create mode 100644 opencda/scenario_testing/scenarios/scenario_8.xml create mode 100644 opencda/scenario_testing/scenarios/scenario_9.py create mode 100644 opencda/scenario_testing/scenarios/scenario_9.xml diff --git a/opencda/scenario_testing/config_yaml/openscenario_1.yaml b/opencda/scenario_testing/config_yaml/openscenario_1.yaml index 94b8f3e7..0ce0816a 100644 --- a/opencda/scenario_testing/config_yaml/openscenario_1.yaml +++ b/opencda/scenario_testing/config_yaml/openscenario_1.yaml @@ -17,7 +17,7 @@ scenario_runner: scenario: Scenario_1 num_actors: 2 configFile: './opencda/scenario_testing/scenarios/scenario_1.xml' - additionalScenario: '/home/ucdavis/OpenCDA/opencda/scenario_testing/scenarios/scenario_1.py' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_1.py' host: *host diff --git a/opencda/scenario_testing/config_yaml/openscenario_11.yaml b/opencda/scenario_testing/config_yaml/openscenario_11.yaml new file mode 100644 index 00000000..06f91097 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_11.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town05 + + # E.g., for the Overtake scenario + scenario: Scenario_11 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_11.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_11.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [155.0, -70.5, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 24 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_12.yaml b/opencda/scenario_testing/config_yaml/openscenario_12.yaml new file mode 100644 index 00000000..1e19066e --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_12.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town06 + + # E.g., for the Overtake scenario + scenario: Scenario_12 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_12.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_12.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [138.0, 48.8, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 25 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_13.yaml b/opencda/scenario_testing/config_yaml/openscenario_13.yaml new file mode 100644 index 00000000..98f3fc25 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_13.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town03 + + # E.g., for the Overtake scenario + scenario: Scenario_13 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_13.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_13.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [246.1, -12.3, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 25 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_14.yaml b/opencda/scenario_testing/config_yaml/openscenario_14.yaml new file mode 100644 index 00000000..12b67b84 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_14.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town06 + + # E.g., for the Overtake scenario + scenario: Scenario_14 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_14.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_14.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [290.3, 52.2, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 40 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_15.yaml b/opencda/scenario_testing/config_yaml/openscenario_15.yaml new file mode 100644 index 00000000..c284b897 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_15.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town03 + + # E.g., for the Overtake scenario + scenario: Scenario_15 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_15.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_15.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [230.1, 41.5, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 34 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_16.yaml b/opencda/scenario_testing/config_yaml/openscenario_16.yaml new file mode 100644 index 00000000..818a2c8d --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_16.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town01 + + # E.g., for the Overtake scenario + scenario: Scenario_16 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_16.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_16.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [-28.8, 300.7, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 30 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_17.yaml b/opencda/scenario_testing/config_yaml/openscenario_17.yaml new file mode 100644 index 00000000..e5d87096 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_17.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town03 + + # E.g., for the Overtake scenario + scenario: Scenario_17 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_17.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_17.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [100.0, 59.1, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 30 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_18.yaml b/opencda/scenario_testing/config_yaml/openscenario_18.yaml new file mode 100644 index 00000000..b0ecb057 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_18.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town06 + + # E.g., for the Overtake scenario + scenario: Scenario_18 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_18.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_18.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [120.2, 52.6, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 35 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_2.yaml b/opencda/scenario_testing/config_yaml/openscenario_2.yaml index 169982a9..07f7bf4d 100644 --- a/opencda/scenario_testing/config_yaml/openscenario_2.yaml +++ b/opencda/scenario_testing/config_yaml/openscenario_2.yaml @@ -17,7 +17,7 @@ scenario_runner: scenario: Scenario_2 num_actors: 2 configFile: './opencda/scenario_testing/scenarios/scenario_2.xml' - additionalScenario: '/home/ucdavis/OpenCDA/opencda/scenario_testing/scenarios/scenario_2.py' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_2.py' host: *host port: *port diff --git a/opencda/scenario_testing/config_yaml/openscenario_3.yaml b/opencda/scenario_testing/config_yaml/openscenario_3.yaml index 2e441cd2..07f0c439 100644 --- a/opencda/scenario_testing/config_yaml/openscenario_3.yaml +++ b/opencda/scenario_testing/config_yaml/openscenario_3.yaml @@ -17,7 +17,7 @@ scenario_runner: scenario: Scenario_3 num_actors: 2 configFile: './opencda/scenario_testing/scenarios/scenario_3.xml' - additionalScenario: '/home/ucdavis/OpenCDA/opencda/scenario_testing/scenarios/scenario_3.py' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_3.py' host: *host port: *port diff --git a/opencda/scenario_testing/config_yaml/openscenario_4.yaml b/opencda/scenario_testing/config_yaml/openscenario_4.yaml new file mode 100644 index 00000000..2a06fa0f --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_4.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town03 + + # E.g., for the Overtake scenario + scenario: Scenario_4 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_4.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_4.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [150.2, 3.7, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 30 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_5.yaml b/opencda/scenario_testing/config_yaml/openscenario_5.yaml new file mode 100644 index 00000000..ef8917c9 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_5.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town03 + + # E.g., for the Overtake scenario + scenario: Scenario_5 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_5.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_5.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [-121.8, 129.5, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 16 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_6.yaml b/opencda/scenario_testing/config_yaml/openscenario_6.yaml new file mode 100644 index 00000000..9c917b69 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_6.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town03 + + # E.g., for the Overtake scenario + scenario: Scenario_6 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_6.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_6.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [-28.8, 134.7, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 18 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_7.yaml b/opencda/scenario_testing/config_yaml/openscenario_7.yaml new file mode 100644 index 00000000..e227cbf2 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_7.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town01 + + # E.g., for the Overtake scenario + scenario: Scenario_7 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_7.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_7.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [-28.8, 300.7, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 25 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_8.yaml b/opencda/scenario_testing/config_yaml/openscenario_8.yaml new file mode 100644 index 00000000..e9a1b912 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_8.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town01 + + # E.g., for the Overtake scenario + scenario: Scenario_8 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_8.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_8.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [-28.8, 300.7, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 25 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/config_yaml/openscenario_9.yaml b/opencda/scenario_testing/config_yaml/openscenario_9.yaml new file mode 100644 index 00000000..38ff0a08 --- /dev/null +++ b/opencda/scenario_testing/config_yaml/openscenario_9.yaml @@ -0,0 +1,74 @@ +description: |- + Author: Wei Shao + Content: Test configurations for `openscenario_carla` that incorporates ScenarioRunner + +# Carla server settings + +world: + sync_mode: true + client_host: &host localhost + client_port: &port 2000 + +# Parameters needed for ScenarioRunner +scenario_runner: + town: town03 + + # E.g., for the Overtake scenario + scenario: Scenario_9 + num_actors: 2 + configFile: './opencda/scenario_testing/scenarios/scenario_9.xml' + additionalScenario: '/home/ucdavis/Desktop/OpenCDA/opencda/scenario_testing/scenarios/scenario_9.py' + + # The following shows how to configure a A-to-B simple scenario +# : AtoB_1 +# # Number of actors to load in, including ego and other actors +# num_actors: 1 +# +# configFile: './EIdrive/scenario_testing/scenarios/AtoB.xml' +# # Absolute path needed here +# additionalScenario: '/home/ucdavis/Desktop/EI-Drive/EIdrive/scenario_testing/scenarios/atob.py' + + host: *host + port: *port + timeout: 10 + debug: false + sync: false + repetitions: 1 + agent: null + openscenario: null + route: null + reloadWorld: false + waitForEgo: false + trafficManagerPort: '8000' + trafficManagerSeed: '0' + record: '' + agentConfig: '' + file: false + json: false + junit: false + list: false + penscenarioparams: null + output: false + outputDir: '' + randomize: false + +# Define OpenCDA scenario +scenario: + single_cav_list: + - name: cav1 + destination: [-30.2, 134.7, 0.5] + v2x: + enabled: false + behavior: + local_planner: + debug_trajectory: false + debug: false + +vehicle_base: &vehicle_base + sensing: &base_sensing +# edge: true + perception: &base_perception + lidar: # lidar sensor configuration, check CARLA sensor reference for more details + visualize: true # whether to visualize lidar points using open3d + behavior: &base_behavior + max_speed: 24 # maximum speed, 60km/h \ No newline at end of file diff --git a/opencda/scenario_testing/openscenario_11.py b/opencda/scenario_testing/openscenario_11.py new file mode 100644 index 00000000..05eeb98c --- /dev/null +++ b/opencda/scenario_testing/openscenario_11.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +from carla.libcarla import VehicleControl + +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_12.py b/opencda/scenario_testing/openscenario_12.py new file mode 100644 index 00000000..05eeb98c --- /dev/null +++ b/opencda/scenario_testing/openscenario_12.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +from carla.libcarla import VehicleControl + +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_13.py b/opencda/scenario_testing/openscenario_13.py new file mode 100644 index 00000000..05eeb98c --- /dev/null +++ b/opencda/scenario_testing/openscenario_13.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +from carla.libcarla import VehicleControl + +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_14.py b/opencda/scenario_testing/openscenario_14.py new file mode 100644 index 00000000..05eeb98c --- /dev/null +++ b/opencda/scenario_testing/openscenario_14.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +from carla.libcarla import VehicleControl + +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_15.py b/opencda/scenario_testing/openscenario_15.py new file mode 100644 index 00000000..05eeb98c --- /dev/null +++ b/opencda/scenario_testing/openscenario_15.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +from carla.libcarla import VehicleControl + +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_16.py b/opencda/scenario_testing/openscenario_16.py new file mode 100644 index 00000000..c3e3bcf3 --- /dev/null +++ b/opencda/scenario_testing/openscenario_16.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_17.py b/opencda/scenario_testing/openscenario_17.py new file mode 100644 index 00000000..2fc2e77d --- /dev/null +++ b/opencda/scenario_testing/openscenario_17.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 60 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_18.py b/opencda/scenario_testing/openscenario_18.py new file mode 100644 index 00000000..2fc2e77d --- /dev/null +++ b/opencda/scenario_testing/openscenario_18.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 60 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_4.py b/opencda/scenario_testing/openscenario_4.py new file mode 100644 index 00000000..c3e3bcf3 --- /dev/null +++ b/opencda/scenario_testing/openscenario_4.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_5.py b/opencda/scenario_testing/openscenario_5.py new file mode 100644 index 00000000..c3e3bcf3 --- /dev/null +++ b/opencda/scenario_testing/openscenario_5.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_6.py b/opencda/scenario_testing/openscenario_6.py new file mode 100644 index 00000000..c3e3bcf3 --- /dev/null +++ b/opencda/scenario_testing/openscenario_6.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_7.py b/opencda/scenario_testing/openscenario_7.py new file mode 100644 index 00000000..c3e3bcf3 --- /dev/null +++ b/opencda/scenario_testing/openscenario_7.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_8.py b/opencda/scenario_testing/openscenario_8.py new file mode 100644 index 00000000..c3e3bcf3 --- /dev/null +++ b/opencda/scenario_testing/openscenario_8.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/openscenario_9.py b/opencda/scenario_testing/openscenario_9.py new file mode 100644 index 00000000..191a558a --- /dev/null +++ b/opencda/scenario_testing/openscenario_9.py @@ -0,0 +1,119 @@ +# -*- coding: utf-8 -*- +# License: TDG-Attribution-NonCommercial-NoDistrib + +import carla + +import opencda.scenario_testing.utils.sim_api as sim_api +from opencda.core.common.cav_world import CavWorld +# from opencda.scenario_testing.utils.keyboard_listener import KeyListener + +import time +from multiprocessing import Process +import psutil + +import scenario_runner as sr + + +def exec_scenario_runner(scenario_params): + """ + Execute the ScenarioRunner process + + Parameters + ---------- + scenario_params: Parameters of ScenarioRunner + + Returns + ------- + """ + scenario_runner = sr.ScenarioRunner(scenario_params.scenario_runner) + scenario_runner.run() + scenario_runner.destroy() + + +def run_scenario(opt, scenario_params): + scenario_runner = None + cav_world = None + scenario_manager = None + + try: + # Create CAV world + cav_world = CavWorld(opt.apply_ml) + # Create scenario manager + scenario_manager = sim_api.ScenarioManager(scenario_params, + opt.apply_ml, + opt.version, + town=scenario_params.scenario_runner.town, + cav_world=cav_world) + + # Create a background process to init and execute scenario runner + sr_process = Process(target=exec_scenario_runner, + args=(scenario_params,)) + sr_process.start() + + # key_listener = KeyListener() + # key_listener.start() + + world = scenario_manager.world + ego_vehicle = None + num_actors = 0 + + while ego_vehicle is None or num_actors < scenario_params.scenario_runner.num_actors: + print("Waiting for the actors") + time.sleep(2) + vehicles = world.get_actors().filter('vehicle.*') + walkers = world.get_actors().filter('walker.*') + for vehicle in vehicles: + if vehicle.attributes['role_name'] == 'hero': + print("Ego vehicle found") + ego_vehicle = vehicle + num_actors = len(vehicles) + len(walkers) + print(f'Found all {num_actors} actors') + + single_cav_list = scenario_manager.create_vehicle_manager_from_scenario_runner( + vehicle=ego_vehicle, + ) + + spectator = ego_vehicle.get_world().get_spectator() + # Bird view following + spectator_altitude = 100 + spectator_bird_pitch = -90 + + while True: + # if key_listener.keys['esc']: + # sr_process.kill() + # # Terminate the main process + # return + # if key_listener.keys['p']: + # psutil.Process(sr_process.pid).suspend() + # continue + # if not key_listener.keys['p']: + # psutil.Process(sr_process.pid).resume() + + scenario_manager.tick() + ego_cav = single_cav_list[0].vehicle + + # Bird view following + view_transform = carla.Transform() + view_transform.location = ego_cav.get_transform().location + view_transform.location.z = view_transform.location.z + spectator_altitude + view_transform.rotation.pitch = spectator_bird_pitch + spectator.set_transform(view_transform) + + # Apply the control to the ego vehicle + for _, single_cav in enumerate(single_cav_list): + single_cav.update_info() + control = single_cav.run_step() + single_cav.vehicle.apply_control(control) + time.sleep(0.01) + + finally: + if cav_world is not None: + cav_world.destroy() + print("Destroyed cav_world") + if scenario_manager is not None: + scenario_manager.close() + print("Destroyed scenario_manager") + if scenario_runner is not None: + scenario_runner.destroy() + print("Destroyed scenario_runner") + diff --git a/opencda/scenario_testing/scenarios/scenario_11.py b/opencda/scenario_testing/scenarios/scenario_11.py new file mode 100644 index 00000000..af0dfdce --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_11.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_11(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Left Turn Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 3 + self.vehicle_01_velocity = 0 # Stopped large vehicle + self.vehicle_02_velocity = 5 # Vehicle blocked by large vehicle + self.vehicle_03_velocity = 0 # CAV + self._trigger_distance = 150 + + super(Scenario_11, self).__init__("Scenario_11", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + if i == 1: + waypoint = [carla.Location(x=142.3, y=1.9, z=0.5), carla.Location(x=149.5, y=1.9, z=0.5), + carla.Location(x=155.3, y=-4.0, z=0.5), carla.Location(x=155.0, y=-70.5, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + else: + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_11.xml b/opencda/scenario_testing/scenarios/scenario_11.xml new file mode 100644 index 00000000..62656345 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_11.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_12.py b/opencda/scenario_testing/scenarios/scenario_12.py new file mode 100644 index 00000000..f12a2505 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_12.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_12(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Left Turn Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 3 + self.vehicle_01_velocity = 0 # Stopped large vehicle + self.vehicle_02_velocity = 2 # Vehicle blocked by large vehicle + self.vehicle_03_velocity = 10 # CAV + self._trigger_distance = 150 + + super(Scenario_12, self).__init__("Scenario_12", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + if i == 1: + waypoint = [carla.Location(x=104.9, y=48.8, z=0.5), carla.Location(x=138.5, y=48.8, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + else: + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_12.xml b/opencda/scenario_testing/scenarios/scenario_12.xml new file mode 100644 index 00000000..b11e67c0 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_12.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_13.py b/opencda/scenario_testing/scenarios/scenario_13.py new file mode 100644 index 00000000..fad51c00 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_13.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_13(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Left Turn Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 6 + self.vehicle_01_velocity = 5 + self.vehicle_02_velocity = 5 + self.vehicle_03_velocity = 5 + self.vehicle_04_velocity = 5 + self.vehicle_05_velocity = 5 + self.vehicle_06_velocity = 5 + self._trigger_distance = 150 + + super(Scenario_13, self).__init__("Scenario_13", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_13.xml b/opencda/scenario_testing/scenarios/scenario_13.xml new file mode 100644 index 00000000..ba9d74ff --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_13.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_14.py b/opencda/scenario_testing/scenarios/scenario_14.py new file mode 100644 index 00000000..bd61f3ec --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_14.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_14(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Left Turn Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 5 + self.vehicle_01_velocity = 10 # Vehicle that may collide + self.vehicle_02_velocity = 10 + self.vehicle_03_velocity = 10 + self.vehicle_04_velocity = 10 + self.vehicle_05_velocity = 10 + self._trigger_distance = 150 + + super(Scenario_14, self).__init__("Scenario_14", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_14.xml b/opencda/scenario_testing/scenarios/scenario_14.xml new file mode 100644 index 00000000..250fd593 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_14.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_15.py b/opencda/scenario_testing/scenarios/scenario_15.py new file mode 100644 index 00000000..7a55b438 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_15.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_15(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Left Turn Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 2 + self.vehicle_01_velocity = 10 # Vehicle that may collide + self.vehicle_02_velocity = 10 + self._trigger_distance = 150 + + super(Scenario_15, self).__init__("Scenario_15", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + if i == 0: + waypoint = [carla.Location(x=235.6, y=-11.5, z=0.5), carla.Location(x=231.6, y=-4.0, z=0.5), + carla.Location(x=193.3, y=-1.8, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + else: + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_15.xml b/opencda/scenario_testing/scenarios/scenario_15.xml new file mode 100644 index 00000000..f6c05813 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_15.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_16.py b/opencda/scenario_testing/scenarios/scenario_16.py new file mode 100644 index 00000000..ac940a48 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_16.py @@ -0,0 +1,139 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_16(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Red-light Violation Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 2 + self.vehicle_01_velocity = 7 # Vehicle in front of ego vehicle + self.vehicle_02_velocity = 7 # CAV + self._trigger_distance = 150 + + super(Scenario_16, self).__init__("Scenario_16", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + if i == 0: + waypoint = [carla.Location(x=-1.9, y=93.8, z=0.5), carla.Location(x=3.8, y=106.8, z=0.5), + carla.Location(x=-3.9, y=113.4, z=0.5), carla.Location(x=3.8, y=130.9, z=0.5), + carla.Location(x=-1.9, y=143.9, z=0.5), carla.Location(x=-1.9, y=300.9, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + elif i == 1: + waypoint = [carla.Location(x=1.9, y=300.8, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + else: + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_16.xml b/opencda/scenario_testing/scenarios/scenario_16.xml new file mode 100644 index 00000000..9aa472d1 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_16.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_17.py b/opencda/scenario_testing/scenarios/scenario_17.py new file mode 100644 index 00000000..9d555013 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_17.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_17(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Red-light Violation Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 2 + self.vehicle_01_velocity = 0 # Vehicle in front of ego vehicle + self.vehicle_02_velocity = 2 # CAV + self._trigger_distance = 150 + + super(Scenario_17, self).__init__("Scenario_17", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_17.xml b/opencda/scenario_testing/scenarios/scenario_17.xml new file mode 100644 index 00000000..b1ebfb91 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_17.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_18.py b/opencda/scenario_testing/scenarios/scenario_18.py new file mode 100644 index 00000000..c9c4aea2 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_18.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_18(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Red-light Violation Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 2 + self.vehicle_01_velocity = 10 # Vehicle in front of ego vehicle + self.vehicle_02_velocity = 3 # CAV + self._trigger_distance = 150 + + super(Scenario_18, self).__init__("Scenario_18", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_18.xml b/opencda/scenario_testing/scenarios/scenario_18.xml new file mode 100644 index 00000000..b5141e51 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_18.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_4.py b/opencda/scenario_testing/scenarios/scenario_4.py new file mode 100644 index 00000000..ad6dc5b1 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_4.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_4(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Left Turn Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 3 + self.vehicle_01_velocity = 7 # Vehicle in front of ego vehicle + self.vehicle_02_velocity = 7 # Vehicle on the other lane + self.vehicle_03_velocity = 7 # Vehicle in front of all vehicle + self._trigger_distance = 150 + + super(Scenario_4, self).__init__("Scenario_4", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_4.xml b/opencda/scenario_testing/scenarios/scenario_4.xml new file mode 100644 index 00000000..32101242 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_4.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_5.py b/opencda/scenario_testing/scenarios/scenario_5.py new file mode 100644 index 00000000..69b435e1 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_5.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_5(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Left Turn Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 7 + self.vehicle_01_velocity = 7 # Violated vehicle + self.vehicle_02_velocity = 0 # Large vehicles from 02 to 06 + self.vehicle_03_velocity = 0 + self.vehicle_04_velocity = 0 + self.vehicle_05_velocity = 0 + self.vehicle_06_velocity = 0 + self.vehicle_07_velocity = 5 + self._trigger_distance = 150 + + super(Scenario_5, self).__init__("Scenario_5", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + if i == 0: + waypoint = [carla.Location(x=-108.6, y=129.5, z=0.5), carla.Location(x=-120.6, y=129.5, z=0.5), + carla.Location(x=-140.6, y=115.2, z=0.5), carla.Location(x=-142.0, y=87.6, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + elif i == 6: + waypoint = [carla.Location(x=-50, y=135.6, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + else: + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_5.xml b/opencda/scenario_testing/scenarios/scenario_5.xml new file mode 100644 index 00000000..e5e76e50 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_5.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_6.py b/opencda/scenario_testing/scenarios/scenario_6.py new file mode 100644 index 00000000..91bd378e --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_6.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_6(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Red-light Violation Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 7 + self.vehicle_01_velocity = 7 # Violated vehicle + self.vehicle_02_velocity = 0 # Large vehicles from 02 to 06 + self.vehicle_03_velocity = 0 + self.vehicle_04_velocity = 0 + self.vehicle_05_velocity = 0 + self.vehicle_06_velocity = 0 + self.vehicle_07_velocity = 7 + self._trigger_distance = 150 + + super(Scenario_6, self).__init__("Scenario_6", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + if i == 0: + waypoint = [carla.Location(x=-108.6, y=129.5, z=0.5), carla.Location(x=-120.6, y=129.5, z=0.5), + carla.Location(x=-140.6, y=115.2, z=0.5), carla.Location(x=-142.0, y=87.6, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + elif i == 6: + waypoint = [carla.Location(x=-122.9, y=133.2, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + else: + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_6.xml b/opencda/scenario_testing/scenarios/scenario_6.xml new file mode 100644 index 00000000..18a97999 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_6.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_7.py b/opencda/scenario_testing/scenarios/scenario_7.py new file mode 100644 index 00000000..86b1837f --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_7.py @@ -0,0 +1,139 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_7(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Red-light Violation Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 2 + self.vehicle_01_velocity = 7 # Vehicle in front of ego vehicle + self.vehicle_02_velocity = 7 # CAV + self._trigger_distance = 150 + + super(Scenario_7, self).__init__("Scenario_7", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + if i == 0: + waypoint = [carla.Location(x=-1.9, y=93.8, z=0.5), carla.Location(x=3.8, y=106.8, z=0.5), + carla.Location(x=-3.9, y=113.4, z=0.5), carla.Location(x=3.8, y=130.9, z=0.5), + carla.Location(x=-1.9, y=143.9, z=0.5), carla.Location(x=-1.9, y=300.9, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + elif i == 1: + waypoint = [carla.Location(x=1.9, y=300.8, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + else: + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_7.xml b/opencda/scenario_testing/scenarios/scenario_7.xml new file mode 100644 index 00000000..894881e3 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_7.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_8.py b/opencda/scenario_testing/scenarios/scenario_8.py new file mode 100644 index 00000000..d12a9366 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_8.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_8(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Red-light Violation Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 3 + self.vehicle_01_velocity = 7 # Vehicle in front of ego vehicle + self.vehicle_02_velocity = 7 # CAV + self.vehicle_03_velocity = 0 # Stopping vehicle + self._trigger_distance = 150 + + super(Scenario_8, self).__init__("Scenario_8", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + if i == 0: + waypoint = [carla.Location(x=-1.9, y=130, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + elif i == 1: + waypoint = [carla.Location(x=1.9, y=300.8, z=0.5)] + drive_behavior = WaypointFollower(actor, velocity, plan=waypoint) + else: + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_8.xml b/opencda/scenario_testing/scenarios/scenario_8.xml new file mode 100644 index 00000000..608328e2 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_8.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/opencda/scenario_testing/scenarios/scenario_9.py b/opencda/scenario_testing/scenarios/scenario_9.py new file mode 100644 index 00000000..d9008fce --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_9.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python + +""" +Overtake Scenario: + +The scripts simulate a scenario where an ego vehicle has to overtake a background vehicle +that is ahead of the ego vehicle and at a lower speed. There are two fearless pedestrians +that suddenly appear in front of the ego vehicle and the ego vehicle has to avoid a collision +""" + +import py_trees +import carla + +from srunner.scenariomanager.carla_data_provider import CarlaDataProvider +from srunner.scenariomanager.scenarioatomics.atomic_behaviors import (ActorTransformSetter, + WaypointFollower, + Idle) +from srunner.scenariomanager.scenarioatomics.atomic_criteria import CollisionTest +from srunner.scenariomanager.scenarioatomics.atomic_trigger_conditions import DriveDistance, InTriggerDistanceToLocation +from srunner.scenarios.basic_scenario import BasicScenario + + +class Scenario_9(BasicScenario): + """ + The class spawns two background vehicles and two pedestrians in front of the ego vehicle. + The ego vehicle is driving behind and overtaking the fast vehicle ahead + + self.other_actors[0] = fast car + self.other_actors[1] = slow car + """ + + timeout = 1200 + + def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True, + timeout=600): + """ + Setup all relevant parameters and create scenario + """ + print("Running Unprotected Left Turn Scenario") + self.timeout = timeout + self._map = CarlaDataProvider.get_map() + self._reference_waypoint = self._map.get_waypoint( + config.trigger_points[0].location) + + self.num_vehicle = 3 + self.vehicle_01_velocity = 0 # Stopped large vehicle + self.vehicle_02_velocity = 5 # Vehicle blocked by large vehicle + self.vehicle_03_velocity = 5 # CAV + self._trigger_distance = 150 + + super(Scenario_9, self).__init__("Scenario_9", + ego_vehicles, + config, + world, + debug_mode, + criteria_enable=criteria_enable) + + def _initialize_actors(self, config): + # Spawn vehicles + for actor_config in config.other_actors: + actor = CarlaDataProvider.request_new_actor( + actor_config.model, actor_config.transform) + self.other_actors.append(actor) + actor.set_simulate_physics(enabled=False) + + # Transformation that renders the vehicle visible + for i in range(self.num_vehicle): + car_transform = self.other_actors[i].get_transform() + setattr(self, f"car_0{i + 1}_visible", carla.Transform( + carla.Location(car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501), + car_transform.rotation)) + + # Trigger location for the actors + setattr(self, f"vehicle_0{i + 1}_trigger_location", carla.Location( + car_transform.location.x, + car_transform.location.y, + car_transform.location.z + 501, )) + + def _create_behavior(self): + + sequence_vehicle = [] + + # Vehicle behaviors + for i in range(self.num_vehicle): + sequence_vehicle.append(py_trees.composites.Sequence(f"Vehicle_0{i + 1}")) + trigger_location = getattr(self, f"vehicle_0{i + 1}_trigger_location") + actor = self.other_actors[i] + transform = getattr(self, f"car_0{i + 1}_visible") + velocity = getattr(self, f"vehicle_0{i + 1}_velocity") + + trigger_behavior = InTriggerDistanceToLocation(self.ego_vehicles[0], trigger_location, + self._trigger_distance) + set_transform_behavior = ActorTransformSetter(actor, transform) + drive_behavior = WaypointFollower(actor, velocity) + + sequence_vehicle[i].add_child(set_transform_behavior) + sequence_vehicle[i].add_child(trigger_behavior) + sequence_vehicle[i].add_child(drive_behavior) + sequence_vehicle[i].add_child(Idle()) + + # End condition + termination = DriveDistance(self.ego_vehicles[0], 100) + + # Build composite behavior tree + root = py_trees.composites.Parallel( + "Parallel Behavior", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE) + for i in range(self.num_vehicle): + root.add_child(sequence_vehicle[i]) + root.add_child(termination) + return root + + def _create_test_criteria(self): + """ + A list of all test criteria will be created that is later used + in parallel behavior tree. + """ + criteria = [] + + collision_criterion = CollisionTest(self.ego_vehicles[0]) + + criteria.append(collision_criterion) + + return criteria + + def __del__(self): + """ + Remove all actors upon deletion + """ + self.remove_all_actors() diff --git a/opencda/scenario_testing/scenarios/scenario_9.xml b/opencda/scenario_testing/scenarios/scenario_9.xml new file mode 100644 index 00000000..e9428a46 --- /dev/null +++ b/opencda/scenario_testing/scenarios/scenario_9.xml @@ -0,0 +1,10 @@ + + + + + + + + + +