14#include "DrawDebugHelpers.h"
19 PrimaryActorTick.bCanEverTick =
false;
21 BoundsComponent = CreateDefaultSubobject<UBoundsVisualizerComponent>(TEXT(
"BoundsComponent"));
40 UPrimitiveComponent* TriggerComponent = Cast<UPrimitiveComponent>(
BoundsComponent);
44 const int32 OverlapSensorIndex = 2;
45 const ECollisionChannel OverlapSensorChannel = UCollisionProfile::Get()->ConvertToCollisionChannel(
false, OverlapSensorIndex);
48 BoundsComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
49 BoundsComponent->SetCollisionResponseToChannel(OverlapSensorChannel, ECollisionResponse::ECR_Overlap);
63 BoundsComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
74 ROSMessages::std_msgs::String StringMsg;
75 ROSMessage = MakeShared<ROSMessages::std_msgs::String>(StringMsg);
91 BoundsComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
113 Super::EndPlay(EndPlayReason);
129 FString ActorID = IActorInformation::Execute_GetActorID(
this);
131 FString Msg = FString::Printf(TEXT(
"OverlapSensor with ID: %s changed overlap bounds to: %s"), *ActorID, *NewSize.ToString());
154 FString Msg = FString::Printf(TEXT(
"OverlapSensor.cpp: Changed overlap relative position to: %s"), *Vector.ToString());
160 if (Response != ECollisionResponse::ECR_Overlap && Response != ECollisionResponse::ECR_Ignore)
173 int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult)
176 AOverlapSensor* OtherOverlapSensor = Cast<AOverlapSensor>(OtherActor);
177 if (OtherOverlapSensor)
186 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
189 AOverlapSensor* OtherOverlapSensor = Cast< AOverlapSensor>(OtherActor);
190 if (OtherOverlapSensor)
210 if (AActor* VehicleActorPtr = GetParentActor())
212 From = VehicleActorPtr;
214 float DistanceInMeters = FVector::Dist(From->GetActorLocation(), Actor->GetActorLocation()) / 100.0f;
217 FVector Location = Actor->GetActorLocation();
220 FString LocationStr = FString::Printf(TEXT(
"Location: (%.2f, %.2f, %.2f)"),
221 Location.X, Location.Y, Location.Z);
226 Message = FString::Printf(TEXT(
"%s: %s, Distance: %.2f m, %s"),
227 *Prefix, *Actor->GetName(), DistanceInMeters, *LocationStr);
231 Message = FString::Printf(TEXT(
"%s: %s: ID: %s, Distance: %.2f m, %s"),
232 *Prefix, *Actor->GetName(), *ID, DistanceInMeters, *LocationStr);
246 FString Msg = FString::Printf(TEXT(
"Actor '%s' with ID: '%s' %s"), *
VehicleName, *
VehicleID, *Message);
266 FileSavePath = DataLocation + AttachedVehicle->GetActorID_Implementation();
289 UE_LOG(LogTemp, Warning, TEXT(
"FileSavePath %s"), *
FileSavePath);
291 LogFile = NewObject<ULogFile>(ULogFile::StaticClass());
297 Prefix = AttachedVehicle->GetActorID_Implementation();
299 FString FileName = Prefix.IsEmpty() ? TEXT(
"overlap") : Prefix + TEXT(
"_overlap");
310 if (Actor && Actor->GetClass()->ImplementsInterface(UActorInformation::StaticClass()))
314 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 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