From 0f087e396ad1a9e5937ccb4d5f5728f297957a5d Mon Sep 17 00:00:00 2001 From: nsubiron Date: Wed, 21 Feb 2018 19:04:05 +0100 Subject: [PATCH] New struct FVehicleControl --- .../Carla/Source/Carla/AI/VehicleControl.h | 27 +++++++++++++++++++ .../Carla/AI/WheeledVehicleAIController.cpp | 4 +-- .../Carla/AI/WheeledVehicleAIController.h | 12 +++------ .../Source/Carla/CarlaWheeledVehicle.cpp | 10 +++++++ .../Carla/Source/Carla/CarlaWheeledVehicle.h | 4 +++ 5 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/VehicleControl.h diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/VehicleControl.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/VehicleControl.h new file mode 100644 index 000000000..f1b2b5000 --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/VehicleControl.h @@ -0,0 +1,27 @@ +// 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 . + +#pragma once + +#include "VehicleControl.generated.h" + +USTRUCT(BlueprintType) +struct CARLA_API FVehicleControl +{ + GENERATED_BODY() + + UPROPERTY(Category = "Vehicle Control", EditAnywhere) + float Throttle = 0.0f; + + UPROPERTY(Category = "Vehicle Control", EditAnywhere) + float Steer = 0.0f; + + UPROPERTY(Category = "Vehicle Control", EditAnywhere) + float Brake = 0.0f; + + UPROPERTY(Category = "Vehicle Control", EditAnywhere) + bool bHandBrake = false; +}; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/WheeledVehicleAIController.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/WheeledVehicleAIController.cpp index b2b887941..e14d32a6a 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/WheeledVehicleAIController.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/WheeledVehicleAIController.cpp @@ -107,9 +107,7 @@ void AWheeledVehicleAIController::Tick(const float DeltaTime) TickAutopilotController(); if (bAutopilotEnabled) { - Vehicle->SetThrottleInput(AutopilotControl.Throttle); - Vehicle->SetSteeringInput(AutopilotControl.Steer); - Vehicle->SetBrakeInput(AutopilotControl.Brake); + Vehicle->ApplyVehicleControl(AutopilotControl); } } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/WheeledVehicleAIController.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/WheeledVehicleAIController.h index fa623f08e..a4ddaa81a 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/WheeledVehicleAIController.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/AI/WheeledVehicleAIController.h @@ -10,6 +10,7 @@ #include "GameFramework/PlayerController.h" #include "TrafficLightState.h" +#include "VehicleControl.h" #include "WheeledVehicleAIController.generated.h" class ACarlaWheeledVehicle; @@ -182,14 +183,7 @@ public: /// @{ protected: - struct FAutopilotControl { - float Throttle = 0.0f; - float Steer = 0.0f; - float Brake = 0.0f; - bool bHandBrake = false; - }; - - const FAutopilotControl &GetAutopilotControl() const + const FVehicleControl &GetAutopilotControl() const { return AutopilotControl; } @@ -237,7 +231,7 @@ private: UPROPERTY(VisibleAnywhere) float MaximumSteerAngle = -1.0f; - FAutopilotControl AutopilotControl; + FVehicleControl AutopilotControl; std::queue TargetLocations; }; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/CarlaWheeledVehicle.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/CarlaWheeledVehicle.cpp index c74aa981c..fc5ca8bdc 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/CarlaWheeledVehicle.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/CarlaWheeledVehicle.cpp @@ -7,6 +7,8 @@ #include "Carla.h" #include "CarlaWheeledVehicle.h" +#include "AI/VehicleControl.h" + #include "Components/BoxComponent.h" #include "Engine/CollisionProfile.h" @@ -64,6 +66,14 @@ float ACarlaWheeledVehicle::GetMaximumSteerAngle() const // -- Set functions ------------------------------------------------------------ // ============================================================================= +void ACarlaWheeledVehicle::ApplyVehicleControl(const FVehicleControl &VehicleControl) +{ + SetThrottleInput(VehicleControl.Throttle); + SetSteeringInput(VehicleControl.Steer); + SetBrakeInput(VehicleControl.Brake); + SetHandbrakeInput(VehicleControl.bHandBrake); +} + void ACarlaWheeledVehicle::SetThrottleInput(const float Value) { GetVehicleMovementComponent()->SetThrottleInput(Value); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/CarlaWheeledVehicle.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/CarlaWheeledVehicle.h index b2cdd2d36..f186e31a9 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/CarlaWheeledVehicle.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/CarlaWheeledVehicle.h @@ -11,6 +11,7 @@ #include "WheeledVehicle.h" #include "CarlaWheeledVehicle.generated.h" +class FVehicleControl; class UBoxComponent; /// Base class for CARLA wheeled vehicles. @@ -63,6 +64,9 @@ public: /// @{ public: + UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable) + void ApplyVehicleControl(const FVehicleControl &VehicleControl); + UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable) void SetThrottleInput(float Value);