def run(self): # Connect to CARLA and retrieve the world running. self._client, self._world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) if self._client is None or self._world is None: raise ValueError('There was an issue connecting to the simulator.') # Replayer time factor is only available in > 0.9.5. # self._client.set_replayer_time_factor(0.1) print( self._client.replay_file(self._flags.carla_replay_file, self._flags.carla_replay_start_time, self._flags.carla_replay_duration, self._flags.carla_replay_id)) # Sleep a bit to allow the server to start the replay. time.sleep(1) self._driving_vehicle = self._world.get_actors().find( self._flags.carla_replay_id) if self._driving_vehicle is None: raise ValueError("There was an issue finding the vehicle.") timestamp = erdos.Timestamp(is_top=True) vehicle_id_msg = erdos.Message(timestamp, self._driving_vehicle.id) self._vehicle_id_stream.send(vehicle_id_msg) self._vehicle_id_stream.send(erdos.WatermarkMessage(timestamp)) self._world.on_tick(self.on_world_tick)
def setup(self, path_to_conf_file): """Setup phase. Invoked by the scenario runner.""" # Disable Tensorflow logging. pylot.utils.set_tf_loglevel(logging.ERROR) # Parse the flag file. Users can use the different flags defined # across the Pylot directory. flags.FLAGS([__file__, '--flagfile={}'.format(path_to_conf_file)]) self.logger = erdos.utils.setup_logging('erdos_agent', FLAGS.log_file_name) self.csv_logger = erdos.utils.setup_csv_logging( 'erdos_agent_csv', FLAGS.csv_log_file_name) enable_logging() self.track = get_track() # Town name is only used when the agent is directly receiving # traffic lights from the simulator. self._town_name = None # Stores a simulator handle to the ego vehicle. This handle is only # used when the agent is using a perfect localization or perception. self._ego_vehicle = None # Stores ego-vehicle's yaw from last game time. This is used in the # naive localization solution. self._last_yaw = 0 # Stores the point cloud from the previous sensor reading. self._last_point_cloud = None if using_perfect_component(): from pylot.simulation.utils import get_world # The agent is using a perfect component. It must directly connect # to the simulator to send perfect data to the data-flow. _, self._world = get_world(FLAGS.simulator_host, FLAGS.simulator_port, FLAGS.simulator_timeout)
def main(argv): client, world = get_world(FLAGS.simulator_host, FLAGS.simulator_port, FLAGS.simulator_timeout) # Replayer time factor is only available in > 0.9.5. client.set_replayer_time_factor(0.1) print( client.replay_file(FLAGS.replay_file, FLAGS.replay_start_time, FLAGS.replay_duration, FLAGS.replay_id)) # Sleep a bit to allow the server to start the replay. time.sleep(1) vehicle = world.get_actors().find(FLAGS.replay_id) if vehicle is None: raise ValueError("There was an issue finding the vehicle.") # Install the camera. camera_blueprint = world.get_blueprint_library().find('sensor.camera.rgb') camera_blueprint.set_attribute('image_size_x', str(FLAGS.camera_image_width)) camera_blueprint.set_attribute('image_size_y', str(FLAGS.camera_image_height)) transform = Transform(Location(2.0, 0.0, 1.4), Rotation(pitch=0, yaw=0, roll=0)) camera = world.spawn_actor(camera_blueprint, transform, attach_to=vehicle) # Register the callback on the camera. camera.listen(process_images) time.sleep(20)
def run(self): # Read the vehicle ID from the vehicle ID stream. vehicle_id_msg = self._vehicle_id_stream.read() vehicle_id = vehicle_id_msg.data self._logger.debug("@{}: Received Vehicle ID: {}".format( vehicle_id_msg.timestamp, vehicle_id)) # Connect to the world. _, world = get_world(self._flags.simulator_host, self._flags.simulator_port, self._flags.simulator_timeout) self._vehicle = get_vehicle_handle(world, vehicle_id) # Install the collision sensor. collision_blueprint = world.get_blueprint_library().find( 'sensor.other.collision') self._logger.debug("Spawning a collision sensor.") self._collision_sensor = world.spawn_actor( collision_blueprint, Transform().as_simulator_transform(), attach_to=self._vehicle) # Register the callback on the collision sensor. self._collision_sensor.listen(self.process_collision)
def run(self): # Read the vehicle ID from the vehicle ID stream. vehicle_id_msg = self._vehicle_id_stream.read() vehicle_id = vehicle_id_msg.data self._logger.debug("@{}: Received Vehicle ID: {}".format( vehicle_id_msg.timestamp, vehicle_id)) # Connect to the world. _, world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) if world is None: raise ValueError("There was an issue connecting to the simulator.") self._vehicle = get_vehicle_handle(world, vehicle_id) self._map = world.get_map() # Install the lane-invasion sensor. lane_invasion_blueprint = world.get_blueprint_library().find( 'sensor.other.lane_invasion') self._logger.debug("Spawning a lane invasion sensor.") self._lane_invasion_sensor = world.spawn_actor(lane_invasion_blueprint, carla.Transform(), attach_to=self._vehicle) # Register the callback on the lane-invasion sensor. self._lane_invasion_sensor.listen(self.process_lane_invasion)
def setup_world(): client, world = get_world() settings = world.get_settings() settings.synchronous_mode = True settings.fixed_delta_seconds = 0.02 world.apply_settings(settings) return world
def __init__(self, ground_traffic_lights_stream, tl_camera_stream, depth_camera_stream, segmented_camera_stream, can_bus_stream, traffic_lights_stream, name, flags, log_file_name=None): ground_traffic_lights_stream.add_callback(self.on_traffic_light_update) tl_camera_stream.add_callback(self.on_bgr_camera_update) depth_camera_stream.add_callback(self.on_depth_camera_update) segmented_camera_stream.add_callback(self.on_segmented_frame) can_bus_stream.add_callback(self.on_can_bus_update) erdos.add_watermark_callback([ ground_traffic_lights_stream, tl_camera_stream, depth_camera_stream, segmented_camera_stream, can_bus_stream ], [traffic_lights_stream], self.on_watermark) self._name = name self._logger = erdos.utils.setup_logging(name, log_file_name) self._flags = flags _, world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) if world is None: raise ValueError("There was an issue connecting to the simulator.") self._town_name = world.get_map().name self._traffic_lights = deque() self._bgr_msgs = deque() self._depth_frame_msgs = deque() self._segmented_msgs = deque() self._can_bus_msgs = deque() self._frame_cnt = 0
def run(self): # Read the vehicle id from the vehicle id stream vehicle_id_msg = self._vehicle_id_stream.read() vehicle_id = vehicle_id_msg.data self._logger.debug( "The CarlaIMUDriverOperator received the vehicle id: {}".format( vehicle_id)) # Connect to the world. We connect here instead of in the constructor # to ensure we're connected to the latest world. _, world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) if world is None: raise ValueError("There was an issue connecting to the simulator.") if self._flags.carla_synchronous_mode: set_synchronous_mode(world, self._flags.carla_fps) self._vehicle = get_vehicle_handle(world, vehicle_id) # Install the IMU. imu_blueprint = world.get_blueprint_library().find('sensor.other.imu') transform = self._imu_setup.get_transform().as_carla_transform() self._logger.debug("Spawning an IMU: {}".format(self._imu_setup)) self._imu = world.spawn_actor(imu_blueprint, transform, attach_to=self._vehicle) # Register the callback on the IMU. self._imu.listen(self.process_imu)
def run(self): # Read the vehicle id from the vehicle id stream vehicle_id_msg = self._vehicle_id_stream.read() vehicle_id = vehicle_id_msg.data self._logger.debug( "The LidarDriverOperator received the vehicle id: {}".format( vehicle_id)) # Connect to the world. We connect here instead of in the constructor # to ensure we're connected to the latest world. client, world = get_world(self._flags.simulator_host, self._flags.simulator_port, self._flags.simulator_timeout) simulator_version = client.get_client_version() set_simulation_mode(world, self._flags) self._vehicle = get_vehicle_handle(world, vehicle_id) # Install the Lidar. lidar_blueprint = world.get_blueprint_library().find( self._lidar_setup.lidar_type) lidar_blueprint.set_attribute('channels', str(self._lidar_setup.channels)) if not (simulator_version.startswith('0.8') or re.match( '0\.9\.[0-6]', simulator_version) is not None): # noqa: W605 # Any simulator version after 0.9.6. lidar_blueprint.set_attribute( 'range', str(self._lidar_setup.get_range_in_meters())) else: lidar_blueprint.set_attribute('range', str(self._lidar_setup.range)) lidar_blueprint.set_attribute('points_per_second', str(self._lidar_setup.points_per_second)) lidar_blueprint.set_attribute( 'rotation_frequency', str(self._lidar_setup.rotation_frequency)) lidar_blueprint.set_attribute('upper_fov', str(self._lidar_setup.upper_fov)) lidar_blueprint.set_attribute('lower_fov', str(self._lidar_setup.lower_fov)) if self._flags.simulator_lidar_frequency == -1: lidar_blueprint.set_attribute('sensor_tick', '0.0') else: lidar_blueprint.set_attribute( 'sensor_tick', str(1.0 / self._flags.simulator_lidar_frequency)) transform = self._lidar_setup.get_transform().as_simulator_transform() self._logger.debug("Spawning a lidar: {}".format(self._lidar_setup)) # NOTE: The LiDAR can be attached on a rigid or a spring arm. If the # LiDAR is attached too low, on a rigit, then the point cloud is empty. # Otherwise, if the LiDAR is attached on a SpringArm it won't provide # 360 degrees point clouds. self._lidar = world.spawn_actor(lidar_blueprint, transform, attach_to=self._vehicle) # Register the callback on the Lidar. self._lidar.listen(self.process_point_clouds)
def run(self): # Read the vehicle id from the vehicle id stream vehicle_id_msg = self._vehicle_id_stream.read() vehicle_id = vehicle_id_msg.data self._logger.debug( "The LidarDriverOperator received the vehicle id: {}".format( vehicle_id)) # Connect to the world. We connect here instead of in the constructor # to ensure we're connected to the latest world. _, world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) if world is None: raise ValueError("There was an issue connecting to the simulator.") if self._flags.carla_synchronous_mode: set_synchronous_mode(world, self._flags.carla_fps) num_tries = 0 while self._vehicle is None and num_tries < 30: self._vehicle = world.get_actors().find(vehicle_id) self._logger.debug( "Could not find vehicle. Try {}".format(num_tries)) time.sleep(1) num_tries += 1 if self._vehicle is None: raise ValueError("There was an issue finding the vehicle.") # Install the Lidar. lidar_blueprint = world.get_blueprint_library().find( self._lidar_setup.lidar_type) lidar_blueprint.set_attribute('channels', str(self._lidar_setup.channels)) if self._flags.carla_version == '0.9.7': lidar_blueprint.set_attribute( 'range', str(self._lidar_setup.get_range_in_meters())) else: lidar_blueprint.set_attribute('range', str(self._lidar_setup.range)) lidar_blueprint.set_attribute('points_per_second', str(self._lidar_setup.points_per_second)) lidar_blueprint.set_attribute( 'rotation_frequency', str(self._lidar_setup.rotation_frequency)) lidar_blueprint.set_attribute('upper_fov', str(self._lidar_setup.upper_fov)) lidar_blueprint.set_attribute('lower_fov', str(self._lidar_setup.lower_fov)) # XXX(ionel): Set sensor tick. # lidar_blueprint.set_attribute('sensor_tick') transform = self._lidar_setup.get_transform().as_carla_transform() self._logger.debug("Spawning a lidar: {}".format(self._lidar_setup)) self._lidar = world.spawn_actor(lidar_blueprint, transform, attach_to=self._vehicle) # Register the callback on the Lidar. self._lidar.listen(self.process_point_clouds)
def setup_world(): # Connect to the Carla simulator. client, world = get_world() settings = world.get_settings() settings.synchronous_mode = True settings.fixed_delta_seconds = 0.02 world.apply_settings(settings) return world
def log_bounding_boxes(simulator_image, depth_msg, segmented_frame, traffic_lights, tl_color, speed_signs, stop_signs, weather, town): game_time = int(simulator_image.timestamp * 1000) print("Processing game time {} in {} with weather {}".format( game_time, town, weather)) transform = pylot.utils.Transform.from_simulator_transform( simulator_image.transform) camera_setup = RGBCameraSetup("rgb_camera", FLAGS.frame_width, FLAGS.camera_height, transform, FLAGS.camera_fov) frame = CameraFrame.from_simulator_frame(simulator_image, camera_setup) _, world = get_world() town_name = world.get_map().name speed_limit_det_obstacles = [] if speed_signs: speed_limit_det_obstacles = \ pylot.simulation.utils.get_detected_speed_limits( speed_signs, depth_msg.frame, segmented_frame) traffic_stop_det_obstacles = [] if stop_signs: traffic_stop_det_obstacles = \ pylot.simulation.utils.get_detected_traffic_stops( stop_signs, depth_msg.frame) traffic_light_det_obstacles = [] if traffic_lights: traffic_light_det_obstacles = get_traffic_light_obstacles( traffic_lights, depth_msg.frame, segmented_frame, tl_color, town_name) det_obstacles = (speed_limit_det_obstacles + traffic_stop_det_obstacles + traffic_light_det_obstacles) # Log the frame. file_name = '{}signs-{}_{}_{}.png'.format(FLAGS.data_path, game_time, weather, town) rgb_img = Image.fromarray(frame.as_rgb_numpy_array()) rgb_img.save(file_name) if FLAGS.log_bbox_images: frame.annotate_with_bounding_boxes(game_time, det_obstacles) file_name = '{}annotated-signs-{}_{}_{}.png'.format( FLAGS.data_path, game_time, weather, town) rgb_img = Image.fromarray(frame.as_rgb_numpy_array()) rgb_img.save(file_name) # Log the bounding boxes. bboxes = [obstacle.get_in_log_format() for obstacle in det_obstacles] file_name = '{}bboxes-{}_{}_{}.json'.format(FLAGS.data_path, game_time, weather, town) with open(file_name, 'w') as outfile: json.dump(bboxes, outfile) if FLAGS.visualize_bboxes: frame.annotate_with_bounding_boxes(game_time, det_obstacles) frame.visualize('bboxes')
def run(self): # Run method is invoked after all operators finished initializing. # Thus, we're sure the world is up-to-date here. if (self._flags.visualize_pose or self._flags.visualize_imu or (self._flags.visualize_waypoints and self._flags.draw_waypoints_on_world)): from pylot.simulation.utils import get_world _, self._world = get_world(self._flags.simulator_host, self._flags.simulator_port, self._flags.simulator_timeout)
def run(self): # Run method is invoked after all operators finished initializing, # including the CARLA operator, which reloads the world. Thus, if # we get the world here we're sure it is up-to-date. _, world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) if world is None: raise ValueError("There was an issue connecting to the simulator.") self._world = world self._map = world.get_map()
def run(self): # Run method is invoked after all operators finished initializing, # including the CARLA operator, which reloads the world. Thus, if # we get the world here we're sure it is up-to-date. from pylot.simulation.utils import get_world _, self._world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) if self._world is None: raise ValueError("Error connecting to the simulator.")
def run(self): # Read the vehicle ID from the vehicle ID stream. vehicle_id_msg = self._vehicle_id_stream.read() vehicle_id = vehicle_id_msg.data # Connect to the world. We connect here instead of in the constructor # to ensure we're connected to the latest world. _, world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) set_simulation_mode(world, self._flags) self._vehicle = get_vehicle_handle(world, vehicle_id)
def run(self): # Read the vehicle id from the vehicle id stream vehicle_id_msg = self._vehicle_id_stream.read() vehicle_id = vehicle_id_msg.data self._logger.debug( "The IMUDriverOperator received the vehicle id: {}".format( vehicle_id)) # Connect to the world. We connect here instead of in the constructor # to ensure we're connected to the latest world. _, world = get_world(self._flags.simulator_host, self._flags.simulator_port, self._flags.simulator_timeout) set_simulation_mode(world, self._flags) self._vehicle = get_vehicle_handle(world, vehicle_id) # Install the IMU. imu_blueprint = world.get_blueprint_library().find('sensor.other.imu') # Set noise attributes. imu_blueprint.set_attribute('noise_accel_stddev_x', str(self._flags.accel_noise_stddev_x)) imu_blueprint.set_attribute('noise_accel_stddev_y', str(self._flags.accel_noise_stddev_y)) imu_blueprint.set_attribute('noise_accel_stddev_z', str(self._flags.accel_noise_stddev_z)) imu_blueprint.set_attribute('noise_gyro_stddev_x', str(self._flags.gyro_noise_stddev_x)) imu_blueprint.set_attribute('noise_gyro_stddev_y', str(self._flags.gyro_noise_stddev_y)) imu_blueprint.set_attribute('noise_gyro_stddev_z', str(self._flags.gyro_noise_stddev_z)) if self._flags.simulator_imu_frequency == -1: imu_blueprint.set_attribute('sensor_tick', '0.0') else: imu_blueprint.set_attribute( 'sensor_tick', str(1.0 / self._flags.simulator_imu_frequency)) transform = self._imu_setup.get_transform().as_simulator_transform() self._logger.debug("Spawning an IMU: {}".format(self._imu_setup)) self._imu = world.spawn_actor(imu_blueprint, transform, attach_to=self._vehicle) # Register the callback on the IMU. self._imu.listen(self.process_imu)
def run(self): # Run method is invoked after all operators finished initializing, # including the CARLA operator, which reloads the world. Thus, if # we get the world here we're sure it is up-to-date. if self._flags.execution_mode == 'simulation': from pylot.map.hd_map import HDMap from pylot.simulation.utils import get_map self._map = HDMap( get_map(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout), self.config.log_file_name) from pylot.simulation.utils import get_world _, self._world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout)
def run(self): # Run method is invoked after all operators finished initializing. # Thus, we're sure the world is up-to-date here. if self._flags.execution_mode == 'simulation': from pylot.map.hd_map import HDMap from pylot.simulation.utils import get_map self._map = HDMap( get_map(self._flags.simulator_host, self._flags.simulator_port, self._flags.simulator_timeout), self.config.log_file_name) from pylot.simulation.utils import get_world _, self._world = get_world(self._flags.simulator_host, self._flags.simulator_port, self._flags.simulator_timeout)
def main(args): # Connect an instance to the simulator to make sure that we can turn the # synchronous mode off after the script finishes running. client, world = get_world(FLAGS.carla_host, FLAGS.carla_port, FLAGS.carla_timeout) if client is None or world is None: raise ValueError("There was an issue connecting to the simulator.") try: driver() except KeyboardInterrupt: set_asynchronous_mode(world) except Exception: set_asynchronous_mode(world) raise
def run(self): # Read the vehicle id from the vehicle id stream vehicle_id_msg = self._vehicle_id_stream.read() vehicle_id = vehicle_id_msg.data self._logger.debug( "The CameraDriverOperator received the vehicle id: {}".format( vehicle_id)) # Connect to the world. We connect here instead of in the constructor # to ensure we're connected to the latest world. _, world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) if world is None: raise ValueError("There was an issue connecting to the simulator.") if self._flags.carla_synchronous_mode: set_synchronous_mode(world, self._flags.carla_fps) num_tries = 0 while self._vehicle is None and num_tries < 30: self._vehicle = world.get_actors().find(vehicle_id) self._logger.debug( "Could not find vehicle. Try {}".format(num_tries)) time.sleep(1) num_tries += 1 if self._vehicle is None: raise ValueError("There was an issue finding the vehicle.") # Install the camera. camera_blueprint = world.get_blueprint_library().find( self._camera_setup.camera_type) camera_blueprint.set_attribute('image_size_x', str(self._camera_setup.width)) camera_blueprint.set_attribute('image_size_y', str(self._camera_setup.height)) camera_blueprint.set_attribute('fov', str(self._camera_setup.fov)) transform = self._camera_setup.get_transform().as_carla_transform() self._logger.debug("Spawning a camera: {}".format(self._camera_setup)) self._camera = world.spawn_actor(camera_blueprint, transform, attach_to=self._vehicle) # Register the callback on the camera. self._camera.listen(self.process_images)
def __init__(self, control_stream, can_bus_stream, ground_traffic_lights_stream, ground_obstacles_stream, ground_speed_limit_signs_stream, ground_stop_signs_stream, vehicle_id_stream, open_drive_stream, global_trajectory_stream, flags): if flags.random_seed: random.seed(flags.random_seed) # Register callback on control stream. control_stream.add_callback(self.on_control_msg) self.can_bus_stream = can_bus_stream self.ground_traffic_lights_stream = ground_traffic_lights_stream self.ground_obstacles_stream = ground_obstacles_stream self.ground_speed_limit_signs_stream = ground_speed_limit_signs_stream self.ground_stop_signs_stream = ground_stop_signs_stream self.vehicle_id_stream = vehicle_id_stream self.open_drive_stream = open_drive_stream self.global_trajectory_stream = global_trajectory_stream self._flags = flags self._logger = erdos.utils.setup_logging(self.config.name, self.config.log_file_name) # Connect to CARLA and retrieve the world running. self._client, self._world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) if self._client is None or self._world is None: raise ValueError('There was an issue connecting to the simulator.') if not self._flags.carla_scenario_runner: # Load the appropriate town. self._initialize_world() # Save the spectator handle so that we don't have to repeteadly get the # handle (which is slow). self._spectator = self._world.get_spectator() self._send_world_messages() # Turn on the synchronous mode so we can control the simulation. if self._flags.carla_synchronous_mode: set_synchronous_mode(self._world, self._flags.carla_fps) if self._flags.carla_scenario_runner: # Waits until the ego vehicle is spawned by the scenario runner. self._wait_for_ego_vehicle() else: # Spawns the person and vehicle actors. self._spawn_actors()
def run(self): # Read the vehicle ID from the vehicle ID stream. vehicle_id = self._vehicle_id_stream.read().data self._logger.debug( "The GNSSDriverOperator received the vehicle id: {}".format( vehicle_id)) # Connect to the world. _, world = get_world(self._flags.simulator_host, self._flags.simulator_port, self._flags.simulator_timeout) set_simulation_mode(world, self._flags) # Retrieve the vehicle and install the GNSS sensor. self._vehicle = get_vehicle_handle(world, vehicle_id) gnss_blueprint = world.get_blueprint_library().find( 'sensor.other.gnss') # Set the noise and bias parameters. gnss_blueprint.set_attribute('noise_alt_stddev', str(self._flags.gnss_noise_stddev_alt)) gnss_blueprint.set_attribute('noise_lat_stddev', str(self._flags.gnss_noise_stddev_lat)) gnss_blueprint.set_attribute('noise_lon_stddev', str(self._flags.gnss_noise_stddev_lon)) gnss_blueprint.set_attribute('noise_alt_bias', str(self._flags.gnss_bias_alt)) gnss_blueprint.set_attribute('noise_lat_bias', str(self._flags.gnss_bias_lat)) gnss_blueprint.set_attribute('noise_lon_bias', str(self._flags.gnss_bias_lon)) if self._flags.simulator_gnss_frequency == -1: gnss_blueprint.set_attribute('sensor_tick', '0.0') else: gnss_blueprint.set_attribute( 'sensor_tick', str(1.0 / self._flags.simulator_gnss_frequency)) transform = self._gnss_setup.get_transform().as_simulator_transform() self._logger.debug("Spawning a GNSS sensor: {}".format( self._gnss_setup)) self._gnss = world.spawn_actor(gnss_blueprint, transform, attach_to=self._vehicle) # Register the callback on the GNSS sensor. self._gnss.listen(self.process_gnss)
def run(self): # Read the vehicle id from the vehicle id stream vehicle_id_msg = self._vehicle_id_stream.read() vehicle_id = vehicle_id_msg.data # Connect to the world. We connect here instead of in the constructor # to ensure we're connected to the latest world. _, world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) if world is None: raise ValueError("There was an issue connecting to the simulator.") self._vehicle = get_vehicle_handle(world, vehicle_id) collision_bp = world.get_blueprint_library().find( 'sensor.other.collision') self._collision_sensor = world.spawn_actor(collision_bp, carla.Transform(), attach_to=self._vehicle) self._collision_sensor.listen(self.on_collision)
def main(args): # Connect an instance to the simulator to make sure that we can turn the # synchronous mode off after the script finishes running. client, world = get_world(FLAGS.simulator_host, FLAGS.simulator_port, FLAGS.simulator_timeout) try: if FLAGS.simulation_recording_file is not None: client.start_recorder(FLAGS.simulation_recording_file) node_handle, control_display_stream = driver() signal.signal(signal.SIGINT, shutdown) if pylot.flags.must_visualize(): pylot.utils.run_visualizer_control_loop(control_display_stream) node_handle.wait() except KeyboardInterrupt: shutdown_pylot(node_handle, client, world) except Exception: shutdown_pylot(node_handle, client, world) raise
def run(self): # Read the vehicle id from the vehicle id stream vehicle_id_msg = self._vehicle_id_stream.read() vehicle_id = vehicle_id_msg.data self._logger.debug( "The CarlaCameraDriverOperator received the vehicle id: {}".format( vehicle_id)) # Connect to the world. We connect here instead of in the constructor # to ensure we're connected to the latest world. _, world = get_world(self._flags.carla_host, self._flags.carla_port, self._flags.carla_timeout) if world is None: raise ValueError("There was an issue connecting to the simulator.") set_simulation_mode(world, self._flags) self._vehicle = get_vehicle_handle(world, vehicle_id) # Install the camera. camera_blueprint = world.get_blueprint_library().find( self._camera_setup.camera_type) camera_blueprint.set_attribute('image_size_x', str(self._camera_setup.width)) camera_blueprint.set_attribute('image_size_y', str(self._camera_setup.height)) camera_blueprint.set_attribute('fov', str(self._camera_setup.fov)) if self._flags.carla_camera_frequency == -1: camera_blueprint.set_attribute('sensor_tick', '0.0') else: camera_blueprint.set_attribute( 'sensor_tick', str(1.0 / self._flags.carla_camera_frequency)) transform = self._camera_setup.get_transform().as_carla_transform() self._logger.debug("Spawning a camera: {}".format(self._camera_setup)) self._camera = world.spawn_actor(camera_blueprint, transform, attach_to=self._vehicle) # Register the callback on the camera. self._camera.listen(self.process_images)
def run_scenario(target_vehicle_transform, sensor_transform): # Reset messages. global lidar_pc, last_frame, depth_pc lidar_pc, last_frame, depth_pc = None, None, None # Connect to the Carla simulator. client, world = get_world(host=FLAGS.carla_host) world = client.load_world('Town01') settings = world.get_settings() settings.synchronous_mode = True world.apply_settings(settings) print("Adding sensors") target_vehicle = add_vehicle(world, target_vehicle_transform) lidar = add_lidar(world, sensor_transform, on_lidar_msg) depth_camera = add_depth_camera(world, sensor_transform, on_depth_msg) camera = add_camera(world, sensor_transform, on_camera_msg) # Move the spectactor view to the camera position. world.get_spectator().set_transform(sensor_transform) print("Target Vehicle Location:", target_vehicle_transform.location.x, target_vehicle_transform.location.y, target_vehicle_transform.location.z) print("Our Location:", sensor_transform.location.x, sensor_transform.location.y, sensor_transform.location.z) try: # Tick the simulator once to get 1 data reading. world.tick() while lidar_pc is None or depth_pc is None or last_frame is None: time.sleep(0.2) cv2.imshow('camera view', last_frame.frame) cv2.waitKey(0) finally: # Destroy the actors. lidar.destroy() depth_camera.destroy() target_vehicle.destroy() camera.destroy()
def main(args): if FLAGS.visualizer_backend == 'pygame': import pygame pygame.init() pylot.utils.create_pygame_display(FLAGS.carla_camera_image_width, FLAGS.carla_camera_image_height) # Connect an instance to the simulator to make sure that we can turn the # synchronous mode off after the script finishes running. client, world = get_world(FLAGS.carla_host, FLAGS.carla_port, FLAGS.carla_timeout) if client is None or world is None: raise ValueError("There was an issue connecting to the simulator.") try: driver() except KeyboardInterrupt: set_asynchronous_mode(world) except Exception: set_asynchronous_mode(world) raise
def setup_world(host, port, delta): """ Connects to the simulator at the given host:port and sets the mode to synchronous. Args: host: The host where the simulator is running. port: The port to connect to at the given host. delta: The delta at which to run the simulation. Returns: The instance of `world` that was returned from the simulator. """ _, world = get_world(host, port) if world is None: print("Could not connect to the simulator at {}:{}".format(host, port), file=sys.stderr) sys.exit(1) # Turn on synchronous mode. set_synchronous_mode(world, True, delta) return world
def run(self): # Read the vehicle ID from the vehicle ID stream. vehicle_id_msg = self._vehicle_id_stream.read() vehicle_id = vehicle_id_msg.data self._logger.debug("@{}: Received Vehicle ID: {}".format( vehicle_id_msg.timestamp, vehicle_id)) # Connect to the world. _, self._world = get_world(self._flags.simulator_host, self._flags.simulator_port, self._flags.simulator_timeout) self._map = self._world.get_map() # Retrieve all the traffic lights from the world. while len(self._world.get_actors()) == 0: time.sleep(1) for _actor in self._world.get_actors(): if 'traffic_light' in _actor.type_id: center, waypoints = self.get_traffic_light_waypoints(_actor) self._traffic_lights.append((_actor, center, waypoints)) # Retrieve the vehicle. self._vehicle = get_vehicle_handle(self._world, vehicle_id)