Implementation:CARLA simulator Carla ServerSideSensor
| Knowledge Sources | |
|---|---|
| Domains | Client Library, Sensors, Data Streaming |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
ServerSideSensor implements the client-side representation of a sensor that processes data on the server, providing methods for subscribing to sensor data streams, GBuffer texture access, and ROS2 integration.
Description
The ServerSideSensor class in the carla::client namespace handles sensor lifecycle management and data streaming for server-processed sensors (cameras, LiDAR, RADAR, etc.).
Lifecycle Management
The destructor implements careful cleanup:
- Warns if the sensor object goes out of scope while still alive in the simulation.
- If still listening and the episode is valid, stops all active GBuffer subscriptions and the main sensor stream.
- Uses a listening_mask bitset to track which streams are active (bit 0 for main sensor, bits 1-13 for GBuffer textures).
Main Sensor Stream
- Listen(callback) -- Subscribes to the sensor's data stream via
GetEpisode().Lock()->SubscribeToSensorand sets bit 0 in the listening mask. - Stop() -- Unsubscribes from the sensor stream and resets bit 0. Warns if not currently listening.
- IsListening() -- Checks if any bit in the listening mask is set.
GBuffer Access
Supports up to 13 GBuffer textures (defined by GBufferTextureCount):
- ListenToGBuffer(GBufferId, callback) -- Subscribes to a specific GBuffer texture stream. Only supported on RGB cameras (
sensor.camera.rgb). Sets the corresponding bit in the listening mask. - StopGBuffer(GBufferId) -- Unsubscribes from a specific GBuffer texture stream.
ROS2 Integration
- EnableForROS() -- Enables the sensor for ROS2 data publishing.
- DisableForROS() -- Disables ROS2 publishing for this sensor.
- IsEnabledForROS() -- Queries whether ROS2 publishing is enabled.
Destruction
- Destroy() -- Overrides Actor::Destroy() to stop all GBuffer subscriptions and the main stream before destroying the actor.
Usage
Server-side sensors are spawned via blueprints and attached to vehicles or placed in the world. Call Listen with a callback to start receiving sensor data. Use GBuffer methods for advanced rendering pipeline access on RGB cameras.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/client/ServerSideSensor.cpp(109 lines)
Signature
namespace carla {
namespace client {
class ServerSideSensor : public Sensor {
public:
void Listen(CallbackFunctionType callback);
void Stop();
bool IsListening() const;
void ListenToGBuffer(uint32_t GBufferId, CallbackFunctionType callback);
void StopGBuffer(uint32_t GBufferId);
void EnableForROS();
void DisableForROS();
bool IsEnabledForROS();
bool Destroy() override;
~ServerSideSensor();
private:
std::bitset<GBufferTextureCount + 1> listening_mask;
};
} // namespace client
} // namespace carla
Import
#include "carla/client/ServerSideSensor.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| callback | CallbackFunctionType | Yes | Callback function invoked with sensor data each frame |
| GBufferId | uint32_t | Yes (for GBuffer methods) | GBuffer texture index (0-12) |
Outputs
| Name | Type | Description |
|---|---|---|
| Sensor data | via callback | Sensor measurements delivered through the registered callback |
| IsListening | bool | Whether the sensor is currently subscribed to any stream |
| IsEnabledForROS | bool | Whether the sensor publishes data to ROS2 |
| Destroy result | bool | Whether the sensor was successfully destroyed |
Usage Examples
// Spawn a camera sensor
auto camera = world.SpawnActor(camera_bp, transform, vehicle);
auto sensor = std::static_pointer_cast<carla::client::ServerSideSensor>(camera);
// Start receiving data
sensor->Listen([](auto data) {
auto image = std::static_pointer_cast<carla::sensor::data::Image>(data);
// Process image...
});
// Access GBuffer for advanced rendering (RGB camera only)
sensor->ListenToGBuffer(0, [](auto data) {
// Process GBuffer texture 0...
});
// Enable ROS2 publishing
sensor->EnableForROS();
// Stop and cleanup
sensor->Stop();
sensor->Destroy();
Related Pages
- Environment:CARLA_simulator_Carla_Simulation_Runtime
- CARLA_simulator_Carla_Actor_Class - Base Actor class
- CARLA_simulator_Carla_Python_SensorData_Bindings - Python bindings for sensor data
- CARLA_simulator_Carla_ROS2_Bridge - ROS2 bridge that publishes sensor data