New struct FVehicleControl

This commit is contained in:
nsubiron 2018-02-21 19:04:05 +01:00
parent 986a3764de
commit 0f087e396a
5 changed files with 45 additions and 12 deletions

View File

@ -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 <https://opensource.org/licenses/MIT>.
#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;
};

View File

@ -107,9 +107,7 @@ void AWheeledVehicleAIController::Tick(const float DeltaTime)
TickAutopilotController(); TickAutopilotController();
if (bAutopilotEnabled) { if (bAutopilotEnabled) {
Vehicle->SetThrottleInput(AutopilotControl.Throttle); Vehicle->ApplyVehicleControl(AutopilotControl);
Vehicle->SetSteeringInput(AutopilotControl.Steer);
Vehicle->SetBrakeInput(AutopilotControl.Brake);
} }
} }

View File

@ -10,6 +10,7 @@
#include "GameFramework/PlayerController.h" #include "GameFramework/PlayerController.h"
#include "TrafficLightState.h" #include "TrafficLightState.h"
#include "VehicleControl.h"
#include "WheeledVehicleAIController.generated.h" #include "WheeledVehicleAIController.generated.h"
class ACarlaWheeledVehicle; class ACarlaWheeledVehicle;
@ -182,14 +183,7 @@ public:
/// @{ /// @{
protected: protected:
struct FAutopilotControl { const FVehicleControl &GetAutopilotControl() const
float Throttle = 0.0f;
float Steer = 0.0f;
float Brake = 0.0f;
bool bHandBrake = false;
};
const FAutopilotControl &GetAutopilotControl() const
{ {
return AutopilotControl; return AutopilotControl;
} }
@ -237,7 +231,7 @@ private:
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
float MaximumSteerAngle = -1.0f; float MaximumSteerAngle = -1.0f;
FAutopilotControl AutopilotControl; FVehicleControl AutopilotControl;
std::queue<FVector> TargetLocations; std::queue<FVector> TargetLocations;
}; };

View File

@ -7,6 +7,8 @@
#include "Carla.h" #include "Carla.h"
#include "CarlaWheeledVehicle.h" #include "CarlaWheeledVehicle.h"
#include "AI/VehicleControl.h"
#include "Components/BoxComponent.h" #include "Components/BoxComponent.h"
#include "Engine/CollisionProfile.h" #include "Engine/CollisionProfile.h"
@ -64,6 +66,14 @@ float ACarlaWheeledVehicle::GetMaximumSteerAngle() const
// -- Set functions ------------------------------------------------------------ // -- 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) void ACarlaWheeledVehicle::SetThrottleInput(const float Value)
{ {
GetVehicleMovementComponent()->SetThrottleInput(Value); GetVehicleMovementComponent()->SetThrottleInput(Value);

View File

@ -11,6 +11,7 @@
#include "WheeledVehicle.h" #include "WheeledVehicle.h"
#include "CarlaWheeledVehicle.generated.h" #include "CarlaWheeledVehicle.generated.h"
class FVehicleControl;
class UBoxComponent; class UBoxComponent;
/// Base class for CARLA wheeled vehicles. /// Base class for CARLA wheeled vehicles.
@ -63,6 +64,9 @@ public:
/// @{ /// @{
public: public:
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void ApplyVehicleControl(const FVehicleControl &VehicleControl);
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable) UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void SetThrottleInput(float Value); void SetThrottleInput(float Value);