Implementation:CARLA simulator Carla SensorRegistry
| Knowledge Sources | |
|---|---|
| Domains | Sensor, Serialization |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
SensorRegistry is the central type alias that maps every CARLA sensor class to its corresponding serializer, enabling compile-time dispatched serialization and deserialization of all sensor data.
Description
The SensorRegistry is a using alias for CompositeSerializer instantiated with std::pair entries that bind each sensor pointer type to its serializer class. It serves as the single registry of all sensor types available in the CARLA simulator.
The registry includes the following sensor-serializer mappings:
- ACollisionSensor paired with CollisionEventSerializer
- ADepthCamera paired with ImageSerializer
- ANormalsCamera paired with NormalsImageSerializer
- ADVSCamera paired with DVSEventArraySerializer
- AGnssSensor paired with GnssSerializer
- AInertialMeasurementUnit paired with IMUSerializer
- ALaneInvasionSensor paired with NoopSerializer (client-side only)
- AObstacleDetectionSensor paired with ObstacleDetectionEventSerializer
- AOpticalFlowCamera paired with OpticalFlowImageSerializer
- ARadar paired with RadarSerializer
- ARayCastSemanticLidar paired with SemanticLidarSerializer
- ARayCastLidar paired with LidarSerializer
- ARssSensor paired with NoopSerializer (client-side only)
- ASceneCaptureCamera paired with ImageSerializer
- ASemanticSegmentationCamera paired with ImageSerializer
- AInstanceSegmentationCamera paired with ImageSerializer
- FWorldObserver paired with EpisodeStateSerializer
- FCameraGBufferUint8 paired with GBufferUint8Serializer
- FCameraGBufferFloat paired with GBufferFloatSerializer
The file is structured with a 4-step registration process documented inline: (1) include the serializer header, (2) forward-declare the sensor class, (3) add the pair to the SensorRegistry type alias, and (4) conditionally include the full sensor header when LIBCARLA_SENSOR_REGISTRY_WITH_SENSOR_INCLUDES is defined. Sensors that operate only on the client side (ALaneInvasionSensor, ARssSensor) use NoopSerializer since they do not transmit data over the network.
Usage
Use SensorRegistry::Serialize to serialize sensor data and SensorRegistry::Deserialize to reconstruct SensorData objects from raw buffers. This is the primary entry point for all sensor data serialization in CARLA.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/sensor/SensorRegistry.h
Signature
using SensorRegistry = CompositeSerializer<
std::pair<ACollisionSensor *, s11n::CollisionEventSerializer>,
std::pair<ADepthCamera *, s11n::ImageSerializer>,
std::pair<ANormalsCamera *, s11n::NormalsImageSerializer>,
std::pair<ADVSCamera *, s11n::DVSEventArraySerializer>,
std::pair<AGnssSensor *, s11n::GnssSerializer>,
std::pair<AInertialMeasurementUnit *, s11n::IMUSerializer>,
std::pair<ALaneInvasionSensor *, s11n::NoopSerializer>,
std::pair<AObstacleDetectionSensor *, s11n::ObstacleDetectionEventSerializer>,
std::pair<AOpticalFlowCamera *, s11n::OpticalFlowImageSerializer>,
std::pair<ARadar *, s11n::RadarSerializer>,
std::pair<ARayCastSemanticLidar *, s11n::SemanticLidarSerializer>,
std::pair<ARayCastLidar *, s11n::LidarSerializer>,
std::pair<ARssSensor *, s11n::NoopSerializer>,
std::pair<ASceneCaptureCamera *, s11n::ImageSerializer>,
std::pair<ASemanticSegmentationCamera *, s11n::ImageSerializer>,
std::pair<AInstanceSegmentationCamera *, s11n::ImageSerializer>,
std::pair<FWorldObserver *, s11n::EpisodeStateSerializer>,
std::pair<FCameraGBufferUint8 *, s11n::GBufferUint8Serializer>,
std::pair<FCameraGBufferFloat *, s11n::GBufferFloatSerializer>
>;
Import
#include "carla/sensor/SensorRegistry.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| sensor | Sensor& | Yes (Serialize) | Any registered sensor type reference |
| args | Args&&... | Yes (Serialize) | Arguments forwarded to the sensor-specific serializer |
| data | Buffer&& | Yes (Deserialize) | Raw buffer with sensor type header for deserialization |
Outputs
| Name | Type | Description |
|---|---|---|
| (Serialize result) | Buffer | Serialized binary data for network transmission |
| (Deserialize result) | SharedPtr<SensorData> | Deserialized sensor data object of the appropriate derived type |
Usage Examples
// Serialize data from a depth camera sensor
Buffer serialized = SensorRegistry::Serialize(depthCamera, frameData...);
// Deserialize incoming buffer into a SensorData object
SharedPtr<SensorData> sensorData = SensorRegistry::Deserialize(std::move(rawBuffer));
// To register a new sensor, follow the 4-step process in SensorRegistry.h:
// 1. Include the serializer header
// 2. Forward-declare the sensor class
// 3. Add std::pair<MySensor*, s11n::MySerializer> to the SensorRegistry
// 4. Include the sensor header under LIBCARLA_SENSOR_REGISTRY_WITH_SENSOR_INCLUDES