CARLA
 
载入中...
搜索中...
未找到
TrafficLightController.cpp
浏览该文件的文档.
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
8
13
14void UTrafficLightController::SetStates(TArray<FTrafficLightStage> States)
15{
16 LightStates = States;
17 ResetState();
18}
19
24
31
33{
34 ElapsedTime += DeltaTime;
35
36 if(ElapsedTime > GetCurrentState().Time)
37 {
38 ElapsedTime = 0;
39 if (IsCycleFinished())
40 {
41 return true;
42 }
43 NextState();
44 }
45 return false;
46}
47
54
55const TArray<UTrafficLightComponent *> &UTrafficLightController::GetTrafficLights()
56{
57 return TrafficLights;
58}
59
65
67{
69 TrafficLight->SetController(this);
70}
71
76
81
86
88{
89 return ControllerId;
90}
91
93{
94 ControllerId = Id;
95}
96
98{
99 return CurrentState == (LightStates.Num() - 1);
100}
101
103{
104 SetCurrentLightState(NewState);
105 for(auto *Light : TrafficLights)
106 {
107 Light->SetLightState(NewState);
108 }
110 {
111 Light->SetTrafficLightState(NewState);
112 }
113}
114
116{
117 return Sequence;
118}
119
121{
122 Sequence = InSequence;
123}
124
131
133{
134 SetStateTime(ETrafficLightState::Yellow, NewTime);
135}
136
138{
139 SetStateTime(ETrafficLightState::Red, NewTime);
140}
141
143{
144 SetStateTime(ETrafficLightState::Green, NewTime);
145}
146
148{
149 return GetStateTime(ETrafficLightState::Green);
150}
151
153{
154 return GetStateTime(ETrafficLightState::Yellow);
155}
156
158{
159 return GetStateTime(ETrafficLightState::Red);
160}
161
163{
164 for(auto& LightState : LightStates)
165 {
166 if(LightState.State == State)
167 {
168 LightState.Time = NewTime;
169 }
170 }
171}
172
174{
175 for(auto& LightState : LightStates)
176 {
177 if(LightState.State == State)
178 {
179 return LightState.Time;
180 }
181 }
182 return 0.0f;
183}
184
186{
187 return ElapsedTime;
188}
189
191{
192 ElapsedTime = InElapsedTime;
193}
194
199
204
Class which implements the state changing of traffic lights
A view over an actor and its properties.
Definition CarlaActor.h:25
float GetStateTime(const ETrafficLightState State) const
void RemoveCarlaActorTrafficLight(FCarlaActor *CarlaActor)
const FString & GetControllerId() const
void SetTrafficLightsState(ETrafficLightState NewState)
void SetGroup(ATrafficLightGroup *Group)
TArray< UTrafficLightComponent * > TrafficLights
bool AdvanceTimeAndCycleFinished(float DeltaTime)
TArray< FTrafficLightStage > LightStates
void SetCurrentLightState(ETrafficLightState NewState)
const FTrafficLightStage & GetCurrentState() const
void AddCarlaActorTrafficLight(FCarlaActor *CarlaActor)
const TArray< UTrafficLightComponent * > & GetTrafficLights()
void SetElapsedTime(float InElapsedTime)
void SetControllerId(const FString &Id)
TArray< FCarlaActor * > TrafficLightCarlaActors
ATrafficLightGroup * TrafficLightGroup
void AddTrafficLight(UTrafficLightComponent *TrafficLight)
ATrafficLightGroup * GetGroup()
void RemoveTrafficLight(UTrafficLightComponent *TrafficLight)
void SetStates(TArray< FTrafficLightStage > States)
void SetStateTime(const ETrafficLightState State, float NewTime)
Defines a stage of a semaphor with a State and the time this state lasts