diff --git a/opencda.py b/opencda.py new file mode 100644 index 00000000..e27d2abf --- /dev/null +++ b/opencda.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +""" +Script to run different scenarios. +""" + +# Author: Runsheng Xu +# License: MIT + +import argparse +import importlib +import os +import sys + +from opencda.version import __version__ + + +def arg_parse(): + parser = argparse.ArgumentParser(description="OpenCDA scenario runner.") + parser.add_argument('-t', "--test_scenario", required=True, type=str, + help='Define the name of the scenario you want to test. The given name must' + 'match one of the testing scripts(e.g. single_2lanefree_carla) in ' + 'opencda/scenario_testing/ folder' + ' as well as the corresponding yaml file in opencda/scenario_testing/config_yaml.') + parser.add_argument("--record", action='store_true', help='whether to record and save the simulation process to' + '.log file') + parser.add_argument("--apply_ml", + action='store_true', + help='whether ml/dl framework such as sklearn/pytorch is needed in the testing. ' + 'Set it to true only when you have installed the pytorch/sklearn package.') + + opt = parser.parse_args() + return opt + + +def main(): + opt = arg_parse() + + try: + testing_scenario = importlib.import_module("opencda.scenario_testing.%s" % opt.test_scenario) + except ModuleNotFoundError: + sys.exit("ERROR: %s.py not found under opencda/scenario_testing" % opt.test_scenario) + + config_yaml = os.path.join(os.path.dirname(os.path.realpath(__file__)), + 'opencda/scenario_testing/config_yaml/%s.yaml' % opt.test_scenario) + if not os.path.isfile(config_yaml): + sys.exit("opencda/scenario_testing/config_yaml/%s.yaml not found!" % opt.test_cenario) + + scenario_runner = getattr(testing_scenario, 'run_scenario') + # run scenario testing + scenario_runner(opt, config_yaml) + + +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + print(' - Exited by user.') \ No newline at end of file diff --git a/opencda/core/common/cav_world.py b/opencda/core/common/cav_world.py index 7d1c6d14..4a28bbdf 100644 --- a/opencda/core/common/cav_world.py +++ b/opencda/core/common/cav_world.py @@ -1,8 +1,5 @@ # -*- coding: utf-8 -*- -"""Platooning World Object to save all platooning-related object -""" - # Author: Runsheng Xu # License: MIT diff --git a/opencda/scenario_testing/config_yaml/platoon_joining_2lanefree_carla.yaml b/opencda/scenario_testing/config_yaml/platoon_joining_2lanefree_carla.yaml index 562ea8ee..329e628e 100644 --- a/opencda/scenario_testing/config_yaml/platoon_joining_2lanefree_carla.yaml +++ b/opencda/scenario_testing/config_yaml/platoon_joining_2lanefree_carla.yaml @@ -124,7 +124,7 @@ scenario: perception: <<: *base_perception activate: false - camera_visualize: false + camera_visualize: true lidar_visualize: true platoon: # we need to add platoon specific params <<: *platoon_base @@ -169,7 +169,7 @@ scenario: perception: <<: *base_perception activate: false - camera_visualize: false + camera_visualize: true lidar_visualize: true localization: <<: *base_localize diff --git a/opencda/scenario_testing/config_yaml/single_2lanefree_carla.yaml b/opencda/scenario_testing/config_yaml/single_2lanefree_carla.yaml index 6091a939..c41e76b9 100644 --- a/opencda/scenario_testing/config_yaml/single_2lanefree_carla.yaml +++ b/opencda/scenario_testing/config_yaml/single_2lanefree_carla.yaml @@ -23,7 +23,7 @@ vehicle_base: &vehicle_base dropoff_zero_intensity: 0.0 noise_stddev: 0.0 localization: &base_localize - activate: false # when not activated, ego position will be retrieved from server directly + activate: true # when not activated, ego position will be retrieved from server directly gnss: # gnss sensor configuration noise_alt_stddev: 0.005 noise_lat_stddev: 2e-6 diff --git a/opencda/scenario_testing/platoon_joining_2lanefree_carla.py b/opencda/scenario_testing/platoon_joining_2lanefree_carla.py index 0ee8f0b5..94a0d271 100644 --- a/opencda/scenario_testing/platoon_joining_2lanefree_carla.py +++ b/opencda/scenario_testing/platoon_joining_2lanefree_carla.py @@ -16,24 +16,10 @@ from opencda.scenario_testing.utils.yaml_utils import load_yaml -def arg_parse(): - parser = argparse.ArgumentParser(description="Platooning Joining Settings") - parser.add_argument("--config_yaml", required=True, type=str, help='corresponding yaml file of the testing') - parser.add_argument("--record", action='store_true', help='whether to record playfile') - parser.add_argument("--apply_ml", - action='store_true', - help='whether ml/dl framework such as sklearn/pytorch is needed in the testing. ' - 'Set it to true only when you have installed the pytorch/sklearn package.') - - opt = parser.parse_args() - return opt - - -def main(): +def run_scenario(opt, config_yaml): try: # first define the path of the yaml file and 2lanefreemap file - opt = arg_parse() - scenario_params = load_yaml(opt.config_yaml) + scenario_params = load_yaml(config_yaml) current_path = os.path.dirname(os.path.realpath(__file__)) xodr_path = os.path.join(current_path, '../assets/2lane_freeway_simplified/map_v7.6_12ft_lane.xodr') @@ -92,7 +78,6 @@ def main(): v.destroy() - if __name__ == '__main__': try: main() diff --git a/opencda/scenario_testing/platoon_joining_2lanefreecomplete_carla.py b/opencda/scenario_testing/platoon_joining_2lanefreecomplete_carla.py index e5b6cdcf..cb4f7994 100644 --- a/opencda/scenario_testing/platoon_joining_2lanefreecomplete_carla.py +++ b/opencda/scenario_testing/platoon_joining_2lanefreecomplete_carla.py @@ -16,24 +16,9 @@ from opencda.scenario_testing.utils.yaml_utils import load_yaml -def arg_parse(): - parser = argparse.ArgumentParser(description="Platooning Joining Settings") - parser.add_argument("--config_yaml", required=True, type=str, help='corresponding yaml file of the testing') - parser.add_argument("--record", action='store_true', help='whether to record playfile') - parser.add_argument("--apply_ml", - action='store_true', - help='whether ml/dl framework such as sklearn/pytorch is needed in the testing. ' - 'Set it to true only when you have installed the pytorch/sklearn package.') - - opt = parser.parse_args() - return opt - - -def main(): +def run_scenario(opt, config_yaml): try: - # first define the path of the yaml file and 2lanefreemap file - opt = arg_parse() - scenario_params = load_yaml(opt.config_yaml) + scenario_params = load_yaml(config_yaml) # create simulation world simulation_config = scenario_params['world'] diff --git a/opencda/scenario_testing/platoon_joining_town06_carla.py b/opencda/scenario_testing/platoon_joining_town06_carla.py index 695ce883..770b5cc6 100644 --- a/opencda/scenario_testing/platoon_joining_town06_carla.py +++ b/opencda/scenario_testing/platoon_joining_town06_carla.py @@ -16,24 +16,9 @@ from opencda.scenario_testing.utils.yaml_utils import load_yaml -def arg_parse(): - parser = argparse.ArgumentParser(description="Platooning Joining Settings") - parser.add_argument("--config_yaml", required=True, type=str, help='corresponding yaml file of the testing') - parser.add_argument("--record", action='store_true', help='whether to record playfile') - parser.add_argument("--apply_ml", - action='store_true', - help='whether ml/dl framework such as sklearn/pytorch is needed in the testing. ' - 'Set it to true only when you have installed the pytorch/sklearn package.') - - opt = parser.parse_args() - return opt - - -def main(): +def run_scenario(opt, config_yaml): try: - # first define the path of the yaml file and 2lanefreemap file - opt = arg_parse() - scenario_params = load_yaml(opt.config_yaml) + scenario_params = load_yaml(config_yaml) # create simulation world simulation_config = scenario_params['world'] diff --git a/opencda/scenario_testing/single_2lanefree_carla.py b/opencda/scenario_testing/single_2lanefree_carla.py index b2b46efb..0eb5b32f 100644 --- a/opencda/scenario_testing/single_2lanefree_carla.py +++ b/opencda/scenario_testing/single_2lanefree_carla.py @@ -18,24 +18,9 @@ from opencda.scenario_testing.utils.yaml_utils import load_yaml -def arg_parse(): - parser = argparse.ArgumentParser(description="Platooning Joining Settings") - parser.add_argument("--config_yaml", required=True, type=str, help='corresponding yaml file of the testing') - parser.add_argument("--record", action='store_true', help='whether to record playfile') - parser.add_argument("--apply_ml", - action='store_true', - help='whether ml/dl framework such as sklearn/pytorch is needed in the testing. ' - 'Set it to true only when you have installed the pytorch/sklearn package.') - - opt = parser.parse_args() - return opt - - -def main(): +def run_scenario(opt, config_yaml): try: - # first define the path of the yaml file and 2lanefreemap file - opt = arg_parse() - scenario_params = load_yaml(opt.config_yaml) + scenario_params = load_yaml(config_yaml) current_path = os.path.dirname(os.path.realpath(__file__)) xodr_path = os.path.join(current_path, '../assets/2lane_freeway_simplified/map_v7.6_12ft_lane.xodr') @@ -79,10 +64,3 @@ def main(): v.destroy() for v in bg_veh_list: v.destroy() - - -if __name__ == '__main__': - try: - main() - except KeyboardInterrupt: - print(' - Exited by user.') diff --git a/opencda/scenario_testing/single_town06_carla.py b/opencda/scenario_testing/single_town06_carla.py index c4a16dd9..954fb513 100644 --- a/opencda/scenario_testing/single_town06_carla.py +++ b/opencda/scenario_testing/single_town06_carla.py @@ -16,24 +16,9 @@ from opencda.scenario_testing.utils.yaml_utils import load_yaml -def arg_parse(): - parser = argparse.ArgumentParser(description="Platooning Joining Settings") - parser.add_argument("--config_yaml", required=True, type=str, help='corresponding yaml file of the testing') - parser.add_argument("--record", action='store_true', help='whether to record playfile') - parser.add_argument("--apply_ml", - action='store_true', - help='whether ml/dl framework such as sklearn/pytorch is needed in the testing. ' - 'Set it to true only when you have installed the pytorch/sklearn package.') - - opt = parser.parse_args() - return opt - - -def main(): +def run_scenario(opt, config_yaml): try: - # first define the path of the yaml file and 2lanefreemap file - opt = arg_parse() - scenario_params = load_yaml(opt.config_yaml) + scenario_params = load_yaml(config_yaml) # create simulation world simulation_config = scenario_params['world']