Implementation:CARLA simulator Carla SensorData Base
| Knowledge Sources | |
|---|---|
| Domains | Sensor, DataModel |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
SensorData is the abstract base class for all objects containing data generated by a CARLA sensor, providing common metadata such as frame count, timestamp, and sensor transform.
Description
The SensorData class serves as the root of the sensor data hierarchy. It inherits from EnableSharedFromThis<SensorData> to support shared pointer semantics and from NonCopyable to prevent copy construction and assignment.
Each SensorData instance stores three core metadata fields: the frame count (size_t) indicating which simulation frame produced the data, the timestamp (double) representing the simulation time, and the sensor transform (rpc::Transform) representing the sensor's world-space position and rotation at capture time. All three fields are declared const after construction, making instances effectively immutable in their metadata.
The class provides two protected constructors: one that accepts explicit frame, timestamp, and transform values, and one that extracts these fields from a RawData object. A virtual destructor ensures proper cleanup of derived classes.
A WeakEpisodeProxy member (_episode) is stored as a friend-accessible field set by client::detail::Simulator, enabling derived sensor data to reference the simulation episode context. This is noted in the source as a design compromise.
Usage
All concrete sensor data types (images, lidar point clouds, collision events, etc.) derive from SensorData. Client code receives SharedPtr<SensorData> from the deserialization pipeline and typically downcasts to the specific sensor data type for access to sensor-specific fields.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/sensor/SensorData.h
Signature
class SensorData
: public EnableSharedFromThis<SensorData>,
private NonCopyable {
protected:
SensorData(size_t frame, double timestamp, const rpc::Transform &sensor_transform);
explicit SensorData(const RawData &data);
public:
virtual ~SensorData() = default;
size_t GetFrame() const;
double GetTimestamp() const;
const rpc::Transform &GetSensorTransform() const;
};
Import
#include "carla/sensor/SensorData.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| frame | size_t | Yes | Frame count when the data was generated |
| timestamp | double | Yes | Simulation-time when the data was generated |
| sensor_transform | const rpc::Transform& | Yes | World-space transform of the sensor at capture time |
| data | const RawData& | Yes (alt. ctor) | Raw data object to extract frame, timestamp, and transform from |
Outputs
| Name | Type | Description |
|---|---|---|
| GetFrame() | size_t | Frame count at data generation time |
| GetTimestamp() | double | Simulation timestamp of data generation |
| GetSensorTransform() | const rpc::Transform& | Sensor's world transform at capture time |
Usage Examples
// Receiving deserialized sensor data from the streaming pipeline
SharedPtr<SensorData> data = SensorRegistry::Deserialize(std::move(buffer));
// Accessing common metadata
size_t frame = data->GetFrame();
double ts = data->GetTimestamp();
const rpc::Transform &xform = data->GetSensorTransform();
// Downcast to specific type for sensor-specific data
auto image = boost::dynamic_pointer_cast<sensor::data::Image>(data);