CARLA
 
载入中...
搜索中...
未找到
TrafficLightController.h
浏览该文件的文档.
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
9#include "CoreMinimal.h"
10#include "Object.h"
11#include "TrafficLightState.h"
13#include "Containers/Map.h"
15#include "TrafficLightController.generated.h"
16
18
19/// 定义信号量的某个阶段,并定义其状态以及该状态的持续时间
20USTRUCT(BlueprintType)
22{
23 // 在类体的第一行添加(如果你的类继承自UObject,你的类名上方需要加入UCLASS()宏)
24 GENERATED_BODY()
25
26 UPROPERTY(EditAnywhere, BlueprintReadWrite)
27 float Time;
28
29 UPROPERTY(EditAnywhere, BlueprintReadWrite)
31};
32
33/// 从 OpenDrive 映射一个控制器。控制相关交通信号灯并包含其循环
34UCLASS(BlueprintType)
35class CARLA_API UTrafficLightController : public UObject
36{
37 GENERATED_BODY()
38
39public:
40
42
43 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
44 void SetStates(TArray<FTrafficLightStage> States);
45
46 UFUNCTION(Category = "Traffic Controller", BlueprintPure)
47 const FTrafficLightStage &GetCurrentState() const;
48
49 // 将交通信号灯组件更新到下一个状态
50 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
51 float NextState();
52
53 // 推进控制器的计数器,如果循环完成则返回 true
54 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
55 bool AdvanceTimeAndCycleFinished(float DeltaTime);
56
57 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
58 void StartCycle();
59
60 UFUNCTION(Category = "Traffic Controller", BlueprintPure)
61 const TArray<UTrafficLightComponent *> &GetTrafficLights();
62
63 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
64 void EmptyTrafficLights();
65
66 UFUNCTION(Category = "Traffic Controller", BlueprintPure)
67 const FString &GetControllerId() const;
68
69 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
70 void SetControllerId(const FString &Id);
71
72 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
73 void AddTrafficLight(UTrafficLightComponent * TrafficLight);
74
75 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
76 void RemoveTrafficLight(UTrafficLightComponent * TrafficLight);
77
78 void AddCarlaActorTrafficLight(FCarlaActor* CarlaActor);
79
80 void RemoveCarlaActorTrafficLight(FCarlaActor* CarlaActor);
81
82 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
83 bool IsCycleFinished() const;
84
85 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
86 void SetTrafficLightsState(ETrafficLightState NewState);
87
88 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
89 int GetSequence() const;
90
91 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
92 void SetSequence(int InSequence);
93
94 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
95 void ResetState();
96
97 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
98 void SetYellowTime(float NewTime);
99
100 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
101 void SetRedTime(float NewTime);
102
103 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
104 void SetGreenTime(float NewTime);
105
106 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
107 float GetGreenTime() const;
108
109 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
110 float GetYellowTime() const;
111
112 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
113 float GetRedTime() const;
114
115 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
116 float GetElapsedTime() const;
117
118 UFUNCTION(Category = "Traffic Controller", BlueprintCallable)
119 void SetElapsedTime(float InElapsedTime);
120
121 void SetGroup(ATrafficLightGroup* Group);
122
123 ATrafficLightGroup* GetGroup();
124
125 const ATrafficLightGroup* GetGroup() const;
126
128 {
129 return CurrentLightState;
130 }
132 {
133 CurrentLightState = NewState;
134 }
135
136private:
137
138 void SetStateTime(const ETrafficLightState State, float NewTime);
139
140 float GetStateTime(const ETrafficLightState State) const;
141
142 UPROPERTY(Category = "Traffic Controller", EditAnywhere)
143 FString ControllerId = "";
144
145 UPROPERTY(Category = "Traffic Controller", EditAnywhere)
146 int CurrentState = 0;
147
148 // 与信号灯的状态配对(时间 - 状态),例如绿灯 10 秒
149 UPROPERTY(Category = "Traffic Controller", EditAnywhere)
150 TArray<FTrafficLightStage> LightStates = {
151 {10, ETrafficLightState::Green},
152 { 3, ETrafficLightState::Yellow},
153 { 2, ETrafficLightState::Red}
154 };
155
156 UPROPERTY(Category = "Traffic Controller", EditAnywhere)
157 TArray<UTrafficLightComponent *> TrafficLights;
158
159 TArray<FCarlaActor *> TrafficLightCarlaActors;
160
161 UPROPERTY(Category = "Traffic Controller", VisibleAnywhere)
162 ATrafficLightGroup* TrafficLightGroup;
163
164 // 交叉路口的序列(暂时未使用)
165 UPROPERTY(Category = "Traffic Controller", EditAnywhere)
166 int Sequence = 0;
167
168 UPROPERTY()
169 float ElapsedTime = 0;
170
171 ETrafficLightState CurrentLightState = ETrafficLightState::Green;
172};
如果你的类继承自UObject,你的类名上方需要加入 UCLASS() 宏 实现交通信号灯状态改变的类
查看一个参与者和它的属性
Definition CarlaActor.h:23
从 OpenDrive 映射一个控制器。控制相关交通信号灯并包含其循环
ETrafficLightState GetCurrentLightState() const
void SetCurrentLightState(ETrafficLightState NewState)
定义信号量的某个阶段,并定义其状态以及该状态的持续时间