14#include "DrawDebugHelpers.h"
21 PrimaryActorTick.bCanEverTick =
false;
23 BoundsComponent = CreateDefaultSubobject<UBoundsVisualizerComponent>(TEXT(
"BoundsComponent"));
42 UPrimitiveComponent* TriggerComponent = Cast<UPrimitiveComponent>(
BoundsComponent);
45 const int32 OverlapSensorIndex = 2;
46 const ECollisionChannel OverlapSensorChannel = UCollisionProfile::Get()->ConvertToCollisionChannel(
false, OverlapSensorIndex);
50 BoundsComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
51 BoundsComponent->SetCollisionResponseToChannel(OverlapSensorChannel, ECollisionResponse::ECR_Overlap);
56 BoundsComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
67 ROSMessages::std_msgs::String StringMsg;
68 ROSMessage = MakeShared<ROSMessages::std_msgs::String>(StringMsg);
85 BoundsComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
107 Super::EndPlay(EndPlayReason);
124 FString ActorID = IActorInformation::Execute_GetActorID(
this);
126 FString Msg = FString::Printf(TEXT(
"OverlapSensor with ID: %s changed overlap bounds to: %s"), *ActorID, *NewSize.ToString());
149 FString Msg = FString::Printf(TEXT(
"OverlapSensor.cpp: Changed overlap relative position to: %s"), *Vector.ToString());
155 if (Response != ECollisionResponse::ECR_Overlap && Response != ECollisionResponse::ECR_Ignore)
168 int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult)
171 AOverlapSensor* OtherOverlapSensor = Cast<AOverlapSensor>(OtherActor);
172 if (OtherOverlapSensor)
181 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
184 AOverlapSensor* OtherOverlapSensor = Cast< AOverlapSensor>(OtherActor);
185 if (OtherOverlapSensor)
205 if (AActor* VehicleActorPtr = GetParentActor())
207 From = VehicleActorPtr;
209 float DistanceInMeters = FVector::Dist(From->GetActorLocation(), Actor->GetActorLocation()) / 100.0f;
214 Message = FString::Printf(TEXT(
"%s: %s, Distance: %.2f m"), *Prefix, *Actor->GetName(), DistanceInMeters);
218 Message = FString::Printf(TEXT(
"%s: %s: ID: %s, Distance: %.2f m"), *Prefix, *Actor->GetName(), *ID, DistanceInMeters);
232 FString Msg = FString::Printf(TEXT(
"Actor '%s' with ID: '%s' %s"), *
VehicleName, *
VehicleID, *Message);
252 FileSavePath = DataLocation + AttachedVehicle->GetActorID_Implementation();
275 UE_LOG(LogTemp, Warning, TEXT(
"FileSavePath %s"), *
FileSavePath);
277 LogFile = NewObject<ULogFile>(ULogFile::StaticClass());
283 Prefix = AttachedVehicle->GetActorID_Implementation();
285 FString FileName = Prefix.IsEmpty() ? TEXT(
"overlap") : Prefix + TEXT(
"_overlap");
296 if (Actor && Actor->GetClass()->ImplementsInterface(UActorInformation::StaticClass()))
300 ID = IActorInformation::Execute_GetActorID(Actor);
static constexpr float SIZE_DIVISOR
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 SetVisualizeOverlapArea(bool Visualize)
void SetOverlapBounds(const FVector &NewSize)
FOverlapSensorParameters Parameters
void BuildAndSendMessage(const FString &Prefix, AActor *Actor)
void SetOverlapResponseToAllChannels(const ECollisionResponse Response)
FString TryGetID(AActor *Actor)
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
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