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
13 #endif // LIBCARLA_INCLUDED_FROM_UE4
14 
15 namespace carla {
16 namespace rpc {
17 
18  #define SET_FLAG(flag, value) flag |= static_cast<flag_type>(value)
19 
20  #define FLAG_ENABLED(flag, value) flag & static_cast<flag_type>(value)
21 
22  /// Defines the physical appearance of a vehicle whitch is obtained
23  /// by the sensors.
25  public:
26 
27  using flag_type = uint32_t;
28 
29  /// Can be used as flags
30  enum class LightState : flag_type {
31  None = 0,
32  Position = 0x1,
33  LowBeam = 0x1 << 1,
34  HighBeam = 0x1 << 2,
35  Brake = 0x1 << 3,
36  RightBlinker = 0x1 << 4,
37  LeftBlinker = 0x1 << 5,
38  Reverse = 0x1 << 6,
39  Fog = 0x1 << 7,
40  Interior = 0x1 << 8,
41  Special1 = 0x1 << 9, // E.g: sirens
42  Special2 = 0x1 << 10,
43  All = 0xFFFFFFFF
44  };
45 
46  VehicleLightState() = default;
47 
49  : light_state(static_cast<flag_type>(light_state)) {}
50 
52  : light_state(light_state) {}
53 
54 #ifdef LIBCARLA_INCLUDED_FROM_UE4
55 
56  VehicleLightState(const FVehicleLightState &InLightState) {
57  light_state = static_cast<flag_type>(LightState::None);
59  if (InLightState.LowBeam) SET_FLAG(light_state, LightState::LowBeam);
61  if (InLightState.Brake) SET_FLAG(light_state, LightState::Brake);
64  if (InLightState.Reverse) SET_FLAG(light_state, LightState::Reverse);
65  if (InLightState.Fog) SET_FLAG(light_state, LightState::Fog);
69  }
70 
71  operator FVehicleLightState() const {
72  FVehicleLightState Lights; // By default all False
76  if (FLAG_ENABLED(light_state, LightState::Brake)) Lights.Brake = true;
80  if (FLAG_ENABLED(light_state, LightState::Fog)) Lights.Fog = true;
84  return Lights;
85  }
86 
87 #endif // LIBCARLA_INCLUDED_FROM_UE4
88 
89  /// Returns the current light state as an enum type
91  return static_cast<LightState>(light_state);
92  }
93 
94  /// Returns the current light state as a value type
96  return light_state;
97  }
98 
99  /// Lights state flag, all turned off by default
101 
102  MSGPACK_DEFINE_ARRAY(light_state)
103 
104  };
105 
106 } // namespace rpc
107 } // namespace carla
#define SET_FLAG(flag, value)
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
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)