CARLA
Loading...
Searching...
No Matches
TrafficLightGroup.cpp
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#include "TrafficLightGroup.h"
8#include "Carla.h"
10
11
12// Sets default values
14{
15 // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
16 PrimaryActorTick.bCanEverTick = true;
17 PrimaryActorTick.bStartWithTickEnabled = true;
18 SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
19 RootComponent = SceneComponent;
20}
21
23{
24 bIsFrozen = InFreeze;
25}
26
28{
29 return bIsFrozen;
30}
31
33{
34 for(auto& Controller : Controllers)
35 {
36 Controller->ResetState();
37 }
40 controller->StartCycle();
41}
42
43// Called every frame
44void ATrafficLightGroup::Tick(float DeltaTime)
45{
46 TRACE_CPUPROFILER_EVENT_SCOPE(ATrafficLightGroup::Tick);
47 Super::Tick(DeltaTime);
48
49 // Do not update if the replayer is replaying
50 auto* Episode = UCarlaStatics::GetCurrentEpisode(GetWorld());
51 if (Episode)
52 {
53 // A Multi-GPU secondary takes every light's state from the primary's
54 // frames: cycling here too would switch lights ahead of the primary.
55 if (!Episode->bIsPrimaryServer)
56 {
57 return;
58 }
59 auto* Replayer = Episode->GetReplayer();
60 if (Replayer)
61 {
62 if(Replayer->IsEnabled())
63 {
64 return;
65 }
66 }
67 }
68
69 if (bIsFrozen)
70 {
71 return;
72 }
73
74 if (Controllers.Num() == 0)
75 {
76 UE_LOG(LogCarla, Error, TEXT("TrafficLightGroup::Tick() JunctionId=%d has NO CONTROLLERS!"), JunctionId);
77 return;
78 }
79
81 if (controller->AdvanceTimeAndCycleFinished(DeltaTime))
82 {
84 }
85}
86
93
95{
96 return JunctionId;
97}
98
100{
101 Controllers.Add(Controller);
102 Controller->SetGroup(this);
103}
TArray< TObjectPtr< UTrafficLightController > > Controllers
virtual void Tick(float DeltaTime) override
TObjectPtr< USceneComponent > SceneComponent
void SetFrozenGroup(bool InFreeze)
void AddController(UTrafficLightController *Controller)
static UCarlaEpisode * GetCurrentEpisode(const UObject *WorldContextObject)
Maps a controller from OpenDrive.
void SetGroup(ATrafficLightGroup *Group)
bool AdvanceTimeAndCycleFinished(float DeltaTime)