Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AirSim UE5 support #4672

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Unreal/Environments/Blocks/Blocks.uproject
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"FileVersion": 3,
"EngineAssociation": "4.27",
"EngineAssociation": "5.0",
"Category": "",
"Description": "",
"Modules": [
Expand Down
8 changes: 4 additions & 4 deletions Unreal/Plugins/AirSim/AirSim.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
}
],
"Plugins": [
{
"Name": "PhysXVehicles",
"Enabled": true
}
{
"Name": "ChaosVehiclesPlugin",
"Enabled": true
}
]
}
2 changes: 1 addition & 1 deletion Unreal/Plugins/AirSim/Source/AirSim.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public AirSim(ReadOnlyTargetRules Target) : base(Target)

bEnableExceptions = true;

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "ImageWrapper", "RenderCore", "RHI", "AssetRegistry", "PhysicsCore", "PhysXVehicles", "PhysXVehicleLib", "PhysX", "APEX", "Landscape", "CinematicCamera" });
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "ImageWrapper", "RenderCore", "RHI", "PhysicsCore", "APEX", "AssetRegistry", "ChaosVehicles", "Landscape", "CinematicCamera" });
PrivateDependencyModuleNames.AddRange(new string[] { "UMG", "Slate", "SlateCore" });

//suppress VC++ proprietary warnings
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Plugins/AirSim/Source/PawnSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ msr::airlib::RCData PawnSimApi::getRCData() const

void PawnSimApi::displayCollisionEffect(FVector hit_location, const FHitResult& hit)
{
if (params_.collision_display_template != nullptr && Utils::isDefinitelyLessThan(hit.ImpactNormal.Z, 0.0f)) {
if (params_.collision_display_template != nullptr && Utils::isDefinitelyLessThan<double>(hit.ImpactNormal.Z, 0.0f)) {
UParticleSystemComponent* particles = UGameplayStatics::SpawnEmitterAtLocation(params_.pawn->GetWorld(),
params_.collision_display_template,
FTransform(hit_location),
Expand Down
52 changes: 28 additions & 24 deletions Unreal/Plugins/AirSim/Source/Vehicles/Car/CarPawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "Components/TextRenderComponent.h"
#include "Components/AudioComponent.h"
#include "Sound/SoundCue.h"
#include "WheeledVehicleMovementComponent4W.h"
#include "ChaosWheeledVehicleMovementComponent.h"

#include "CarWheelFront.h"
#include "CarWheelRear.h"
Expand Down Expand Up @@ -85,32 +85,33 @@ ACarPawn::ACarPawn()

void ACarPawn::setupVehicleMovementComponent()
{
UWheeledVehicleMovementComponent4W* movement = CastChecked<UWheeledVehicleMovementComponent4W>(getVehicleMovementComponent());
UChaosWheeledVehicleMovementComponent* movement = CastChecked<UChaosWheeledVehicleMovementComponent>(getVehicleMovementComponent());
movement->WheelSetups.SetNum(4);
check(movement->WheelSetups.Num() == 4);

// Wheels/Tires
// Setup the wheels
movement->WheelSetups[0].WheelClass = UCarWheelFront::StaticClass();
movement->WheelSetups[0].BoneName = FName("PhysWheel_FL");
movement->WheelSetups[0].BoneName = FName("WheelFL");
movement->WheelSetups[0].AdditionalOffset = FVector(0.f, -8.f, 0.f);

movement->WheelSetups[1].WheelClass = UCarWheelFront::StaticClass();
movement->WheelSetups[1].BoneName = FName("PhysWheel_FR");
movement->WheelSetups[1].BoneName = FName("WheelFR");
movement->WheelSetups[1].AdditionalOffset = FVector(0.f, 8.f, 0.f);

movement->WheelSetups[2].WheelClass = UCarWheelRear::StaticClass();
movement->WheelSetups[2].BoneName = FName("PhysWheel_BL");
movement->WheelSetups[2].BoneName = FName("WheelBL");
movement->WheelSetups[2].AdditionalOffset = FVector(0.f, -8.f, 0.f);

movement->WheelSetups[3].WheelClass = UCarWheelRear::StaticClass();
movement->WheelSetups[3].BoneName = FName("PhysWheel_BR");
movement->WheelSetups[3].BoneName = FName("WheelBR");
movement->WheelSetups[3].AdditionalOffset = FVector(0.f, 8.f, 0.f);

// Adjust the tire loading
movement->MinNormalizedTireLoad = 0.0f;
movement->MinNormalizedTireLoadFiltered = 0.2308f;
movement->MaxNormalizedTireLoad = 2.0f;
movement->MaxNormalizedTireLoadFiltered = 2.0f;
//movement->MinNormalizedTireLoad = 0.0f;
//movement->MinNormalizedTireLoadFiltered = 0.2308f;
//movement->MaxNormalizedTireLoad = 2.0f;
//movement->MaxNormalizedTireLoadFiltered = 2.0f;

// Engine
// Torque setup
Expand All @@ -121,22 +122,22 @@ void ACarPawn::setupVehicleMovementComponent()
movement->EngineSetup.TorqueCurve.GetRichCurve()->AddKey(5730.0f, 400.0f);

// Adjust the steering
movement->SteeringCurve.GetRichCurve()->Reset();
movement->SteeringCurve.GetRichCurve()->AddKey(0.0f, 1.0f);
movement->SteeringCurve.GetRichCurve()->AddKey(40.0f, 0.7f);
movement->SteeringCurve.GetRichCurve()->AddKey(120.0f, 0.6f);
movement->SteeringSetup.SteeringCurve.GetRichCurve()->Reset();
movement->SteeringSetup.SteeringCurve.GetRichCurve()->AddKey(0.0f, 1.0f);
movement->SteeringSetup.SteeringCurve.GetRichCurve()->AddKey(40.0f, 0.7f);
movement->SteeringSetup.SteeringCurve.GetRichCurve()->AddKey(120.0f, 0.6f);

// Transmission
// We want 4wd
movement->DifferentialSetup.DifferentialType = EVehicleDifferential4W::LimitedSlip_4W;
movement->DifferentialSetup.DifferentialType = EVehicleDifferential::AllWheelDrive;

// Drive the front wheels a little more than the rear
movement->DifferentialSetup.FrontRearSplit = 0.65;

// Automatic gearbox
movement->TransmissionSetup.bUseGearAutoBox = true;
movement->TransmissionSetup.GearSwitchTime = 0.15f;
movement->TransmissionSetup.GearAutoBoxLatency = 1.0f;
movement->TransmissionSetup.bUseAutomaticGears = true;
movement->TransmissionSetup.GearChangeTime = 0.15f;
//movement->TransmissionSetup.GearAutoBoxLatency = 1.0f;

// Disable reverse as brake, this is needed for SetBreakInput() to take effect
movement->bReverseAsBrake = false;
Expand All @@ -147,10 +148,11 @@ void ACarPawn::setupVehicleMovementComponent()
if (primitive) {
primitive->BodyInstance.COMNudge = FVector(8.0f, 0.0f, 0.0f);
}

movement->UpdatedPrimitive = primitive;
// Set the inertia scale. This controls how the mass of the vehicle is distributed.
movement->InertiaTensorScale = FVector(1.0f, 1.333f, 1.2f);
movement->bDeprecatedSpringOffsetMode = true;
//movement->bDeprecatedSpringOffsetMode = true;
movement->bAutoRegisterUpdatedComponent = true;
}

void ACarPawn::NotifyHit(class UPrimitiveComponent* MyComp, class AActor* Other, class UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation,
Expand All @@ -159,7 +161,7 @@ void ACarPawn::NotifyHit(class UPrimitiveComponent* MyComp, class AActor* Other,
pawn_events_.getCollisionSignal().emit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalImpulse, Hit);
}

UWheeledVehicleMovementComponent* ACarPawn::getVehicleMovementComponent() const
UChaosVehicleMovementComponent* ACarPawn::getVehicleMovementComponent() const
{
return GetVehicleMovement();
}
Expand Down Expand Up @@ -250,8 +252,9 @@ void ACarPawn::Tick(float Delta)
updateInCarHUD();

// Pass the engine RPM to the sound component
float RPMToAudioScale = 2500.0f / GetVehicleMovement()->GetEngineMaxRotationSpeed();
engine_sound_audio_->SetFloatParameter(FName("RPM"), GetVehicleMovement()->GetEngineRotationSpeed() * RPMToAudioScale);
UChaosWheeledVehicleMovementComponent* movement = CastChecked<UChaosWheeledVehicleMovementComponent>(getVehicleMovementComponent());
float RPMToAudioScale = 2500.0f / movement->GetEngineMaxRotationSpeed();
engine_sound_audio_->SetFloatParameter(FName("RPM"), movement->GetEngineRotationSpeed() * RPMToAudioScale);

pawn_events_.getPawnTickSignal().emit(Delta);
}
Expand Down Expand Up @@ -283,9 +286,10 @@ void ACarPawn::updateHUDStrings()
last_gear_ = (Gear == 0) ? LOCTEXT("N", "N") : FText::AsNumber(Gear);
}

UChaosWheeledVehicleMovementComponent* movement = CastChecked<UChaosWheeledVehicleMovementComponent>(getVehicleMovementComponent());
UAirBlueprintLib::LogMessage(TEXT("Speed: "), last_speed_.ToString(), LogDebugLevel::Informational);
UAirBlueprintLib::LogMessage(TEXT("Gear: "), last_gear_.ToString(), LogDebugLevel::Informational);
UAirBlueprintLib::LogMessage(TEXT("RPM: "), FText::AsNumber(GetVehicleMovement()->GetEngineRotationSpeed()).ToString(), LogDebugLevel::Informational);
UAirBlueprintLib::LogMessage(TEXT("RPM: "), FText::AsNumber(movement->GetEngineRotationSpeed()).ToString(), LogDebugLevel::Informational);
}

void ACarPawn::updateInCarHUD()
Expand Down
7 changes: 4 additions & 3 deletions Unreal/Plugins/AirSim/Source/Vehicles/Car/CarPawn.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include "CoreMinimal.h"
#include "WheeledVehicle.h"
#include "ChaosWheeledVehicleMovementComponent.h"
#include "WheeledVehiclePawn.h"
#include "Components/SkeletalMeshComponent.h"
#include "PhysicalMaterials/PhysicalMaterial.h"
#include "UObject/ConstructorHelpers.h"
Expand All @@ -26,7 +27,7 @@ class UInputComponent;
class UAudioComponent;

UCLASS(config = Game)
class ACarPawn : public AWheeledVehicle
class ACarPawn : public AWheeledVehiclePawn
{
GENERATED_BODY()

Expand All @@ -46,7 +47,7 @@ class ACarPawn : public AWheeledVehicle
{
return &pawn_events_;
}
UWheeledVehicleMovementComponent* getVehicleMovementComponent() const;
UChaosVehicleMovementComponent* getVehicleMovementComponent() const;
const msr::airlib::CarApiBase::CarControls& getKeyBoardControls() const
{
return keyboard_controls_;
Expand Down
24 changes: 12 additions & 12 deletions Unreal/Plugins/AirSim/Source/Vehicles/Car/CarPawnApi.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "CarPawnApi.h"
#include "AirBlueprintLib.h"

#include "PhysXVehicleManager.h"
#include "ChaosVehicleManager.h"

CarPawnApi::CarPawnApi(ACarPawn* pawn, const msr::airlib::Kinematics::State* pawn_kinematics,
msr::airlib::CarApiBase* vehicle_api)
: pawn_(pawn), pawn_kinematics_(pawn_kinematics), vehicle_api_(vehicle_api)
{
movement_ = pawn->GetVehicleMovement();
movement_ = CastChecked<UChaosWheeledVehicleMovementComponent>(pawn->GetVehicleMovement());
}

void CarPawnApi::updateMovement(const msr::airlib::CarApiBase::CarControls& controls)
Expand All @@ -23,7 +23,7 @@ void CarPawnApi::updateMovement(const msr::airlib::CarApiBase::CarControls& cont
movement_->SetSteeringInput(controls.steering);
movement_->SetBrakeInput(controls.brake);
movement_->SetHandbrakeInput(controls.handbrake);
movement_->SetUseAutoGears(!controls.is_manual_gear);
movement_->SetUseAutomaticGears(!controls.is_manual_gear);
}

msr::airlib::CarApiBase::CarState CarPawnApi::getCarState() const
Expand Down Expand Up @@ -56,15 +56,15 @@ void CarPawnApi::reset()
movement_->SetActive(true, true);
vehicle_api_->setCarControls(msr::airlib::CarApiBase::CarControls());
updateMovement(msr::airlib::CarApiBase::CarControls());

auto pv = movement_->PVehicle;
if (pv) {
pv->mWheelsDynData.setToRestState();
}
auto pvd = movement_->PVehicleDrive;
if (pvd) {
pvd->mDriveDynData.setToRestState();
}
movement_->ResetVehicleState();
//auto pv = movement_->PVehicle;
//if (pv) {
// pv->mWheelsDynData.setToRestState();
//}
//auto pvd = movement_->PVehicleDrive;
//if (pvd) {
// pvd->mDriveDynData.setToRestState();
//}
},
true);

Expand Down
4 changes: 2 additions & 2 deletions Unreal/Plugins/AirSim/Source/Vehicles/Car/CarPawnApi.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "vehicles/car/api/CarApiBase.hpp"
#include "WheeledVehicleMovementComponent4W.h"
#include "ChaosWheeledVehicleMovementComponent.h"
#include "physics/Kinematics.hpp"
#include "CarPawn.h"

Expand All @@ -23,7 +23,7 @@ class CarPawnApi
virtual ~CarPawnApi();

private:
UWheeledVehicleMovementComponent* movement_;
UChaosWheeledVehicleMovementComponent* movement_;
msr::airlib::CarApiBase::CarControls last_controls_;
ACarPawn* pawn_;
const msr::airlib::Kinematics::State* pawn_kinematics_;
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Plugins/AirSim/Source/Vehicles/Car/CarPawnSimApi.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "CoreMinimal.h"
#include "WheeledVehicleMovementComponent4W.h"
#include "ChaosWheeledVehicleMovementComponent.h"

#include "CarPawn.h"
#include "CarPawnApi.h"
Expand Down
22 changes: 9 additions & 13 deletions Unreal/Plugins/AirSim/Source/Vehicles/Car/CarWheelFront.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

#include "CarWheelFront.h"
#include "TireConfig.h"
#include "UObject/ConstructorHelpers.h"

UCarWheelFront::UCarWheelFront()
{
ShapeRadius = 18.f;
ShapeWidth = 15.0f;
Mass = 20.0f;
DampingRate = 0.25f;
WheelRadius = 38.f;
WheelWidth = 17.0f;
//WheelMass = 20.0f;
bAffectedByHandbrake = false;
SteerAngle = 40.f;
bAffectedBySteering = true;
MaxSteerAngle = 50.f;
AxleType = EAxleType::Front;

// Setup suspension forces
SuspensionForceOffset = 0.0f;
SuspensionForceOffset = FVector(0.0f, 0.0f, 0.0f);
SuspensionMaxRaise = 10.0f;
SuspensionMaxDrop = 10.0f;
SuspensionNaturalFrequency = 9.0f;
SuspensionDampingRatio = 1.05f;

// Find the tire object and set the data for it
static ConstructorHelpers::FObjectFinder<UTireConfig> TireData(TEXT("/AirSim/VehicleAdv/Vehicle/WheelData/Vehicle_FrontTireConfig.Vehicle_FrontTireConfig"));
TireConfig = TireData.Object;
//SuspensionNaturalFrequency = 9.0f;
SuspensionDampingRatio = 1.5f;
}
4 changes: 2 additions & 2 deletions Unreal/Plugins/AirSim/Source/Vehicles/Car/CarWheelFront.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#pragma once

#include "CoreMinimal.h"
#include "VehicleWheel.h"
#include "ChaosVehicleWheel.h"
#include "CarWheelFront.generated.h"

UCLASS()
class UCarWheelFront : public UVehicleWheel
class UCarWheelFront : public UChaosVehicleWheel
{
GENERATED_BODY()

Expand Down
19 changes: 8 additions & 11 deletions Unreal/Plugins/AirSim/Source/Vehicles/Car/CarWheelRear.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

#include "CarWheelRear.h"
#include "TireConfig.h"
//#include "TireConfig.h"
#include "UObject/ConstructorHelpers.h"

UCarWheelRear::UCarWheelRear()
{
ShapeRadius = 18.f;
ShapeWidth = 15.0f;
WheelRadius = 38.f;
WheelWidth = 17.0f;
bAffectedByHandbrake = true;
SteerAngle = 0.f;
MaxSteerAngle = 0.f;
AxleType = EAxleType::Rear;

// Setup suspension forces
SuspensionForceOffset = -0.0f;
SuspensionForceOffset = FVector(0.0f, 0.0f, 0.0f);
SuspensionMaxRaise = 10.0f;
SuspensionMaxDrop = 10.0f;
SuspensionNaturalFrequency = 9.0f;
SuspensionDampingRatio = 1.05f;

// Find the tire object and set the data for it
static ConstructorHelpers::FObjectFinder<UTireConfig> TireData(TEXT("/AirSim/VehicleAdv/Vehicle/WheelData/Vehicle_BackTireConfig.Vehicle_BackTireConfig"));
TireConfig = TireData.Object;
//SuspensionNaturalFrequency = 9.0f;
SuspensionDampingRatio = 1.5f;
}
4 changes: 2 additions & 2 deletions Unreal/Plugins/AirSim/Source/Vehicles/Car/CarWheelRear.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#pragma once

#include "CoreMinimal.h"
#include "VehicleWheel.h"
#include "ChaosVehicleWheel.h"
#include "CarWheelRear.generated.h"

UCLASS()
class UCarWheelRear : public UVehicleWheel
class UCarWheelRear : public UChaosVehicleWheel
{
GENERATED_BODY()

Expand Down