CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Vehicle
WheeledVehicleMovementComponentNW.cpp
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
#include "
WheeledVehicleMovementComponentNW.h
"
8
9
#include <util/ue-header-guard-begin.h>
10
#include "PhysicsPublic.h"
11
#include "Components/PrimitiveComponent.h"
12
#include "Logging/MessageLog.h"
13
#include <util/ue-header-guard-end.h>
14
15
UWheeledVehicleMovementComponentNW::UWheeledVehicleMovementComponentNW(
const
FObjectInitializer& ObjectInitializer) :
16
Super(ObjectInitializer)
17
{
18
/*
19
FVehicleEngineConfig DefEngineData;
20
DefEngineData.InitDefaults();
21
EngineSetup.MOI = DefEngineData.EngineRevUpMOI;
22
EngineSetup.MaxRPM = DefEngineData.MaxRPM;
23
24
//
25
-- We need to investigate about this --
26
EngineSetup.DampingRateFullThrottle = DefEngineData.mDampingRateFullThrottle;
27
EngineSetup.DampingRateZeroThrottleClutchEngaged = DefEngineData.mDampingRateZeroThrottleClutchEngaged;
28
EngineSetup.DampingRateZeroThrottleClutchDisengaged = DefEngineData.mDampingRateZeroThrottleClutchDisengaged;
29
30
// Convert from Chaos curve to ours
31
FRichCurve* TorqueCurveData = EngineSetup.TorqueCurve.GetRichCurve();
32
for (uint32 KeyIdx = 0; KeyIdx < DefEngineData.TorqueCurve.getNbDataPairs(); ++KeyIdx)
33
{
34
float Input = DefEngineData.TorqueCurve.getX(KeyIdx) * EngineSetup.MaxRPM;
35
float Output = DefEngineData.TorqueCurve.getY(KeyIdx) * DefEngineData.MaxTorque;
36
TorqueCurveData->AddKey(Input, Output);
37
}
38
39
FVehicleTransmissionConfig TransmissionData;
40
TransmissionSetup.GearChangeTime = DefGearSetup.mSwitchTime;
41
TransmissionSetup.ReverseGearRatio = DefGearSetup.mRatios[PxVehicleGearsData::eREVERSE];
42
TransmissionSetup.FinalRatio = DefGearSetup.mFinalRatio;
43
44
PxVehicleAutoBoxData DefAutoBoxSetup;
45
TransmissionSetup.NeutralGearUpRatio = DefAutoBoxSetup.mUpRatios[PxVehicleGearsData::eNEUTRAL];
46
TransmissionSetup.GearAutoBoxLatency = DefAutoBoxSetup.getLatency();
47
TransmissionSetup.bUseAutomaticGears = true;
48
49
for (uint32 i = PxVehicleGearsData::eFIRST; i < DefGearSetup.mNbRatios; ++i)
50
{
51
FVehicleNWGearData GearData;
52
GearData.DownRatio = DefAutoBoxSetup.mDownRatios[i];
53
GearData.UpRatio = DefAutoBoxSetup.mUpRatios[i];
54
GearData.Ratio = DefGearSetup.mRatios[i];
55
TransmissionSetup.ForwardGearRatios.Add(GearData);
56
}
57
58
*/
59
60
// Init steering speed curve
61
//FRichCurve* SteeringCurveData = SteeringCurve.GetRichCurve();
62
//SteeringCurveData->AddKey(0.0f, 1.0f);
63
//SteeringCurveData->AddKey(20.0f, 0.9f);
64
//SteeringCurveData->AddKey(60.0f, 0.8f);
65
//SteeringCurveData->AddKey(120.0f, 0.7f);
66
67
// Initialize WheelSetups array with 4 wheels, this can be modified via editor later
68
const
int32 NbrWheels = 4;
69
WheelSetups.SetNum(NbrWheels);
70
//DifferentialSetup.SetNum(NbrWheels);
71
72
IdleBrakeInput = 10;
73
}
74
75
#if WITH_EDITOR
76
void
UWheeledVehicleMovementComponentNW::PostEditChangeProperty(
struct
FPropertyChangedEvent& PropertyChangedEvent)
77
{
78
Super::PostEditChangeProperty(PropertyChangedEvent);
79
/*
80
const FName PropertyName = PropertyChangedEvent.Property ? PropertyChangedEvent.Property->GetFName() : NAME_None;
81
82
if (PropertyName == TEXT("DownRatio"))
83
{
84
for (int32 GearIdx = 0; GearIdx < TransmissionSetup.ForwardGearRatios.Num(); ++GearIdx)
85
{
86
FVehicleNWGearData& GearData = TransmissionSetup.ForwardGearRatios[GearIdx];
87
GearData.DownRatio = FMath::Min(GearData.DownRatio, GearData.UpRatio);
88
}
89
}
90
else if (PropertyName == TEXT("UpRatio"))
91
{
92
for (int32 GearIdx = 0; GearIdx < TransmissionSetup.ForwardGearRatios.Num(); ++GearIdx)
93
{
94
FVehicleNWGearData& GearData = TransmissionSetup.ForwardGearRatios[GearIdx];
95
GearData.UpRatio = FMath::Max(GearData.DownRatio, GearData.UpRatio);
96
}
97
}
98
else if (PropertyName == TEXT("SteeringCurve"))
99
{
100
//make sure values are capped between 0 and 1
101
TArray<FRichCurveKey> SteerKeys = SteeringCurve.GetRichCurve()->GetCopyOfKeys();
102
for (int32 KeyIdx = 0; KeyIdx < SteerKeys.Num(); ++KeyIdx)
103
{
104
float NewValue = FMath::Clamp(SteerKeys[KeyIdx].Value, 0.0f, 1.0f);
105
SteeringCurve.GetRichCurve()->UpdateOrAddKey(SteerKeys[KeyIdx].Time, NewValue);
106
}
107
}
108
*/
109
}
110
#endif
111
112
float
FVehicleNWEngineData::FindPeakTorque
()
const
113
{
114
// Find max torque
115
float
PeakTorque = 0.0f;
116
TArray<FRichCurveKey> TorqueKeys =
TorqueCurve
.GetRichCurveConst()->GetCopyOfKeys();
117
for
(int32 KeyIdx = 0; KeyIdx < TorqueKeys.Num(); ++KeyIdx)
118
{
119
FRichCurveKey& Key = TorqueKeys[KeyIdx];
120
PeakTorque = FMath::Max(PeakTorque, Key.Value);
121
}
122
123
return
PeakTorque;
124
}
WheeledVehicleMovementComponentNW.h
FVehicleNWEngineData::FindPeakTorque
float FindPeakTorque() const
Find the peak torque produced by the TorqueCurve.
Definition
WheeledVehicleMovementComponentNW.cpp:112
FVehicleNWEngineData::TorqueCurve
FRuntimeFloatCurve TorqueCurve
Torque (Nm) at a given RPM.
Definition
WheeledVehicleMovementComponentNW.h:37
Generated by
1.18.0