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