CARLA
 
载入中...
搜索中...
未找到
WheeledVehicleMovementComponentNW.h
浏览该文件的文档.
1// Copyright (c) 2022 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#include "WheeledVehicleMovementComponent.h"
9#include "Curves/CurveFloat.h"
10#include "WheeledVehicleMovementComponentNW.generated.h"
11
12namespace physx
13{
14 class PxVehicleWheelData;
15}
16
17USTRUCT()
19{
20 GENERATED_USTRUCT_BODY()
21
22 /** If True, torque is applied to this wheel */
23 UPROPERTY(EditAnywhere, Category = Setup)
24 bool bDriven;
25
27 : bDriven(true)
28 { }
29};
30
31USTRUCT()
33{
34 GENERATED_USTRUCT_BODY()
35
36 /** Torque (Nm) at a given RPM*/
37 UPROPERTY(EditAnywhere, Category = Setup)
38 FRuntimeFloatCurve TorqueCurve;
39
40 /** Maximum revolutions per minute of the engine */
41 UPROPERTY(EditAnywhere, Category = Setup, meta = (ClampMin = "0.01", UIMin = "0.01"))
42 float MaxRPM;
43
44 /** Moment of inertia of the engine around the axis of rotation (Kgm^2). */
45 UPROPERTY(EditAnywhere, Category = Setup, meta = (ClampMin = "0.01", UIMin = "0.01"))
46 float MOI;
47
48 /** Damping rate of engine when full throttle is applied (Kgm^2/s) */
49 UPROPERTY(EditAnywhere, Category = Setup, AdvancedDisplay, meta = (ClampMin = "0.0", UIMin = "0.0"))
50 float DampingRateFullThrottle;
51
52 /** Damping rate of engine in at zero throttle when the clutch is engaged (Kgm^2/s)*/
53 UPROPERTY(EditAnywhere, Category = Setup, AdvancedDisplay, meta = (ClampMin = "0.0", UIMin = "0.0"))
54 float DampingRateZeroThrottleClutchEngaged;
55
56 /** Damping rate of engine in at zero throttle when the clutch is disengaged (in neutral gear) (Kgm^2/s)*/
57 UPROPERTY(EditAnywhere, Category = Setup, AdvancedDisplay, meta = (ClampMin = "0.0", UIMin = "0.0"))
58 float DampingRateZeroThrottleClutchDisengaged;
59
60 /** Find the peak torque produced by the TorqueCurve */
61 float FindPeakTorque() const;
62};
63
64USTRUCT()
66{
67 GENERATED_USTRUCT_BODY()
68
69 /** Determines the amount of torque multiplication*/
70 UPROPERTY(EditAnywhere, Category = Setup)
71 float Ratio;
72
73 /** Value of engineRevs/maxEngineRevs that is low enough to gear down*/
74 UPROPERTY(EditAnywhere, meta = (ClampMin = "0.0", UIMin = "0.0", ClampMax = "1.0", UIMax = "1.0"), Category = Setup)
75 float DownRatio;
76
77 /** Value of engineRevs/maxEngineRevs that is high enough to gear up*/
78 UPROPERTY(EditAnywhere, meta = (ClampMin = "0.0", UIMin = "0.0", ClampMax = "1.0", UIMax = "1.0"), Category = Setup)
79 float UpRatio;
80};
81
82USTRUCT()
84{
85 GENERATED_USTRUCT_BODY()
86 /** Whether to use automatic transmission */
87 UPROPERTY(EditAnywhere, Category = VehicleSetup, meta = (DisplayName = "Automatic Transmission"))
88 bool bUseGearAutoBox;
89
90 /** Time it takes to switch gears (seconds) */
91 UPROPERTY(EditAnywhere, Category = Setup, meta = (ClampMin = "0.0", UIMin = "0.0"))
92 float GearSwitchTime;
93
94 /** Minimum time it takes the automatic transmission to initiate a gear change (seconds)*/
95 UPROPERTY(EditAnywhere, Category = Setup, meta = (editcondition = "bUseGearAutoBox", ClampMin = "0.0", UIMin = "0.0"))
96 float GearAutoBoxLatency;
97
98 /** The final gear ratio multiplies the transmission gear ratios.*/
99 UPROPERTY(EditAnywhere, AdvancedDisplay, Category = Setup)
100 float FinalRatio;
101
102 /** Forward gear ratios (up to 30) */
103 UPROPERTY(EditAnywhere, Category = Setup, AdvancedDisplay)
104 TArray<FVehicleNWGearData> ForwardGears;
105
106 /** Reverse gear ratio */
107 UPROPERTY(EditAnywhere, AdvancedDisplay, Category = Setup)
108 float ReverseGearRatio;
109
110 /** Value of engineRevs/maxEngineRevs that is high enough to increment gear*/
111 UPROPERTY(EditAnywhere, AdvancedDisplay, Category = Setup, meta = (ClampMin = "0.0", UIMin = "0.0", ClampMax = "1.0", UIMax = "1.0"))
112 float NeutralGearUpRatio;
113
114 /** Strength of clutch (Kgm^2/s)*/
115 UPROPERTY(EditAnywhere, Category = Setup, AdvancedDisplay, meta = (ClampMin = "0.0", UIMin = "0.0"))
116 float ClutchStrength;
117};
118
119UCLASS(ClassGroup = (Physics), meta = (BlueprintSpawnableComponent), hidecategories = (PlanarMovement, "Components|Movement|Planar", Activation, "Components|Activation"))
120class CARLA_API UWheeledVehicleMovementComponentNW : public UWheeledVehicleMovementComponent
121{
122 GENERATED_UCLASS_BODY()
123
124 /** Engine */
125 UPROPERTY(EditAnywhere, Category = MechanicalSetup)
126 FVehicleNWEngineData EngineSetup;
127
128 /** Differential */
129 UPROPERTY(EditAnywhere, Category = MechanicalSetup)
130 TArray<FVehicleNWWheelDifferentialData> DifferentialSetup;
131
132 /** Transmission data */
133 UPROPERTY(EditAnywhere, Category = MechanicalSetup)
134 FVehicleNWTransmissionData TransmissionSetup;
135
136 /** Maximum steering versus forward speed (km/h) */
137 UPROPERTY(EditAnywhere, Category = SteeringSetup)
138 FRuntimeFloatCurve SteeringCurve;
139
140 virtual void Serialize(FArchive& Ar) override;
141 virtual void ComputeConstants() override;
142#if WITH_EDITOR
143 virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;
144#endif
145
146protected:
147
148 virtual const void* GetTireData(physx::PxVehicleWheels* Wheels, UVehicleWheel* Wheel);
149 virtual const int32 GetWheelShapeMapping(physx::PxVehicleWheels* Wheels, uint32 Wheel);
150 virtual const physx::PxVehicleWheelData GetWheelData(physx::PxVehicleWheels* Wheels, uint32 Wheel);
151
152 /** Allocate and setup the PhysX vehicle */
153 virtual void SetupVehicle() override;
154
155 virtual int32 GetCustomGearBoxNumForwardGears() const;
156
157 virtual void UpdateSimulation(float DeltaTime) override;
158
159 /** update simulation data: engine */
160 virtual void UpdateEngineSetup(const FVehicleNWEngineData& NewEngineSetup);
161
162 /** update simulation data: differential */
163 virtual void UpdateDifferentialSetup(const TArray<FVehicleNWWheelDifferentialData>& NewDifferentialSetup);
164
165 /** update simulation data: transmission */
166 virtual void UpdateTransmissionSetup(const FVehicleNWTransmissionData& NewGearSetup);
167};