CarlaWheeledVehicle: Added debug telemetry

This commit is contained in:
Daniel Santos-Oliván 2021-06-29 10:14:21 +02:00 committed by bernat
parent c8f14d4b42
commit c2a50f070e
4 changed files with 56 additions and 9 deletions

View File

@ -17,6 +17,12 @@ void ACarlaHUD::DrawHUD()
return;
}
if(DebugVehicle) {
float YL = 1600.0f;
float Y0 = 0.0f;
DebugVehicle->DrawDebug(Canvas, YL, Y0);
}
double Now = FPlatformTime::Seconds();
int i = 0;
while (i < StringList.Num())

View File

@ -23,7 +23,7 @@
#include "Containers/Array.h"
#include "GameFramework/HUD.h"
#include "WheeledVehicleMovementComponent.h"
#include "CarlaHUD.generated.h"
struct HUDString
@ -50,6 +50,9 @@ public:
virtual void DrawHUD() override;
UWheeledVehicleMovementComponent* DebugVehicle{nullptr};
void AddDebugVehicleForTelemetry(UWheeledVehicleMovementComponent* Veh) { DebugVehicle = Veh; }
void AddHUDString(const FString Str, const FVector Location, const FColor Color, double LifeTime);
private:

View File

@ -5,23 +5,24 @@
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "Carla/Vehicle/CarlaWheeledVehicle.h"
#include "Carla/Game/CarlaStatics.h"
#include "Components/BoxComponent.h"
#include "Engine/CollisionProfile.h"
#include "MovementComponents/DefaultMovementComponent.h"
#include "Rendering/SkeletalMeshRenderData.h"
#include "PhysXPublic.h"
#include "PhysXVehicleManager.h"
#include "TireConfig.h"
#include "VehicleWheel.h"
#include "Carla.h"
#include "Carla/Game/CarlaHUD.h"
#include "Carla/Game/CarlaStatics.h"
#include "Carla/Trigger/FrictionTrigger.h"
#include "Carla/Util/ActorAttacher.h"
#include "Carla/Util/EmptyActor.h"
#include "MovementComponents/DefaultMovementComponent.h"
#include "Carla/Trigger/FrictionTrigger.h"
#include "Carla/Util/BoundingBoxCalculator.h"
#include "Rendering/SkeletalMeshRenderData.h"
#include "Carla/Vehicle/CarlaWheeledVehicle.h"
// =============================================================================
// -- Constructor and destructor -----------------------------------------------
@ -472,6 +473,31 @@ void ACarlaWheeledVehicle::DeactivateVelocityControl()
VelocityControl->Deactivate();
}
void ACarlaWheeledVehicle::EnableDebugTelemetry()
{
if (GetWorld()->GetFirstPlayerController())
{
ACarlaHUD* hud = Cast<ACarlaHUD>(GetWorld()->GetFirstPlayerController()->GetHUD());
if (hud)
hud->AddDebugVehicleForTelemetry(GetVehicleMovementComponent());
else
UE_LOG(LogCarla, Warning, TEXT("ACarlaWheeledVehicle::EnableDebugTelemetry:: Cannot find HUD for debug info"));
}
}
void ACarlaWheeledVehicle::DisableDebugTelemetry()
{
if (GetWorld()->GetFirstPlayerController())
{
ACarlaHUD* hud = Cast<ACarlaHUD>(GetWorld()->GetFirstPlayerController()->GetHUD());
if (hud)
hud->AddDebugVehicleForTelemetry(nullptr);
else
UE_LOG(LogCarla, Warning, TEXT("ACarlaWheeledVehicle::DisableDebugTelemetry:: Cannot find HUD for debug info"));
}
}
void ACarlaWheeledVehicle::SetVehicleLightState(const FVehicleLightState &LightState)
{
InputControl.LightState = LightState;
@ -562,3 +588,8 @@ FVector ACarlaWheeledVehicle::GetVelocity() const
{
return BaseMovementComponent->GetVelocity();
}
void ACarlaWheeledVehicle::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
DisableDebugTelemetry();
}

View File

@ -176,6 +176,12 @@ public:
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void DeactivateVelocityControl();
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void EnableDebugTelemetry();
UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable)
void DisableDebugTelemetry();
/// @todo This function should be private to AWheeledVehicleAIController.
void FlushVehicleControl();
@ -240,6 +246,7 @@ public:
protected:
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason);
UFUNCTION(BlueprintImplementableEvent)
void RefreshLightState(const FVehicleLightState &VehicleLightState);