CARLA
Loading...
Searching...
No Matches
TrafficLightComponent.h
Go to the documentation of this file.
1// Copyright (c) 2026 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 "CoreMinimal.h"
10#include "SignComponent.h"
11#include "TrafficLightState.h"
13#include "TrafficLightComponent.generated.h"
14
18
19// Delegate to define dispatcher
20DECLARE_DYNAMIC_MULTICAST_DELEGATE(FLightChangeDispatcher);
21
22/// Class representing an OpenDRIVE Traffic Signal
23UCLASS(Blueprintable, ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
24class CARLA_API UTrafficLightComponent : public USignComponent
25{
26 GENERATED_BODY()
27
28public:
29 // Sets default values for this component's properties
30 UTrafficLightComponent();
31
32 UFUNCTION(Category = "Traffic Light", BlueprintCallable)
33 void SetLightState(ETrafficLightState NewState);
34
35 UFUNCTION(Category = "Traffic Light", BlueprintCallable)
36 ETrafficLightState GetLightState() const;
37
38 UFUNCTION(Category = "Traffic Light", BlueprintCallable)
39 void SetFrozenGroup(bool InFreeze);
40
41 UFUNCTION(Category = "Traffic Light", BlueprintPure)
42 ATrafficLightGroup* GetGroup();
43
44 const ATrafficLightGroup* GetGroup() const;
45
46 void SetController(UTrafficLightController* Controller);
47
48 UFUNCTION(Category = "Traffic Light", BlueprintPure)
49 UTrafficLightController* GetController();
50
51 const UTrafficLightController* GetController() const;
52
53 virtual void InitializeSign(const carla::road::Map &Map) override;
54
55 /// Deregister from the controller so streamed-out lights (World Partition)
56 /// never leave dangling entries behind.
57 virtual void OnComponentDestroyed(bool bDestroyingHierarchy) override;
58
59 UPROPERTY(Category = "Traffic Light", BlueprintAssignable)
60 FLightChangeDispatcher LightChangeDispatcher;
61
62protected:
63
64 UFUNCTION(BlueprintCallable)
65 void OnBeginOverlapTriggerBox(UPrimitiveComponent *OverlappedComp,
66 AActor *OtherActor,
67 UPrimitiveComponent *OtherComp,
68 int32 OtherBodyIndex,
69 bool bFromSweep,
70 const FHitResult &SweepResult);
71
72 UFUNCTION(BlueprintCallable)
73 void OnEndOverlapTriggerBox(UPrimitiveComponent *OverlappedComp,
74 AActor *OtherActor,
75 UPrimitiveComponent *OtherComp,
76 int32 OtherBodyIndex);
77
78
79
80private:
81
83
84 void GenerateTrafficLightBox(
85 const FTransform BoxTransform,
86 const FVector BoxSize);
87
88 UPROPERTY(Category = "Traffic Light", EditAnywhere)
89 ETrafficLightState LightState;
90
91 // UPROPERTY(Category = "Traffic Light", VisibleAnywhere)
92 // ATrafficLightGroup *TrafficLightGroup = nullptr;
93
94 UPROPERTY(Category = "Traffic Light", VisibleAnywhere)
95 UTrafficLightController *TrafficLightController = nullptr;
96
97 // Vehicles that have entered the trigger box of the traffic light
98 UPROPERTY()
99 TArray<AWheeledVehicleAIController*> Vehicles;
100
101};
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FLightChangeDispatcher)
std::map< std::string, unsigned int > road
Class which implements the state changing of traffic lights.
Class In charge of creating and assigning traffic light groups, controllers and components.
Wheeled vehicle controller with optional AI.
Maps a controller from OpenDrive.
This file contains definitions of common data structures used in traffic manager.