Пример #1
0
def spawn_lidar(
    hero: carla.ActorBlueprint,  # pylint: disable=no-member
    config: Mapping[str, Any],
) -> carla.ServerSideSensor:  # pylint: disable=no-member
    """Spawns LIDAR sensor on `hero`.

  Args:
    hero: The agent to attach the LIDAR sensor on.
    config: The attribute-value pairs for the configuration
      of the sensor.

  Returns:
    The spawned LIDAR sensor.
  """
    # Get hero's world.
    world = hero.get_world()
    # Blueprints library.
    bl = world.get_blueprint_library()
    # Configure blueprint.
    lidar_bp = bl.find("sensor.lidar.ray_cast")
    for attribute, value in config["attributes"].items():
        lidar_bp.set_attribute(attribute, value)
    logging.debug("Spawns a LIDAR sensor")
    return world.spawn_actor(
        lidar_bp,
        carla.Transform(  # pylint: disable=no-member
            carla.Location(**config["actor"]["location"]),  # pylint: disable=no-member
            carla.Rotation(),  # pylint: disable=no-member
        ),
        attach_to=hero,
    )
Пример #2
0
def spawn_camera(
    hero: carla.ActorBlueprint,  # pylint: disable=no-member
    config: Mapping[str, Any],
    camera_type: str,
) -> carla.ServerSideSensor:  # pylint: disable=no-member
    """Spawns a camera on `hero`.

  Args:
    hero: The agent to attach the camera on.
    config: The attribute-value pairs for the configuration
      of the sensor.
    camera_type: Camera type, one of ("rgb", "semantic_segmentation", "depth").

  Returns:
    The spawned  camera sensor.
  """
    assert camera_type in ("rgb", "semantic_segmentation", "depth")

    # Get hero's world.
    world = hero.get_world()
    # Blueprints library.
    bl = world.get_blueprint_library()
    # Configure blueprint.
    camera_bp = bl.find("sensor.camera.{}".format(camera_type))
    for attribute, value in config["attributes"].items():
        camera_bp.set_attribute(attribute, value)
    logging.debug("Spawns a {} camera".format(camera_type))
    return world.spawn_actor(
        camera_bp,
        carla.Transform(  # pylint: disable=no-member
            carla.Location(**config["actor"]["location"]),  # pylint: disable=no-member
            carla.Rotation(**config["actor"]["rotation"]),  # pylint: disable=no-member
        ),
        attach_to=hero,
    )
Пример #3
0
def spawn_lane_invasion(
    hero: carla.ActorBlueprint,  # pylint: disable=no-member
) -> carla.ServerSideSensor:  # pylint: disable=no-member
    """Spawns lane invasion sensor on `hero`.

  Args:
    hero: The agent to attach the collision sensor on.

  Returns:
    The spawned lane invasion sensor.
  """
    # Get hero's world.
    world = hero.get_world()
    # Blueprints library.
    bl = world.get_blueprint_library()
    # Configure blueprint.
    collision_bp = bl.find("sensor.other.lane_invasion")
    logging.debug("Spawns a lane invasion sensor")
    return world.spawn_actor(
        collision_bp,
        carla.Transform(),  # pylint: disable=no-member
        attach_to=hero,
    )