forked from HARPLab/DReyeVR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarlaWheeledVehicle.h
379 lines (292 loc) · 12.7 KB
/
CarlaWheeledVehicle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "WheeledVehicle.h"
#include "Vehicle/CarlaWheeledVehicleState.h"
#include "Vehicle/VehicleControl.h"
#include "Vehicle/VehicleLightState.h"
#include "Vehicle/VehicleInputPriority.h"
#include "Vehicle/VehiclePhysicsControl.h"
#include "VehicleVelocityControl.h"
#include "WheeledVehicleMovementComponent4W.h"
#include "VehicleAnimInstance.h"
#include "PhysicsEngine/PhysicsConstraintComponent.h"
#include "MovementComponents/BaseCarlaMovementComponent.h"
#include "Components/AudioComponent.h" // UAudioComponent
#include "Sound/SoundCue.h" // USoundCue
#include "CoreMinimal.h"
//-----CARSIM--------------------------------
#ifdef WITH_CARSIM
#include "CarSimMovementComponent.h"
#endif
//-------------------------------------------
#include "CarlaWheeledVehicle.generated.h"
class UBoxComponent;
UENUM()
enum class EVehicleWheelLocation : uint8 {
FL_Wheel = 0,
FR_Wheel = 1,
BL_Wheel = 2,
BR_Wheel = 3,
//Use for bikes and bicycles
Front_Wheel = 0,
Back_Wheel = 1,
};
/// Type of door to open/close
// When adding new door types, make sure that All is the last one.
UENUM(BlueprintType)
enum class EVehicleDoor : uint8 {
FL = 0,
FR = 1,
RL = 2,
RR = 3,
Hood = 4,
Trunk = 5,
All = 6
};
/// Base class for CARLA wheeled vehicles.
UCLASS()
class CARLA_API ACarlaWheeledVehicle : public AWheeledVehicle
{
GENERATED_BODY()
// ===========================================================================
/// @name Constructor and destructor
// ===========================================================================
/// @{
public:
ACarlaWheeledVehicle(const FObjectInitializer &ObjectInitializer);
~ACarlaWheeledVehicle();
/// @}
// ===========================================================================
/// @name Get functions
// ===========================================================================
/// @{
public:
/// Vehicle control currently applied to this vehicle.
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
const FVehicleControl &GetVehicleControl() const
{
return LastAppliedControl;
}
/// Transform of the vehicle. Location is shifted so it matches center of the
/// vehicle bounds rather than the actor's location.
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
FTransform GetVehicleTransform() const
{
return GetActorTransform();
}
/// Forward speed in cm/s. Might be negative if goes backwards.
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
float GetVehicleForwardSpeed() const;
/// Orientation vector of the vehicle, pointing forward.
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
FVector GetVehicleOrientation() const;
/// Active gear of the vehicle.
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
int32 GetVehicleCurrentGear() const;
/// Transform of the vehicle's bounding box relative to the vehicle.
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
FTransform GetVehicleBoundingBoxTransform() const;
/// Extent of the vehicle's bounding box.
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
FVector GetVehicleBoundingBoxExtent() const;
/// Get vehicle's bounding box component.
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
UBoxComponent *GetVehicleBoundingBox() const
{
return VehicleBounds;
}
/// Get the maximum angle at which the front wheel can steer.
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
float GetMaximumSteerAngle() const;
/// @}
// ===========================================================================
/// @name AI debug state
// ===========================================================================
/// @{
public:
/// @todo This function should be private to AWheeledVehicleAIController.
void SetAIVehicleState(ECarlaWheeledVehicleState InState)
{
State = InState;
}
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
ECarlaWheeledVehicleState GetAIVehicleState() const
{
return State;
}
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
FVehiclePhysicsControl GetVehiclePhysicsControl() const;
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void RestoreVehiclePhysicsControl();
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
FVehicleLightState GetVehicleLightState() const;
void ApplyVehiclePhysicsControl(const FVehiclePhysicsControl &PhysicsControl);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void SetSimulatePhysics(bool enabled);
void SetWheelCollision(UWheeledVehicleMovementComponent4W *Vehicle4W, const FVehiclePhysicsControl &PhysicsControl);
void SetVehicleLightState(const FVehicleLightState &LightState);
UFUNCTION(BlueprintNativeEvent)
bool IsTwoWheeledVehicle();
virtual bool IsTwoWheeledVehicle_Implementation() {
return false;
}
/// @}
// ===========================================================================
/// @name Vehicle input control
// ===========================================================================
/// @{
public:
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void ApplyVehicleControl(const FVehicleControl &Control, EVehicleInputPriority Priority)
{
if (InputControl.Priority <= Priority)
{
InputControl.Control = Control;
InputControl.Priority = Priority;
}
}
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void ActivateVelocityControl(const FVector &Velocity);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void DeactivateVelocityControl();
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void ShowDebugTelemetry(bool Enabled);
/// @todo This function should be private to AWheeledVehicleAIController.
void FlushVehicleControl();
/// @}
// ===========================================================================
/// @name DEPRECATED Set functions
// ===========================================================================
/// @{
public:
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void SetThrottleInput(float Value);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void SetSteeringInput(float Value);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void SetBrakeInput(float Value);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void SetReverse(bool Value);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void ToggleReverse()
{
SetReverse(!LastAppliedControl.bReverse);
}
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void SetHandbrakeInput(bool Value);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void HoldHandbrake()
{
SetHandbrakeInput(true);
}
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void ReleaseHandbrake()
{
SetHandbrakeInput(false);
}
TArray<float> GetWheelsFrictionScale();
void SetWheelsFrictionScale(TArray<float> &WheelsFrictionScale);
void SetCarlaMovementComponent(UBaseCarlaMovementComponent* MoementComponent);
template<typename T = UBaseCarlaMovementComponent>
T* GetCarlaMovementComponent() const
{
return Cast<T>(BaseMovementComponent);
}
static float Volume;
virtual void SetVolume(const float VolumeIn);
void PlayCrashSound(const float DelayBeforePlay = 0.f) const;
/// @}
// ===========================================================================
/// @name Overriden from AActor
// ===========================================================================
/// @{
virtual void Tick(float DeltaTime) override; // called once per frame
protected:
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason);
// sounds (DReyeVR)
void ConstructSounds();
virtual void TickSounds(float DeltaSeconds);
UPROPERTY(Category = "Audio", EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
FVector EngineLocnInVehicle{180.f, 0.f, 70.f};
// need to disable these for EgoVehicle to have our own Ego versions
UPROPERTY(Category = "Audio", EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
class UAudioComponent *EngineRevSound = nullptr; // driver feedback on throttle
UPROPERTY(Category = "Audio", EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
class UAudioComponent *CrashSound = nullptr; // crashing with another actor
double CollisionCooldownTime = 0.0;
// can add more sounds here... like a horn maybe?
// collisions (DReyeVR)
bool EnableCollisionForActor(AActor *OtherActor);
void ConstructCollisionHandler(); // needs to be called in the constructor
UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent *OverlappedComp, AActor *OtherActor, UPrimitiveComponent *OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
UFUNCTION(BlueprintImplementableEvent)
void RefreshLightState(const FVehicleLightState &VehicleLightState);
UFUNCTION(BlueprintCallable, CallInEditor)
void AdjustVehicleBounds();
UPROPERTY(Category="Door Animation", EditAnywhere, BlueprintReadWrite)
TArray<FName> ConstraintComponentNames;
UPROPERTY(Category="Door Animation", EditAnywhere, BlueprintReadWrite)
float DoorOpenStrength = 100.0f;
UFUNCTION(BlueprintCallable, CallInEditor)
void ResetConstraints();
private:
/// Current state of the vehicle controller (for debugging purposes).
UPROPERTY(Category = "AI Controller", VisibleAnywhere)
ECarlaWheeledVehicleState State = ECarlaWheeledVehicleState::UNKNOWN;
UPROPERTY(Category = "CARLA Wheeled Vehicle", EditAnywhere)
UBoxComponent *VehicleBounds;
UPROPERTY(Category = "CARLA Wheeled Vehicle", EditAnywhere)
UVehicleVelocityControl* VelocityControl;
struct
{
EVehicleInputPriority Priority = EVehicleInputPriority::INVALID;
FVehicleControl Control;
FVehicleLightState LightState;
}
InputControl;
FVehicleControl LastAppliedControl;
FVehiclePhysicsControl LastPhysicsControl;
public:
/// Set the rotation of the car wheels indicated by the user
/// 0 = FL_VehicleWheel, 1 = FR_VehicleWheel, 2 = BL_VehicleWheel, 3 = BR_VehicleWheel
/// NOTE : This is purely aesthetic. It will not modify the physics of the car in any way
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void SetWheelSteerDirection(EVehicleWheelLocation WheelLocation, float AngleInDeg);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
float GetWheelSteerAngle(EVehicleWheelLocation WheelLocation);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void OpenDoor(const EVehicleDoor DoorIdx);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void CloseDoor(const EVehicleDoor DoorIdx);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void OpenDoorPhys(const EVehicleDoor DoorIdx);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void CloseDoorPhys(const EVehicleDoor DoorIdx);
virtual FVector GetVelocity() const override;
//-----CARSIM--------------------------------
UPROPERTY(Category="CARLA Wheeled Vehicle", EditAnywhere)
float CarSimOriginOffset = 150.f;
//-------------------------------------------
private:
UPROPERTY(Category="CARLA Wheeled Vehicle", VisibleAnywhere)
bool bPhysicsEnabled = true;
// Small workarround to allow optional CarSim plugin usage
UPROPERTY(Category="CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
UBaseCarlaMovementComponent * BaseMovementComponent = nullptr;
UPROPERTY(Category="CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
TArray<UPhysicsConstraintComponent*> ConstraintsComponents;
UPROPERTY(Category="CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
TMap<UPhysicsConstraintComponent*, UPrimitiveComponent*> ConstraintDoor;
// container of the initial transform of the door, used to reset its position
UPROPERTY(Category="CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
TMap<UPrimitiveComponent*, FTransform> DoorComponentsTransform;
UPROPERTY(Category="CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
TMap<UPrimitiveComponent*, UPhysicsConstraintComponent*> CollisionDisableConstraints;
};