def main(): arguments = specify_args() arguments.debug = True statistics_manager = StatisticsManager() # Fixed Hyperparameters # if use_actors = False, no other actors will be generated use_actors = False using_customized_route_and_scenario = True multi_actors_scenarios = ['Scenario12'] arguments.scenarios = 'leaderboard/data/fuzzing_scenarios.json' town_name = 'Town03' scenario = 'Scenario12' direction = 'front' route = 0 # sample_factor is an integer between [1, 5] sample_factor = 5 # waypoints_num_limit: the maximum number of waypoints that we consider to perturb. waypoints_num_limit = 10 # lane_width = 3.5 max_num_of_vehicle = 2 max_num_of_pedestrians = 2 # Parameters to optimize # Set up environment parameters # real, [0, 1] friction = 0.1 # integer, [0, 20] weather_index = 2 # Laundry Stuff------------------------------------------------------------- arguments.weather_index = weather_index os.environ['WEATHER_INDEX'] = str(weather_index) town_scenario_direction = town_name + '/' + scenario folders = [os.environ['SAVE_FOLDER'], town_name, scenario] if scenario in multi_actors_scenarios: town_scenario_direction += '/' + direction folders.append(direction) cur_folder_name = make_hierarchical_dir(folders) os.environ['SAVE_FOLDER'] = cur_folder_name arguments.save_folder = os.environ['SAVE_FOLDER'] route_prefix = 'leaderboard/data/customized_routes/' + town_scenario_direction + '/route_' route_str = str(route) if route < 10: route_str = '0' + route_str arguments.routes = route_prefix + route_str + '.xml' os.environ['ROUTES'] = arguments.routes # extract waypoints along route import xml.etree.ElementTree as ET tree = ET.parse(arguments.routes) route_waypoints = [] # this iteration should only go once since we only keep one route per file for route in tree.iter("route"): route_id = route.attrib['id'] route_town = route.attrib['town'] for waypoint in route.iter('waypoint'): route_waypoints.append( carla.Transform( carla.Location(x=float(waypoint.attrib['x']), y=float(waypoint.attrib['y']), z=float(waypoint.attrib['z'])), carla.Rotation(float(waypoint.attrib['pitch']), float(waypoint.attrib['yaw']), float(waypoint.attrib['roll'])))) # extract waypoints for the scenario world_annotations = RouteParser.parse_annotations_file(arguments.scenarios) info = world_annotations[town_name][0]["available_event_configurations"][0] center = info["center"] RouteParser.convert_waypoint_float(center) center_location = carla.Location(float(center['x']), float(center['y']), float(center['z'])) center_rotation = carla.Rotation(float(center['pitch']), float(center['yaw']), 0.0) center_transform = carla.Transform(center_location, center_rotation) # -------------------------------------------------------------------------- if use_actors: # Set up actors # ego car ego_car_waypoints_perturbation = [] for i in range(waypoints_num_limit): dx = np.clip(np.random.normal(0, 2, 1)[0], -0.5, 0.5) dy = np.clip(np.random.normal(0, 2, 1)[0], -0.5, 0.5) ego_car_waypoints_perturbation.append((dx, dy)) # static static_1_transform = center_transform static_1 = Static(model='static.prop.barrel', spawn_transform=static_1_transform) static_list = [static_1] # pedestrians pedestrian_1_transform = create_transform( route_waypoints[0].location.x - 2, route_waypoints[0].location.y - 8, 0, 0, route_waypoints[0].rotation.yaw, 0) pedestrian_1 = Pedestrian(model='walker.pedestrian.0001', spawn_transform=pedestrian_1_transform, trigger_distance=20, speed=1.5, dist_to_travel=6, after_trigger_behavior='stop') pedestrian_list = [pedestrian_1] # vehicles waypoint_follower = True vehicle_1_transform = create_transform( route_waypoints[1].location.x, route_waypoints[1].location.y - 5, 0, 0, route_waypoints[1].rotation.yaw, 0) # if waypoint_follower == False vehicle_1_dist_to_travel = 5 vehicle_1_target_direction = carla.Vector3D(x=0.2, y=1, z=0) # else targeted_waypoint = create_transform( route_waypoints[1].location.x, route_waypoints[1].location.y - 40, 0, 0, route_waypoints[1].rotation.yaw, 0) # targeted_waypoint = route_waypoints[-1] vehicle_1_waypoints_perturbation = [] for i in range(waypoints_num_limit): dx = np.clip(np.random.normal(0, 2, 1)[0], -0.5, 0.5) dy = np.clip(np.random.normal(0, 2, 1)[0], -0.5, 0.5) vehicle_1_waypoints_perturbation.append((dx, dy)) vehicle_1 = Vehicle( model='vehicle.audi.a2', spawn_transform=vehicle_1_transform, avoid_collision=True, initial_speed=0, trigger_distance=10, waypoint_follower=waypoint_follower, targeted_waypoint=targeted_waypoint, dist_to_travel=vehicle_1_dist_to_travel, target_direction=vehicle_1_target_direction, targeted_speed=10, after_trigger_behavior='stop', color='(0, 0, 0)', waypoints_perturbation=vehicle_1_waypoints_perturbation) vehicle_list = [vehicle_1] else: static_list = [] pedestrian_list = [] vehicle_list = [] ego_car_waypoints_perturbation = [] customized_data = { 'friction': friction, 'static_list': static_list, 'pedestrian_list': pedestrian_list, 'vehicle_list': vehicle_list, 'center_transform': center_transform, 'using_customized_route_and_scenario': True, 'destination': route_waypoints[-1].location, 'sample_factor': sample_factor, 'ego_car_waypoints_perturbation': ego_car_waypoints_perturbation } try: leaderboard_evaluator = LeaderboardEvaluator(arguments, statistics_manager) leaderboard_evaluator.run(arguments, customized_data) except Exception as e: traceback.print_exc() finally: del leaderboard_evaluator