Skip to content

Commit

Permalink
outside script added
Browse files Browse the repository at this point in the history
  • Loading branch information
DerrickXuNu committed Jun 13, 2021
1 parent 6f7cdb0 commit 474cbe9
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 98 deletions.
57 changes: 57 additions & 0 deletions opencda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
"""
Script to run different scenarios.
"""

# Author: Runsheng Xu <[email protected]>
# 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.')
3 changes: 0 additions & 3 deletions opencda/core/common/cav_world.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-

"""Platooning World Object to save all platooning-related object
"""

# Author: Runsheng Xu <[email protected]>
# License: MIT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,7 +169,7 @@ scenario:
perception:
<<: *base_perception
activate: false
camera_visualize: false
camera_visualize: true
lidar_visualize: true
localization:
<<: *base_localize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 2 additions & 17 deletions opencda/scenario_testing/platoon_joining_2lanefree_carla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -92,7 +78,6 @@ def main():
v.destroy()



if __name__ == '__main__':
try:
main()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
19 changes: 2 additions & 17 deletions opencda/scenario_testing/platoon_joining_town06_carla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
26 changes: 2 additions & 24 deletions opencda/scenario_testing/single_2lanefree_carla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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.')
19 changes: 2 additions & 17 deletions opencda/scenario_testing/single_town06_carla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 474cbe9

Please sign in to comment.