Sensors Reference

Scenic sensors provide observations from the selected simulator during a simulation. Use these abstract classes in with sensors { ... } blocks; the selected simulator (CARLA, MetaDrive, etc.) supplies the concrete implementation.

Note

The sensors API is a prototype and may undergo changes.

Added in version 3.1.

Built-in Sensors

class RGBSensor[source]

Abstract RGB camera sensor.

Parameters:
  • offset – Sensor position offset relative to the attached object (x, y, z).

  • rotation – Sensor rotation relative to the attached object (yaw, pitch, roll).

  • width – Output image width.

  • height – Output image height.

  • attributes – Simulator-specific options (dict).

class SSSensor[source]

Abstract semantic segmentation camera sensor.

Parameters:
  • offset – Sensor position offset relative to the attached object (x, y, z).

  • rotation – Sensor rotation relative to the attached object (yaw, pitch, roll).

  • width – Output image width.

  • height – Output image height.

  • attributes – Simulator-specific options (dict).

Usage

param map = localPath('../../assets/maps/CARLA/Town05.xodr')
param carla_map = 'Town05'
model scenic.domains.driving.model

# Sample a lane at random
lane = Uniform(*network.lanes)

spot = new OrientedPoint on lane.centerline

attrs = {"convert": "CityScapesPalette"}  # Used by CARLA

# Spawn car on that spot with follow lane behavior and
# - an RGB Camera pointing forward
# - a semantic segmentation sensor
ego = new Car at spot,
    with behavior FollowLaneBehavior(),
    with sensors {"front_ss": SSSensor(offset=(1.6, 0, 1.7), width=1056, height=704, attributes=attrs),
              "front_rgb": RGBSensor(offset=(1.6, 0, 1.7), width=1056, height=704, attributes=attrs)
                }

other = new Car offset by 0 @ Range(10, 30),
    with behavior FollowLaneBehavior()

param recordFolder = "out/{simulation}"
record ego.observations["front_ss"] every 0.5 seconds after 5 seconds to "frontss_{time}.jpg"
record ego.observations["front_rgb"] after 5 seconds to "frontrgb.mp4"

terminate after 15 seconds