CARLA
LibCarla/source/carla/rpc/VehicleLightState.h
Go to the documentation of this file.
1 // Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include "carla/MsgPack.h"
10 
11 #ifdef LIBCARLA_INCLUDED_FROM_UE4
15 #endif // LIBCARLA_INCLUDED_FROM_UE4
16 
17 namespace carla {
18 namespace rpc {
19 
20  #define SET_FLAG(flag, value) flag |= static_cast<flag_type>(value)
21 
22  #define FLAG_ENABLED(flag, value) flag & static_cast<flag_type>(value)
23 
24  /// Defines the physical appearance of a vehicle whitch is obtained
25  /// by the sensors.
27  public:
28 
29  using flag_type = uint32_t;
30 
31  /// Can be used as flags
32  enum class LightState : flag_type {
33  None = 0,
34  Position = 0x1,
35  LowBeam = 0x1 << 1,
36  HighBeam = 0x1 << 2,
37  Brake = 0x1 << 3,
38  RightBlinker = 0x1 << 4,
39  LeftBlinker = 0x1 << 5,
40  Reverse = 0x1 << 6,
41  Fog = 0x1 << 7,
42  Interior = 0x1 << 8,
43  Special1 = 0x1 << 9, // E.g: sirens
44  Special2 = 0x1 << 10,
45  All = 0xFFFFFFFF
46  };
47 
48  VehicleLightState() = default;
49 
51  : light_state(static_cast<flag_type>(light_state)) {}
52 
54  : light_state(light_state) {}
55 
56 #ifdef LIBCARLA_INCLUDED_FROM_UE4
57 
58  VehicleLightState(const FVehicleLightState &InLightState) {
59  light_state = static_cast<flag_type>(LightState::None);
61  if (InLightState.LowBeam) SET_FLAG(light_state, LightState::LowBeam);
63  if (InLightState.Brake) SET_FLAG(light_state, LightState::Brake);
66  if (InLightState.Reverse) SET_FLAG(light_state, LightState::Reverse);
67  if (InLightState.Fog) SET_FLAG(light_state, LightState::Fog);
71  }
72 
73  operator FVehicleLightState() const {
74  FVehicleLightState Lights; // By default all False
78  if (FLAG_ENABLED(light_state, LightState::Brake)) Lights.Brake = true;
82  if (FLAG_ENABLED(light_state, LightState::Fog)) Lights.Fog = true;
86  return Lights;
87  }
88 
89 #endif // LIBCARLA_INCLUDED_FROM_UE4
90 
91  /// Returns the current light state as an enum type
93  return static_cast<LightState>(light_state);
94  }
95 
96  /// Returns the current light state as a value type
98  return light_state;
99  }
100 
101  /// Lights state flag, all turned off by default
103 
104  MSGPACK_DEFINE_ARRAY(light_state)
105 
106  };
107 
108 } // namespace rpc
109 } // namespace carla
#define SET_FLAG(flag, value)
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
flag_type GetLightStateAsValue() const
Returns the current light state as a value type.
LightState GetLightStateEnum() const
Returns the current light state as an enum type.
flag_type light_state
Lights state flag, all turned off by default.
Defines the physical appearance of a vehicle whitch is obtained by the sensors.
#define FLAG_ENABLED(flag, value)