Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla VehicleLightState

From Leeroopedia
Knowledge Sources
Domains Vehicle Systems, RPC Serialization
Last Updated 2026-02-15 05:00 GMT

Overview

VehicleLightState is an RPC-serializable class that represents the state of a vehicle's lights using a bitmask flag system, covering position lights, beams, blinkers, brake lights, and special lights.

Description

Defined in the carla::rpc namespace (~109 lines), this class uses a uint32_t bitmask (flag_type) to represent which lights are active. The LightState enum defines the following flags:

  • None (0x0): all lights off
  • Position (0x1): position/parking lights
  • LowBeam (0x2): low beam headlights
  • HighBeam (0x4): high beam headlights
  • Brake (0x8): brake lights
  • RightBlinker (0x10) / LeftBlinker (0x20): turn signals
  • Reverse (0x40): reverse lights
  • Fog (0x80): fog lights
  • Interior (0x100): interior lights
  • Special1 (0x200) / Special2 (0x400): special lights (e.g., sirens)
  • All (0xFFFFFFFF): all lights on

Helper macros SET_FLAG and FLAG_ENABLED are provided for bitwise operations. The class supports UE4 conversion via FVehicleLightState.

Usage

Use this type to get or set the light state of vehicles in the simulation via the CARLA client API.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/carla/rpc/VehicleLightState.h

Signature

namespace carla {
namespace rpc {

  class VehicleLightState {
  public:
    using flag_type = uint32_t;

    enum class LightState : flag_type {
      None = 0, Position = 0x1, LowBeam = 0x2,
      HighBeam = 0x4, Brake = 0x8,
      RightBlinker = 0x10, LeftBlinker = 0x20,
      Reverse = 0x40, Fog = 0x80, Interior = 0x100,
      Special1 = 0x200, Special2 = 0x400,
      All = 0xFFFFFFFF
    };

    VehicleLightState() = default;
    VehicleLightState(LightState light_state);
    VehicleLightState(flag_type light_state);

    LightState GetLightStateEnum() const;
    flag_type GetLightStateAsValue() const;

    flag_type light_state = static_cast<flag_type>(LightState::None);

    MSGPACK_DEFINE_ARRAY(light_state);
  };

} // namespace rpc
} // namespace carla

Import

#include "carla/rpc/VehicleLightState.h"

I/O Contract

Flag Hex Value Description
None 0x0 All lights off
Position 0x1 Position/parking lights
LowBeam 0x2 Low beam headlights
HighBeam 0x4 High beam headlights
Brake 0x8 Brake lights
RightBlinker 0x10 Right turn signal
LeftBlinker 0x20 Left turn signal
Reverse 0x40 Reverse lights
Fog 0x80 Fog lights
Interior 0x100 Interior lights
Special1 0x200 Special (e.g., sirens)
Special2 0x400 Special lights
All 0xFFFFFFFF All lights on

Usage Examples

#include "carla/rpc/VehicleLightState.h"

using LS = carla::rpc::VehicleLightState::LightState;

// Turn on headlights and brake lights
carla::rpc::VehicleLightState lights;
lights.light_state = static_cast<uint32_t>(LS::LowBeam) |
                     static_cast<uint32_t>(LS::Brake);

vehicle->SetLightState(lights);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment