def make_carla_settings(): """Make a CarlaSettings object with the settings we need.""" settings = CarlaSettings() settings.set(SynchronousMode=False, SendNonPlayerAgentsInfo=True, NumberOfVehicles=15, NumberOfPedestrians=30, WeatherId=random.choice([1, 3, 7, 8, 14])) settings.randomize_seeds() camera0 = sensor.Camera('CameraRGB') camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT) camera0.set_position(200, 0, 140) camera0.set_rotation(0.0, 0.0, 0.0) settings.add_sensor(camera0) camera1 = sensor.Camera('CameraDepth', PostProcessing='Depth') camera1.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT) camera1.set_position(200, 0, 140) camera1.set_rotation(0.0, 0.0, 0.0) settings.add_sensor(camera1) camera2 = sensor.Camera('CameraSemSeg', PostProcessing='SemanticSegmentation') camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT) camera2.set_position(200, 0, 140) camera2.set_rotation(0.0, 0.0, 0.0) settings.add_sensor(camera2) return settings
def run_driving_benchmark(agent, experiment_suite, city_name='Town01', log_name='Test', continue_experiment=False, host='127.0.0.1', port=2000): while True: try: with make_carla_client(host, port) as client: # Hack to fix for the issue 310, we force a reset, so it does not get # the positions on first server reset. client.load_settings(CarlaSettings()) client.start_episode(0) # We instantiate the driving benchmark, that is the engine used to # benchmark an agent. The instantiation starts the log process, sets benchmark = DrivingBenchmark( city_name=city_name, name_to_save=log_name + '_' + type(experiment_suite).__name__ + '_' + city_name, continue_experiment=continue_experiment) # This function performs the benchmark. It returns a dictionary summarizing # the entire execution. benchmark_summary = benchmark.benchmark_agent( experiment_suite, agent, client) print("") print("") print( "----- Printing results for training weathers (Seen in Training) -----" ) print("") print("") av = results_printer.print_summary( benchmark_summary, experiment_suite.train_weathers, benchmark.get_path()) open( '/home/rsi/Desktop/CAL/PythonClient/_benchmarks_results/' + log_name + '_av_succ_' + str(av) + '.txt', 'w') print("") print("") print( "----- Printing results for test weathers (Unseen in Training) -----" ) print("") print("") results_printer.print_summary(benchmark_summary, experiment_suite.test_weathers, benchmark.get_path()) break except TCPConnectionError as error: logging.error(error) time.sleep(2)
def carla_settings(self): settings = CarlaSettings() settings.set(SynchronousMode=False, SendNonPlayerAgentsInfo=False, NumberOfVehicles=0, NumberOfPedestrians=0, WeatherId=0) settings.randomize_seeds() camera0 = sensor.Camera('CameraCenter') camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT) camera0.set_position(200, 0, 140) camera0.set_rotation(0.0, 0.0, 0.0) settings.add_sensor(camera0) camera1 = sensor.Camera('CameraLeft') camera1.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT) camera1.set_position(200, 0, 140) camera1.set_rotation(0.0, 0.0, -30.0) settings.add_sensor(camera1) camera2 = sensor.Camera('CameraRight') camera2.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT) camera2.set_position(200, 0, 140) camera2.set_rotation(0.0, 0.0, 30.0) settings.add_sensor(camera2) if self.map_view is not None: camera3 = sensor.Camera('TPPCamera') camera3.set_image_size(self.map_view.shape[1], WINDOW_HEIGHT // 2) camera3.set_position(-450, 0, 400) camera3.set_rotation(-30.0, 0.0, 0.0) settings.add_sensor(camera3) self.settings = settings
def _reset(self): self.num_steps = 0 self.total_reward = 0 self.prev_measurement = None self.prev_image = None self.episode_id = datetime.today().strftime("%Y-%m-%d_%H-%M-%S_%f") self.measurements_file = None # Create a CarlaSettings object. This object is a wrapper around # the CarlaSettings.ini file. Here we set the configuration we # want for the new episode. settings = CarlaSettings() self.scenario = random.choice(self.config["scenarios"]) assert self.scenario["city"] == self.city, (self.scenario, self.city) self.weather = random.choice(self.scenario["weather_distribution"]) settings.set(SynchronousMode=True, SendNonPlayerAgentsInfo=True, NumberOfVehicles=self.scenario["num_vehicles"], NumberOfPedestrians=self.scenario["num_pedestrians"], WeatherId=self.weather) settings.randomize_seeds() if self.config["use_depth_camera"]: camera1 = Camera("CameraDepth", PostProcessing="Depth") camera1.set_image_size(self.config["render_x_res"], self.config["render_y_res"]) camera1.set_position(0.1, 0, 1.7) settings.add_sensor(camera1) camera2 = Camera("CameraRGB") camera2.set_image_size(self.config["render_x_res"], self.config["render_y_res"]) camera2.set_position(0.1, 0, 1.7) settings.add_sensor(camera2) # Setup start and end positions scene = self.client.load_settings(settings) positions = scene.player_start_spots self.start_pos = positions[self.scenario["start_pos_id"]] self.end_pos = positions[self.scenario["end_pos_id"]] self.start_coord = [ self.start_pos.location.x // 100, self.start_pos.location.y // 100 ] self.end_coord = [ self.end_pos.location.x // 100, self.end_pos.location.y // 100 ] print("Start pos {} ({}), end {} ({})".format( self.scenario["start_pos_id"], self.start_coord, self.scenario["end_pos_id"], self.end_coord)) # Notify the server that we want to start the episode at the # player_start index. This function blocks until the server is ready # to start the episode. print("Starting new episode...") self.client.start_episode(self.scenario["start_pos_id"]) image, py_measurements = self._read_observation() self.prev_measurement = py_measurements return self.encode_obs(self.preprocess_image(image), py_measurements)
def get_default_carla_settings(args): settings = CarlaSettings(SynchronousMode=args.synchronous, SendNonPlayerAgentsInfo=False, NumberOfVehicles=20, NumberOfPedestrians=40, WeatherId=1) settings.add_sensor(Camera('Camera1')) return str(settings)
def run(self): settings = CarlaSettings() settings.set(SynchronousMode=True, SendNonPlayerAgentsInfo=True, NumberOfVehicles=60, NumberOfPedestrians=90) settings.add_sensor(Camera('DefaultCamera')) self.run_carla_client(settings, 3, 100)
def run(self): settings = CarlaSettings(QualityLevel='Low') settings.add_sensor(Lidar('DefaultLidar')) settings.add_sensor(Camera('DefaultCamera')) settings.add_sensor(Camera('DefaultDepth', PostProcessing='Depth')) settings.add_sensor( Camera('DefaultSemSeg', PostProcessing='SemanticSegmentation')) self.run_carla_client(settings, 3, 200)
def run(self): settings = CarlaSettings() settings.add_sensor(Camera('DefaultCamera')) camera2 = Camera('Camera2') camera2.set(PostProcessing='Depth', CameraFOV=120) camera2.set_image_size(1924, 1028) settings.add_sensor(camera2) self.run_carla_client(settings, 3, 100)
def build_experiments(self): """ Creates the whole set of experiment objects, The experiments created depend on the selected Town. """ # We set the camera # This single RGB camera is used on every experiment camera = Camera('CameraRGB') camera.set(FOV=90) camera.set_image_size(800, 600) camera.set_position(1.44, 0.0, 1.2) camera.set_rotation(0, 0, 0) if self._city_name == 'Town01': poses_tasks = self._poses_town01() vehicles_tasks = [0, 20, 100] pedestrians_tasks = [0, 50, 250] else: poses_tasks = self._poses_town02() vehicles_tasks = [0, 15, 70] pedestrians_tasks = [0, 50, 150] experiments_vector = [] for weather in self.weathers: for iteration in range(len(poses_tasks)): poses = poses_tasks[iteration] vehicles = vehicles_tasks[iteration] pedestrians = pedestrians_tasks[iteration] conditions = CarlaSettings() conditions.set( SendNonPlayerAgentsInfo=True, NumberOfVehicles=vehicles, NumberOfPedestrians=pedestrians, WeatherId=weather ) conditions.set(DisableTwoWheeledVehicles=True) # Add all the cameras that were set for this experiments conditions.add_sensor(camera) experiment = Experiment() experiment.set( Conditions=conditions, Poses=poses, Task=iteration, Repetitions=1 ) experiments_vector.append(experiment) return experiments_vector
def view_start_positions(args): # We assume the CARLA server is already waiting for a client to connect at # host:port. The same way as in the client example. with make_carla_client(args.host, args.port) as client: print('CarlaClient connected') # We load the default settings to the client. scene = client.load_settings(CarlaSettings()) print("Received the start positions") # We get the number of player starts, in order to detect the city. number_of_player_starts = len(scene.player_start_spots) if number_of_player_starts > 100: # WARNING: unsafe way to check for city, see issue #313 image = mpimg.imread("carla/planner/Town01.png") carla_map = CarlaMap('Town01', 0.1653, 50) else: image = mpimg.imread("carla/planner/Town02.png") carla_map = CarlaMap('Town02', 0.1653, 50) fig, ax = plt.subplots(1) ax.imshow(image) if args.positions == 'all': positions_to_plot = range(len(scene.player_start_spots)) else: positions_to_plot = map(int, args.positions.split(',')) for position in positions_to_plot: # Check if position is valid if position >= len(scene.player_start_spots): raise RuntimeError('Selected position is invalid') # Convert world to pixel coordinates pixel = carla_map.convert_to_pixel([ scene.player_start_spots[position].location.x, scene.player_start_spots[position].location.y, scene.player_start_spots[position].location.z ]) circle = Circle((pixel[0], pixel[1]), 12, color='r', label='A point') ax.add_patch(circle) if not args.no_labels: plt.text(pixel[0], pixel[1], str(position), size='x-small') plt.axis('off') plt.show() fig.savefig('town_positions.pdf', orientation='landscape', bbox_inches='tight')
def make_base_settings(): return CarlaSettings(WeatherId=1, SendNonPlayerAgentsInfo=False, SynchronousMode=False, NumberOfVehicles=20, NumberOfPedestrians=30, SeedVehicles=123456789, SeedPedestrians=123456789, QualityLevel='Epic')
def build_experiments(self): """ Creates the whole set of experiment objects, The experiments created depends on the selected Town. """ # We check the town, based on that we define the town related parameters # The size of the vector is related to the number of tasks, inside each # task there is also multiple poses ( start end, positions ) if self._city_name == 'Town01': poses_tasks = [[[7, 3]], [[138, 17]], [[140, 134]], [[140, 134]]] vehicles_tasks = [0, 0, 0, 20] pedestrians_tasks = [0, 0, 0, 50] else: poses_tasks = [[[4, 2]], [[37, 76]], [[19, 66]], [[19, 66]]] vehicles_tasks = [0, 0, 0, 15] pedestrians_tasks = [0, 0, 0, 50] # We set the camera # This single RGB camera is used on every experiment camera = Camera('CameraRGB') camera.set(FOV=100) camera.set_image_size(800, 600) camera.set_position(2.0, 0.0, 1.4) camera.set_rotation(-15.0, 0, 0) # Based on the parameters, creates a vector with experiment objects. experiments_vector = [] for weather in self.weathers: for iteration in range(len(poses_tasks)): poses = poses_tasks[iteration] vehicles = vehicles_tasks[iteration] pedestrians = pedestrians_tasks[iteration] conditions = CarlaSettings() conditions.set( SendNonPlayerAgentsInfo=True, NumberOfVehicles=vehicles, NumberOfPedestrians=pedestrians, WeatherId=weather ) # Add all the cameras that were set for this experiments conditions.add_sensor(camera) experiment = Experiment() experiment.set( Conditions=conditions, Poses=poses, Task=iteration, Repetitions=1 ) experiments_vector.append(experiment) return experiments_vector
def _build_experiments(self): """ Creates the whole set of experiment objects, The experiments created depend on the selected Town. """ # We set the camera # This single RGB camera is used on every experiment camera = Camera('CameraRGB') camera.set(FOV=100) camera.set_image_size(800, 600) camera.set_position(200, 0, 140) camera.set_rotation(-15.0, 0, 0) weathers = [1, 3, 6, 8, 4, 14] if self._city_name == 'Town01': poses_tasks = self._poses_town01() vehicles_tasks = [0, 0, 0, 20] pedestrians_tasks = [0, 0, 0, 50] else: poses_tasks = self._poses_town02() vehicles_tasks = [0, 0, 0, 15] pedestrians_tasks = [0, 0, 0, 50] experiments_vector = [] for weather in weathers: for iteration in range(len(poses_tasks)): poses = poses_tasks[iteration] vehicles = vehicles_tasks[iteration] pedestrians = pedestrians_tasks[iteration] conditions = CarlaSettings() conditions.set(SynchronousMode=True, SendNonPlayerAgentsInfo=True, NumberOfVehicles=vehicles, NumberOfPedestrians=pedestrians, WeatherId=weather, SeedVehicles=123456789, SeedPedestrians=123456789) # Add all the cameras that were set for this experiments conditions.add_sensor(camera) experiment = Experiment() experiment.set(Conditions=conditions, Poses=poses, Id=iteration, Repetitions=1) experiments_vector.append(experiment) return experiments_vector
def reset(self): """ :return: """ settings = CarlaSettings() settings.set(SynchronousMode=True, SendNonPlayerAgentsInfo=True, NumberOfVehicles=20, NumberOfPedestrians=40, WeatherId=random.choice([1, 3, 7, 8, 14]), QualityLevel='Epic') # CAMERA camera0 = Camera('CameraRGB', PostProcessing='SceneFinal') # Set image resolution in pixels. camera0.set_image_size(800, 600) # Set its position relative to the car in meters. camera0.set_position(0.30, 0, 1.30) settings.add_sensor(camera0) # Let's add another camera producing ground-truth depth. # camera1 = Camera('CameraDepth', PostProcessing='Depth') # camera1.set_image_size(800, 600) # camera1.set_position(0.30, 0, 1.30) # settings.add_sensor(camera1) # LIDAR # lidar = Lidar('Lidar32') # lidar.set_position(0, 0, 2.50) # lidar.set_rotation(0, 0, 0) # lidar.set( # Channels=32, # Range=50, # PointsPerSecond=100000, # RotationFrequency=10, # UpperFovLimit=10, # LowerFovLimit=-30) # settings.add_sensor(lidar) scene = self.carla_client.load_settings(settings) self.pre_image = None self.cur_image = None self.pre_measurements = None self.cur_measurements = None # define a random starting point of the agent for the appropriate trainning number_of_player_starts = len(scene.player_start_spots) player_start = random.randint(0, max(0, number_of_player_starts - 1)) # player_start = 140 self.carla_client.start_episode(player_start) print('Starting new episode at %r, %d...' % (scene.map_name, player_start)) # TODO: read and return status after reset return
def view_start_positions(args): # We assume the CARLA server is already waiting for a client to connect at # host:port. The same way as in the client example. with make_carla_client(args.host, args.port) as client: print('CarlaClient connected') # We load the default settings to the client. scene = client.load_settings(CarlaSettings()) print("Received the start positions") try: print(scene.map_name) image = mpimg.imread('./environment/%s.png' % scene.map_name) carla_map = CarlaMap(scene.map_name, 0.1653, 50) except IOError as exception: logging.error(exception) logging.error('Cannot find map "%s"', scene.map_name) sys.exit(1) fig, ax = plt.subplots(1) ax.imshow(image) if args.positions == 'all': positions_to_plot = range(len(scene.player_start_spots)) else: positions_to_plot = map(int, args.positions.split(',')) for position in positions_to_plot: # Check if position is valid if position >= len(scene.player_start_spots): raise RuntimeError('Selected position is invalid') # Convert world to pixel coordinates pixel = carla_map.convert_to_pixel([ scene.player_start_spots[position].location.x, scene.player_start_spots[position].location.y, scene.player_start_spots[position].location.z ]) circle = Circle((pixel[0], pixel[1]), 12, color='r', label='A point') ax.add_patch(circle) if not args.no_labels: plt.text(pixel[0], pixel[1], str(position), size='x-small') plt.axis('off') plt.show() fig.savefig('town_positions.pdf', orientation='landscape', bbox_inches='tight')
def build_experiments(self): """ Creates the whole set of experiment objects, The experiments created depend on the selected Town. """ # We set the camera # This single RGB camera is used on every experiment camera = Camera('CameraRGB') camera.set(FOV=100) camera.set_image_size(800, 600) camera.set_position(2.0, 0.0, 1.4) camera.set_rotation(-15.0, 0, 0) if self._city_name == 'Town01': poses_tasks = self._poses_town01() vehicles_tasks = [25] pedestrians_tasks = [25] else: poses_tasks = self._poses_town02() vehicles_tasks = [0, 25] pedestrians_tasks = [0, 25] experiments_vector = [] #weathers = [1,3,6,8] for weather in self.weathers: #prinst(weather , vehicles_tasks) for scenario in range(len(vehicles_tasks)): for iteration in range(len(poses_tasks)): #print(f"interation : {iteration} , scenario:{scenario}") poses = poses_tasks[iteration] #print("poses re",poses) vehicles = vehicles_tasks[scenario] #print("Vehicles: ",vehicles) pedestrians = pedestrians_tasks[scenario] #print("pedestrians: ",pedestrians) conditions = CarlaSettings() conditions.set(SendNonPlayerAgentsInfo=True, NumberOfVehicles=vehicles, NumberOfPedestrians=pedestrians, WeatherId=weather) # Add all the cameras that were set for this experiments conditions.add_sensor(camera) experiment = Experiment() experiment.set(Conditions=conditions, Poses=poses, Task=iteration, Repetitions=1) experiments_vector.append(experiment) return experiments_vector
def generate_settings(args, sync_mode=True): settings = CarlaSettings() settings.set(SynchronousMode=sync_mode, SendNonPlayerAgentsInfo=False, NumberOfVehicles=0, NumberOfPedestrians=0, WeatherId=args.weather, QualityLevel=args.quality_level) settings.randomize_seeds() return settings
def make_carla_settings(args): """Make a CarlaSettings object with the settings we need.""" settings = CarlaSettings() settings.set(SynchronousMode=False, SendNonPlayerAgentsInfo=False, NumberOfVehicles=0, NumberOfPedestrians=0, WeatherId=random.choice([1, 3, 7, 8, 14]), QualityLevel=args.quality_level) settings.randomize_seeds() return settings
def build_experiments(self): """ Creates the whole set of experiment objects, The experiments created depend on the selected Town. """ # We set the camera # This single RGB camera is used on every experiment camera = Camera('rgb') camera.set(FOV=90) camera.set_image_size(300, 300) camera.set_position(0.2, 0.0, 0.85) camera.set_rotation(-3.0, 0, 0) poses_tasks = self._poses() vehicles_tasks = [0, 0, 0, 15] pedestrians_tasks = [0, 0, 0, 50] experiments_vector = [] for weather in self.weathers: for iteration in range(len(poses_tasks)): poses = poses_tasks[iteration] vehicles = vehicles_tasks[iteration] pedestrians = pedestrians_tasks[iteration] conditions = CarlaSettings() conditions.set( SendNonPlayerAgentsInfo=True, NumberOfVehicles=vehicles, NumberOfPedestrians=pedestrians, WeatherId=weather, QualityLevel='Epic' ) # Add all the cameras that were set for this experiments conditions.add_sensor(camera) experiment = Experiment() experiment.set( Conditions=conditions, Poses=poses, Task=iteration, Repetitions=1 ) experiments_vector.append(experiment) return experiments_vector
def make_carla_settings(args): """Make a CarlaSettings object with the settings we need.""" settings = CarlaSettings() settings.set(SynchronousMode=True, SendNonPlayerAgentsInfo=True, NumberOfVehicles=0, NumberOfPedestrians=0, SeedVehicles='00000', WeatherId=1, QualityLevel=args.quality_level) settings.randomize_seeds() return settings
def __init__(self, client, frame_skip=1, cam_width=800, cam_height=600, town_string='Town01'): super(StraightDriveEnv, self).__init__() self.frame_skip = frame_skip self.client = client self._planner = Planner(town_string) camera0 = Camera('CameraRGB') camera0.set(CameraFOV=100) camera0.set_image_size(cam_height, cam_width) camera0.set_position(200, 0, 140) camera0.set_rotation(-15.0, 0, 0) self.start_goal_pairs = [[36, 40], [39, 35], [110, 114], [7, 3], [0, 4], [68, 50], [61, 59], [47, 64], [147, 90], [33, 87], [26, 19], [80, 76], [45, 49], [55, 44], [29, 107], [95, 104], [84, 34], [53, 67], [22, 17], [91, 148], [20, 107], [78, 70], [95, 102], [68, 44], [45, 69]] vehicles = 0 pedestrians = 0 weather = 1 settings = CarlaSettings() settings.set( SynchronousMode=True, SendNonPlayerAgentsInfo=True, NumberOfVehicles=vehicles, NumberOfPedestrians=pedestrians, WeatherId=weather, ) settings.randomize_seeds() settings.add_sensor(camera0) self.scene = self.client.load_settings(settings) img_shape = (cam_width, cam_height, 3) self.observation_space = spaces.Tuple( (spaces.Box(-np.inf, np.inf, (3, )), spaces.Box(0, 255, img_shape))) self.action_space = spaces.Box(-np.inf, np.inf, shape=(3, )) self.prev_state = np.array([0., 0., 0.]) self.prev_collisions = np.array([0., 0., 0.]) self.prev_intersections = np.array([0., 0.])
def setup_carla_client(self, client, params): self.client = client self.param_sensors = params.get('sensors', {}) self.carla_settings = CarlaSettings() self.carla_settings.set( SendNonPlayerAgentsInfo=params.get('SendNonPlayerAgentsInfo', True), NumberOfVehicles=params.get('NumberOfVehicles', 20), NumberOfPedestrians=params.get('NumberOfPedestrians', 40), WeatherId=params.get('WeatherId', random.choice([1, 3, 7, 8, 14])), SynchronousMode=params.get('SynchronousMode', True), QualityLevel=params.get('QualityLevel', 'Low')) self.carla_settings.randomize_seeds()
def reset(self): # connect to server self._client = CarlaClient(self._host, self._port, self._timeout) self._client.connect() # settings index = random.randint(0, 4) # Last one is for testing # print(index) # index = 0 seed = npc_vehicle_seeds[index] start_list_index = start_list_indices[index] settings = CarlaSettings() settings.set(SynchronousMode=True, SendNonPlayerAgentsInfo=True, NumberOfVehicles=1, NumberOfPedestrians=0, SeedVehicles=seed, SeedPedestrians=123456789, WeatherId=weathers[index]) self._client.load_settings(settings) self._client.start_episode(start_list_index) # simulator init stage for i in range(10): measurements, _ = self._client.read_data() self._client.send_control(steer=0, throttle=0, brake=0, hand_brake=False, reverse=False) self._client.send_control(steer=0, throttle=0, brake=0, hand_brake=False, reverse=False) # Reset Flags self._reset = True self._history_path = np.zeros([self._history_path_num, 4]) self._cur_steer = 0 self._his_steer = 0 observation = self._observe() self._observation = observation return observation
def make_carla_settings(args): """Make a CarlaSettings object with the settings we need.""" settings = CarlaSettings() settings.set( SynchronousMode=False, SendNonPlayerAgentsInfo=True, NumberOfVehicles=NUM_VEHICLES, NumberOfPedestrians=NUM_PEDESTRIANS, DisableTwoWheeledVehicles=NO_BIKE, # WeatherId=random.choice([1, 3, 7, 8, 14]), WeatherId=1, QualityLevel=args.quality_level) settings.randomize_seeds() camera0 = sensor.Camera('CameraRGB') camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT) camera0.set_position(0, 0.0, CAMERA_HEIGHT_POS) camera0.set_rotation(0.0, 0.0, 0.0) settings.add_sensor(camera0) lidar = sensor.Lidar('Lidar32') lidar.set_position(0, 0.0, LIDAR_HEIGHT_POS) lidar.set_rotation(0, 0, 0) lidar.set(Channels=40, Range=MAX_RENDER_DEPTH_IN_METERS, PointsPerSecond=720000, RotationFrequency=10, UpperFovLimit=7, LowerFovLimit=-16) settings.add_sensor(lidar) """ Depth camera for filtering out occluded vehicles """ depth_camera = sensor.Camera('DepthCamera', PostProcessing='Depth') depth_camera.set(FOV=90.0) depth_camera.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT) depth_camera.set_position(0, 0, CAMERA_HEIGHT_POS) depth_camera.set_rotation(0, 0, 0) settings.add_sensor(depth_camera) # (Intrinsic) K Matrix # | f 0 Cu # | 0 f Cv # | 0 0 1 # (Cu, Cv) is center of image k = np.identity(3) k[0, 2] = WINDOW_WIDTH_HALF k[1, 2] = WINDOW_HEIGHT_HALF f = WINDOW_WIDTH / \ (2.0 * math.tan(90.0 * math.pi / 360.0)) k[0, 0] = k[1, 1] = f camera_to_car_transform = camera0.get_unreal_transform() lidar_to_car_transform = lidar.get_transform() * Transform( Rotation(yaw=90), Scale(z=-1)) return settings, k, camera_to_car_transform, lidar_to_car_transform
def make_carla_settings(): """ Make a CarlaSettings object with the settings we need. Sets exactly three vehicles and pedestrians, with random weather conditions. """ settings = CarlaSettings() settings.set( SynchronousMode=False, SendNonPlayerAgentsInfo=True, NumberOfVehicles=3, NumberOfPedestrians=3, WeatherId=random.choice([1, 3, 7, 8, 14]), QualityLevel=QUALITY_LEVEL) return settings
def make_carla_settings(): """Make a CarlaSettings object with the settings we need.""" settings = CarlaSettings() settings.set( SendNonPlayerAgentsInfo=True, SynchronousMode=True, NumberOfVehicles=30, NumberOfPedestrians=50, WeatherId=1) settings.set(DisableTwoWheeledVehicles=True) # --------------------------- CENTRAL CAMERA --------------------------- settings.randomize_seeds() # IMPORTANT TO RANDOMIZE THE SEEDS EVERY TIME camera0 = sensor.Camera('CentralSemanticSeg', PostProcessing='SemanticSegmentation') camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT) camera0.set(FOV=FOV) camera0.set_position(2.0, 0.0, 1.4) camera0.set_rotation(-15.0, 0, 0) settings.add_sensor(camera0) camera0 = sensor.Camera('CentralRGB') camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT) camera0.set(FOV=FOV) camera0.set_position(2.0, 0.0, 1.4) camera0.set_rotation(-15.0, 0, 0) settings.add_sensor(camera0) # --------------------------- TOP CAMERA --------------------------- camera0 = sensor.Camera('TopSemanticSeg', PostProcessing='SemanticSegmentation') camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT) camera0.set(FOV=FOV) camera0.set_position(12.0, 0.0, 15.0) camera0.set_rotation(-90.0, 90.0, -90.0) settings.add_sensor(camera0) camera0 = sensor.Camera('TopRGB') camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT) camera0.set(FOV=FOV) camera0.set_position(12.0, 0.0, 15.0) camera0.set_rotation(-90.0, 90.0, -90.0) settings.add_sensor(camera0) return settings
def _reset(self): self.num_steps = 0 self.prev_measurement = None self.episode_id = datetime.today().strftime("%Y-%m-%d_%H-%M-%S_%f") self.measurements_file = None # Create a CarlaSettings object. This object is a wrapper around # the CarlaSettings.ini file. Here we set the configuration we # want for the new episode. settings = CarlaSettings() self.weather = random.choice(self.config["weather"]) settings.set(SynchronousMode=True, SendNonPlayerAgentsInfo=True, NumberOfVehicles=self.config["num_vehicles"], NumberOfPedestrians=self.config["num_pedestrians"], WeatherId=self.weather) settings.randomize_seeds() camera1 = Camera("CameraDepth", PostProcessing="Depth") camera1.set_image_size(self.config["render_x_res"], self.config["render_y_res"]) camera1.set_position(30, 0, 130) settings.add_sensor(camera1) camera2 = Camera("CameraRGB") camera2.set_image_size(self.config["render_x_res"], self.config["render_y_res"]) camera2.set_position(30, 0, 130) settings.add_sensor(camera2) scene = self.client.load_settings(settings) # Choose one player start at random. number_of_player_starts = len(scene.player_start_spots) if self.config["random_starting_location"]: self.player_start = random.randint( 0, max(0, number_of_player_starts - 1)) else: self.player_start = 0 # Notify the server that we want to start the episode at the # player_start index. This function blocks until the server is ready # to start the episode. print("Starting new episode...") self.client.start_episode(self.player_start) image, py_measurements = self._read_observation() self.prev_measurement = py_measurements return self.preprocess_image(image)
def build_experiments(self): """ Creates the whole set of experiment objects, The experiments created depend on the selected Town. """ # We set the camera # This single RGB camera is used on every experiment camera = Camera('rgb') camera.set(FOV=100) camera.set_image_size(800, 600) camera.set_position(2.0, 0.0, 1.4) camera.set_rotation(-15.0, 0, 0) poses_tasks = self._poses() vehicles_tasks = [0, 0, 0, 20] pedestrians_tasks = [0, 0, 0, 50] task_names = ['straight', 'one_curve', 'navigation', 'navigation_dyn'] experiments_vector = [] for weather in self.weathers: for iteration in range(len(poses_tasks)): poses = poses_tasks[iteration] vehicles = vehicles_tasks[iteration] pedestrians = pedestrians_tasks[iteration] conditions = CarlaSettings() conditions.set(SendNonPlayerAgentsInfo=True, NumberOfVehicles=vehicles, NumberOfPedestrians=pedestrians, WeatherId=weather) conditions.set(DisableTwoWheeledVehicles=True) # Add all the cameras that were set for this experiments conditions.add_sensor(camera) experiment = Experiment() experiment.set(Conditions=conditions, Poses=poses, Task=iteration, TaskName=task_names[iteration], Repetitions=1) experiments_vector.append(experiment) return experiments_vector
def make_carla_settings(args): """Make a CarlaSettings object with the settings we need.""" settings = CarlaSettings() settings.set( SynchronousMode=True, SendNonPlayerAgentsInfo=True, NumberOfVehicles=10, NumberOfPedestrians=100, WeatherId=random.choice([1, 3, 7, 8, 14]), QualityLevel=args.quality_level) settings.randomize_seeds() # camera0 = sensor.Camera('CameraRGB_main') # camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT) # camera0.set_position(2.0, 0.0, 1.4) # camera0.set_rotation(0.0, 0.0, 0.0) # settings.add_sensor(camera0) # camera1 = sensor.Camera('CameraDepth', PostProcessing='Depth') # camera1.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT) # camera1.set_position(2.0, 0.0, 1.4) # camera1.set_rotation(0.0, 0.0, 0.0) # settings.add_sensor(camera1) # camera2 = sensor.Camera('CameraSemSeg', PostProcessing='SemanticSegmentation') # camera2.set_image_size(MINI_WINDOW_WIDTH, MINI_WINDOW_HEIGHT) # camera2.set_position(2.0, 0.0, 1.4) # camera2.set_rotation(0.0, 0.0, 0.0) # settings.add_sensor(camera2) cameraNN = sensor.Camera('CameraRGB') cameraNN.set_image_size(H5_WINDOW_WIDTH, H5_WINDOW_HEIGHT) cameraNN.set_position(2.0, 0.0, 1.4) cameraNN.set_rotation(0.0, 0.0, 0.0) settings.add_sensor(cameraNN) camera3 = sensor.Camera('CameraRGB_h5') camera3.set_image_size(H5_WINDOW_WIDTH, H5_WINDOW_HEIGHT) camera3.set_position(2.0, 0.0, 1.4) camera3.set_rotation(0.0, 0.0, 0.0) settings.add_sensor(camera3) if args.lidar: lidar = sensor.Lidar('Lidar32') lidar.set_position(0, 0, 2.5) lidar.set_rotation(0, 0, 0) lidar.set( Channels=32, Range=50, PointsPerSecond=100000, RotationFrequency=10, UpperFovLimit=10, LowerFovLimit=-30) settings.add_sensor(lidar) return settings
def __init__(self, name, flags, auto_pilot, camera_setups=[], lidar_setups=[], log_file_name=None, csv_file_name=None): super(CarlaLegacyOperator, self).__init__(name) self._flags = flags self._logger = setup_logging(self.name, log_file_name) self._csv_logger = setup_csv_logging(self.name + '-csv', csv_file_name) self._auto_pilot = auto_pilot if self._flags.carla_high_quality: quality = 'Epic' else: quality = 'Low' self._settings = CarlaSettings() self._settings.set( SynchronousMode=self._flags.carla_synchronous_mode, SendNonPlayerAgentsInfo=True, NumberOfVehicles=self._flags.carla_num_vehicles, NumberOfPedestrians=self._flags.carla_num_pedestrians, WeatherId=self._flags.carla_weather, QualityLevel=quality) self._settings.randomize_seeds() self._transforms = {} # Add cameras to the simulation. for cs in camera_setups: self.__add_camera(cs) self._transforms[cs.name] = cs.get_transform() # Add lidars to the simulation. for ls in lidar_setups: self.__add_lidar(ls) self._transforms[ls.name] = ls.get_transform() self.agent_id_map = {} self.pedestrian_count = 0 # Initialize the control state. self.control = { 'steer': 0.0, 'throttle': 0.0, 'brake': 0.0, 'hand_brake': False, 'reverse': False } # Register custom serializers for Messages and WatermarkMessages ray.register_custom_serializer(Message, use_pickle=True) ray.register_custom_serializer(WatermarkMessage, use_pickle=True)