Sensors and data
Sensors are actors that retrieve data from their surroundings. They are crucial to creating a learning environment for driving agents.
This page summarizes everything necessary to start handling sensors. It introduces the types available and a step-by-step guide of their life cycle. The specifics for every sensor can be found in the sensors reference.
Types of sensors

Cameras
Take a shot of the world from their point of view. For cameras that return carla.Image, you can use the helper class carla.ColorConverter to modify the image to represent different information.
- Retrieve data every simulation step.
| Sensor | Output | Overview |
|---|---|---|
| Depth | carla.Image | Renders the depth of the elements in the field of view in a gray-scale map. |
| RGB | carla.Image | Provides clear vision of the surroundings. Looks like a normal photo of the scene. |
| Optical Flow | carla.Image | Renders the motion of every pixel from the camera. |
| Semantic segmentation | carla.Image | Renders elements in the field of view with a specific color according to their tags. |
| Instance segmentation | carla.Image | Renders elements in the field of view with a specific color according to their tags and a unique object ID. |
| DVS | carla.DVSEventArray | Measures changes of brightness intensity asynchronously as an event stream. |
| Normals | carla.Image | Renders the surface normal of every pixel. |
| Fisheye | as the camera each one mirrors | Wide-angle versions of the RGB, depth and segmentation cameras, with their own intrinsics and distortion. |
| Ray-traced lens | carla.Image | Path-traced camera with a physical lens model, plus its distance and instance twins. |
Camera images also depend on the server's quality level and on each camera's post-process profile. See Rendering options and Camera post-process presets.
Detectors
Retrieve data when the object they are attached to registers a specific event.
- Retrieve data when triggered.
| Sensor | Output | Overview |
|---|---|---|
| Collision | carla.CollisionEvent | Retrieves collisions between its parent and other actors. |
| Lane invasion | carla.LaneInvasionEvent | Registers when its parent crosses a lane marking. |
| Obstacle | carla.ObstacleDetectionEvent | Detects possible obstacles ahead of its parent. |
Other
Different functionalities such as navigation, measurement of physical properties and 2D/3D point maps of the scene.
- Retrieve data every simulation step.
| Sensor | Output | Overview |
|---|---|---|
| GNSS | carla.GNSSMeasurement | Retrieves the geolocation of the sensor. |
| IMU | carla.IMUMeasurement | Comprises an accelerometer, a gyroscope, and a compass. |
| LIDAR | carla.LidarMeasurement | A rotating LIDAR. Generates a 4D point cloud with coordinates and intensity per point to model the surroundings. |
| Radar | carla.RadarMeasurement | Point cloud of detections, each with depth, azimuth, altitude and the velocity relative to the sensor. |
| Semantic LIDAR | carla.SemanticLidarMeasurement | A rotating LIDAR. Generates a 3D point cloud with extra information regarding instance and semantic segmentation. |
| Hybrid Solid-State LiDAR | carla.LidarMeasurement | A forward-facing solid-state LiDAR with a fixed scan pattern. |
| V2X | carla.CAMEvent | Receives ETSI cooperative awareness messages from other V2X sensors. |
| Custom V2X | carla.CustomV2XEvent | Sends and receives arbitrary messages between V2X sensors. |
| Vehicle status | carla.SensorData | The parent vehicle's kinematic and control state, for the Autoware bridge. |
| Autoware GNSS | carla.GnssMeasurement | A GNSS sensor publishing in the shape the Autoware stack expects. |
Semantic classes
The semantic segmentation camera, the instance segmentation camera and the semantic LiDAR label what they see with the tags in carla.CityObjectLabel. An asset of your own is labelled by the folder it lives in, and a class of your own is added in Create semantic tags.
Sensors step-by-step
Agentic CARLA
"Attach a front RGB camera and a 64-channel lidar to the ego vehicle and save their data to disk."
Skills: create-sensor, read-sensor, bounding-boxes. Set up Agentic CARLA.
The class carla.Sensor defines a special type of actor able to measure and stream data.
- What is this data? It varies a lot depending on the type of sensor. All the types of data are inherited from the general carla.SensorData.
- When do they retrieve the data? Either on every simulation step or when a certain event is registered. Depends on the type of sensor.
- How do they retrieve the data? Every sensor has a
listen()method to receive and manage the data.
Despite their differences, all the sensors are used in a similar way.
Setting
As with every other actor, find the blueprint and set specific attributes. This is essential when handling sensors. Their attributes will determine the results obtained. These are detailed in the sensors reference.
The following example sets a dashboard HD camera.
# Find the blueprint of the sensor.
blueprint = world.get_blueprint_library().find('sensor.camera.rgb')
# Modify the attributes of the blueprint to set image resolution and field of view.
blueprint.set_attribute('image_size_x', '1920')
blueprint.set_attribute('image_size_y', '1080')
blueprint.set_attribute('fov', '110')
# Set the time in seconds between sensor captures
blueprint.set_attribute('sensor_tick', '1.0')
Spawning
attach_to and attachment_type are the two arguments that matter. A sensor is normally attached to a parent actor, usually a vehicle, so it follows it around; the attachment type decides how its position is updated relative to that vehicle.
- Rigid attachment. Movement is strict regarding its parent location. This is the proper attachment to retrieve data from the simulation.
- SpringArm attachment. Movement is eased with little accelerations and decelerations. This attachment is only recommended to record videos from the simulation. The movement is smooth and "hops" are avoided when updating the cameras' positions.
- SpringArmGhost attachment. Like the previous one but without doing the collision test, so the camera or sensor could cross walls or other geometries.
transform = carla.Transform(carla.Location(x=0.8, z=1.7))
sensor = world.spawn_actor(blueprint, transform, attach_to=my_vehicle,
attachment_type=carla.AttachmentType.Rigid)
Important
When spawning with attachment, location must be relative to the parent actor.
Listening
Every sensor has a listen() method. This is called every time the sensor retrieves data.
listen() takes any callable that accepts one argument, the data. A lambda, a named function, or a bound method such as queue.put all work. It runs on the sensor's own thread, not the one running your script.
# do_something() will be called each time a new image is generated by the camera.
sensor.listen(lambda data: do_something(data))
# This collision sensor prints every time a collision is detected.
def callback(event):
print('Collision with %s' % event.other_actor.type_id)
sensor02.listen(callback)
A free function like that is fine for one sensor. Two patterns carry further.
Keep the data on an object. Make the callback a method, and the sensor's readings become state you can query from anywhere else in the program. This is how manual_control.py wraps each of its sensors:
class CollisionSensor:
def __init__(self, parent_actor):
world = parent_actor.get_world()
bp = world.get_blueprint_library().find('sensor.other.collision')
self.sensor = world.spawn_actor(bp, carla.Transform(), attach_to=parent_actor)
self.history = []
self.sensor.listen(self._on_collision)
def _on_collision(self, event):
self.history.append((event.frame, event.other_actor.type_id))
Note
The callback holds a reference to the object, and the object holds the sensor, so neither is ever collected. manual_control.py passes a weakref to the callback to break that cycle.
Funnel several sensors into one queue. In synchronous mode the world snapshot and each sensor's stream arrive independently, so returning from world.tick() does not mean every sensor has delivered. Have each sensor put its data in the same queue, then block the loop until one reading has come back from each. PythonAPI/examples/sensor_synchronization.py does exactly this:
from queue import Queue, Empty
sensor_queue = Queue()
def sensor_callback(data, queue, name):
queue.put((data.frame, name, data))
camera.listen(lambda data: sensor_callback(data, sensor_queue, 'camera'))
lidar.listen(lambda data: sensor_callback(data, sensor_queue, 'lidar'))
world.tick()
for _ in range(2): # one reading per sensor
frame, name, data = sensor_queue.get(timeout=2.0)
This assumes every sensor reports on every tick. One with a sensor_tick of its own reports less often, so the loop has to know how many readings to expect that frame.
Data
carla.Image, carla.LidarMeasurement and carla.SemanticLidarMeasurement have a save_to_disk() method, which covers every camera and every LiDAR. The other data types are read from their fields and saved however you like.
Sensor data differs a lot between sensor types. Take a look at the sensors reference to get a detailed explanation. However, all of them are always tagged with some basic information.
| Sensor data attribute | Type | Description |
|---|---|---|
frame |
int | Frame number when the measurement took place. |
timestamp |
double | Timestamp of the measurement in simulation seconds since the beginning of the episode. |
transform |
carla.Transform | World reference of the sensor at the time of the measurement. |
Note
is_listening() reports whether the sensor is currently streaming; start and stop it with listen() and stop().
sensor_tick is a blueprint attribute that sets the simulation time between readings.