14#include "Components/InstancedStaticMeshComponent.h"
15#include "Components/SkeletalMeshComponent.h"
16#include "Components/StaticMeshComponent.h"
17#include "Engine/SkeletalMesh.h"
18#include "Engine/StaticMesh.h"
22 PrimaryActorTick.bCanEverTick =
false;
24 BoundsComponent = CreateDefaultSubobject<UBoundsVisualizerComponent>(TEXT(
"BoundsComponent"));
43 UPrimitiveComponent* TriggerComponent = Cast<UPrimitiveComponent>(
BoundsComponent);
47 const int32 OverlapSensorIndex = 2;
48 const ECollisionChannel OverlapSensorChannel = UCollisionProfile::Get()->ConvertToCollisionChannel(
false, OverlapSensorIndex);
51 BoundsComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
52 BoundsComponent->SetCollisionResponseToChannel(OverlapSensorChannel, ECollisionResponse::ECR_Overlap);
66 BoundsComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
77 ROSMessages::std_msgs::String StringMsg;
78 ROSMessage = MakeShared<ROSMessages::std_msgs::String>(StringMsg);
94 BoundsComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
116 Super::EndPlay(EndPlayReason);
132 FString ActorID = IActorInformation::Execute_GetActorID(
this);
134 FString Msg = FString::Printf(TEXT(
"OverlapSensor with ID: %s changed overlap bounds to: %s"), *ActorID, *NewSize.ToString());
157 FString Msg = FString::Printf(TEXT(
"OverlapSensor.cpp: Changed overlap relative position to: %s"), *Vector.ToString());
163 if (Response != ECollisionResponse::ECR_Overlap && Response != ECollisionResponse::ECR_Ignore)
175void AOverlapSensor::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult)
193 if (!IsValid(OtherComp))
return false;
194 if (OtherActor && OtherActor->IsA<
AOverlapSensor>())
return false;
195 if (OtherComp->IsA<UBoundsVisualizerComponent>())
return false;
198 return OtherComp->IsA<UInstancedStaticMeshComponent>() ||
199 OtherComp->IsA<UStaticMeshComponent>() ||
200 OtherComp->IsA<USkeletalMeshComponent>();
210 if (AActor* VehicleActorPtr = GetParentActor())
212 From = VehicleActorPtr;
222 FVector Location = Actor->GetActorLocation();
226 if (
const UInstancedStaticMeshComponent* ISM = Cast<UInstancedStaticMeshComponent>(Comp))
231 if (ISM->GetInstanceTransform(Index, Xf,
true))
234 Location = Xf.GetLocation();
241 const float DistanceInMeters = FVector::Dist(From->GetActorLocation(), Location) / 100.0f;
243 const FString Phase = Prefix.Replace(TEXT(
" "), TEXT(
"_"));
244 const FString ActorNm = Actor->GetName();
245 const FString CompCls = Comp ? Comp->GetClass()->GetName() : TEXT(
"none");
249 if (
const UInstancedStaticMeshComponent* ISM = Cast<UInstancedStaticMeshComponent>(Comp))
251 if (
const UStaticMesh* SM = ISM->GetStaticMesh()) { MeshName = SM->GetName(); }
253 else if (
const UStaticMeshComponent* SMC = Cast<UStaticMeshComponent>(Comp))
255 if (
const UStaticMesh* SM = SMC->GetStaticMesh()) { MeshName = SM->GetName(); }
257 else if (
const USkeletalMeshComponent* SKC = Cast<USkeletalMeshComponent>(Comp))
259 if (
const USkeletalMesh* Skel = SKC->GetSkeletalMeshAsset()) { MeshName = Skel->GetName(); }
262 auto Quote = [](FString S)
264 S.ReplaceInline(TEXT(
"\""), TEXT(
"\\\""));
return FString::Printf(TEXT(
"%s"), *S);
268 const FString FullMessage = FString::Printf(
269 TEXT(
"phase=%s actor=%s id=%s distance_m=%.2f location=%.2f,%.2f,%.2f component=%s mesh=%s timestamp=%s"),
274 Location.X, Location.Y, Location.Z,
304 FileSavePath = DataLocation + AttachedVehicle->GetActorID_Implementation();
327 UE_LOG(LogTemp, Warning, TEXT(
"FileSavePath %s"), *
FileSavePath);
329 LogFile = NewObject<ULogFile>(ULogFile::StaticClass());
335 Prefix = AttachedVehicle->GetActorID_Implementation();
337 FString FileName = Prefix.IsEmpty() ? TEXT(
"overlap") : Prefix + TEXT(
"_overlap");
347 if (Actor && Actor->GetClass()->ImplementsInterface(UActorInformation::StaticClass()))
351 ID = IActorInformation::Execute_GetActorID(Actor);
void OnOverlapEnd(UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex)
void CreateDataSavePath() override
void SetOverlapRelativePosition(const FVector &Vector)
TSharedPtr< ROSMessages::std_msgs::String > ROSMessage
AOverlapSensor(const FObjectInitializer &ObjectInitializer)
void CreateLogFile() override
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
virtual void BeginPlay() override
UBoundsVisualizerComponent * BoundsComponent
void Init(FOverlapSensorParameters InParameters)
void BuildAndSendMessage(const FString &Prefix, AActor *Actor, UPrimitiveComponent *Comp, int32 Index)
void SetVisualizeOverlapArea(bool Visualize)
void SetOverlapBounds(const FVector &NewSize)
FOverlapSensorParameters Parameters
void SetOverlapResponseToAllChannels(const ECollisionResponse Response)
FString TryGetID(AActor *Actor)
FORCEINLINE bool IsValidOverlap(const AActor *OtherActor, const UPrimitiveComponent *OtherComp) const
void OnOverlapBegin(UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
void SetSimulateSensor(bool SimulateSensor)
UTopic * GetROSTopic() const
AVehicle * IsAttachedToVehicle() const
virtual FString GetActorID_Implementation() const override
FString CreateTimeStampString() const
void WriteToLogFile(const FString &Message)
FORCEINLINE bool IsROSConnected() const
virtual void CreateROSTopic()
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)
static FString GetDataFolder()
void Create(const FString &FileNameWithoutExtension, FLogFileSettings Settings)
FFileWriteOptions FileWriteOptions
FFileCreationOptions FileCreationOptions