CARLA
TrafficLightGroup.cpp
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 #include "Carla.h"
9 #include "TrafficLightGroup.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  SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
18  RootComponent = SceneComponent;
19 }
20 
22 {
23  bIsFrozen = InFreeze;
24 }
25 
27 {
28  return bIsFrozen;
29 }
30 
32 {
33  for(auto * Controller : Controllers)
34  {
35  Controller->ResetState();
36  }
38  UTrafficLightController* controller = Controllers[CurrentController];
39  controller->StartCycle();
40 }
41 
42 // Called every frame
43 void ATrafficLightGroup::Tick(float DeltaTime)
44 {
45  TRACE_CPUPROFILER_EVENT_SCOPE(ATrafficLightGroup::Tick);
46  Super::Tick(DeltaTime);
47 
48  // Do not update if the replayer is replaying
49  auto* Episode = UCarlaStatics::GetCurrentEpisode(GetWorld());
50  if (Episode)
51  {
52  auto* Replayer = Episode->GetReplayer();
53  if (Replayer)
54  {
55  if(Replayer->IsEnabled())
56  {
57  return;
58  }
59  }
60  }
61 
62  if (bIsFrozen)
63  {
64  return;
65  }
66 
68  if (controller->AdvanceTimeAndCycleFinished(DeltaTime))
69  {
71  }
72 }
73 
75 {
78  controller->StartCycle();
79 }
80 
82 {
83  return JunctionId;
84 }
85 
87 {
88  Controllers.Add(Controller);
89  Controller->SetGroup(this);
90 }
void AddController(UTrafficLightController *Controller)
USceneComponent * SceneComponent
TArray< UTrafficLightController * > Controllers
virtual void Tick(float DeltaTime) override
bool AdvanceTimeAndCycleFinished(float DeltaTime)
void SetGroup(ATrafficLightGroup *Group)
static UCarlaEpisode * GetCurrentEpisode(const UObject *WorldContextObject)
Definition: CarlaStatics.h:68
void SetFrozenGroup(bool InFreeze)
Maps a controller from OpenDrive.