CARLA
Loading...
Searching...
No Matches
WheeledVehicleAIController.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
11
12#include <util/ue-header-guard-begin.h>
13#include "GameFramework/Controller.h"
14#include <util/ue-header-guard-end.h>
15
16#include <queue>
17
18#include "WheeledVehicleAIController.generated.h"
19
21class URandomEngine;
22class URoadMap;
23
24/// Wheeled vehicle controller with optional AI.
25UCLASS()
26class CARLA_API AWheeledVehicleAIController final : public AController
27{
28 GENERATED_BODY()
29
30 // ===========================================================================
31 /// @name Constructor and destructor
32 // ===========================================================================
33 /// @{
34
35public:
36
37 AWheeledVehicleAIController(const FObjectInitializer &ObjectInitializer);
38
40
41 /// @}
42 // ===========================================================================
43 /// @name Controller overrides
44 // ===========================================================================
45 /// @{
46
47public:
48
49 void OnPossess(APawn *aPawn) override;
50
51 void OnUnPossess() override;
52
53 void Tick(float DeltaTime) override;
54
55 /// @}
56 // ===========================================================================
57 /// @name Possessed vehicle
58 // ===========================================================================
59 /// @{
60
61public:
62
63 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
65 {
66 return Vehicle != nullptr;
67 }
68
69 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
74
76 {
77 return Vehicle;
78 }
79
80 /// @}
81 // ===========================================================================
82 /// @name Control options
83 // ===========================================================================
84 /// @{
85
86 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
87 void SetStickyControl(bool bEnabled)
88 {
89 bControlIsSticky = bEnabled;
90 }
91
92 /// @}
93 // ===========================================================================
94 /// @name Road map
95 // ===========================================================================
96 /// @{
97
98public:
99
100 void SetRoadMap(URoadMap *InRoadMap)
101 {
102 RoadMap = InRoadMap;
103 }
104
105 UFUNCTION(Category = "Road Map", BlueprintCallable)
107 {
108 return RoadMap;
109 }
110
111 /// @}
112 // ===========================================================================
113 /// @name Random engine
114 // ===========================================================================
115 /// @{
116
117public:
118
119 UFUNCTION(Category = "Random Engine", BlueprintCallable)
121 {
122 check(RandomEngine != nullptr);
123 return RandomEngine;
124 }
125
126 /// @}
127 // ===========================================================================
128 /// @name Autopilot
129 // ===========================================================================
130 /// @{
131
132public:
133
134 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
136 {
137 return bAutopilotEnabled;
138 }
139
140 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
141 void SetAutopilot(bool Enable, bool KeepState = false)
142 {
143 if (IsAutopilotEnabled() != Enable)
144 {
145 ConfigureAutopilot(Enable, KeepState);
146 }
147 }
148
149 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
154
155private:
156
157 void ConfigureAutopilot(const bool Enable, const bool KeepState = false);
158
159 /// @}
160 // ===========================================================================
161 /// @name Traffic
162 // ===========================================================================
163 /// @{
164
165public:
166
167 /// Get current speed limit in km/h.
168 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
169 float GetSpeedLimit() const
170 {
171 return SpeedLimit;
172 }
173
174 /// Set vehicle's speed limit in km/h.
175 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
176 void SetSpeedLimit(float InSpeedLimit)
177 {
178 SpeedLimit = InSpeedLimit;
179 }
180
181 /// Get traffic light state currently affecting this vehicle.
182 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
187
188 /// Set traffic light state currently affecting this vehicle.
189 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
190 void SetTrafficLightState(ETrafficLightState InTrafficLightState)
191 {
192 TrafficLightState = InTrafficLightState;
193 }
194
195 /// Get traffic light currently affecting this vehicle.
196 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
198 {
199 return TrafficLight;
200 }
201
202 /// Set traffic light currently affecting this vehicle.
203 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
204 void SetTrafficLight(ATrafficLightBase *InTrafficLight)
205 {
206 TrafficLight = InTrafficLight;
207 }
208
209 /// Set a fixed route to follow if autopilot is enabled.
210 UFUNCTION(Category = "Wheeled Vehicle Controller", BlueprintCallable)
211 void SetFixedRoute(const TArray<FVector> &Locations, bool bOverwriteCurrent = true);
212
213 /// @}
214
215private:
216
217 UPROPERTY()
219
220 UPROPERTY()
221 URoadMap *RoadMap = nullptr;
222
223 UPROPERTY()
225
226 UPROPERTY(VisibleAnywhere)
227 bool bAutopilotEnabled = false;
228
229 UPROPERTY(VisibleAnywhere)
230 bool bControlIsSticky = true;
231
232 UPROPERTY(VisibleAnywhere)
233 float SpeedLimit = 30.0f;
234
235 UPROPERTY(VisibleAnywhere)
237
238 UPROPERTY(VisibleAnywhere)
239 float MaximumSteerAngle = -1.0f;
240
241 UPROPERTY()
243
244 std::queue<FVector> TargetLocations;
245};
Base class for CARLA wheeled vehicles.
ACarlaWheeledVehicle * GetPossessedVehicle()
const ACarlaWheeledVehicle * GetPossessedVehicle() const
void SetTrafficLightState(ETrafficLightState InTrafficLightState)
Set traffic light state currently affecting this vehicle.
void ConfigureAutopilot(const bool Enable, const bool KeepState=false)
AWheeledVehicleAIController(const FObjectInitializer &ObjectInitializer)
ATrafficLightBase * GetTrafficLight() const
Get traffic light currently affecting this vehicle.
void SetSpeedLimit(float InSpeedLimit)
Set vehicle's speed limit in km/h.
void SetAutopilot(bool Enable, bool KeepState=false)
void OnPossess(APawn *aPawn) override
float GetSpeedLimit() const
Get current speed limit in km/h.
ETrafficLightState GetTrafficLightState() const
Get traffic light state currently affecting this vehicle.
void Tick(float DeltaTime) override
void SetTrafficLight(ATrafficLightBase *InTrafficLight)
Set traffic light currently affecting this vehicle.
Road map of the level.
Definition RoadMap.h:95