CARLA
TrafficLightManager.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 
10 #include "TrafficLightGroup.h"
11 #include "TrafficSignBase.h"
13 
14 #include "TrafficLightManager.generated.h"
15 
16 /// Class In charge of creating and assigning traffic
17 /// light groups, controllers and components.
18 UCLASS()
19 class CARLA_API ATrafficLightManager : public AActor
20 {
21  GENERATED_BODY()
22 
23 public:
24 
26 
27  UFUNCTION(BlueprintCallable, Category = "Traffic Light Manager")
28  void RegisterLightComponentFromOpenDRIVE(UTrafficLightComponent * TrafficLight);
29 
30  UFUNCTION(BlueprintCallable, Category = "Traffic Light Manager")
31  void RegisterLightComponentGenerated(UTrafficLightComponent * TrafficLight);
32 
33  const boost::optional<carla::road::Map> &GetMap();
34 
35  UFUNCTION(BlueprintCallable, Category = "Traffic Light Manager")
36  ATrafficLightGroup* GetTrafficGroup(int JunctionId);
37 
38  UFUNCTION(BlueprintCallable, Category = "Traffic Light Manager")
39  UTrafficLightController* GetController(FString ControllerId);
40 
41  UFUNCTION(BlueprintCallable, Category = "Traffic Light Manager")
42  USignComponent* GetTrafficSign(FString SignId);
43 
44  UFUNCTION(BlueprintCallable, Category = "Traffic Light Manager")
45  void SetFrozen(bool InFrozen);
46 
47  UFUNCTION(BlueprintCallable, Category = "Traffic Light Manager")
48  bool GetFrozen();
49 
50  UFUNCTION(CallInEditor, Category = "Traffic Light Manager")
51  void GenerateSignalsAndTrafficLights();
52 
53  UFUNCTION(CallInEditor, Category = "Traffic Light Manager")
54  void RemoveGeneratedSignalsAndTrafficLights();
55 
56  UFUNCTION(CallInEditor, Category = "Traffic Light Manager")
57  void MatchTrafficLightActorsWithOpenDriveSignals();
58 
59  // Called when the game starts by the gamemode
60  void InitializeTrafficLights();
61 
62 private:
63 
64  void SpawnTrafficLights();
65 
66  void SpawnSignals();
67 
68  void RemoveRoadrunnerProps() const;
69 
70  void RemoveAttachedProps(TArray<AActor*> Actors) const;
71 
72  // Mapped references to ATrafficLightGroup (junction)
73  UPROPERTY()
74  TMap<int, ATrafficLightGroup *> TrafficGroups;
75 
76  // Mapped references to UTrafficLightController (controllers)
77  UPROPERTY()
78  TMap<FString, UTrafficLightController *> TrafficControllers;
79 
80  // Mapped references to individual TrafficLightComponents
81  UPROPERTY()
82  TMap<FString, USignComponent *> TrafficSignComponents;
83 
84  // Mapped references to TrafficSigns
85  TArray<ATrafficSignBase*> TrafficSigns;
86 
87  UPROPERTY(EditAnywhere, Category= "Traffic Light Manager")
88  TSubclassOf<AActor> TrafficLightModel;
89 
90  // Relates an OpenDRIVE type to a traffic sign blueprint
91  UPROPERTY(EditAnywhere, Category= "Traffic Light Manager")
92  TMap<FString, TSubclassOf<AActor>> TrafficSignsModels;
93 
94  UPROPERTY(EditAnywhere, Category= "Traffic Light Manager")
95  TMap<FString, TSubclassOf<USignComponent>> SignComponentModels;
96 
97  UPROPERTY(EditAnywhere, Category= "Traffic Light Manager")
98  TMap<FString, TSubclassOf<AActor>> SpeedLimitModels;
99 
100  UPROPERTY(Category = "Traffic Light Manager", VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
101  USceneComponent *SceneComponent;
102 
103  UPROPERTY(EditAnywhere, Category= "Traffic Light Manager")
104  bool TrafficLightsGenerated = false;
105 
106  // Id for TrafficLightGroups without corresponding OpenDRIVE junction
107  UPROPERTY()
108  int TrafficLightGroupMissingId = -2;
109 
110  // Id for TrafficLightControllers without corresponding OpenDRIVE junction
111  UPROPERTY()
112  int TrafficLightControllerMissingId = -1;
113 
114  // Id for TrafficLightComponents without corresponding OpenDRIVE junction
115  UPROPERTY()
116  int TrafficLightComponentMissingId = -1;
117 
118  UPROPERTY()
119  bool bTrafficLightsFrozen = false;
120 
121 };
std::string SignId
Definition: RoadTypes.h:25
Class which implements the state changing of traffic lights.
Maps a controller from OpenDrive.
Class In charge of creating and assigning traffic light groups, controllers and components.