Implementation:CARLA simulator Carla LightManager Class
| Knowledge Sources | |
|---|---|
| Domains | Client Library, Lighting, Scene Management |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
LightManager is the client-side class for querying and controlling all lights in a CARLA simulation scene, supporting bulk operations on light groups with color, intensity, and state management.
Description
The LightManager class in the carla::client namespace extends EnableSharedFromThis<LightManager> and provides comprehensive light control. It is non-copyable by design via carla::NonCopyable (though a copy constructor is explicitly defined for internal use).
Light Group Type
Uses rpc::LightState::LightGroup as the LightGroup type alias for categorizing lights (e.g., Street, Building, Vehicle, None).
Bulk Operations (vector-based)
Each operation works on a std::vector<Light>:
- TurnOn / TurnOff -- Toggle lights on/off.
- SetActive / IsActive -- Set or query active state with paired boolean vectors.
- GetTurnedOnLights / GetTurnedOffLights -- Query lights by on/off state, optionally filtered by LightGroup.
- SetColor / GetColor -- Uniform or per-light color setting/querying.
- SetIntensity / GetIntensity -- Uniform or per-light intensity setting/querying.
- SetLightGroup / GetLightGroup -- Uniform or per-light group assignment/querying.
- SetLightState / GetLightState -- Uniform or per-light LightState setting/querying.
Individual Operations (by LightId)
Per-light operations indexed by LightId:
- GetColor(id), GetIntensity(id), GetLightState(id), GetLightGroup(id), IsActive(id)
- SetActive(id, active), SetColor(id, color), SetIntensity(id, intensity), SetLightState(id, state), SetLightStateNoLock(id, state), SetLightGroup(id, group)
Day/Night Cycle
- SetDayNightCycle(active) -- Enables or disables the automatic day/night cycle.
Internal State Management
- _lights_state -- Map of current light states keyed by LightId.
- _lights_changes -- Map of pending light state changes.
- _lights -- Map of Light objects.
- _episode -- WeakEpisodeProxy for simulator communication.
- _mutex -- Thread safety for concurrent access.
- _on_tick_register_id / _on_light_update_register_id -- Event registration IDs.
- _dirty -- Flag indicating pending changes.
Private methods QueryLightsStateToServer, UpdateServerLightsState, and ApplyChanges handle server synchronization.
Usage
Obtain the LightManager from the world and use it to control scene lighting for day/night scenarios, specific lighting conditions, or visual debugging.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/client/LightManager.h(113 lines)
Signature
namespace carla {
namespace client {
class LightManager : public EnableSharedFromThis<LightManager> {
using LightGroup = rpc::LightState::LightGroup;
public:
LightManager();
~LightManager();
void SetEpisode(detail::WeakEpisodeProxy episode);
std::vector<Light> GetAllLights(LightGroup type = LightGroup::None) const;
void TurnOn(std::vector<Light>& lights);
void TurnOff(std::vector<Light>& lights);
void SetActive(std::vector<Light>& lights, std::vector<bool>& active);
std::vector<bool> IsActive(std::vector<Light>& lights) const;
void SetColor(std::vector<Light>& lights, Color color);
void SetColor(std::vector<Light>& lights, std::vector<Color>& colors);
std::vector<Color> GetColor(std::vector<Light>& lights) const;
void SetIntensity(std::vector<Light>& lights, float intensity);
void SetIntensity(std::vector<Light>& lights, std::vector<float>& intensities);
std::vector<float> GetIntensity(std::vector<Light>& lights) const;
void SetLightState(std::vector<Light>& lights, LightState state);
void SetLightState(std::vector<Light>& lights, std::vector<LightState>& states);
std::vector<LightState> GetLightState(std::vector<Light>& lights) const;
void SetDayNightCycle(const bool active);
// Per-ID accessors
Color GetColor(LightId id) const;
float GetIntensity(LightId id) const;
LightState GetLightState(LightId id) const;
void SetLightState(LightId id, const LightState& new_state);
// ... additional per-ID methods
};
} // namespace client
} // namespace carla
Import
#include "carla/client/LightManager.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| episode | detail::WeakEpisodeProxy | Yes | Weak episode proxy for server communication |
| lights | std::vector<Light> | Yes (for bulk ops) | List of lights to operate on |
| color | Color | No | Color to set on lights |
| intensity | float | No | Intensity to set on lights |
| state | LightState | No | Complete light state to apply |
| type | LightGroup | No | Light group filter (default: None = all) |
Outputs
| Name | Type | Description |
|---|---|---|
| all_lights | std::vector<Light> | All lights matching the group filter |
| colors | std::vector<Color> | Queried colors for specified lights |
| intensities | std::vector<float> | Queried intensities for specified lights |
| states | std::vector<LightState> | Queried light states for specified lights |
| active | std::vector<bool> | Active state for specified lights |
Usage Examples
auto light_manager = world.GetLightManager();
// Get all street lights
auto street_lights = light_manager->GetAllLights(
carla::rpc::LightState::LightGroup::Street);
// Turn on all street lights
light_manager->TurnOn(street_lights);
// Set warm color
light_manager->SetColor(street_lights, carla::sensor::data::Color{255, 200, 150});
// Disable day/night cycle for manual control
light_manager->SetDayNightCycle(false);
Related Pages
- Environment:CARLA_simulator_Carla_Simulation_Runtime
- CARLA_simulator_Carla_Python_LightManager_Bindings - Python bindings for this class