diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Carla.Build.cs b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Carla.Build.cs index 2301151d4..4422f1eb6 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Carla.Build.cs +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Carla.Build.cs @@ -6,6 +6,7 @@ using UnrealBuildTool; public class Carla : ModuleRules { + bool UsingCarSim = false; private bool IsWindows(ReadOnlyTargetRules Target) { return (Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32); @@ -20,6 +21,21 @@ public class Carla : ModuleRules bEnableExceptions = true; } + // Read config about carsim + string CarlaPluginPath = Path.GetFullPath( ModuleDirectory ); + string ConfigDir = Path.GetFullPath(Path.Combine(CarlaPluginPath, "../../../../Config/")); + string CarSimConfigFile = Path.Combine(ConfigDir, "CarSimConfig.ini"); + string[] text = System.IO.File.ReadAllLines(CarSimConfigFile); + foreach (string line in text) + { + Console.WriteLine(line); + if (line == "CarSim ON") + { + UsingCarSim = true; + PublicDefinitions.Add("WITH_CARSIM"); + } + } + PublicIncludePaths.AddRange( new string[] { // ... add public include paths required here ... @@ -42,13 +58,10 @@ public class Carla : ModuleRules // ... add other public dependencies that you statically link with here ... } ); - PublicDependencyModuleNames.AddRange( - new string[] - { - "CarSim" - // ... add other public dependencies that you statically link with here ... - } - ); + if (UsingCarSim) + { + PublicDependencyModuleNames.AddRange(new string[] { "CarSim" }); + } if (Target.Type == TargetType.Editor) { @@ -75,14 +88,12 @@ public class Carla : ModuleRules // ... add private dependencies that you statically link with here ... } ); - PrivateDependencyModuleNames.AddRange( - new string[] - { - "CarSim" - // ... add private dependencies that you statically link with here ... - } - ); - PrivateIncludePathModuleNames.AddRange(new string[] { "CarSim" }); + if (UsingCarSim) + { + PrivateDependencyModuleNames.AddRange(new string[] { "CarSim" }); + PrivateIncludePathModuleNames.AddRange(new string[] { "CarSim" }); + } + DynamicallyLoadedModuleNames.AddRange( new string[] diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index 8e8d7643e..c361d9890 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -942,7 +942,9 @@ void FCarlaServer::FPimpl::BindActions() if(Vehicle) { Vehicle->SetActorEnableCollision(true); + #ifdef WITH_CARSIM if(!Vehicle->IsCarSimEnabled()) + #endif { RootComponent->SetSimulatePhysics(bEnabled); RootComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); @@ -1098,6 +1100,7 @@ void FCarlaServer::FPimpl::BindActions() bool bEnabled, std::string SimfilePath) -> R { + #ifdef WITH_CARSIM REQUIRE_CARLA_EPISODE(); auto ActorView = Episode->FindActor(ActorId); if (!ActorView.IsValid()) @@ -1111,12 +1114,16 @@ void FCarlaServer::FPimpl::BindActions() } Vehicle->SetCarSimEnabled(bEnabled, carla::rpc::ToFString(SimfilePath)); return R::Success(); + #else + RESPOND_ERROR("CarSim plugin is not enabled"); + #endif }; BIND_SYNC(use_carsim_road) << [this]( cr::ActorId ActorId, bool bEnabled) -> R { + #ifdef WITH_CARSIM REQUIRE_CARLA_EPISODE(); auto ActorView = Episode->FindActor(ActorId); if (!ActorView.IsValid()) @@ -1130,6 +1137,9 @@ void FCarlaServer::FPimpl::BindActions() } Vehicle->UseCarSimRoad(bEnabled); return R::Success(); + #else + RESPOND_ERROR("CarSim plugin is not enabled"); + #endif }; //-----CARSIM-------------------------------- // ~~ Traffic lights ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp index 81842f672..602bf0373 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp @@ -33,8 +33,11 @@ ACarlaWheeledVehicle::ACarlaWheeledVehicle(const FObjectInitializer& ObjectIniti VelocityControl = CreateDefaultSubobject(TEXT("VelocityControl")); VelocityControl->Deactivate(); - CarSimMovementComponent = CreateDefaultSubobject(TEXT("CarSimMovement")); + #ifdef WITH_CARSIM + ExternalMovementComponent = CreateDefaultSubobject(TEXT("CarSimMovement")); + CarSimMovementComponent = Cast(ExternalMovementComponent); CarSimMovementComponent->DisableVehicle = true; + #endif GetVehicleMovementComponent()->bReverseAsBrake = false; } @@ -114,7 +117,9 @@ void ACarlaWheeledVehicle::BeginPlay() Vehicle4W->WheelSetups = NewWheelSetups; + #ifdef WITH_CARSIM SetCarSimEnabled(false); + #endif } void ACarlaWheeledVehicle::AdjustVehicleBounds() @@ -144,14 +149,13 @@ void ACarlaWheeledVehicle::AdjustVehicleBounds() float ACarlaWheeledVehicle::GetVehicleForwardSpeed() const { + #ifdef WITH_CARSIM if (bCarSimEnabled) { return CarSimMovementComponent->GetForwardSpeed(); } - else - { - return GetVehicleMovementComponent()->GetForwardSpeed(); - } + #endif + return GetVehicleMovementComponent()->GetForwardSpeed(); } FVector ACarlaWheeledVehicle::GetVehicleOrientation() const @@ -161,14 +165,13 @@ FVector ACarlaWheeledVehicle::GetVehicleOrientation() const int32 ACarlaWheeledVehicle::GetVehicleCurrentGear() const { + #ifdef WITH_CARSIM if (bCarSimEnabled) { return CarSimMovementComponent->GetCurrentGear(); } - else - { - return GetVehicleMovementComponent()->GetCurrentGear(); - } + #endif + return GetVehicleMovementComponent()->GetCurrentGear(); } FTransform ACarlaWheeledVehicle::GetVehicleBoundingBoxTransform() const @@ -196,6 +199,7 @@ float ACarlaWheeledVehicle::GetMaximumSteerAngle() const void ACarlaWheeledVehicle::FlushVehicleControl() { + #ifdef WITH_CARSIM if (bCarSimEnabled) { //-----CARSIM-------------------------------- @@ -224,6 +228,7 @@ void ACarlaWheeledVehicle::FlushVehicleControl() //----------------------------------------- } else + #endif { auto *MovementComponent = GetVehicleMovementComponent(); MovementComponent->SetThrottleInput(InputControl.Control.Throttle); @@ -539,12 +544,15 @@ void ACarlaWheeledVehicle::SwitchToUE4Physics() void ACarlaWheeledVehicle::RevertToCarSimPhysics() { + #ifdef WITH_CARSIM SetCarSimEnabled(true, CarSimMovementComponent->VsConfigFile); carla::log_warning("Collision: giving control to carsim"); + #endif } void ACarlaWheeledVehicle::SetCarSimEnabled(bool bEnabled, FString SimfilePath) { + #ifdef WITH_CARSIM if (bEnabled == bCarSimEnabled) { return; @@ -605,16 +613,20 @@ void ACarlaWheeledVehicle::SetCarSimEnabled(bool bEnabled, FString SimfilePath) GetMesh()->SetCollisionProfileName("Vehicle"); } bCarSimEnabled = bEnabled; + #endif } void ACarlaWheeledVehicle::UseCarSimRoad(bool bEnabled) { + #ifdef WITH_CARSIM carla::log_warning("Enabling CarSim Road", bEnabled); CarSimMovementComponent->UseVehicleSimRoad = bEnabled; CarSimMovementComponent->ResetVsVehicle(false); CarSimMovementComponent->SyncVsVehicleLocOri(); + #endif } +#ifdef WITH_CARSIM FVector ACarlaWheeledVehicle::GetVelocity() const { if (bCarSimEnabled) @@ -626,6 +638,7 @@ FVector ACarlaWheeledVehicle::GetVelocity() const return Super::GetVelocity(); } } +#endif bool ACarlaWheeledVehicle::IsCarSimEnabled() const { diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h index 59c332a86..193c6389e 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h @@ -19,7 +19,9 @@ #include "CoreMinimal.h" //-----CARSIM-------------------------------- +#ifdef WITH_CARSIM #include "CarSimMovementComponent.h" +#endif //------------------------------------------- #include "CarlaWheeledVehicle.generated.h" @@ -241,7 +243,7 @@ private: FVehicleControl LastAppliedControl; - //-----CARSIM-------------------------------- +//-----CARSIM-------------------------------- public: UFUNCTION(Category="CARLA Wheeled Vehicle", BlueprintCallable) @@ -250,7 +252,9 @@ public: UFUNCTION(Category="CARLA Wheeled Vehicle", BlueprintCallable) void UseCarSimRoad(bool bEnabled); + #ifdef WITH_CARSIM virtual FVector GetVelocity() const override; + #endif UFUNCTION(Category="CARLA Wheeled Vehicle", BlueprintPure) bool IsCarSimEnabled() const; @@ -281,6 +285,11 @@ private: bool bCarSimEnabled = false; UPROPERTY(Category="CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true")) + UMovementComponent * ExternalMovementComponent; + + #ifdef WITH_CARSIM + // Casted version of ExternalMovementComponent UCarSimMovementComponent * CarSimMovementComponent; + #endif //------------------------------------------- }; diff --git a/Util/BuildTools/BuildCarlaUE4.sh b/Util/BuildTools/BuildCarlaUE4.sh index 371262e14..e0c5e962b 100755 --- a/Util/BuildTools/BuildCarlaUE4.sh +++ b/Util/BuildTools/BuildCarlaUE4.sh @@ -24,11 +24,12 @@ REMOVE_INTERMEDIATE=false HARD_CLEAN=false BUILD_CARLAUE4=false LAUNCH_UE4_EDITOR=false +USE_CARSIM=false GDB= RHI="-vulkan" -OPTS=`getopt -o h --long help,build,rebuild,launch,clean,hard-clean,gdb,opengl -n 'parse-options' -- "$@"` +OPTS=`getopt -o h --long help,build,rebuild,launch,clean,hard-clean,gdb,opengl,carsim -n 'parse-options' -- "$@"` eval set -- "$OPTS" @@ -57,6 +58,9 @@ while [[ $# -gt 0 ]]; do --opengl ) RHI="-opengl"; shift ;; + --carsim ) + USE_CARSIM=true; + shift ;; -h | --help ) echo "$DOC_STRING" echo "$USAGE_STRING" @@ -123,6 +127,12 @@ if ${BUILD_CARLAUE4} ; then fi + if ${USE_CARSIM} ; then + echo "CarSim ON" > ${PWD}/Config/CarSimConfig.ini + else + echo "CarSim OFF" > ${PWD}/Config/CarSimConfig.ini + fi + log "Build CarlaUE4 project." make CarlaUE4Editor diff --git a/Util/BuildTools/BuildPythonAPI.sh b/Util/BuildTools/BuildPythonAPI.sh index 8757d0d60..a93feaf31 100755 --- a/Util/BuildTools/BuildPythonAPI.sh +++ b/Util/BuildTools/BuildPythonAPI.sh @@ -17,7 +17,7 @@ REMOVE_INTERMEDIATE=false BUILD_RSS_VARIANT=false BUILD_PYTHONAPI=true -OPTS=`getopt -o h --long help,config:,rebuild,clean,rss,python-version:,packages:,clean-intermediate,all,xml, -n 'parse-options' -- "$@"` +OPTS=`getopt -o h --long help,config:,rebuild,clean,rss,carsim,python-version:,packages:,clean-intermediate,all,xml, -n 'parse-options' -- "$@"` eval set -- "$OPTS" diff --git a/Util/BuildTools/Package.sh b/Util/BuildTools/Package.sh index f5a9a0757..894e938ec 100755 --- a/Util/BuildTools/Package.sh +++ b/Util/BuildTools/Package.sh @@ -15,8 +15,9 @@ DO_TARBALL=true DO_CLEAN_INTERMEDIATE=false PROPS_MAP_NAME=PropsMap PACKAGE_CONFIG=Shipping +USE_CARSIM=false -OPTS=`getopt -o h --long help,config:,no-zip,clean-intermediate,packages:,python-version: -n 'parse-options' -- "$@"` +OPTS=`getopt -o h --long help,config:,no-zip,clean-intermediate,carsim,packages:,python-version: -n 'parse-options' -- "$@"` eval set -- "$OPTS" @@ -34,6 +35,9 @@ while [[ $# -gt 0 ]]; do --packages ) PACKAGES="$2" shift 2 ;; + --carsim ) + USE_CARSIM=true; + shift ;; -h | --help ) echo "$DOC_STRING" echo "$USAGE_STRING" @@ -87,6 +91,12 @@ if ${DO_CARLA_RELEASE} ; then pushd "${CARLAUE4_ROOT_FOLDER}" >/dev/null + if [ ${USE_CARSIM} ]; then + echo "CarSim ON" > ${PWD}/Config/CarSimConfig.ini + else + echo "CarSim OFF" > ${PWD}/Config/CarSimConfig.ini + fi + log "Cooking CARLA project." rm -Rf ${RELEASE_BUILD_FOLDER}