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